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
This commit is contained in:
PiRDub 2024-12-05 17:21:24 +01:00 committed by GitHub
parent 27e94fed35
commit 844b9d80c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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