Add try/catch around use of navigator.sendBeacon (#5943)

There is a range of historical browser versions where navigator.sendBeacon is available but will throw an error if it's called with an unacceptable mime-typed Blob as the data: https://bugs.chromium.org/p/chromium/issues/detail?id=490015

GitOrigin-RevId: 7b534cb482ba0de920d2e53b9f0afbf3240b20aa
This commit is contained in:
Miguel Serrano 2021-11-29 12:59:18 +01:00 committed by Copybot
parent 26d5241eaa
commit 33ea150b98

View file

@ -49,5 +49,10 @@ function sendBeacon(key, data) {
const blob = new Blob([JSON.stringify(data)], { const blob = new Blob([JSON.stringify(data)], {
type: 'application/json; charset=UTF-8', type: 'application/json; charset=UTF-8',
}) })
navigator.sendBeacon(`/event/${key}`, blob) try {
navigator.sendBeacon(`/event/${key}`, blob)
} catch (error) {
// Ignored. There's a range of browser for which `navigator.sendBeacon` is available but
// will throw an error if it's called with an unacceptable mime-typed Blob as the data.
}
} }