Skip to content

Commit

Permalink
Merge pull request #158 from izayl/fix/sendBeacon
Browse files Browse the repository at this point in the history
fix: beacon throw
  • Loading branch information
dasfmi authored Oct 25, 2023
2 parents edfe59c + 59ab551 commit 679b67c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ export class Logger {
} else if (config.isBrowser && isVercel && navigator.sendBeacon) {
// sendBeacon fails if message size is greater than 64kb, so
// we fall back to fetch.
if (!navigator.sendBeacon(url, body)) {
// Navigator has to be bound to ensure it does not error in some browsers
// https://xgwang.me/posts/you-may-not-know-beacon/#it-may-throw-error%2C-be-sure-to-catch
try {
if (!navigator.sendBeacon.bind(navigator)(url, body)) {
return sendFallback();
}
} catch (error) {
return sendFallback();
}
} else {
Expand Down

1 comment on commit 679b67c

@vercel
Copy link

@vercel vercel bot commented on 679b67c Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

next-axiom-example – ./

next-axiom-example.axiom.dev
next-axiom-example-git-main.axiom.dev
next-axiom-example-lemon.vercel.app

Please sign in to comment.