web-worker

Transferable custom classes with ES6 web workers

与世无争的帅哥 提交于 2019-12-23 08:45:49
问题 In Javascript ES6, in the browser, I want to transfer custom class objects to a web worker using the "Transferable" interface. Is this possible? I can find documentation about this for ArrayBuffer objects, but not for custom class objects. This is not a duplicate of How to pass custom class instances through Web-Workers? since my question is specifically about the Transferable interface. I want to pass my custom class instance to the worker without copying it. 回答1: I already addressed this

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

旧巷老猫 提交于 2019-12-22 20:18:30
问题 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

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

北城以北 提交于 2019-12-22 20:14:49
问题 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

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

爷,独闯天下 提交于 2019-12-22 20:14:04
问题 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

How can I customize a permission request popup for push notifications in a browser?

放肆的年华 提交于 2019-12-22 08:23:06
问题 I see that some websites have a fancy push notification permission request popups like this one whereas official API documentation doesn't provide any clue how to customize permission requests; and the only request I can generate looks like that How can I create a less ugly popup? 回答1: Click the Allow button on the House of Bots site and you'll see exactly how they do it--they don't. The pop-up you see is just plain html, nothing special. When you click allow, it opens a new window that asks

Is there an easy way to run Firebase in a web worker?

喜夏-厌秋 提交于 2019-12-22 08:13:22
问题 I have a single page React application which consists of many files, bundled with gulp/browserify. Firebase javascript is embedded in this bundle. I'd like to know if there is an easy way to run certain Firebase operations on another worker thread ? What I have tried : Setting up a worker and sending the Firebase object, or instance, via worker.postMessage(xxx) . In both cases, it throws an error which says the object cannot be cloned . Example bellow with the Firebase object. var blobURL =

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

回眸只為那壹抹淺笑 提交于 2019-12-22 07:58:35
问题 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

DOM manipulation inside web worker

心已入冬 提交于 2019-12-22 05:23:40
问题 I know that workers can't manipulate the document directly, but how about the DOM API methods? Where did they go?! For example if I make a request that receives a HTML fragment, what I'm supposed to do if need just to parse it in order to retrieve some data from a specific node?! There's absolutely no way to work with virtual DOM on web workers?! 回答1: Support in browsers DOMParser or document.implementation are usually used to parse HTML to DOM in browsers. Neither is available in worker

Chrome not loading latest version of web worker script (runs a cached version)

半世苍凉 提交于 2019-12-22 03:51:11
问题 If I edit my web worker script and refresh the page, the web worker script is a cached version. I am reasonably confident it is not my webserver, because I can immediately load the latest copies of all other files, and even restarting the webserver does not fix the problem. It only loads the newest version of the web worker script if I reboot chrome, which is highly inefficient, needless to say! It doesn't fix it even if I restart chrome. Is there anything I can do to get around this? 回答1:

Javascript code for making my browser slow down

a 夏天 提交于 2019-12-21 07:07:13
问题 I'm writing a library for WebWorkers, and I want to test the difference between running a script in the main page thread, versus in one or more workers. The problem is: I can't find out of hand a short function which will strain my browser enough that I can observe the difference. A quick search didn't return much, but it might just be that I don't really know what to search for; usually I try to optimise my code, not make it slower... I'm looking for algorithms or patterns that can be easily