Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for loading iframes with custom web components in chrome #1635

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 5 additions & 4 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 @@ -343,15 +344,15 @@ function onceIframeLoaded(
// check blank frame for Chrome
const blankUrl = 'about:blank';
if (
win.location.href !== blankUrl ||
iframeEl.src === blankUrl ||
iframeEl.src === ''
(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