
Bug: 1465781 Change-Id: I38c59336269a2dd80dd25731a9c4302b92837ea7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5215810 Auto-Submit: Ming-Ying Chung <mych@chromium.org> Reviewed-by: Fergal Daly <fergal@chromium.org> Commit-Queue: Fergal Daly <fergal@chromium.org> Cr-Commit-Position: refs/heads/main@{#1249259}
3.9 KiB
fecthLater API
- Contact: pending-beacon-experiment@chromium.org
- API Feedback: https://github.com/WICG/pending-beacon/issues
This document describes the status of the current implementation of the FetchLater API in Chrome, and how to enable it manually.
Starting from version 121, Chrome experimentally supports the FetchLater API, which allows website authors to specify one or more beacons (HTTPS requests) that should be sent reliably when the page is being unloaded.
See the public explainer to learn more about how it works.
Note that this API is not enabled by default. Instead, Chrome plans to run Origin Trials to evaluate its impact. But Chrome also provides some ways to fully opt-in to the API for web developers who what to try the features.
What’s supported
Chrome supports all the JavaScript APIs described in the spec PR, specifically:
fetchLater()
method, afetch()
-like API.Deferred fetching
behavior.
What’s not supported
The following features are not finalized in the spec PR, and hence not supported in Chrome:
- The API is only supported in Document context. Supporting in ServiceWorker is blocked by ServiceWorker version of https://crbug.com/1356128.
- Crash recovery related behaviors is not supported. (Discussed in pending-beacon/issues/34)
- Retry after network failure is not supported. (Discussed in pending-beacon-/issues/40)
- A fetchLater request is not observable in Chrome DevTools after its initiating document is closed, which is due to the current DevTools limitation; if the document is still alive, the request should be visible.
The following features work differently than the one described in explainer and spec:
- To address the privacy requirement (see pending-beacon/issues/30), any pending fetchLater requests on a document are all flushed out if the document enters BFCache, no matter BackgroundSync permission is on or not.
- The maximum time a fetchLater request can be pending is bound by Chrome's back/forward cache TTL, which is currently 10 minutes after page goes into the cache. Note that due to the above forced-flushing behavior, in reality there should be no request pending after a page being cached.
Activation
The API can be enabled by a command line flag.
Using command line flag
Passing --enable-features=FetchLaterAPI --enable-blink-features=FetchLaterAPI
command line flag to Chrome enables FetchLater API support.
Verifying the API is working
Added the following line to an HTTPS web page, and load the page into a Chrome tab.
<script>
fetchLater('/test');
</script>
Close the tab, and you should be able to observe a request sent to /test
on
your web server that hosts the page.
Related Links
- Chrome Platform Status - Feature: FetchLater API
- FetchLater Explainer on GitHub
- FetchLater API Spec (draft)
- Ask questions about API & Spec via new issue
- FetchLater API Design Doc in Chromium