fix(tracker): safe start/stop callbacks

This commit is contained in:
Alex Kaminskii 2022-08-31 14:22:52 +02:00
parent 6ae9599425
commit 7782679f7d
3 changed files with 16 additions and 10 deletions

View file

@ -233,10 +233,16 @@ export default class App {
// For example - attachEventListener() called during dynamic <iframe> appearance
this.commitCallbacks.push(cb)
}
attachStartCallback(cb: StartCallback): void {
attachStartCallback(cb: StartCallback, useSafe = false): void {
if (useSafe) {
cb = this.safe(cb)
}
this.startCallbacks.push(cb)
}
attachStopCallback(cb: () => any): void {
attachStopCallback(cb: () => any, useSafe = false): void {
if (useSafe) {
cb = this.safe(cb)
}
this.stopCallbacks.push(cb)
}
attachEventListener(
@ -249,8 +255,8 @@ export default class App {
if (useSafe) {
listener = this.safe(listener)
}
this.attachStartCallback(() => target.addEventListener(type, listener, useCapture))
this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture))
this.attachStartCallback(() => target.addEventListener(type, listener, useCapture), useSafe)
this.attachStopCallback(() => target.removeEventListener(type, listener, useCapture), useSafe)
}
// TODO: full correct semantic

View file

@ -61,7 +61,7 @@ export default class TopObserver extends Observer {
private readonly contextCallbacks: Array<ContextCallback> = []
// Attached once per Tracker instance
private readonly contextsSet: Set<Context> = new Set()
private readonly contextsSet: Set<Window> = new Set()
attachContextCallback(cb: ContextCallback) {
this.contextCallbacks.push(cb)
}
@ -105,11 +105,11 @@ export default class TopObserver extends Observer {
currentWin &&
// Sometimes currentWin.window is null (not in specification). Such window object is not functional
currentWin === currentWin.window &&
!this.contextsSet.has(currentWin.window) // for each context callbacks called once per Tracker (TopObserver) instance
!this.contextsSet.has(currentWin) // for each context callbacks called once per Tracker (TopObserver) instance
) {
this.contextsSet.add(currentWin.window)
//+ https://github.com/microsoft/TypeScript/issues/41684
this.contextCallbacks.forEach((cb) => cb(currentWin.window))
this.contextsSet.add(currentWin)
//@ts-ignore https://github.com/microsoft/TypeScript/issues/41684
this.contextCallbacks.forEach((cb) => cb(currentWin))
win = currentWin
}
})

View file

@ -97,7 +97,7 @@ export default class BatchWriter {
this.finaliseBatch()
while (!this.writeWithSize(message)) {
if (this.beaconSize === this.beaconSizeLimit) {
console.warn('OpenReplay: beacon size overflow. Skipping large message.', message)
console.warn('OpenReplay: beacon size overflow. Skipping large message.', message, this)
this.encoder.reset()
this.prepare()
return