Created
April 18, 2023 18:47
-
-
Save adrianhorning08/4cef92457b9987ce4f293d93ad139b21 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
function convertHtml(text) { | |
const newHtml = text.replace(/>/g, ">").replace(/</g, "<"); | |
return newHtml; | |
} | |
async function renderPageToHtml(page) { | |
const iframes = await page.$$("iframe"); | |
for (const iframe of iframes) { | |
const frame = await iframe.contentFrame(); | |
if (!frame) continue; | |
const frameWithinFrame = await frame.$$("iframe#Iframe1"); | |
const frameWithinFrame2 = await frameWithinFrame[0].contentFrame(); | |
const context = await frameWithinFrame2.executionContext(); | |
// 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