web-worker

How to profile web workers in Chrome?

耗尽温柔 提交于 2019-12-14 00:51:52
问题 Does anyone know an easy way to profile web workers in Chrome? I found this question from last year, but unfortunately the only provided answer didn't work. Is there any way to do this or am I just out of look? It seems like a rather large oversight that hinders web development if you can't even do profiling. 回答1: To profile Web Workers navigate to "Developer Tools -> Sources -> Workers" and enable the checkbox "Pause on start". Now, when you refresh the page, a popup window with an inspector

Posting Three.js meshes to web worker using javascript

不羁岁月 提交于 2019-12-13 23:50:19
问题 I have an array on objects, meshes created with Three.js, that I want to do some operations in a web worker. So the questions is how do I post them to the worker? From what I understand there's something called transferable objects that uses something called ArrayBuffer but I can't find any info about how to convert my array of objects to that. Or is this perhaps not possible? 回答1: Unless your object is already in binary buffer format, there is not performance benefit in converting it into

Web Worker: How to prevent that file gets loaded from cache?

旧时模样 提交于 2019-12-13 15:31:26
问题 This is incredibly annoying.. I am wondering why the heck my changes aren't reflected as I notice that my JavaScript file for my Web Worker always gets loaded from cache: I have disabled the Cache and hitting Ctrl + F5 does not work either. How can I make sure that this file does not get loaded from cache? _worker = new Worker('js/toy-cpu.js'); 回答1: You could add a kind of version number, for example like this: _worker = new Worker('js/toy-cpu.js?v=' + new Date().getTime()); 回答2: If you are

InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable javascript error

半城伤御伤魂 提交于 2019-12-13 05:34:00
问题 I'm trying to follow this answer https://stackoverflow.com/a/28213834/632224 to get some files hashed in browser, but when i replace "importScripts('http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js');"+ with something like "importScripts('path to local copy of md5.js');"+ i'm getting error InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable in blob line 1. Here is content of that blob: importScripts('path to local copy of md5.js')

How can I get back an array of objects from Worker?

帅比萌擦擦* 提交于 2019-12-13 04:34:35
问题 I have a simple Pixel pseudoclass that has .H() , .S() and .L() methods. I use these in image analysis - like this watermark detection: To get the objects out of ImageData, I just loop through the ImageData and create multi-dimensional array: //Get image data var id = ctx.getImageData(0, 0, canvas1.width, canvas1.height); //The Uint8 array var pixels = id.data; //Dimensions var length = pixels.length; var width = id.width; var height = id.height; //Create empty array for 2D data var pixels2D

What happens when new listener is attached when an event is pending?

荒凉一梦 提交于 2019-12-13 03:45:37
问题 Say I have a web worker _worker, and I attach a listener to it like so: _worker.addEventListener('message', (event) => { window["test"] = event.data||"foo" }); Let's say I later conditionally attach another listener inside a promise like so: if (window["test"] === undefined) { _worker.addEventListener('message', (event) => { window["test"] = event.data || "foo"; resolve(window["test"]) }); } else { resolve (window["test"]); } Basically the first listener's job is to set window["test"] to the

Download Blob from webworker in IE11

白昼怎懂夜的黑 提交于 2019-12-13 02:34:45
问题 I m trying to download a large blob from a web worker. With Firefox and Chrome it's quite simple: url = URL.createObjectURL(oMyBlob); //Then i return the url to the main thread and go to it But according to this thread IE doesn't allow that, and we must use this: navigator.msSaveBlob(blob, defaultName); But navigator seems to not have access to msSaveBlob within a webworker... What's the best way then to download a Blob (~100MB) within an IE11 worker? 来源: https://stackoverflow.com/questions

tensorflow.js in webworkers

时间秒杀一切 提交于 2019-12-12 19:11:45
问题 I want to import 2 scripts in webWorker by importScripts() as follows,but it failed to import. How to deal with it? self.importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs'); self.importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter'); error figure 回答1: Currently, it is not possible to use the webgl implementation on web-worker, the offlineCanvas being an experimental features. However, it is possible to use the CPU backend. Here is an example of delegation to the

An effective way to implement semaphore locking in a web worker?

为君一笑 提交于 2019-12-12 17:43:12
问题 I have a huge piece of code (compiled with Emscripten) running inside a web worker. The page kicks off a task in the worker with one postMessage, and when the worker is finished, it sends another postMessage back. Great. However, I have a new feature I'd like to add that requires me to pause the worker mid-execution, kick a message back to the browser via postMessage, wait for the user to submit a valid response via postMessage, and then finish execution. However, I can't figure out anything

How to wait for multiple WebWorkers in a loop

ぃ、小莉子 提交于 2019-12-12 05:48:31
问题 I have the following issue with Web Workers in JS. I have a heavy duty application doing some simulation. The code runs in multiple Web Workers. The main thread is running on a WebPage. But could also be a Web Worker, if it makes sense. Example: var myWebWorkers = []; function openWorker(workerCount){ for(var i = 0; i < workerCount; i++){ myWebWorkers[i] = new Worker('worker.js'); myWebWorkers[i].onmessage = function(e){ this.result = e.data; this.isReady = true; } } } function setWorkerData