Example 1 — Queue a Beacon
Send a small string payload and check whether it was queued.
if (typeof navigator.sendBeacon !== "function") {
console.log("sendBeacon unavailable");
} else {
const ok = navigator.sendBeacon("/log", "session=demo");
console.log(ok); // true if queued
} How It Works
- Detect. Older environments may lack the method.
- Call. First argument is the URL; second is optional body data.
- Queue. The browser schedules an async POST — your code does not wait.
- Read
ok.truemeans queued, not “server accepted.”

