web-worker

What can service workers do that web workers cannot?

时光怂恿深爱的人放手 提交于 2019-12-28 07:48:12
问题 What can service workers do that web workers cannot? Or vice versa? It seems that web workers are a subset of the functionality of service workers. Is this correct? 回答1: There is a big difference in what they are intended for: Web Workers Web Workers provide a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface. In addition, they can perform I/O using XMLHttpRequest (although the responseXML and

Accessing localStorage from a webWorker

流过昼夜 提交于 2019-12-27 17:08:00
问题 Can a WebWorker access the localStorage? If not why not? Is it problematic from a security stand point? 回答1: No, localStorage and sessionStorage are both undefined in a webworker process. You would have to call postMessage() back to the Worker's originating code, and have that code store the data in localStorage. Interestingly, a webworker can use an AJAX call to send/retrieve info to/from a server, so that may open possibilities, depending on what you're trying to do. 回答2: Web workers only

Cannot read property of NULL

泄露秘密 提交于 2019-12-25 11:52:35
问题 I have the following html file in which I try to highlight some code using a web worker: <link rel="stylesheet" href="./highlight/styles/default.css"> <script src="./highlight/highlight.pack.js"></script> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> if (typeof(Worker) !== "undefined") { addEventListener('load', function() { var code = document.querySelector('#code'); var worker = new Worker('worker.js'); worker.onmessage = function(event) { code.innerHTML =

Cannot read property of NULL

余生长醉 提交于 2019-12-25 11:52:13
问题 I have the following html file in which I try to highlight some code using a web worker: <link rel="stylesheet" href="./highlight/styles/default.css"> <script src="./highlight/highlight.pack.js"></script> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script> if (typeof(Worker) !== "undefined") { addEventListener('load', function() { var code = document.querySelector('#code'); var worker = new Worker('worker.js'); worker.onmessage = function(event) { code.innerHTML =

How to handle massive computation on websites? Web workers or CGI?

懵懂的女人 提交于 2019-12-25 08:47:42
问题 I've written a JavaScript-based Website that is able to enter, edit and solve Nonograms. As you may know, solving a nonogram is an NP-complete problem. My first attempt was pure (single threaded) JavaScript. But on larger nonograms, Chrome showed its BSOD and killed the JS script after a few minutes. Next attempt was to use Web Workers. I split the solving algorithm so that each worker gets one row/column to solve and returns the result. This was an improvement and it was able to solve medium

Is it possible to read local variables of parent stackframes?

拟墨画扇 提交于 2019-12-25 05:06:38
问题 Scenario : I am working on Javascript code that allows running arbitrary user-supplied code in a web worker environment, similar to this approach. Let's call the two parties host (launches the worker) and guest (inside the worker). Now, I want to be able to run multiple scripts on the worker at the same time, or at least have them sent to the worker right away, without having to wait for the previous script to finish. It is crucial to reduce delay and overhead because a single "session" could

ReferenceError: Worker is not defined in simple Firefox Extension

 ̄綄美尐妖づ 提交于 2019-12-25 04:51:58
问题 I'm creating an incredibly simple Firefox extension. I used cfx init to create the directory structure and have code in lib/main.js and data/my_worker.js main.js is as follows: var worker = new Worker("my_worker.js"); worker.onmessage = function(e) { console.log(e.data); }; worker.postMessage("Bobby"); and my_worker.js is as follows: self.onmessage = function(e) { self.postMessage("Hello " + e.data); }; Then I run: cfx run to run the extension. The results are as follows: (addon-sdk-1.17)me

ChemDoodle Ajax Incompatibility with Pollen.js

天大地大妈咪最大 提交于 2019-12-25 03:54:14
问题 I'm trying to use iChemLabs cloud services from a html5 web worker. Normally the cloudservices requires jQuery but I can't import that into a web worker so I'm using Pollen instead with a ChemDoodle Web Components library with which I have stripped out the document-related things. jQuery.Hive.Pollen provides a nice ajax function very similar to jQuery, but I can't seem to get it to work at all. I know this problem will be tricky to solve considering that Access-control-headers need to be set

Using promise to work with web worker inside a JavaScript closure

泄露秘密 提交于 2019-12-25 00:01:46
问题 I was executing an image processing operation in JavaScript which was working as expected expect one thing that sometimes it was freezing the UI, which made me to use Web worker to excute the image processing functions. I have a scenario where i need to process multiple. Below is a summary of workflow which i am using to achieve the above feat. //closure var filter = (function(){ function process(args){ var promise = new Promise(function (resolve, reject) { if (typeof (Worker) !== "undefined"

web worker constructor does not fail even with invalid file path

妖精的绣舞 提交于 2019-12-24 11:39:08
问题 I have this code in a web file bundled with webpack 3: let _worker = new Worker("x.js") _worker.addEventListener('message', (event) => { resolve(event.data as any) }); The worker creation always succeeds, no matter what path I pass to the constructor. How is this possible? 回答1: How is this possible? Because it's asynchronous . You wouldn't want your main JavaScript thread to sit around, blocked, waiting for the browser to fetch the script file from the server. So it's done asynchronously. If