fix: wrong rootId value in special iframes (#1100)

1. When some same-origin iframes are nested in cross-origin iframes, their `rootId`s are wrong.

2. The property `rootId` is missing in serialized cross-origin iframes
This commit is contained in:
Yun Feng
2026-04-01 12:00:00 +08:00
committed by GitHub
parent d97c82c41d
commit d5ff6efc9a
5 changed files with 639 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import type { Page } from 'puppeteer';
import type { eventWithTime, recordOptions } from '../../src/types';
import type { eventWithTime } from '@rrweb/types';
import type { recordOptions } from '../../src/types';
import { startServer, launchPuppeteer, ISuite, getServerURL } from '../utils';
const suites: Array<

View File

@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import type { eventWithTime, recordOptions } from '../../src/types';
import type { eventWithTime } from '@rrweb/types';
import type { recordOptions } from '../../src/types';
import { launchPuppeteer, ISuite } from '../utils';
const suites: Array<{

View File

@@ -517,6 +517,24 @@ describe('cross origin iframes', function (this: ISuite) {
serverBURL: string;
};
it('should record same-origin iframe in cross-origin iframe', async () => {
const frame = ctx.page.mainFrame().childFrames()[0];
await frame.evaluate(() => {
const iframe2 = document.createElement('iframe');
// Append a same-origin iframe in a cross-origin iframe.
document.body.appendChild(iframe2);
iframe2.contentDocument!.body.appendChild(
document.createTextNode('Same-origin iframe in cross-origin iframe'),
);
});
await waitForRAF(ctx.page);
const snapshots = (await ctx.page.evaluate(
'window.snapshots',
)) as eventWithTime[];
assertSnapshot(snapshots);
});
it('should filter out forwarded cross origin rrweb messages', async () => {
const frame = ctx.page.mainFrame().childFrames()[0];
const iframe2URL = `${ctx.serverBURL}/html/blank.html`;
@@ -533,10 +551,11 @@ describe('cross origin iframes', function (this: ISuite) {
// Wait for iframe2 to load
await ctx.page.waitForFrame(iframe2URL);
const iframe2 = frame.childFrames()[0];
// Record iframe2
await injectRecordScript(frame.childFrames()[0]);
await injectRecordScript(iframe2);
await waitForRAF(frame.childFrames()[0]);
await waitForRAF(iframe2);
const snapshots = (await ctx.page.evaluate(
'window.snapshots',
)) as eventWithTime[];