sendBeacon not working on window close

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
User avatar
mahks
Posts: 32
Joined: September 9th, 2009, 5:08 pm

sendBeacon not working on window close

Post by mahks »

Trying to get navigator.sendBeacon to work from onbeforeunload.

This is what I have found:
Works as expected if the page is in a tab and that is closed.
If the whole window is closed PHP does not receive the request and I cannot confirm if the browser sent it as the window is closed (no persistent logs)
If I place a synchronous XMLHttpRequest in the event, then the sendBeacon works as expected.

It is my understanding that since synchronous XMLHttpRequests are depreciated, we must now use sendBeacon to send data from onbeforeunload as
asynchronous XMLHttpRequests do not work in that event.

Is anyone using sendBeacon in onbeforeunload successfully?
Last edited by mahks on October 18th, 2015, 3:34 pm, edited 1 time in total.
Ignorance is being uninformed, persisting once informed is being ignorant.
User avatar
DanRaisch
Moderator
Posts: 127187
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: sendBeacon not working on window close

Post by DanRaisch »

Moving to Web Development.
Post Reply