network proxy: prevent referring to window object on import, fixes #2742

This commit is contained in:
nick-delirium 2024-11-14 11:18:06 +01:00
parent f321ffbdda
commit 769d8851bb
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
2 changed files with 3 additions and 2 deletions

View file

@ -74,7 +74,7 @@ export class BeaconProxyHandler<T extends typeof navigator.sendBeacon> implement
} }
export default class BeaconProxy { export default class BeaconProxy {
public static origSendBeacon = window?.navigator?.sendBeacon public static origSendBeacon = typeof window !== 'undefined' ? window.navigator?.sendBeacon : undefined
public static hasSendBeacon() { public static hasSendBeacon() {
return !!BeaconProxy.origSendBeacon return !!BeaconProxy.origSendBeacon

View file

@ -54,6 +54,7 @@ export default function createNetworkProxy(
}, },
tokenUrlMatcher?: (url: string) => boolean, tokenUrlMatcher?: (url: string) => boolean,
): void { ): void {
if (!context) return;
if (modules.xhr) { if (modules.xhr) {
if (context.XMLHttpRequest) { if (context.XMLHttpRequest) {
context.XMLHttpRequest = XHRProxy.create( context.XMLHttpRequest = XHRProxy.create(
@ -83,7 +84,7 @@ export default function createNetworkProxy(
} }
} }
if (modules.beacon) { if (modules.beacon) {
if (context?.navigator?.sendBeacon) { if (context.navigator?.sendBeacon) {
context.navigator.sendBeacon = BeaconProxy.create( context.navigator.sendBeacon = BeaconProxy.create(
ignoredHeaders, ignoredHeaders,
setSessionTokenHeader, setSessionTokenHeader,