diff --git a/networkProxy/package.json b/networkProxy/package.json index 918b352c6..4e3828f9c 100644 --- a/networkProxy/package.json +++ b/networkProxy/package.json @@ -1,6 +1,6 @@ { "name": "@openreplay/network-proxy", - "version": "1.0.3", + "version": "1.0.4", "description": "this library helps us to create proxy objects for fetch, XHR and beacons for proper request tracking.", "main": "dist/index.js", "module": "dist/index.js", diff --git a/networkProxy/src/beaconProxy.ts b/networkProxy/src/beaconProxy.ts index 7d2581c17..cc32c1d0d 100644 --- a/networkProxy/src/beaconProxy.ts +++ b/networkProxy/src/beaconProxy.ts @@ -1,5 +1,5 @@ import NetworkMessage from './networkMessage' -import { RequestState, INetworkMessage, RequestResponseData } from './types'; +import { INetworkMessage, RequestResponseData } from './types'; import { genStringBody, getURL } from './utils' // https://fetch.spec.whatwg.org/#concept-bodyinit-extract @@ -74,24 +74,19 @@ export class BeaconProxyHandler implement } export default class BeaconProxy { - public static origSendBeacon = typeof window !== 'undefined' ? window.navigator?.sendBeacon : undefined - - public static hasSendBeacon() { - return !!BeaconProxy.origSendBeacon - } - public static create( + originalSendBeacon: typeof window.navigator.sendBeacon, ignoredHeaders: boolean | string[], setSessionTokenHeader: (cb: (name: string, value: string) => void) => void, sanitize: (data: RequestResponseData) => RequestResponseData | null, sendMessage: (item: INetworkMessage) => void, isServiceUrl: (url: string) => boolean, ) { - if (!BeaconProxy.hasSendBeacon()) { + if (!originalSendBeacon) { return undefined } return new Proxy( - BeaconProxy.origSendBeacon, + originalSendBeacon, new BeaconProxyHandler( ignoredHeaders, setSessionTokenHeader, diff --git a/networkProxy/src/index.ts b/networkProxy/src/index.ts index c452eddfc..49e0ca122 100644 --- a/networkProxy/src/index.ts +++ b/networkProxy/src/index.ts @@ -85,7 +85,9 @@ export default function createNetworkProxy( } if (modules.beacon) { if (context.navigator?.sendBeacon) { + const origBeacon = context.navigator.sendBeacon context.navigator.sendBeacon = BeaconProxy.create( + origBeacon, ignoredHeaders, setSessionTokenHeader, sanitize,