Tracker: use sendBeacon or keepalive on fetch requests
Describe the feature or enhancement
Hey there,
I need to report events to my Umami instance right before navigating to a new page. Currently, the fetch request gets terminated—as expected—when the page unloads and the request hasn't completed yet.
The Navigator API offers two ways to work around this:
- Using
navigator.sendBeacon - Setting the
keepaliveoption to true in the fetch request
It would be great if the tracker script could make use of one of these approaches. I'm happy to open a PR if needed!
We investigated this a while ago and the result was:
- Almost every adblock blocks sendBeacon requests
- Firefox didn't support
keepalive.
Not sure what the current state of things are.
I had some success on Brave (shields up) using the keepalive parameter, and Safari 18.3. At least those two would work.
What could happen if the option is added anyway?
EDIT: as of now, seems supported by all major browsers: https://developer.mozilla.org/en-US/docs/Web/API/Request/keepalive
Firefox 133 (Released 2024-11-26). I can't believe Firefox only supported keepalive recently. But I think it's fine to add keepalive at this point. Not so sure about sendBeacon.
Keepalive should work fine for this use case, and I don’t think sendBeacon is necessary either. Would you like me to open a PR?
This issue is stale because it has been open for 60 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.