diff --git a/networkProxy/src/beaconProxy.ts b/networkProxy/src/beaconProxy.ts index 11eac6e33..7d2581c17 100644 --- a/networkProxy/src/beaconProxy.ts +++ b/networkProxy/src/beaconProxy.ts @@ -74,7 +74,7 @@ export class BeaconProxyHandler implement } export default class BeaconProxy { - public static origSendBeacon = window?.navigator?.sendBeacon + public static origSendBeacon = typeof window !== 'undefined' ? window.navigator?.sendBeacon : undefined public static hasSendBeacon() { return !!BeaconProxy.origSendBeacon diff --git a/networkProxy/src/index.ts b/networkProxy/src/index.ts index f5cd0ca68..c452eddfc 100644 --- a/networkProxy/src/index.ts +++ b/networkProxy/src/index.ts @@ -54,6 +54,7 @@ export default function createNetworkProxy( }, tokenUrlMatcher?: (url: string) => boolean, ): void { + if (!context) return; if (modules.xhr) { if (context.XMLHttpRequest) { context.XMLHttpRequest = XHRProxy.create( @@ -83,7 +84,7 @@ export default function createNetworkProxy( } } if (modules.beacon) { - if (context?.navigator?.sendBeacon) { + if (context.navigator?.sendBeacon) { context.navigator.sendBeacon = BeaconProxy.create( ignoredHeaders, setSessionTokenHeader,