1.2 Where sendBeacon lives: Window only
Navigator versus WorkerNavigator, the two-step feature detection that covers every runtime, and an honest separation of spec maturity from shipping folklore.
Basic
An API's signature tells you how to call it; its exposure tells you where you can call it at all.
sendBeacon is defined on the
Navigator interface — the object pages know as
window.navigator. Workers expose a different interface,
WorkerNavigator, which shares many members but was never given
sendBeacon. The method exists in ordinary page contexts and nowhere else: not in dedicated workers, not in shared workers, not in service workers.
This is not an oversight the spec warns you about in prose — it is simply the shape of the IDL. There is no note, no deprecation, no runtime guard: inside a worker,
navigator.sendBeacon is
undefined, and calling it as if it existed throws a plain
TypeError about reading a property of undefined. Code that needs to send telemetry from both worlds must detect, then choose — which is exactly the pattern the isomorphic-sender recipe later in this series implements.
Feature detection done right
Because the method can be absent, the guard is not optional. Two checks are needed, and the order matters.
typeof navigator protects non-browser hosts (server-side rendering, Node tooling) where the global does not exist at all — dereferencing it would throw before you ever reach the second check.
typeof navigator.sendBeacon === 'function' then confirms the member in contexts where
navigator exists but the method does not — which is precisely the worker case:
Output
Ready to run.
Notice what the example does not do: it does not sniff user-agent strings, does not consult a version table, and does not try to detect workers specifically. Capability detection collapses all of those cases — old browsers, worker contexts, sandboxed frames with unusual permissions — into one branch that is true exactly when a call would work.
Browser support, stated honestly
Specification maturity and shipping reality are different axes, and this series keeps them separate. On the spec axis, Beacon has been stable for years: the published Candidate Recommendation Draft and the live Editor's Draft are substantively identical, and the processing model has not changed in substance since 2017. On the shipping axis, every current engine implements
sendBeacon — it shipped progressively across browsers during the mid-2010s and has been universal on the evergreen web for a long time. For any concrete minimum version (which mobile vendor dropped support in which year, which engine shipped first), consult current browser-compatibility data at the time you read this, because those tables change and this series does not reproduce them — nothing in the specification pins them.
Quick check
Inside a dedicated worker, what does the correct guard check first?
if (typeof !== 'undefined') { /* ... */ }
Key takeaways
-
sendBeacon is exposed on
Navigator— ordinary pages only.WorkerNavigatornever had it. -
In any worker global,
navigator.sendBeaconisundefined— no spec note warns you; the IDL shape is the whole story. -
Detect with
typeof navigatorthentypeof navigator.sendBeacon === 'function'— capability, not versions. - Spec stability and shipping status are separate questions; verify per-version claims against live compatibility data, not folklore.
-
Workers send telemetry with
fetch(url, {keepalive: true})— the substitute the workers page of this series develops.
Thanks for your feedback.
Mark this learning resource complete to track your learning progress.