Async Clipboard API and User Activation vs Beacon API and visibilitychange Lifecycle
sendBeacon dispatches background requests without user gesture, whereas Async Clipboard requires transient user activation.
Structured Comparison Matrix
| Dimension | Async Clipboard API and User Activation | Beacon API and visibilitychange Lifecycle |
|---|---|---|
| Mental Model | Promise-based OS clipboard access gated by HTTPS, document focus, and transient user activation tokens, supporting deferred Blob resolution via ClipboardItem. | Prevent dropped analytics and broken bfcache on tab close by handing <= 64 KB POST payloads to the browser network process on visibilitychange. |
| Maturity & Domain | Baseline · Widely · Web APIs Chrome 66+ (writeText), 76+ (ClipboardItem) · Firefox 63+ (writeText), 127+ (ClipboardItem) · Safari 13.1+ | Baseline · Widely · Web APIs Chrome 39+ · Firefox 31+ · Safari 11.1+ |
| Prerequisites | ||
| When Not to Use | When not to use navigator.clipboard.readText(): Never poll clipboard contents on focus; it triggers intrusive browser permission prompts and erodes user trust. | When not to use sendBeacon(): If your code needs the HTTP response status, custom Authorization headers, or payloads > 64 KB, use fetch(..., { keepalive: true }) (for headers/status within 64 KB) or flush eagerly before exit; unlike Async Clipboard, sendBeacon() requires no transient user activation. |
Engine Mechanics & Trade-Offs
The browser gates OS pasteboard IPC behind HTTPS, document focus, and a decaying transient activation token, re-encoding images to strip exploit payloads.
Key Pitfalls: Awaiting before calling write(): Even a 300ms fetch() before navigator.clipboard.writeText() triggers NotAllowedError in Safari; wrap the fetch() inside ClipboardItem. Unfocused document or iframe: Calling clipboard methods inside an iframe without allow="clipboard-write" or while DevTools holds focus throws NotAllowed
The renderer hands the serialized payload to the browser network process with a 64 KB keepalive cap so the OS socket survives tab destruction.
Key Pitfalls: Wiring sendBeacon() to unload: Any unload listener disqualifies the document from bfcache in Chrome and Firefox; use visibilitychange and pagehide. Ignoring the boolean return value: sendBeacon() never throws on quota overflow, it silently returns false when the 64 KB buffer is exhausted.