Skip to content

Instantly share code, notes, and snippets.

@dwsmart
Last active December 6, 2019 15:52
Show Gist options
  • Save dwsmart/15268239a08149661bf9647b02cd995d to your computer and use it in GitHub Desktop.
Save dwsmart/15268239a08149661bf9647b02cd995d to your computer and use it in GitHub Desktop.
Puppeteer Shadow Dom > Dom
const puppeteer = require('puppeteer');
const url = process.env.URL || 'https://lit-element.polymer-project.org/';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
await page.evaluate(() => {
// loop through elements and copy shadow to inner
for (let element of document.getElementsByTagName('*')) {
if (element.shadowRoot) element.innerHTML = element.shadowRoot.innerHTML;
}
});
let bodyHTML = await page.content();
console.log(bodyHTML);
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment