Skip to content

Commit b32a8ec

Browse files
author
Josh Goldberg
authored
fix(tracking): super-bind the sendBeacon to navigator
Another attempt to fix our `navigator.sendBeacon` `IllegalInvocation` woes.
1 parent 39b1e31 commit b32a8ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/tracking/src/events/track.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ export const createTracker = ({ apiBaseUrl, verbose }: TrackerOptions) => {
2424
}
2525

2626
// Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
27-
// [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
28-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
29-
if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
27+
const sendBeacon =
28+
// [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
29+
// It seems similar to this: https://github.com/vercel/next.js/issues/23856
30+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
31+
navigator.sendBeacon && navigator.sendBeacon.bind(navigator);
32+
if (sendBeacon?.(uri, form)) {
3033
return;
3134
}
3235

0 commit comments

Comments
 (0)