Questions tagged [sendbeacon]
33 questions
18
votes
3 answers
sendBeacon API not working temporarily due to security issue, any workaround?
I have the following code to send asynchronous HTTP request using sendBeacon method,
var data = {
name: 'test',
uniqueId: Math.random()
};
var blob = new Blob([JSON.stringify(data)], {type :…

webblover
- 1,196
- 2
- 12
- 30
16
votes
1 answer
HTTP request beforeunload: sendBeacon vs img.src
In the context of a beforeunload handler, what is the functional difference between fetch(keep-alive: true) and setting the src attribute of an img tag, and which of these is the preferred method for making GET requests?
Background:
I want to send…

Emmett Butler
- 5,969
- 2
- 29
- 47
7
votes
2 answers
Closing Chrome window not sending data with sendBeacon in unload event handler
I am trying to send data when the window closes to prevent 2 people from editing and overwriting each others data. Currently I am using a sendBeacon within a unload event handler.
FireFox:
Refresh: Works
Back button: Works
Close window:…

webdevtrev
- 79
- 1
- 3
6
votes
1 answer
Event onbeforeunload isn't fired in Chrome Incognito
I've been trying to send a beacon on beforeunload and it seems to work on pretty much all modern browsers, except Chrome in incognito mode.
This is the code that works in all modern browsers, except Chrome in incognito mode:
window.onbeforeunload =…

Alex
- 4,674
- 5
- 38
- 59
5
votes
2 answers
Perform an asynchronous service get when closing browser window / tab with Angular
I'm currently trying to make an Angular app make an API service call when the user tries to navigate away from my page. Either by closing the tab / window, or typing in an external URL.
I've tried to implement several different ways I've seen…

Chronus
- 301
- 3
- 17
4
votes
1 answer
sendBeacon JSON Data not getting read (serverside) Nodejs and JS
I am trying to send a POST request on visibility change (as described in the docs) and am having limited success. I make the sendBeacon request successfully, but cannot seem to read the object on my Node.js Express server. Here is my Send Beacon js…

imaginate
- 567
- 2
- 13
4
votes
1 answer
why use beacon api when it does not provide a response
I am using navigator.sendBeacon() api, I understand its benefits of sending data even onunload, but why should we use it when it only returns a value of whether the data is being queued or not and does not help us in checking if the data is sent to…

astudent
- 67
- 1
- 7
4
votes
1 answer
IOS pagehide not triggered. Cannot detecting page unload
I call this function when my page is loaded:
function setBeacon() {
if (!navigator.sendBeacon) {
alert("No navigator beacon available. This is a critical bug which must be fixed.");
}
else
{
if ('beforeunload' in window) {
…

jonsploder
- 307
- 2
- 8
3
votes
0 answers
should navigator.sendBeacon be synchronous?
I am using navigator.sendBeacon to send a small payload in the onclick event of an anchor
Click Here
But it seems that the user does not navigate away…

sheamus
- 3,001
- 4
- 31
- 54
3
votes
0 answers
Identify bad requests(4xx response code) from navigator.sendBeacon()
How can I get response code from navigator.sendBeacon? I need to have some indicator that can say me that request is failed? Particularly, I am looking for a way to identify bad request (request that was send with “bad” malformed json and got 4xx…

WomenWhoCode
- 396
- 1
- 6
- 18
2
votes
1 answer
Can I use sendBeacon to save session duration metric real-time in iOS devices?
I have integrated the timeonsite library to store the time users spend on the site in a MySQL database. I'm using the following code to achieve the same.
However, the data is not getting stored in IOS devices like iPhone or iPad but works in all…

webblover
- 1,196
- 2
- 12
- 30
2
votes
1 answer
Navigator.sendBeacon not working with Authorization Headers
Recently chrome stop support for synchronos xmlhttprequest on page unload or beforeunload event https://www.chromestatus.com/feature/4664843055398912
i try this solution Perform an asynchronous service get when closing browser window / tab with…

Buzz
- 6,030
- 4
- 33
- 47
1
vote
1 answer
How to call rest API on Windowunload event
My application is using angular 12. I have an use case to update data in db when user closes the tab. For this use case, I have tried calling API during window unload using promises which is not working. How to achieve this use case?

priya
- 21
- 2
1
vote
0 answers
Request stalled indefinitely in chrome browser
I use the bellow code in order to send requests when my page changes. When I try it with Firefox browser I have no issues but in Chrome browser the request stay pending indefinitely. Can you guys help on this ?
navigator.sendBeacon('my-url/session',…

Carlos Cardoso
- 315
- 1
- 2
- 9
1
vote
1 answer
Parse sendBeacon data in Express
I'm trying to start logging my own WebVitals. The simple use-case in their example docs looks like this:
function sendToAnalytics(metric) {
// Replace with whatever serialization method you prefer.
// Note: JSON.stringify will likely include…

philolegein
- 1,099
- 10
- 28