-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should pageHideTimeout
support additional events
#13
Comments
/cc @philipwalton |
The problem with I've just created a test case that uses
On desktop, this works reliably in all cases I tested, but on mobile I can get it to fail relatively easily. Here's how:
I can also get this to fail without closing the browser app if I choose a timeout like 5 minutes or more. If I choose a short timeout (e.g. 5 second) then I reliably get the The unreliability of DOM events after a tab (or the browser app itself) has been backgrounded on mobile is exactly why developers today have to rely on See our Page Lifecycle guidance as an example of this: Another problem with using For example, consider a web app like Gmail. When was the last time you closed that tab? You may keep it open for days or weeks. Do you really want to postpone sending any data until that tab is closed? This is why I think a more useful feature would be |
Should we have a general timeout too? I mentioned this the last time I presented at WebPerfWG and it was pointed out that it was easy to do with setTimeout but as you point out setTimeout is not reliable and pages would have to write visibility change handlers to do something like
That all seems like a pain and just being able to set
and have the beacon handle it seems nicer. There's a clear use case for data to be delivered within N mins of some event that causes a beacon to be
If someone was doing complex sending decisions and timeouts then they might want to set an N-mins from backgrounded timer since they know their complex logic is probably unreliable but do we actually have a concrete use case for N-mins from backgrounded if we could the ones above? |
@fergald in additional to the use cases you described, I'm particularly concerned about cases where a user switches (on mobile) from the browser app to another app without closing the tab, and then hours or days later shuts down or restarts their phone before using the browser app again. Do you think data could be sent in those cases? We've heard from a number of RUM providers that it's unclear how they should report on performance data on a timeline for metrics like INP or CLS in cases where the user has the page open for multiple days. I see general timeouts being really useful for cases like this, e.g. send the this data at |
@philipwalton my question is, what's a concrete use-case for pagehide-timeout that isn't met by just a general timeout? I.e. when is the preferred delivery time pagehide+N rather than (data_collected or some user/site-action)+N? So I'm happy to add a general timeout, I just would like to be convinced that a pagehide timeout is really needed in addition. If it is, then I would suggest we really want a "JS is frozen or timers become unreliable"+N timeout although that might be harder to spec since much of that is impl dependent. |
@philipwalton friendly ping
by general timeout, do you mean to support separate timeouts for every visibility events like above, or just a single timeout and let browser decides when to use it? |
I can't think of a good use case for pagehide specifically, as opposed to all background/frozen situations. However, I do think there's something nice about being able to configure everything in one place (e.g. when you create the I think my ordered preference would be as follows:
I believe (1) above is the best because if you want (2) you can easily implement it with |
I propose we do 1 and 2. I think 2 is important because, as you described above, because implementing 2 with just I'm not sure about the resetting when new data is added though. I think there's a use-case of "some data within 5 min no matter what" and auto-reset makes that impossible. People who want to reset can always manually reset when adding data. For |
When you say "manually reset" do you mean view some API method or just deactivating and creating a new beacon? (Either is fine with me.) |
I was thinking we could either have a method or a mutable property for the timeout(s) and setting it (even to the same value) resets the timer. |
Wouldn't this intrdocue #8 again, i.e. things can happen between setData() & setTimeout()?
How about updating it to |
- Fix WICG#13: Replace `pageHideTimeout` with `backgroundTimeout` and `timeout`. Allow to set them in constructor & data/url setters. - Address WICG#14: Rename `isPending` to `pending` and specify its behaviors. - Address WICG#14: Keep the low-level sync API, and mark it as chosen. - Fix WICG#6: Add `PendingGETBeacon` and `PendingPOSTBeacon`.
It's different because the timeout does not alter what gets sent, so there's no danger of a non-atomic update being interrupted by a crash. So there's not need to combine the data and timeout in 1 method call. |
* Update API spec in explainer to match latest discussion - Fix #13: Replace `pageHideTimeout` with `backgroundTimeout` and `timeout`. Allow to set them in constructor & via property setters. - Address #14: Rename `isPending` to `pending` and specify its behaviors. - Address #14: Keep the low-level sync API, and mark it as chosen. - Fix #6: Add `PendingGETBeacon` and `PendingPOSTBeacon`. - Update some tables & formatting - Addressed the comments in #16
whatwg/fetch#1647 doesn't consider a general timeout. Re-opening this issue for further discussion. |
I'm going to make 2 arguments for a general timeout rather than a timer that only starts when the page goes into BFCache (or maybe some other events): JS Timers are unreliableAt least on Chrome and Firefox mobile
What you will find is that the interval callback stopped getting called after some time (Chrome=5min, Firefox=1min). No This means that it is impossible to reliably send a beacon after N minutes. A page has to choose between sending on Using timers from JS and
|
Also, |
The timeout field is now called |
The main intention for this property is to shorten the wait time after a page goes into bfcache and frozen. A page could send a beacon earlier before it's actually unloaded (or evicted from bfcache).
Some offline discussions suggest to not limit it to only
pagehide
, but also includevisibilitychange
orfreeze
, mainly for easier doing analytics. For now, users can approximate it by executingsetTimeout(sendNow(), timeout)
in the corresponding event listeners.The text was updated successfully, but these errors were encountered: