Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 243
morpheus Avatar asked Nov 30 '15 02:11

morpheus


1 Answers

You are correct. This is a bug. You can find the reported bug here and a polyfill is available here.

like image 165
Daniel Rasmuson Avatar answered Oct 17 '22 15:10

Daniel Rasmuson