Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving iFrame content using Playwright

I am trying the contents of iFrame and the iFrame doesn't have an src or URL. It has id element. Below is code I am trying to use . Is there anything I am missing here ? Content is empty

await page.goto("https://sites.google.com/view/pinnednote/home", { waitUntil: 'load', timeout: 30000 });
const myFrames = await page.frames();
console.log("Parent IFrame = "+myFrames.length)

for ( x of myFrames) { // Getting all iFrames
  try {
    const frameElement = await x.frameElement();
    const contentFrame = await frameElement.contentFrame();
    console.log(await contentFrame.content());
  } catch(error){
    console.log(error)
  }
  childs = await x.childFrames();
  console.log("Child IFrame = "+childs.length)
  for ( y of childs) { 
    const frameElement = await y.frameElement();
    const contentFrame = await frameElement.contentFrame();
    console.log(await contentFrame.content());
  }
}
like image 642
Sunil Avatar asked Oct 17 '25 12:10

Sunil


1 Answers

Try this:

await page.goto("https://sites.google.com/view/pinnednote/home", { waitUntil: 'load', timeout: 30000 });
const myFrames = await page.frames();
console.log("Parent IFrame = "+myFrames.length)

for ( x of myFrames) { // Getting all iFrames
  try {
    const frameContent = await x.content();
    console.log(frameContent)
  } catch(error){
    console.log(error)
  }
}

You already have the frames in your myFrames array. When you are making the loop you only need to take the content.

like image 100
Jaky Ruby Avatar answered Oct 21 '25 00:10

Jaky Ruby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!