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",
|
"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.",
|
"description": "this library helps us to create proxy objects for fetch, XHR and beacons for proper request tracking.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.js",
|
"module": "dist/index.js",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import NetworkMessage from './networkMessage'
|
import NetworkMessage from './networkMessage'
|
||||||
import { RequestState, INetworkMessage, RequestResponseData } from './types';
|
import { INetworkMessage, RequestResponseData } from './types';
|
||||||
import { genStringBody, getURL } from './utils'
|
import { genStringBody, getURL } from './utils'
|
||||||
|
|
||||||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract
|
// 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 {
|
export default class BeaconProxy {
|
||||||
public static origSendBeacon = typeof window !== 'undefined' ? window.navigator?.sendBeacon : undefined
|
|
||||||
|
|
||||||
public static hasSendBeacon() {
|
|
||||||
return !!BeaconProxy.origSendBeacon
|
|
||||||
}
|
|
||||||
|
|
||||||
public static create(
|
public static create(
|
||||||
|
originalSendBeacon: typeof window.navigator.sendBeacon,
|
||||||
ignoredHeaders: boolean | string[],
|
ignoredHeaders: boolean | string[],
|
||||||
setSessionTokenHeader: (cb: (name: string, value: string) => void) => void,
|
setSessionTokenHeader: (cb: (name: string, value: string) => void) => void,
|
||||||
sanitize: (data: RequestResponseData) => RequestResponseData | null,
|
sanitize: (data: RequestResponseData) => RequestResponseData | null,
|
||||||
sendMessage: (item: INetworkMessage) => void,
|
sendMessage: (item: INetworkMessage) => void,
|
||||||
isServiceUrl: (url: string) => boolean,
|
isServiceUrl: (url: string) => boolean,
|
||||||
) {
|
) {
|
||||||
if (!BeaconProxy.hasSendBeacon()) {
|
if (!originalSendBeacon) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
return new Proxy(
|
return new Proxy(
|
||||||
BeaconProxy.origSendBeacon,
|
originalSendBeacon,
|
||||||
new BeaconProxyHandler(
|
new BeaconProxyHandler(
|
||||||
ignoredHeaders,
|
ignoredHeaders,
|
||||||
setSessionTokenHeader,
|
setSessionTokenHeader,
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,9 @@ export default function createNetworkProxy(
|
||||||
}
|
}
|
||||||
if (modules.beacon) {
|
if (modules.beacon) {
|
||||||
if (context.navigator?.sendBeacon) {
|
if (context.navigator?.sendBeacon) {
|
||||||
|
const origBeacon = context.navigator.sendBeacon
|
||||||
context.navigator.sendBeacon = BeaconProxy.create(
|
context.navigator.sendBeacon = BeaconProxy.create(
|
||||||
|
origBeacon,
|
||||||
ignoredHeaders,
|
ignoredHeaders,
|
||||||
setSessionTokenHeader,
|
setSessionTokenHeader,
|
||||||
sanitize,
|
sanitize,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue