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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Support ShadowDOM for Page.content() #30816

Open
mantou132 opened this issue May 15, 2024 · 0 comments
Open

[Feature]: Support ShadowDOM for Page.content() #30816

mantou132 opened this issue May 15, 2024 · 0 comments

Comments

@mantou132
Copy link

mantou132 commented May 15, 2024

馃殌 Feature Request

current Page.content() not include shadow dom content

Example

API:

await page.content({ serializableShadowRoots: true });

Related spec: https://html.spec.whatwg.org/#dom-parsing-and-serialization

Implement

const doctype = document.doctype
  ? new XMLSerializer().serializeToString(document.doctype)
  : '';
// https://html.spec.whatwg.org/#dom-parsing-and-serialization
if (!('getHTML' in Element.prototype)) {
  return `${doctype}${document.documentElement.outerHTML}`;
}
const body = (document.documentElement as any).getHTML({ serializableShadowRoots: true });
const uid = crypto.randomUUID();
document.documentElement.innerHTML = uid;
return `${doctype}${document.documentElement.outerHTML.replace(
  uid,
  body
)}`;

Motivation

Let the crawler(e.g: renderscript) grab everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants