impl shadow DOM manager

part of #38
1. observe DOM mutations in shadow DOM
2. rebuild DOM mutations in shadow DOM
This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 66c7c8f028
commit 0e688bba0c
12 changed files with 680 additions and 48 deletions

View File

@@ -419,4 +419,41 @@ describe('record integration tests', function (this: ISuite) {
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots, __filename, 'iframe');
});
it('should record shadow DOM', async () => {
const page: puppeteer.Page = await this.browser.newPage();
await page.goto('about:blank');
await page.setContent(getHtml.call(this, 'shadow-dom.html'));
await page.evaluate(() => {
const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
const el = document.querySelector('.my-element') as HTMLDivElement;
const shadowRoot = el.shadowRoot as ShadowRoot;
shadowRoot.appendChild(document.createElement('p'));
sleep(1)
.then(() => {
shadowRoot.lastChild!.appendChild(document.createElement('p'));
return sleep(1);
})
.then(() => {
const firstP = shadowRoot.querySelector('p') as HTMLParagraphElement;
shadowRoot.removeChild(firstP);
return sleep(1);
})
.then(() => {
(shadowRoot.lastChild!.childNodes[0] as HTMLElement).innerText = 'hi';
return sleep(1);
})
.then(() => {
(shadowRoot.lastChild!.childNodes[0] as HTMLElement).innerText =
'123';
});
});
await page.waitFor(50);
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots, __filename, 'shadow-dom');
});
});