WICG / pending-beacon

A better beaconing API
Other
43 stars 8 forks source link

the proposal doesn't consider using Page Lifecycle API #32

Closed smaug---- closed 1 year ago

smaug---- commented 2 years ago

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?

fergald commented 2 years 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?

smaug---- commented 2 years ago

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.

fergald commented 2 years ago

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.

mingyc commented 2 years ago

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.

mingyc commented 1 year ago

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.