navigator.sendBeacon
Sends a small POST that the browser delivers even while the person is leaving the page.
In one line
Can send a small report that the browser delivers even as you leave the page
Sends a small POST that the browser delivers even while the person is leaving the page.
Lets analytics report time on page, scroll depth and exit clicks after the tab is closed or navigated away. No response is readable. The person cannot see or stop it, and it carries cookies for the target origin.
What it can and can't do
What the user does: Nothing. It happens when you close or leave a page
It can
- Send a small message as the page closes
- Report time spent, clicks or errors
- Deliver the message even after the tab is gone
It cannot
- Send large amounts of data, since there is a size limit
- Get a reply back to the page
- Run if a blocker stops the request
- Show a prompt or any sign
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 39 | 2014-11-18 | None |
| Edge | Supported | 14 | 2016-08-02 | None |
| Firefox | Supported | 31 | 2014-07-22 | None |
| Safari | Supported | 11.1 | 2018-04-12 | None |
| Safari on iPhone | Supported | 11.3 | 2018-03-29 | None |
| Chrome on Android | Supported | 42 | 2015-04-15 | None |
| Samsung Internet | Supported | 4.0 | 2016-03-11 | None |
How a site asks for it
| API | navigator.sendBeacon(url, data) |
| Browser compat keys | api.Navigator.sendBeacon |
| How access is granted | none |
| What the user sees | None |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| How long it lasts | Fire and forget; queued by the browser until sent |
| How to take it back | Clear site data, browser privacy settings |
| Inside an iframe | Not listed |
Data you get
What comes back: Beacon request
Shape: event
How often: at page exit
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
payload | integer | bytes | up to about 65536 | exact |
Technical limits
- About 64 KiB of queued beacon and keepalive data per page (Chrome)
- POST only, response not readable
- Returns false if the data is refused
- Blocked by tracker blockers
The story
What it is
Sends a small message that the browser delivers even as you leave the page.
For you
You never see it. You close a tab or click away, and the page sends a last note that gets delivered. You cannot read it, stop it or know what it held.
For makers
Normal requests are cut off when a page closes. sendBeacon lets analytics finish a report about time on page, scrolls or exits. It is simple, so it is everywhere.
Where you see it
| Type | Example | Apps |
|---|---|---|
| analytics | A news site sends how long you read and how far you scrolled when you leave the article. | Google Analytics, Chartbeat |
| games | A browser game sends final stats when you close the tab, so the server records your run. | None named |
| video | A video site sends your watch time so it can resume next visit. | YouTube, Vimeo |
| ads | An ad tag reports that an ad was seen for 2 seconds. | Google Ad Manager |
| security | A fraud tool sends last mouse and key data on exit from a checkout page. | Sift |
| developer | An app sends crash and speed data as the tab closes. | Sentry, Datadog |
Risks
- Hard to see or stop
- Carries cookies to the target site
What the platform says
- Mozilla: sendBeacon. Developer docs describe it as a way to send a small amount of data in the background, even on page exit.
Good uses and abuse
Legitimate uses
- Exit analytics, error logs
Known abuse
- Post-visit tracking that survives page close
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 3 of 5 | How revealing the data is |
| Utility | 4 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough identifying entropy, when known |
History
- 2014-11, Chrome 39: Shipped
- 2018-03, Safari 11.1: Shipped in Safari
Related capabilities
Related
- fetch keepalive. Can finish sending a request after you leave or close the page
- fetchLater. Can queue a report now and have the browser send it later, even after you close
- pagehide, visibilitychange and unload. Can tell a page when you hide or leave it, so it can send a report
Sources
How well checked: Checked against real behavior.