question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of navigator `sendBeacon`?

See original GitHub issue

Hi,

Would you consider using navigator.sendBeacon when available (modern browsers) rather than xhr requests? The advantages are:

  • offline support (events are queued if loss of connectivity)
  • execution in a worker thread
  • page unloads doesn’t cancel in-flight requests

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ajhorstcommented, Aug 16, 2021

@joshunger and others, sendBeacon is now available in beta as of SDK version 8.5.0. There are notes on how to use it here, and let me know if you encounter any issues with it.

3reactions
ajhorstcommented, Aug 3, 2021

@joshunger theoretically, one could do that by making a fetch request directly to amplitude’s HTTP endpoint from the browser inside a navigator.sendBeacon call.

However, this feature is actively being worked on now, and will be available in the JS SDK by the end of next week at the latest. So if you’re able to wait it will be ready natively soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigator.sendBeacon() - Web APIs | MDN
The navigator.sendBeacon() method asynchronously sends an HTTP POST request containing a small amount of data to a web server.
Read more >
How and why to use navigator.sendBeacon - Ben Borgers
The navigator.sendBeacon() method makes POST requests without waiting for a response. It's often used for analytics and diagnostics, ...
Read more >
"sendbeacon" | Can I use... Support tables for HTML5, CSS3, etc
Allows data to be sent asynchronously to a server with navigator.sendBeacon , even after a page was closed. Useful for posting analytics data...
Read more >
What is sendBeacon in JavaScript? - Educative.io
The sendBeacon will send an HTTP POST request. ... To overcome this problem, we can use sendBeacon , which includes the following benefits:...
Read more >
JavaScript's sendBeacon - Medium
A method from the Beacon API, it allows you to send a POST request with two parameters — the URL endpoint for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found