diff --git a/CHANGELOG.md b/CHANGELOG.md index af487028..95fabe75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ * v2.22.5 - Fixes an issue with Core Web Vital tracking not being able to be disabled. +- Fixes an issue where `navigator.sendBeacon` errors were not being handled gracefully. * v2.22.4 - Upgrade the web-vitals vendor library to v2.1.0. diff --git a/src/raygun.rum/index.js b/src/raygun.rum/index.js index 37d427b7..a6633576 100644 --- a/src/raygun.rum/index.js +++ b/src/raygun.rum/index.js @@ -916,15 +916,22 @@ var raygunRumFactory = function(window, $, Raygun) { var stringifiedPayload = JSON.stringify(payload); - /** + /** * Use the navigator.sendBeacon method instead of a XHR requests when transmitting data - * This occurs mostly when the document is about to be discarded or hidden as + * This occurs mostly when the document is about to be discarded or hidden as * all inflight XHR requests either will be or can be canceled. - */ + */ if (self.sendUsingNavigatorBeacon && navigator.sendBeacon) { - navigator.sendBeacon(url, stringifiedPayload); + try { + navigator.sendBeacon(url, stringifiedPayload); + } catch (e) { + log(e, { + url: url, + payload: stringifiedPayload + }); + } return; - } + } makePostCorsRequest(url, stringifiedPayload, successCallback, errorCallback); }