diff --git a/.changeset/nice-planes-dress.md b/.changeset/nice-planes-dress.md new file mode 100644 index 0000000000..532c0aee67 --- /dev/null +++ b/.changeset/nice-planes-dress.md @@ -0,0 +1,5 @@ +--- +"rrweb-snapshot": minor +--- + +fix for iframe loads in chrome - specifically iframes with custom web components diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 0e8ec68be9..a07e44270b 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -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, @@ -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);