developit / developit/workerize-loader

Error when initializing Child Workers

Open
#99 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.3k
Forks
85
PR merge metrics
No merged PRs in 30d

Description

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. (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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.