Created
March 6, 2021 11:05
-
-
Save jgontrum/5a9060e40c7fc04c2c3bae3f1a9b28ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async renderPageToHtml(page: Page): Promise<string> { | |
const iframes = await page.$$("iframe"); | |
for (const iframe of iframes) { | |
const frame = await iframe.contentFrame(); | |
if (!frame) continue; | |
const context = await frame.executionContext(); | |
const res = await context.evaluate(() => { | |
const el = document.querySelector("*"); | |
if (el) return el.outerHTML; | |
}); | |
if (res) { | |
await iframe.evaluate((a, res) => { | |
a.innerHTML = res; | |
}, res); | |
} | |
} | |
return await page.evaluate(() => new XMLSerializer().serializeToString(document)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment