Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

365
Views
Target an iFrame using Node.js/Puppeteer

Is it possible to target an iFrame when using the GUI Workflow builder in AWS Cloudwatch Synthetics?

I've set up the canary to log in to a website and redirect the page which has run successfully, but one of the elements I need to check with Node.js is within an iFrame which isn't being recognised.

This is the iframe code. It loads from Javascript, but all content is from the same domain:

<iframe id="paramsFrame" src="empty.htm" frameborder="0" ppTabId="-1"
                    onload="paramsDocumentLoaded('paramsFrame', true);"></iframe>

This is the code I'm using for this section, but it's just returning a timeout error:

   await synthetics.executeStep('verifyText', async function() {
    const elementHandle = await page.waitForSelector('#paramsFrame');
    const frame = await elementHandle.contentFrame();
    await frame.waitForXPath("//div[@class=\'css7\'][contains(text(),'Specificity')]", { timeout: 30000 });
})

This code is trying to target a div with class css7 found within an iframe with id paramsFrame

Edit: I did a null check on frame and it came back as not null, not sure if that is relevant.

I also tried to target an element directly:

const next = await frame.waitForSelector('.protocol-name-link');

but I got the error message:

TimeoutError: waiting for selector .protocol-name-link

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If the iframe is on a different origin (e.g. different domain), you cannot access it through Puppeteer.

You can try to disable some security features of Puppeteer, although this is not advised.

Specifically, you'd probably want to add these args to puppeteer.launch

 --disable-web-security
 --disable-features=IsolateOrigins,site-per-process
about 4 years ago · Juan Pablo Isaza Report

0

I tried running similar code on a website which had a youtube iframe and I didnt need the puppeteer launch args

i.e

args: [
  "--disable-web-security",
  "--disable-features=IsolateOrigins,site-per-process",
],

But, First I would like to suggest is for the iframe try to confirm it is the same iframe that you need maybe by logging, debugging or even just going on dev console.

And the second is to use full xpath of the element in the frame.

Here is my code which I tried running.

  const page = await browser.newPage();
  console.log("open page");

  await page.goto("https://captioncrusher.com/");
  console.log("page opened");

  // use this if you want to wait for all the requests to be done.
  // await page.waitForNetworkIdle();

  const elementHandle = await page.waitForSelector("iframe.yt");
  const frame = await elementHandle.contentFrame();

  //These both work for me
  const aLink = await frame.waitForXPath("/html/body/div/div/a");
  const classLink = await frame.waitForSelector(".ytp-impression-link");
 
  await browser.close();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!