From c76aed39f7fbe2d641ccdb6be862436b1d6c07e3 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Mon, 7 Oct 2024 16:41:01 +0200 Subject: [PATCH] fix domain name -> event.source --- tracker/tracker/package.json | 2 +- tracker/tracker/src/main/app/index.ts | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tracker/tracker/package.json b/tracker/tracker/package.json index b8e07772f..ce8d5c5fc 100644 --- a/tracker/tracker/package.json +++ b/tracker/tracker/package.json @@ -1,7 +1,7 @@ { "name": "@openreplay/tracker", "description": "The OpenReplay tracker main package", - "version": "14.0.10-beta.5", + "version": "14.0.10-beta.7", "keywords": [ "logging", "replay" diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index 5f924d35c..4b99a9590 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -239,7 +239,6 @@ export default class App { private rootId: number | null = null private pageFrames: HTMLIFrameElement[] = [] private frameOderNumber = 0 - private readonly initialHostName = location.hostname private features = { 'feature-flags': true, 'usability-test': true, @@ -456,11 +455,13 @@ export default class App { if (data.line === proto.iframeSignal) { // @ts-ignore event.source?.postMessage({ ping: true, line: proto.parentAlive }, '*') - const childIframeDomain = data.domain as string const pageIframes = Array.from(document.querySelectorAll('iframe')) this.pageFrames = pageIframes const signalId = async () => { - const id = await this.checkNodeId(pageIframes, childIframeDomain) + if (event.source === null) { + return console.error('Couldnt connect to event.source for child iframe tracking') + } + const id = await this.checkNodeId(pageIframes, event.source) if (id && !this.trackedFrames.includes(id)) { try { this.trackedFrames.push(id) @@ -469,7 +470,6 @@ export default class App { const iframeData = { line: proto.iframeId, context: this.contextId, - domain: childIframeDomain, id, token, frameOrderNumber: this.trackedFrames.length, @@ -494,7 +494,7 @@ export default class App { if (msg[0] === MType.MouseMove) { let fixedMessage = msg this.pageFrames.forEach((frame) => { - if (frame.dataset.domain === event.data.domain) { + if (frame.contentWindow === event.source) { const [type, x, y] = msg const { left, top } = frame.getBoundingClientRect() fixedMessage = [type, x + left, y + top] @@ -505,7 +505,7 @@ export default class App { if (msg[0] === MType.MouseClick) { let fixedMessage = msg this.pageFrames.forEach((frame) => { - if (frame.dataset.domain === event.data.domain) { + if (frame.contentWindow === event.source) { const [type, id, hesitationTime, label, selector, normX, normY] = msg const { left, top, width, height } = frame.getBoundingClientRect() @@ -557,7 +557,6 @@ export default class App { } signalIframeTracker = () => { - const domain = this.initialHostName const thisTab = this.session.getTabId() const signalToParent = (n: number) => { window.parent.postMessage( @@ -565,7 +564,6 @@ export default class App { line: proto.iframeSignal, source: thisTab, context: this.contextId, - domain, }, this.options.crossdomain?.parentDomain ?? '*', ) @@ -587,9 +585,12 @@ export default class App { } } - private async checkNodeId(iframes: HTMLIFrameElement[], domain: string): Promise { + private async checkNodeId( + iframes: HTMLIFrameElement[], + source: MessageEventSource, + ): Promise { for (const iframe of iframes) { - if (iframe.dataset.domain === domain) { + if (iframe.contentWindow && iframe.contentWindow === source) { /** * Here we're trying to get node id from the iframe (which is kept in observer) * because of async nature of dom initialization, we give 100 retries with 100ms delay each @@ -732,7 +733,6 @@ export default class App { { line: proto.iframeBatch, messages: this.messages, - domain: this.initialHostName, }, this.options.crossdomain?.parentDomain ?? '*', )