Closed smaug---- closed 1 year ago
I might be misunderstanding what you mean but it sounds like you're suggesting pages would use sendBeacon
in some event handlers and PendingBeacon
to handle the cases where no event handlers are called? Is that correct?
I'm wondering about the motivation section, since it talks about some same issues which Page Lifecycle API was designed to solve. So if one would use freeze event, not unload or beforeunload, or not even pagehide, wouldn't that solve some of the issues we have today. And visibilitychange event could be use for some background tab issues. In other words, which cases are left if those events were used.
I'm assuming you're talking about using events plus existing network APIs like fetch with keepalive or sendBeacon.
Some of the goals of PendingBeacon are
JS is paused in BFCache and sometimes when backgrounded and may never be unpaused before the page is discarded. So the only way to achieve "definitely send" is to eagerly send when an event occurs that might result in paused JS. That conflicts with allowing data to accumulate within time limits. We don't want pages sending on every visibility event just in case it might be their last chance to send.
Also, no combination of events+sendBeacon can provide the ability to send after a crash or other sudden termination (common on Mobile), so authors who want that will put their data in a beacon.
if one would use freeze event, not unload or beforeunload, or not even pagehide, wouldn't that solve some of the issues we have today
There were some discussions around which lifecycle event we should support in this thread https://github.com/WICG/unload-beacon/issues/13#issuecomment-1179350019 and the API ends up switching from supporting pagehide
to hidden
.
Later discussion in https://github.com/WICG/pending-beacon/issues/52#issuecomment-1293152655 adds more valuable points why we want a dedicated API that bundles these capabilities together.
I'll close this bug for now. Feel free to re-open with any other concerns.
Page Lifecycle API, isn't a proper spec yet, but it is trying to solve some of the issues https://github.com/WICG/unload-beacon/blob/main/README.md#problem-and-motivation talks about. Is there a reason why existing sendBeacon couldn't be used when freeze or visibilitychange event fires?