bugsnag-js icon indicating copy to clipboard operation
bugsnag-js copied to clipboard

Use `sendBeacon` to ensure the report is sent even if the page gets navigated away or reloaded

Open sompylasar opened this issue 8 years ago • 3 comments

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

sompylasar avatar Jan 11 '17 20:01 sompylasar

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

sompylasar avatar Jan 11 '17 20:01 sompylasar

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';

jmshal avatar Jan 11 '17 21:01 jmshal

It's supported in all major browsers now.

image

sandstrom avatar Jun 27 '19 12:06 sandstrom