bugsnag-js
bugsnag-js copied to clipboard
Use `sendBeacon` to ensure the report is sent even if the page gets navigated away or reloaded
Currently, if the navigation occurs right after the notify call, the HTTP request gets cancelled.
This new Navigator.sendBeacon() browser API is here to solve this:
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
Unfortunately, it's not cross-browser, so a fallback (polyfill) is needed for IE, Safari and old Android Browser. http://caniuse.com/#feat=beacon
Another solution would be to store the report queue in localStorage and process when possible, e.g. after page reload.
This relates to offline support: https://github.com/bugsnag/bugsnag-js/issues/117
Another solution would be to store the report queue in localStorage and process when possible, e.g. after page reload. This relates to offline support: #117
I'm going to see if I can get the PR (#151) to be compacted a bit more, as the main roadblock is due to the minified filesize.
I think it would still be a neat idea to support navigator.sendBeacon though. It would be minor to add.
Unfortunately, it's not cross-browser, so a fallback (polyfill) is needed for IE, Safari and old Android Browser. http://caniuse.com/#feat=beacon
I almost want to say this could be handled by the apps, rather than the notifier itself - to save on space as well. Or another solution would be to support fallbacks through the configuration itself.
For example...
Bugsnag.notifyHandler = 'beacon,xhr';
It's supported in all major browsers now.
