From 0e90603d945aead0dc774dcf96c43a85c3397283 Mon Sep 17 00:00:00 2001 From: "James M. Greene" Date: Fri, 2 Jul 2021 14:42:42 -0500 Subject: [PATCH] Only send beacons if the feature is not disabled (#20282) Fixes https://github.com/github/docs-internal/issues/20263 --- javascripts/events.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/javascripts/events.ts b/javascripts/events.ts index db0abac290..f29321d369 100644 --- a/javascripts/events.ts +++ b/javascripts/events.ts @@ -103,8 +103,13 @@ export function sendEvent({ type, version = '1.0.0', ...props }: SendEventProps) ...props, } - const blob = new Blob([JSON.stringify(body)], { type: 'application/json' }) - navigator.sendBeacon('/events', blob) + + // Only send the beacon if the feature is not disabled in the user's browser + if (navigator?.sendBeacon) { + const blob = new Blob([JSON.stringify(body)], { type: 'application/json' }) + navigator.sendBeacon('/events', blob) + } + return body }