Unable to create Web Worker from inside webworker in Chrome - javascript

Using Chrome 17.0.963.46 m, I tried to create a new web worker from inside a web worker. But got a "Uncaught ReferenceError: Worker is not defined"
Any info. on this? (Google throw surprisingly few links on creating web worker inside webworkers)

That is the current state even on Chrome 19 - here is the bug:
http://code.google.com/p/chromium/issues/detail?id=31666
It's working on FF.

Creating workers within workers is not available in chrome. FF implemented this with the Example.
See the link for Example and Chroem bug.
https://developer.mozilla.org/en-US/docs/DOM/Worker/Functions_available_to_workers
https://developer.mozilla.org/en-US/docs/DOM/Using_web_workers?redirectlocale=en-US&redirectslug=Using_web_workers
Example specified by Mozilla Developer network.
https://developer.mozilla.org/samples/workers/fibonacci/
Chroem BUg
http://code.google.com/p/chromium/issues/detail?id=31666

Related

Uncaught TypeError: navigator.getBattery is not a function

I'm developping a website which is meant to be used on mobile devices using Google Chrome, the purpose is to list information such as time (hh:mm) and battery level.
I saw the Battery Web API but I'm experiencing a strange error:
click to see the chrome error
Here is the code I used in order to get the battery level:
navigator.getBattery().then(function (battery) {
console.log(Math.round(battery.level * 100))
});
I had the error yesterday, without changing any line of code, it is working today on my tablet (chrome version: 103), but I tested on another tablet (Samsung Galaxy TAB A7 LITE, Chrome version: 103) and I encounter the error, I restarted several times the devices, inspected pages using the devtools connected by cable to my laptop, but I can't solve this error.
I saw a topic having the same error but he was developing a web worker it is not the same context as I.
No matter when I'm calling the navigator.getBattery() if the error appeared in the beginning it will stay undefined later, so it is not a problem of timing to call it (I even bound it to the body.onload but it didn't work).
I thought it could be authorization issues on system information but there's nothing refering to the battery which is not authorized in the application settings of Chrome.
Any help is welcome :D
I found out where my error was coming from.
It is a problem of HTTPS, my testing environment is configured behind a NGINX HTTP Server, which serves HTTP and HTTPS version of my application in order to use a single certificate for every of my projects, Chrome on my laptop prefix URLs I'm accessing with https:// and it is hidden in the navbar, but it is not the case on Chrome tablet or mobile, I thought I was consulting the HTTPS version but it was HTTP, and Battery Web API isn't accessible on HTTP websites, it is required to have a secure connection using HTTPS and certificates. It has nothing to do with version number since Battery Web API is fully supported since Chrome version 38 according to MDN Documentation.

Cannot debug web worker in chrome

I am using Angular 8, and I am using web workers.
I created web worker according to angular standard documentation https://angular.io/guide/web-worker.
I have problem to debug my code into the web worker. In Firefox debugging works perfectly but in chrome I cannot set break point to any line of the my code. Chrome version is: 83.0.4103.
When ever I want to put breakpoints to the code I wrote in the web worker it automatically jump to the line:
module.exports = __webpack_public_path__ + "1.worker.js"
After it I see that breakpoints is here, but code never stop at that line, sometimes even console log does not work.
Image below show how breakpoints are there but debugger never stops.
Is there any trick here which I do not get it ?
I had the same problem when debugging and had to downgrade to version 81, and I still can't find a solution for higher versions

Is it possible to access Web Workers from a chrome extension?

I have an app which contains several iFrames and Web Workers which communicate via postMessages. I am interested in creating a chrome extension which lists and display all of the messages in a comfortable and easy to inspect way.
Is there a way to access the workers from the window that created them, without a reference to the created instance? (i.e - can I get a list of workers on a given site from the chrome dev-tools console?) Would it be possible to retrieve this information from a chrome extension?
Update
Since the Chrome Devtools Sources Panel does classify web-workers, I was hoping that this can be done with a devtools extension. I also searched through the frontend code of the devtools to understand how a worker is identified there and found this, but am still unable to find how I can get a reference to the workers using the chrome extension api.

Web Worker profiling in Internet Explorer 11

According to this page https://msdn.microsoft.com/en-us/library/dn255005(v=vs.85).aspx it is possible to profile Web Worker code in Internet Explorer 11 (11.576.14393 in my case) Developer Tools (F12). But when I finish profiling, I can see only report from code running on main thread and threre is no Worker ID colum in the results as described on the mentioned page. Also, when I try to programatically start profiling from the Web Worker using Console.profile() method https://msdn.microsoft.com/en-us/library/jj152133(v=vs.85).aspx, I get error:
Object doesn't support property or method 'profile'
Do you have any clue what may be wrong? Do you please know how to profile Web Worker code in Internet Explorer?
PS: Same applies to Edge 38.14393.0.0. Rewriting the Web Worker code to run and profile it on main thread is not an option because it would take several months. The same code runs reasonably fast on Chrome and Firefox.
I tried to profile a simple web worker from the following demo
Web Worker Demo
It seems a bit weird but I was able to profile the worker only in the following scenario
I had started profiling the page and then started the worker and then stopped the worker and then stopped profiling.Exported the Data with Worker Id.
I had used IE11 in windows 7 environment.
Hope this helps :)

Uncaught ReferenceError: Worker is not defined while trying to create a Worker within another Worker in Chrome

This link says:
Workers may spawn more workers if they wish. So-called sub-workers
must be hosted within the same origin as the parent page. Also, the
URIs for subworkers are resolved relative to the parent worker's
location rather than that of the owning page. This makes it easier for
workers to keep track of where their dependencies are.
But when I try to create a Worker in another Worker:
var worker = new Worker('foo.js');
I get an exception in Chrome.
Uncaught ReferenceError: Worker is not defined
IE works though (surprisingly). Is this documented somewhere? Is there a proper cross browser way to spawn a Worker from another Worker? Doing web search I don't see many (or rather any) code samples of spawning subworkers.
EDIT: Adding some more links:
https://html.spec.whatwg.org/multipage/workers.html#delegation
https://whatwg.org/demos/workers/multicore/page.html (does not work in Chrome)
You are correct. This is a bug. You can find the reported bug here and a polyfill is available here.

Categories

Resources