From 844b9d80c3363115019e007ecc4955b1dbdc30aa Mon Sep 17 00:00:00 2001 From: PiRDub Date: Thu, 5 Dec 2024 17:21:24 +0100 Subject: [PATCH] fix(tracker): prevent raising security error accessing window.top (#2818) * fix(tracker): prevent raising security error accessing window.top * fix(canAccessTop): check window document access --- tracker/tracker/src/main/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tracker/tracker/src/main/index.ts b/tracker/tracker/src/main/index.ts index 2d090aebf..9349c05ca 100644 --- a/tracker/tracker/src/main/index.ts +++ b/tracker/tracker/src/main/index.ts @@ -97,7 +97,7 @@ function processOptions(obj: any): obj is Options { const canAccessTop = () => { try { - return Boolean(window.top) + return Boolean(window.top?.document) } catch { return false } @@ -116,7 +116,7 @@ export default class API { } if ( (window as any).__OPENREPLAY__ || - (!this.crossdomainMode && inIframe() && canAccessTop() && (window.top as any)?.__OPENREPLAY__) + (!this.crossdomainMode && inIframe() && canAccessTop() && (window.top as any).__OPENREPLAY__) ) { console.error('OpenReplay: one tracker instance has been initialised already') return