Skip to content
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

addEventListener("unhandledexception", ...) is ignored in workers. #1190

Closed
lddubeau opened this issue Aug 8, 2016 · 0 comments
Closed

addEventListener("unhandledexception", ...) is ignored in workers. #1190

lddubeau opened this issue Aug 8, 2016 · 0 comments

Comments

@lddubeau
Copy link
Contributor

lddubeau commented Aug 8, 2016

Versions

Bluebird: 3.4.1. I don't know if it happens with earlier versions but I suspect it does.

Browsers: Chrome 51, Firefox 46. AFAIK, this would be reproducible on all platforms that support workers.

Reproducing the case

Run this plunker, and observe the console output.

The important code is in the file test.js. This file is run both in the context of the main window and in a worker:

var inWorker = typeof window === "undefined";
var context = inWorker ? self : window;

if (inWorker) {
  self.importScripts("https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.4.1/bluebird.js");
  console.log("worker running");
}

context.addEventListener("unhandledrejection", function() {
  console.log("Unahndled rejection detected by custom handler!", inWorker);
});
Promise.reject(new Error("X"));

Expected behavior

The console should show these lines:

Unahndled rejection detected by custom handler! false
worker running
Unahndled rejection detected by custom handler! true

The first one unhandled rejection is from the main window. The 2nd is from the worker. Bluebird does produce warnings but those are not the issue here.

Actual behavior

Unahndled rejection detected by custom handler! false
worker running

The unhandled rejection in the worker is never detected by the handler.

Observations

On Chrome, removing Bluebird from the worker produces the expected behavior.

Also, assigning to self.onunhandledrejection works fine.

I believe the issue is with fireDomEvent. document is not available in a worker, so the fallback is used.

fireDomEvent should be modified to create events using new Event, which is available in workers.

lextiz added a commit to lextiz/bluebird that referenced this issue Aug 8, 2016
petkaantonov pushed a commit that referenced this issue Aug 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants