developit / developit/workerize-loader

Error when initializing Child Workers

Ouverte
#99 2 commentaires 2 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
2.3k
Forks
85
Métriques de merge des PR
Aucune PR mergée en 30 j

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start in rpc-wrapper.js at the ready-event code around line 20 and trace how child workers are initialized from a parent worker. Check why document is accessed in that path and how the ready event is expected to behave. Done means child workers initialize without the document error while preserving the ready event and its IE compatibility.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, webpack
Domaine
tooling, web-dev
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.