bugsnag-js
bugsnag-js copied to clipboard
Decouple Bugsnag from DOM for running in WebWorker environment
Description
The CDN version doesn't work in WebWorker environment https://docs.bugsnag.com/platforms/javascript/cdn-guide/. It requires below polyfill as a workaround for now.
/**
* CDN polyfill
*/
(() => {
const document = {
documentElement: {
outerHTML: '',
createElement: () => ({}),
clientWidth: 0,
clientHeight: 0,
},
addEventListener: () => {},
};
const history = {};
const window = self;
self.window = window;
window.document = document;
window.history = history;
})();
Describe the solution you'd like Either decouple Bugsnag from DOM or at least check for null value.
For context, we are building an extensibility system for Shopify that runs third-party code in a web worker. The code they run in the web worker look just like "regular" web code, and some can be quite complicated, so we'd like to make it so they are able to use common error reporting tools like Bugsnag. We have documented that, for Bugsnag, developers have to include the above "polyfill" as the first thing in their application, but it would be great if they didn't need it :)
Hi @henrytao-me , @lemonmade.
Adding support for WebWorkers is something that is on our roadmap. I don't have an exact timeframe for when this might be available but I will let you know of updates.
Our web worker and service worker package is now fully released. See our docs for more details and I'll close this issue. Any problems please open another issue or contact BugSnag support. Thanks for your patience!