web-worker

Service Worker vs Shared Worker

こ雲淡風輕ζ 提交于 2019-12-02 20:13:38
What is the difference between Service Worker and Shared Worker? When should I use Service Worker instead of Shared Worker and vice versa? A service worker has additional functionality beyond what's available in shared workers, and once registered, they persist outside the lifespan of a given web page. Service workers can respond to message events, like shared workers, but they also have access to additional events. Handling fetch events allows service workers to intercept any network traffic (originating from a controlled page) and take specific actions, including serving responses from a

Create a Web Worker from a Chrome Extension content script

北慕城南 提交于 2019-12-02 18:30:55
I'm trying to create a Web Worker from my extension's content script, but it's getting blocked by a SecurityError (same origin policy). What's the best way to do this? From my content script: var workerURL = chrome.extension.getURL("js/searchWorker.js"); var lunrWorker = new Worker(workerURL); From the manifest: "content_scripts": [ { "matches": ["http://localhost:8000/*"], "js": ["js/jquery.min.js", "js/jquery.highlight.js", "js/index.js"], "css": ["css/bootstrap.css", "css/styles.css"] } ] I also tried setting this in my manifest, but it didn't help: "content_security_policy": "default-src

Parallel.js have problems with Blob in IE

你。 提交于 2019-12-02 18:28:12
问题 I need to execute functions in "parallel" and I use parallel.js : var p = new Parallel(items); var fn1 = function (item) { doSomething(item); }; p.map(fn1).then(function () { otherFunction(); }); But IE shows the following error: [Q] Unhandled rejection reasons (should be empty): (no stack) SecurityError HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed. How to fix this

Can Web Workers utilize 100% of a multi-core CPU?

人盡茶涼 提交于 2019-12-02 18:10:40
I've been trying to find out just how capable web workers are of distributing processor load. I've yet to find any demos that seem to be able to get my quad core 2600k to even 50%, let alone 100%. Here's a web worker demo I've tried to max my CPU on: http://nerget.com/rayjs-mt/rayjs.html (If you go into the page's HTML with firebug /chrome-inspect-element and make the canvas larger, you can make it raytrace a much larger image - I set mine to 1920 x 1080) Even with 4, 8, 16 workers selected, I can't get my CPU utilization above around 25% per core. Does anyone know if you can utilize 100% of

Javascript Web Workers File Upload

不想你离开。 提交于 2019-12-02 17:47:22
I am trying to make a html uploader for very large files using HTML5 and Web Workers. Atm it uploads slowly but consumes alot of memory. I think it is transferring the whole file to the memory when it adds it to the form. Heres the code: jswebworker.js: /*importScripts('webworkerFormData.js');*/ (function() { // Export variable to the global scope (this == undefined ? self : this)['FormData'] = FormData; var ___send$rw = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype['send'] = function(data) { if (data instanceof FormData) { if (!data.__endedMultipart) data.__append('--' + data

How can I access chrome.history from a Web Worker?

故事扮演 提交于 2019-12-02 10:59:29
问题 Is there any way I can access the chrome.* apis (specifically chrome.history ) from a Web Worker? If I pass the chrome.history or chrome object in with postMessage , it is not working because of a conversion error to Transferable type. I can successfully query the history from my extension and pass the results, but I would like to leave the heavy lifting to the worker instead of the main thread and then pass the results. 回答1: Web Workers are meant to be light-weight, and do not inherit any

Web workers and Canvas data

懵懂的女人 提交于 2019-12-02 08:39:33
I have seen a lot of threads about web workers and <canvas> data passing, and I'm not sure if my scenario is implementable. I want to create a small site for users to learn to code in Javascript. When users click a button, the code is run in a web worker. To help them, I have also created methods for "printing" (which basically just adds text to a <pre> element. // get code from user and prepend helper "functions" var userCode = editor.getValue(); var codeWithMessages = "\n\ function print(data) { postMessage(\"\"+data); } \n\ function println(data) { postMessage(\"\"+data+\'\\n\'); } \n\

Parallel.js have problems with Blob in IE

痴心易碎 提交于 2019-12-02 07:47:48
I need to execute functions in "parallel" and I use parallel.js : var p = new Parallel(items); var fn1 = function (item) { doSomething(item); }; p.map(fn1).then(function () { otherFunction(); }); But IE shows the following error: [Q] Unhandled rejection reasons (should be empty): (no stack) SecurityError HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed. How to fix this error? I had review parallel.js page in IE and all examples work fine. I use Durandal, Breeze and Knockout

How can I access chrome.history from a Web Worker?

痴心易碎 提交于 2019-12-02 07:18:49
Is there any way I can access the chrome.* apis (specifically chrome.history ) from a Web Worker? If I pass the chrome.history or chrome object in with postMessage , it is not working because of a conversion error to Transferable type. I can successfully query the history from my extension and pass the results, but I would like to leave the heavy lifting to the worker instead of the main thread and then pass the results. Web Workers are meant to be light-weight, and do not inherit any permissions ( not even host permissions ) from the extension (besides, chrome is not even defined in a Web

Why is synchronous sleep function not made async by being inside promise?

梦想的初衷 提交于 2019-12-02 01:06:44
问题 I'm trying to wrap my head around promises, and how JavaScript works with it's queue and event loop etc. I thought that if I put a slow synchronous function inside a promise, that slow sync function would be delegated to the background and I could use .then to deal with it when it was done. function syncSleep(ms){ var end = new Date().getTime() + ms; var start = new Date().getTime(); while (start < end) { start = new Date().getTime(); } } function p() { return new Promise(function(resolve) {