-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebWorker Safari iOS - ReferenceError: Can't find variable: document #2
Comments
workers have no dom, right? so I am not sure you're supposed to use CustomEvent within a worker, |
I don't see how postMessage would remove the need for CustomEvent if the app-architecture inside the worker makes use of it. |
any reason not to use that does feature detection and it should patch Safari too. |
The reason to choose CustomEvent instead was the standardized details property, but I guess it would be possible to extend Event to create our own derived class... We'll consider doing so. You may close this issue if you have no intend to pursue this further! Thanks a lot for all your good work and help! |
@caritasverein the thing is, even IE11 fails at will try to fix this soon(ish) |
@caritasverein although ...
how am I supposed to patch that in there? |
@caritasverein let's do this the other way around .... would this work? /*! (c) Andrea Giammarchi - ISC */
var self = this || /* istanbul ignore next */ {};
try { new CustomEvent('!'); }
catch (shenanigans) {
self.CustomEvent = typeof document === typeof void 0 ?
// the Safari case
(function (CustomEvent) {
FakeCustomEvent.prototype = CustomEvent.prototype;
return FakeCustomEvent;
function FakeCustomEvent() {
return Reflect.construct(CustomEvent, arguments, this.constructor);
}
}(CustomEvent)) :
// the IE11 case
(function () {
FakeCustomEvent.prototype = CustomEvent.prototype;
return FakeCustomEvent;
function FakeCustomEvent(type, init) {
if (!init) init = {};
var e = document.createEvent('CustomEvent');
e.initCustomEvent(type, !!init.bubbles, !!init.cancelable, init.detail);
return e;
}
}());
} |
When runnning the polyfill inside a Webworker, Safari on iOS 12 complains about document not being available. I'm not entirely sure how this would be doable instead, as neither the
createEvent
norCustomEvent
function seems to be available in that context...The text was updated successfully, but these errors were encountered: