This document describes the status of the current implementation of the Pending Beacon API (a.k.a. PendingBeacon API) in Chrome, and how to enable it manually.
Starting from version 107, Chrome experimentally supports the Pending Beacon API, which allows website authors to specify one or more beacons (HTTP 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 A/B testing 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.
Chrome supports all the JavaScript APIs described in the explainer, specifically:
class PendingPostBeacon
class PendingGetBeacon
The following features are not yet supported in Chrome:
setData(data)
on a PendingPostBeacon
, the data
payload cannot bedata
of FormData
type, it can only have single entry/part.data
cannot be a ReadableStream.The following features work differently than the one described in explainer:
PendingGetBeacon
can update its URL via setURL()
method.PendingPostBeacon
is only queued if it has non-undefined and non-null data (described in setData()
method).Pending*Beacon
with HTTP URL property, it will still work.The API can be enabled by a command line flag, or via Origin Trial.
Passing the --enable-features=PendingBeaconAPI
command line flag to Chrome enables PendingBeacon API support.
You can opt any page on your origin into PendingBeacon API Origin Trial by requesting a token for your origin via the above link. Include the token in your page so that Chrome can recognize your page is opted in.
The simplest way is to include the following line in your page:
<meta http-equiv="origin-trial" content="**your token**">
Or you can also include the token in your HTTP request.
Added the following line to a web page, and load the page into a Chrome tab.
<script> new PendingGetBeacon('/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.