From 7a2d87c54eb8d51586602b703f33328ae878b928 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 9 Oct 2024 13:10:03 +0100 Subject: [PATCH] Add rel notes for Fx132 fetch() keepalive support, and tweak docs (#36236) * Add rel notes for Fx132 fetch() keepalive support, and tweak docs * change KB back to kibibytes * Update files/en-us/mozilla/firefox/releases/132/index.md Co-authored-by: Vadim Makeev --------- Co-authored-by: Vadim Makeev --- .../firefox/experimental_features/index.md | 42 ++++++++++++++++++ .../mozilla/firefox/releases/132/index.md | 6 +++ files/en-us/web/api/request/index.md | 2 + .../en-us/web/api/request/keepalive/index.md | 44 +++++++++++++++++++ files/en-us/web/api/requestinit/index.md | 4 +- 5 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 files/en-us/web/api/request/keepalive/index.md diff --git a/files/en-us/mozilla/firefox/experimental_features/index.md b/files/en-us/mozilla/firefox/experimental_features/index.md index 48ca35b3c619144..6f34c469d48ba1b 100644 --- a/files/en-us/mozilla/firefox/experimental_features/index.md +++ b/files/en-us/mozilla/firefox/experimental_features/index.md @@ -1290,6 +1290,48 @@ The [(?ims-ims:...)](/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Mo ## APIs +### Fetch `keepalive` + +The global {{domxref('Window.fetch','fetch()')}} method has a [`keepalive`](/en-US/docs/Web/API/RequestInit#keepalive) initialization option. When `keepalive` is set to `true`, the browser will not abort the associated request if the page that initiated it is unloaded before the request is complete. + +This enables a fetch request to function as an alternative to {{domxref("Navigator.sendBeacon()")}} when sending analytics at the end of a session, which has some advantages (you can use HTTP methods other than [`POST`](/en-US/docs/Web/HTTP/Methods/POST), customize request properties, and access the server response via the fetch {{jsxref("Promise")}} fulfillment). It is also available in [service workers](/en-US/docs/Web/API/Service_Worker_API). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Release channelVersion addedEnabled by default?
Nightly132Yes
Developer Edition132Yes
Beta132Yes
Release132No
Preference namedom.fetchKeepalive.enabled
+ ### Graphics: Canvas, WebGL, and WebGPU #### Request video frame callbacks diff --git a/files/en-us/mozilla/firefox/releases/132/index.md b/files/en-us/mozilla/firefox/releases/132/index.md index c7c26f02b4b5fb2..cfadd402994cafb 100644 --- a/files/en-us/mozilla/firefox/releases/132/index.md +++ b/files/en-us/mozilla/firefox/releases/132/index.md @@ -75,6 +75,12 @@ This article provides information about the changes in Firefox 132 that affect d These features are newly shipped in Firefox 132 but are disabled by default. To experiment with them, search for the appropriate preference on the `about:config` page and set it to `true`. You can find more such features on the [Experimental features](/en-US/docs/Mozilla/Firefox/Experimental_features) page. +- **The `fetch()` `keepalive` option:** `dom.fetchKeepalive.enabled`. + + The global {{domxref('Window.fetch','fetch()')}} method has a [`keepalive`](/en-US/docs/Web/API/RequestInit#keepalive) initialization option. When `keepalive` is set to `true`, the browser will not abort the associated request if the page that initiated it is unloaded before the request is complete. + + This enables a fetch request to function as an alternative to {{domxref("Navigator.sendBeacon()")}} when sending analytics at the end of a session, which has some advantages (you can use HTTP methods other than [`POST`](/en-US/docs/Web/HTTP/Methods/POST), customize request properties, and access the server response via the fetch {{jsxref("Promise")}} fulfillment). It is also available in [service workers](/en-US/docs/Web/API/Service_Worker_API). ([Firefox bug 1906952](https://bugzil.la/1906952)). + - **`Promise.try()`**: javascript.options.experimental.promise_try. {{jsxref("Promise.try()")}} is a convenience method that takes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result in a {{jsxref("Promise")}} so that promise semantics (e.g. {{jsxref("Promise.then", ".then()")}}, {{jsxref("Promise.catch", ".catch()")}}) can be used to handle it ([Firefox bug 1905364](https://bugzil.la/1905364)). ## Older versions diff --git a/files/en-us/web/api/request/index.md b/files/en-us/web/api/request/index.md index 3a0c609f5aa83f4..851e00658794020 100644 --- a/files/en-us/web/api/request/index.md +++ b/files/en-us/web/api/request/index.md @@ -32,6 +32,8 @@ You can create a new `Request` object using the {{domxref("Request.Request","Req - : Contains the associated {{domxref("Headers")}} object of the request. - {{domxref("Request.integrity")}} {{ReadOnlyInline}} - : Contains the [subresource integrity](/en-US/docs/Web/Security/Subresource_Integrity) value of the request (e.g., `sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=`). +- {{domxref("Request.keepalive")}} {{ReadOnlyInline}} + - : Contains the request's `keepalive` setting (`true` or `false`), which indicates whether the browser will keep the associated request alive if the page that initiated it is unloaded before the request is complete. - {{domxref("Request.method")}} {{ReadOnlyInline}} - : Contains the request's method (`GET`, `POST`, etc.) - {{domxref("Request.mode")}} {{ReadOnlyInline}} diff --git a/files/en-us/web/api/request/keepalive/index.md b/files/en-us/web/api/request/keepalive/index.md new file mode 100644 index 000000000000000..59a2f35a1339909 --- /dev/null +++ b/files/en-us/web/api/request/keepalive/index.md @@ -0,0 +1,44 @@ +--- +title: "Request: keepalive property" +short-title: keepalive +slug: Web/API/Request/keepalive +page-type: web-api-instance-property +browser-compat: api.Request.keepalive +--- + +{{APIRef("Fetch API")}} + +The **`keepalive`** read-only property of the {{domxref("Request")}} interface contains the request's `keepalive` setting (`true` or `false`), which indicates whether the browser will keep the associated request alive if the page that initiated it is unloaded before the request is complete. + +This enables a {{domxref('Window.fetch','fetch()')}} request to function as an alternative to {{domxref("Navigator.sendBeacon()")}} when sending analytics at the end of a session, which has some advantages (you can use HTTP methods other than [`POST`](/en-US/docs/Web/HTTP/Methods/POST), customize request properties, and access the server response via the fetch {{jsxref("Promise")}} fulfillment). It is also available in [service workers](/en-US/docs/Web/API/Service_Worker_API). + +## Value + +A boolean value indicating the `keepalive` status of the request. + +## Examples + +In the following snippet, we create a new request using the {{domxref("Request.Request", "Request()")}} constructor with `keepalive` set to `true`, then save the `keepalive` value of the request in a variable: + +```js +const options = { + keepalive: true, +}; + +const myRequest = new Request("flowers.jpg", options); +let mykeepalive = myRequest.keepalive; // true +``` + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- [ServiceWorker API](/en-US/docs/Web/API/Service_Worker_API) +- [HTTP access control (CORS)](/en-US/docs/Web/HTTP/CORS) +- [HTTP](/en-US/docs/Web/HTTP) diff --git a/files/en-us/web/api/requestinit/index.md b/files/en-us/web/api/requestinit/index.md index 70ba65ed8d8d36e..f206dae64126c55 100644 --- a/files/en-us/web/api/requestinit/index.md +++ b/files/en-us/web/api/requestinit/index.md @@ -131,9 +131,9 @@ You can also construct a `Request` with a `RequestInit`, and pass the `Request` - `keepalive` {{optional_inline}} - - : A boolean. If `true`, the browser will not abort the request if the page that made it is unloaded before the request is complete. This enables a Fetch request to function as an alternative to {{domxref("Navigator.sendBeacon()")}} when sending analytics at the end of a session. + - : A boolean. When set to `true`, the browser will not abort the associated request if the page that initiated it is unloaded before the request is complete. This enables a {{domxref('Window.fetch','fetch()')}} request to function as an alternative to {{domxref("Navigator.sendBeacon()")}} when sending analytics at the end of a session, which has some advantages (you can use HTTP methods other than [`POST`](/en-US/docs/Web/HTTP/Methods/POST), customize request properties, and access the server response via the fetch {{jsxref("Promise")}} fulfillment). It is also available in [service workers](/en-US/docs/Web/API/Service_Worker_API). - The body size for keepalive requests is limited to 64 kibibytes. + The body size for `keepalive` requests is limited to 64 kibibytes. Defaults to `false`.