navigator.sendBeacon

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

navigator.sendBeacon

Postby davetclark » Wed Aug 24, 2016 10:47 am

navigator.sendBeacon is a great way to phone home, especially in onunload or onbeforeunload.

Shutting down CEF doesn't wait for the sendBeacon queue to be flushed before exiting. Is there any way to wait for this to happen before quitting?
davetclark
Newbie
 
Posts: 4
Joined: Wed Aug 24, 2016 10:44 am

Re: navigator.sendBeacon

Postby magreenblatt » Wed Aug 24, 2016 11:35 am

What OS and CEF version? How does it behave in cefclient? How does it behave in Google Chrome at the same version?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: navigator.sendBeacon

Postby davetclark » Wed Aug 24, 2016 12:03 pm

Windows 10, 64bit
CEF version 51.2704.1434

In cefclient, I close the app, get the onunload, send a navigator.sendBeacon, and do not usually see the request in Fiddler as expected. Sometimes the request does get sent, so it's racing. The request ALWAYS gets sent if I use the deprected synchronous XHLHttpRequest instead of navigator.sendBeacon.

How would you recommend running an equivalent test in Chrome, considering that Chrome likes to stay alive after you hit "X" on it?
davetclark
Newbie
 
Posts: 4
Joined: Wed Aug 24, 2016 10:44 am

Re: navigator.sendBeacon

Postby magreenblatt » Wed Aug 24, 2016 12:09 pm

I don't think successful completion of async network requests from onunload is guaranteed by any browser. See for example http://stackoverflow.com/questions/3584 ... ax-request
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: navigator.sendBeacon

Postby davetclark » Wed Aug 24, 2016 12:23 pm

That page talks about receiving responses from AJAX requests in onunload. In this case, we don't care about the response, because navigator.sendBeacon doesn't even give you a response, it's for 204 No-Content type messages.

Because synchronous XMLHttpRequest is deprecated in favor of navigator.sendBeacon, I was expecting to be able to use it for this usecase, but it won't work if the browser doesn't at least try to send the data before shutdown.
davetclark
Newbie
 
Posts: 4
Joined: Wed Aug 24, 2016 10:44 am

Re: navigator.sendBeacon

Postby magreenblatt » Thu Aug 25, 2016 3:04 am

davetclark wrote:That page talks about receiving responses from AJAX requests in onunload. In this case, we don't care about the response, because navigator.sendBeacon doesn't even give you a response, it's for 204 No-Content type messages.

Because synchronous XMLHttpRequest is deprecated in favor of navigator.sendBeacon, I was expecting to be able to use it for this usecase, but it won't work if the browser doesn't at least try to send the data before shutdown.

It probably is trying to send the data, but depending on how long shutdown takes it may not complete. In other words, you're introducing a race condition during shutdown.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: navigator.sendBeacon

Postby davetclark » Thu Aug 25, 2016 11:54 am

It probably is trying to send the data, but depending on how long shutdown takes it may not complete. In other words, you're introducing a race condition during shutdown.


I agree, it's racing. I'm looking for a way to ensure that the sendBeacon queue gets flushed before app exit. Not worrying about responses at all. If CEF has no visibility into the sendBeacon queue then maybe it's impossible, but that's what I'm looking for.
davetclark
Newbie
 
Posts: 4
Joined: Wed Aug 24, 2016 10:44 am

Re: navigator.sendBeacon

Postby magreenblatt » Thu Aug 25, 2016 12:03 pm

There is no visibility into when the sendBeacon has completed. Presumably you control the native application and the web content, so you have many alternative options for sending a network request during application shutdown.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: navigator.sendBeacon

Postby fddima » Thu Aug 25, 2016 1:01 pm

As idea, sendBeacon requests sent to resource scheme factory (with browser == null), because they not tied to browser in chrome. so it is possible provide own resource handler which exec actual request, but count usages. after what it is should be easy to wait BEFORE CefShutdown call. On other side this is very unclear, and as for me better introduce own API (or override sendBeacon) to handle this situation.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 112 guests