Skip to content

Commit f428d6f

Browse files
committed
fix for loading iframes with custom web components in chrome
1 parent 18fcf74 commit f428d6f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/nice-planes-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb-snapshot": minor
3+
---
4+
5+
fix for iframe loads in chrome - specifically iframes with custom web components

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ export function needMaskingText(
308308
}
309309

310310
// https://stackoverflow.com/a/36155560
311+
// https://stackoverflow.com/a/69694808 (for handling blank frames in chrome)
311312
function onceIframeLoaded(
312313
iframeEl: HTMLIFrameElement,
313314
listener: () => unknown,
@@ -342,16 +343,15 @@ function onceIframeLoaded(
342343
}
343344
// check blank frame for Chrome
344345
const blankUrl = 'about:blank';
345-
if (
346-
win.location.href !== blankUrl ||
347-
iframeEl.src === blankUrl ||
348-
iframeEl.src === ''
346+
if ((iframeEl.src === blankUrl ||
347+
(iframeEl.src !== blankUrl && win.location.href !== blankUrl)) &&
348+
readyState === 'complete'
349349
) {
350350
// iframe was already loaded, make sure we wait to trigger the listener
351351
// till _after_ the mutation that found this iframe has had time to process
352352
nativeSetTimeout(listener, 0);
353353

354-
return iframeEl.addEventListener('load', listener); // keep listing for future loads
354+
return iframeEl.addEventListener('load', listener); // keep listening for future loads
355355
}
356356
// use default listener
357357
iframeEl.addEventListener('load', listener);

0 commit comments

Comments
 (0)