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 channel | +Version added | +Enabled by default? | +
---|---|---|
Nightly | +132 | +Yes | +
Developer Edition | +132 | +Yes | +
Beta | +132 | +Yes | +
Release | +132 | +No | +
Preference name | +dom.fetchKeepalive.enabled |
+
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`.