workerize-loader icon indicating copy to clipboard operation
workerize-loader copied to clipboard

Error when initializing Child Workers

Open kevinfmoody opened this issue 5 years ago • 2 comments

I tried initializing child web workers from a parent worker, and it seems to work well with the exception of the following error being thrown:

rpc-wrapper.js:20 Uncaught ReferenceError: document is not defined
    at Worker.<anonymous> (rpc-wrapper.js:20)

Digging in, it seems like its part of building up the ready event, although document is not in scope in the context of a WebWorker.

let evt = document.createEvent('Event');
evt.initEvent(d.method, false, false);
evt.data = d.params;
worker.dispatchEvent(evt);

What is the purpose of the ready event? Is there a way to build the event in a WebWorker-safe manner? I've looked into new Event, but that's not IE compatible.

kevinfmoody avatar Jun 18 '20 00:06 kevinfmoody

I've got the same problem.

bigbug avatar Dec 23 '20 11:12 bigbug

~You can disable the ready event using the ready:false option.~

This is used for the ready event, but can't be disabled. I've opened #113 with a fix.

developit avatar Jan 09 '21 01:01 developit