Skip to content

Commit

Permalink
fix for loading iframes with custom web components in chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
megboehlert committed Jan 22, 2025
1 parent 83c66c4 commit 66eeb13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-planes-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb-snapshot": minor
---

fix for iframe loads in chrome - specifically iframes with custom web components
10 changes: 5 additions & 5 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export function needMaskingText(
}

// https://stackoverflow.com/a/36155560
// https://stackoverflow.com/a/69694808 (for handling blank frames in chrome)
function onceIframeLoaded(
iframeEl: HTMLIFrameElement,
listener: () => unknown,
Expand Down Expand Up @@ -342,16 +343,15 @@ function onceIframeLoaded(
}
// check blank frame for Chrome
const blankUrl = 'about:blank';
if (
win.location.href !== blankUrl ||
iframeEl.src === blankUrl ||
iframeEl.src === ''
if ((iframeEl.src === blankUrl ||
(iframeEl.src !== blankUrl && win.location.href !== blankUrl)) &&
readyState === 'complete'
) {
// iframe was already loaded, make sure we wait to trigger the listener
// till _after_ the mutation that found this iframe has had time to process
setTimeout(listener, 0);

return iframeEl.addEventListener('load', listener); // keep listing for future loads
return iframeEl.addEventListener('load', listener); // keep listening for future loads
}
// use default listener
iframeEl.addEventListener('load', listener);
Expand Down

0 comments on commit 66eeb13

Please sign in to comment.