Skip to content

Commit

Permalink
Add rel notes for Fx132 fetch() keepalive support, and tweak docs (#3…
Browse files Browse the repository at this point in the history
…6236)

* 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 <[email protected]>

---------

Co-authored-by: Vadim Makeev <[email protected]>
  • Loading branch information
chrisdavidmills and pepelsbey authored Oct 9, 2024
1 parent 11135cd commit 7a2d87c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
42 changes: 42 additions & 0 deletions files/en-us/mozilla/firefox/experimental_features/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<table>
<thead>
<tr>
<th>Release channel</th>
<th>Version added</th>
<th>Enabled by default?</th>
</tr>
</thead>
<tbody>
<tr>
<th>Nightly</th>
<td>132</td>
<td>Yes</td>
</tr>
<tr>
<th>Developer Edition</th>
<td>132</td>
<td>Yes</td>
</tr>
<tr>
<th>Beta</th>
<td>132</td>
<td>Yes</td>
</tr>
<tr>
<th>Release</th>
<td>132</td>
<td>No</td>
</tr>
<tr>
<th>Preference name</th>
<td colspan="2"><code>dom.fetchKeepalive.enabled</code></td>
</tr>
</tbody>
</table>

### Graphics: Canvas, WebGL, and WebGPU

#### Request video frame callbacks
Expand Down
6 changes: 6 additions & 0 deletions files/en-us/mozilla/firefox/releases/132/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`**: <code>javascript.options.experimental.promise_try</code>. {{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
Expand Down
2 changes: 2 additions & 0 deletions files/en-us/web/api/request/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
44 changes: 44 additions & 0 deletions files/en-us/web/api/request/keepalive/index.md
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions files/en-us/web/api/requestinit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down

0 comments on commit 7a2d87c

Please sign in to comment.