change(tracker): fix iframe network handling

This commit is contained in:
nick-delirium 2023-04-11 17:46:34 +02:00
parent d74ed000fa
commit 0e1ba6650d
4 changed files with 20 additions and 2 deletions

View file

@ -4,6 +4,7 @@
- remove useless logs
- added gzip compression to large messages
- tune mouse thrashing detection
- fix iframe handling
# 6.0.0

View file

@ -1,7 +1,7 @@
{
"name": "@openreplay/tracker",
"description": "The OpenReplay tracker main package",
"version": "6.0.1",
"version": "6.0.1-beta.1",
"keywords": [
"logging",
"replay"

View file

@ -8,7 +8,7 @@ import IFrameOffsets, { Offset } from './iframe_offsets.js'
import { CreateDocument } from '../messages.gen.js'
import App from '../index.js'
import { IN_BROWSER, hasOpenreplayAttribute } from '../../utils.js'
import { IN_BROWSER, hasOpenreplayAttribute, canAccessIframe } from '../../utils.js'
export interface Options {
captureIFrames: boolean
@ -75,6 +75,7 @@ export default class TopObserver extends Observer {
//log
return
}
if (!canAccessIframe(iframe)) return
const currentWin = iframe.contentWindow
const currentDoc = iframe.contentDocument
if (currentDoc && currentDoc !== doc) {

View file

@ -81,3 +81,19 @@ export function hasOpenreplayAttribute(e: Element, attr: string): boolean {
return false
}
export function isIframeCrossdomain(e: HTMLIFrameElement): boolean {
try {
return e.contentWindow?.location.href !== window.location.href
} catch (e) {
return true
}
}
export function canAccessIframe(iframe: HTMLIFrameElement) {
try {
return Boolean(iframe.contentDocument)
} catch (e) {
return false
}
}