network layer: change beacon creation, publish .4
This commit is contained in:
parent
1b748293d5
commit
1bf697e5d9
3 changed files with 7 additions and 10 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<T extends typeof navigator.sendBeacon> 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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue