Skip to content

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

@lddubeau

Description

@lddubeau

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions