web-worker

Running JS in a killable 'thread'; detecting and canceling long-running processes

时光怂恿深爱的人放手 提交于 2019-12-06 12:04:26
Summary : How can I execute a JavaScript function, but then "execute" (kill) it if it does not finish with a timeframe (e.g. 2 seconds)? Details I'm writing a web application for interactively writing and testing PEG grammars . Unfortunately, the JavaScript library I'm using for parsing using a PEG has a 'bug' where certain poorly-written or unfinished grammars cause infinite execution (not even detected by some browsers). You can be happily typing along, working on your grammar, when suddenly the browser locks up and you lose all your hard work. Right now my code is (very simplified):

Shared worker do share variables

倖福魔咒の 提交于 2019-12-06 11:14:19
I've been reading some documents about shared worker context. Lots of them point out shared worker do not share variables, which means they can not use each other variables. However, my experiment againsts that. Parent worker var port = new SharedWorker('worker.js').port; port.start(); port.postMessage('Hello'); Worker var ports = []; onconnect = function(e){ var port = e.ports[0]; port.start(); ports.push(port); console.log('Number of tabs: '+ports.length); }; ports.length keeps increasing when I open more tabs, which means ports is shared between workers. Could anybody please explain this? I

Javascript web workers: why do I need to postMessage twice to trigger event?

半腔热情 提交于 2019-12-06 08:50:05
I am a newcomer to Javascript and web programming in general. I am trying to figure out web workers, and have the following code (running in chrome): worker_example.html <!DOCTYPE html> <html> <head> <script type="text/javascript" src="worker_example.js"></script> </head> <html> worker_example.js var worker = new Worker("worker.js"); worker.addEventListener('message', function(e) { document.write("hello"); }, false); worker.postMessage(""); worker.js // self.postMessage(""); My question is why doesn't worker.postMessage("") trigger the event? If I uncomment the single line in worker.js,

Web worker file is cached and never re-loaded in IE 11

删除回忆录丶 提交于 2019-12-06 08:37:07
问题 I am running a simple HTML5 app that works in Chrome and Firefox. It uses a web worker, as in: var worker = new Worker("the/worker/URL/Code.js"); I have experimented for over an hour in IE, and I finally found that the web worker's code is never reloaded. When I get the version that it has, to throw an error, the debugger shows me a completely outdated version of the worker code file, even though, all other files have been reloaded properly. I flushed the cache, using the standard advice

failed to load script - Webworker (PDF.JS)

ぐ巨炮叔叔 提交于 2019-12-06 02:49:26
问题 I'm trying to load the pdf.js webworker, but I can't!? The URL //cdn.localhost/js/pdf/worker_loader.js?v=280 exists when opening it in the browser error Failed to load script: //cdn.localhost/js/pdf/worker_loader.js?v=280 (nsresult = 0x805303f4) html (URL = //secure.localhost) <!DOCTYPE html> <html> <head></head> <body> <script type="text/javascript" src="//cdn.localhost/js/pdf/core.js?v=280"></script> <script type="text/javascript" src="//cdn.localhost/js/pdf/util.js?v=280"></script> <script

Obtain data synchronously from WebWorker?

假装没事ソ 提交于 2019-12-06 02:05:20
问题 While I understand that JavaScript is inherently single-threaded and generally frowns upon such things, I am wondering if there is any way to get a WebWorker to wait until some data is made available from the main thread without destroying the call stack of the WebWorker. As this is for a fun project, I can use new technologies and things that won't reliably run on older browsers, and I don't mind esoteric hacks as long as they work. Some other solutions that I have thought about:

How to get web workers to function cross domain, multiple browsers? IE SCRIPT5022: SecurityError

谁说胖子不能爱 提交于 2019-12-05 22:17:52
I have created web workers that are being called from both a separate file and inline workers (blobs). Neither of which will work consistently in most browsers. I am using CORs following the the tutorials below. http://www.html5rocks.com/en/tutorials/workers/basics/ http://www.html5rocks.com/en/tutorials/cors/ The issues is that when I use inline workers (blobs) they work in Chrome and Firefox but not in IE, Safari, or Opera. This code will be used for tracking purpose, so will need to work across many domains. On the backend I have: Response.AppendHeader("Access-Control-Allow-Origin", "*");

WebWorkers in GWT Elemental

我与影子孤独终老i 提交于 2019-12-05 17:28:53
问题 Workers JSNI at GWT svn It looks like WebWorkers have not been fully implemented yet. I know that elemental is in early stage of development but might be someone already have tried to make it works? 回答1: The problem with web workers is that they don't really fit the standard GWT/Java model - in my opinion they barely fit the standard JS model. Web workers work by passing data back and forth between what are essentially different JavaScript VMs. That data must be in the form of a string, and

Phonegap and WebWorkers

冷暖自知 提交于 2019-12-05 15:34:22
问题 I am trying to write a PhoneGap/Cordova app. I am trying to do some of the more long running background stuff in Web Workers. However I am finding that some of the functionality is not available from within the Web Workers. navigator.connection is available from within the main script but is undefined from within the web worker, same goes for navigator.geolocation . I would also like to access an sql-lite database from within a web worker too. Any ideas of how to do background operations like

Locale string comparison does not work properly in Firefox extension web worker

旧街凉风 提交于 2019-12-05 13:43:52
The localeCompare() function does not behave the same in a Firefox extension main code and in a web worker (or chrome worker). For instance, in the main code, I have this code: var array = ["École", "Frère", "frère", "école"]; array.sort(function(a, b) { return a.localeCompare(b); }); console.log('Main: ' + array); it shows: Main: �cole,�cole,Fr�re,fr�re Which is the right sorting (the encoding is not my problem). In the worker, I have this code: var array = ["École", "Frère", "frère", "école"]; array.sort(function(a, b) { return a.localeCompare(b); }); self.postMessage(array); it prints: