Closed
Description
We are seeing an exception coming from shell.js because the worker accesses document.currentScript.
From src/shell.js#231
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WEB) {
if (document.currentScript) {
scriptDirectory = document.currentScript.src;
}
} else { // worker
scriptDirectory = self.location.href;
}
I've tested and at least in our environment, the worker has ENVIRONMENT_IS_WEB and ENVIRONMENT_IS_WORKER true. If this is always the case, the else clause is a no-op. I'm not completely familiar with this code but would suggest this becomes:
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = self.location.href;
} else if (document.currentScript) { // web
scriptDirectory = document.currentScript.src;
}
The other approach would be:
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WEB) {
if (typeof document !== 'undefined' && document.currentScript) {
scriptDirectory = document.currentScript.src;
}
} else { // worker
scriptDirectory = self.location.href;
}
The code was introduced in #6894, maybe @kripken can provide some insight on the right approach. Let me know if you'd like me to open a PR.
Metadata
Metadata
Assignees
Labels
No labels