Settings when used as a module not honored
See original GitHub issueThe docs state:
In situations where Bugsnag is not in its own script tag, you can set this with:
Bugsnag.autoNotify = false;
However bugsnag does all the patching which is contingent on this being true (the default) before the value can actually be set — it seems it is only actually possible to control this behavior if you inject bugsnag via a script element. Since the main reason to disable autoNotify is to prevent overzealous patching of performance sensitive functions like requestAnimationFrame
, it becomes necessary to do things like:
const raf = window.requestAnimationFrame;
const bugsnag = require('bugsnag');
window.requestAnimationFrame = raf;
Rather awkward! Plus, if you aren’t concerned with stuff like IE6 support, all of the various mutations of the global space seem pointless. Why is this patching enabled by default, why isn’t it disclosed in the documentation, and why do the docs state that autoNotify can be meaningfully set this way?
This is what I came up with BTW for anybody else trying to use bugsnag without the global decoration. In my case I actually do want bugsnag to register an onerror handler, but I don’t want it to do all the wrapping. This module needs to be imported prior to bugsnag and its exported function needs to be invoked afterwards:
const restorations = [
[ 'ApplicationCache', 'prototype', 'addEventListener' ],
[ 'AudioTrackList', 'prototype', 'addEventListener' ],
[ 'ChannelMergerNode', 'prototype', 'addEventListener' ],
[ 'CryptoOperation', 'prototype', 'addEventListener' ],
[ 'EventSource', 'prototype', 'addEventListener' ],
[ 'EventTarget', 'prototype', 'addEventListener' ],
[ 'FileReader', 'prototype', 'addEventListener' ],
[ 'HTMLUnknownElement', 'prototype', 'addEventListener' ],
[ 'IDBDatabase', 'prototype', 'addEventListener' ],
[ 'IDBRequest', 'prototype', 'addEventListener' ],
[ 'IDBTransaction', 'prototype', 'addEventListener' ],
[ 'KeyOperation', 'prototype', 'addEventListener' ],
[ 'MediaController', 'prototype', 'addEventListener' ],
[ 'MessagePort', 'prototype', 'addEventListener' ],
[ 'ModalWindow', 'prototype', 'addEventListener' ],
[ 'Node', 'prototype', 'addEventListener' ],
[ 'Notification', 'prototype', 'addEventListener' ],
[ 'requestAnimationFrame' ],
[ 'Screen', 'prototype', 'addEventListener' ],
[ 'setImmediate' ],
[ 'setInterval' ],
[ 'setTimeout' ],
[ 'SVGElementInstance', 'prototype', 'addEventListener' ],
[ 'TextTrack', 'prototype', 'addEventListener' ],
[ 'TextTrackCue', 'prototype', 'addEventListener' ],
[ 'TextTrackList', 'prototype', 'addEventListener' ],
[ 'WebSocket', 'prototype', 'addEventListener' ],
[ 'WebSocketWorker', 'prototype', 'addEventListener' ],
[ 'Window', 'prototype', 'addEventListener' ],
[ 'Worker', 'prototype', 'addEventListener' ],
[ 'XMLHttpRequest', 'prototype', 'addEventListener' ],
[ 'XMLHttpRequestEventTarget', 'prototype', 'addEventListener' ],
[ 'XMLHttpRequestUpload', 'prototype', 'addEventListener' ],
].map(path => {
const values = [ window ];
for (const key of path) {
if (values[0].hasOwnProperty(key)) {
values.unshift(values[0][key]);
} else {
return;
}
}
const [ value, target ] = values;
const key = path.pop();
return () => target[key] = value;
}).filter(Boolean);
export default () => restorations.forEach(restore => restore());
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Thanks for the report, @bathos. It sounds like a rethinking of a lot of this logic (and workarounds) is needed, especially to put users in better control of which browsers they care about. I’m updating the roadmap to ensure this is addressed soon.
The update sounds fantastic! I happen to be working on a project that isn’t in prod yet so it’s a perfect time for me to do some test driving.