blob: a0562dc2d89c3850de5055da123279adef1392f4 [file] [log] [blame] [view]
Ming-Ying Chung141600c2023-11-14 03:12:411# fecthLater API
2
3- Contact: pending-beacon-experiment@chromium.org
4- API Feedback: https://github.com/WICG/pending-beacon/issues
5
6This document describes the status of the current implementation of the
7[**FetchLater API**][spec-pr] in Chrome, and how to enable it manually.
8
Ming-Ying Chung251a52dc2024-01-19 07:35:309Starting from [version 121][status], Chrome experimentally supports the
Ming-Ying Chung141600c2023-11-14 03:12:4110FetchLater API,
11which allows website authors to specify one or more beacons (HTTPS requests)
12that should be sent reliably when the page is being unloaded.
13
14See the [public explainer][explainer] to learn more about how it works.
15
16Note that this API is not enabled by default. Instead, Chrome plans to run
17Origin Trials to evaluate its impact. But Chrome also provides some ways to
18fully opt-in to the API for web developers who what to try the features.
19
20[spec-pr]: https://github.com/whatwg/fetch/pull/1647
21[explainer]: https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md
22[status]: https://chromestatus.com/feature/4654499737632768
23
24## What’s supported
25
26Chrome supports all the JavaScript APIs described in the spec PR,
27specifically:
28
29- [`fetchLater()`](https://whatpr.org/fetch/1647/9ca4bda...37a66c9.html#dom-global-fetch-later)
30 method, a `fetch()`-like API.
31- [`Deferred fetching`](https://whatpr.org/fetch/1647/9ca4bda...37a66c9.html#deferred-fetching)
32 behavior.
33
34## What’s not supported
35
36The following features are not finalized in the spec PR, and hence not supported
37in Chrome:
38
39- The API is only supported in Document context. Supporting in ServiceWorker is
40 blocked by ServiceWorker version of https://crbug.com/1356128.
41- Crash recovery related behaviors is not supported.
42 (Discussed in [pending-beacon/issues/34](https://github.com/WICG/pending-beacon/issues/34))
43- Retry after network failure is not supported.
44 (Discussed in [pending-beacon-/issues/40](https://github.com/WICG/pending-beacon/issues/40))
Ming-Ying Chung251a52dc2024-01-19 07:35:3045- A fetchLater request is not observable in Chrome DevTools after its initiating
46 document is closed, which is due to the current
47 [DevTools limitation](https://chromestatus.com/feature/4654499737632768?gate=4947446974644224);
48 if the document is still alive, the request should be visible.
Ming-Ying Chung141600c2023-11-14 03:12:4149
50The following features work differently than the one described in explainer and
51spec:
52
53- To address the privacy requirement (see
Ming-Ying Chung251a52dc2024-01-19 07:35:3054 [pending-beacon/issues/30](https://github.com/WICG/pending-beacon/issues/30#issuecomment-1888554622)),
55 any pending fetchLater requests on a document are **all flushed out** if the
56 document enters BFCache, no matter BackgroundSync permission is on or not.
57- The maximum time a fetchLater request can be pending is bound by Chrome's
58 back/forward cache TTL, which is currently **10 minutes** after page goes into
59 the cache. Note that due to the above forced-flushing behavior, in reality
60 there should be no request pending after a page being cached.
Ming-Ying Chung141600c2023-11-14 03:12:4161
62## Activation
63
64The API can be enabled by a command line flag.
65
66### Using command line flag
67
68Passing `--enable-features=FetchLaterAPI --enable-blink-features=FetchLaterAPI`
69command line flag to Chrome enables FetchLater API support.
70
71### Verifying the API is working
72
73Added the following line to an HTTPS web page, and load the page into a Chrome
74tab.
75
76```html
77<script>
78fetchLater('/test');
79</script>
80```
81
82Close the tab, and you should be able to observe a request sent to `/test` on
83your web server that hosts the page.
84
85## Related Links
86
87- [Chrome Platform Status - Feature: FetchLater API][status]
88- [FetchLater Explainer on GitHub](https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md)
89- [FetchLater API Spec (draft)](https://whatpr.org/fetch/1647/9ca4bda...37a66c9.html#dom-global-fetch-later)
90- Ask questions about API & Spec via [new issue](https://github.com/WICG/pending-beacon/issues/new)
91- [FetchLater API Design Doc in Chromium](https://docs.google.com/document/d/1U8XSnICPY3j-fjzG35UVm6zjwL6LvX6ETU3T8WrzLyQ/edit#heading=h.ms1oipx914vf)