Skip to content

Instantly share code, notes, and snippets.

@adrianhorning08
Created April 18, 2023 18:47
Show Gist options
  • Save adrianhorning08/4cef92457b9987ce4f293d93ad139b21 to your computer and use it in GitHub Desktop.
Save adrianhorning08/4cef92457b9987ce4f293d93ad139b21 to your computer and use it in GitHub Desktop.
function convertHtml(text) {
const newHtml = text.replace(/&gt;/g, ">").replace(/&lt;/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