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

Created on 11 Jan 2017  路  3Comments  路  Source: bugsnag/bugsnag-js

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

feature request

Most helpful comment

It's supported in all major browsers now.

image

All 3 comments

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.

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lifeiscontent picture lifeiscontent  路  6Comments

vikrantnegi picture vikrantnegi  路  5Comments

kilianc picture kilianc  路  5Comments

waynebloss picture waynebloss  路  3Comments

bathos picture bathos  路  6Comments