← Back to release summary

fetchLater API

Category
Network / Connectivity
Type
New or changed feature
Status
Origin trial (Chrome 135)
Intent stage
None

Summary

fetchLater() is a JavaScript API to request a deferred fetch. Once called in a document, a deferred request is queued by the browser in the PENDING state, and will be invoked by the earliest of the following conditions: * The document is destroyed. * After a user-specified time. For privacy reason, all pending requests will be flushed upon document entering bfcache no matter how much time is left. * Browser decides it's time to send it. The API returns a FetchLaterResult that contains a boolean field "activated" that may be updated to tell whether the deferred request has been sent out or not. On successful sending, the whole response will be ignored by browser, including body and headers. Nothing at all should be processed or updated, as the page may have already be gone. Note that from the point of view of the API user, the exact send time is unknown.

Motivation

Web developers have a need for ‘beaconing’ - that is, sending a bundle of data to a backend server, without expecting a particular response, ideally at the ‘end’ of a user’s visit to a page. There are currently four major methods of beaconing used around the web; all suffer from reliability problems, stemming from one core issue: There is not an ideal time in a page’s lifecycle to make the Javascript call to send out the beacon. ‘unload’ and ‘beforeUnload’ are unreliable (and outright ignored by several major browsers), and pageHide and visibilityChanged have issues on mobile platforms. To simplify this issue and make beaconing more reliable, we propose adding a stateful JavaScript API where a page can register that it wants a beacon (or beacons) issued when it unloads or the page is hidden. Developers can populate beacon(s) with data as the user uses the page, and the browser ensures beacon(s) are reliably sent at some point in time. This frees developers from worrying about which part of the page lifecycle to send their beacon calls in.

Standards & signals

Docs: https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md https://docs.google.com/document/d/1U8XSnICPY3j-fjzG35UVm6zjwL6LvX6ETU3T8WrzLyQ/edit#heading=h.ms1oipx914vf

Samples: https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md#key-scenarios

Explainers: https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md

View on chromestatus.com