Skip to content

Commit

Permalink
Support ShadowDOM
Browse files Browse the repository at this point in the history
Use `getInnerHTML`
  • Loading branch information
mantou132 committed Jan 10, 2024
1 parent 93fad22 commit a2f1eb2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/lib/browser/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,23 @@ export class BrowserPage {
return await promiseWithTimeout(
(async (): Promise<string | null> => {
const start = Date.now();
const content = await this.#ref?.content();
// `getInnerHTML` unstable: https://github.com/whatwg/html/issues/8867
const content = await this.#ref?.evaluate(() => {
const doctype = document.doctype
? new XMLSerializer().serializeToString(document.doctype)
: '';
if (!('getInnerHTML' in Element.prototype)) {
return `${doctype}${document.documentElement.outerHTML}`;
}
const body = (document.body as any).getInnerHTML();
const uid = crypto.randomUUID();
document.body.innerHTML = uid;
return `${doctype}${document.documentElement.outerHTML.replace(
uid,
body
)}`;
});

stats.timing('renderscript.renderBody', Date.now() - start, {
browser: this.#engine as string,
});
Expand Down

0 comments on commit a2f1eb2

Please sign in to comment.