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

269
Views
Create new context for the iframe with chromedp

I couldn't find all the pieces that answer my question, so I'm sorry if this question is duplicated.

I'm working with Go and chromedp, and my challenge is to scroll the element in the iframe to somewhere visible.

Unfortunately the iframe's space is very tight in the page, so a lot of inputs and buttons are hidden behind the main page and chromedp's Click command doesn't work as expected because it clicks on the main page where the iframe's element is located at.

The solution I've used until recently was locate the element as regular element like chromedp.Nodes("iframe", chromedp.ByQuery)} and execute element.scrollIntoView() JS command via chromedp.EvaluateAsDevTools() but this recently this solution started failing with error message

Reason: exception "Uncaught" (1:4): TypeError: Cannot read properties of undefined (reading 'scrollIntoView')
    at <anonymous>:2:5
    at <anonymous>:3:4

After researching about it, I've found out that the reason is that JS is executed on the main browser's context instead of the iframe's, and chrome doesn't allow the parent html page to access iframe's html, even when running chrome with --disable-web-security flag.

So, I'm now trying to create a new chromedp's context pointing to the iframe instead of the main browser hoping that would allow run the JS command mentioned above.

Seems that chromedp is not adding a new Target for the iframe, so the code doesn't find the iframe's target anymore.
To find te iframe's target, I'm doing the following way:

var tgt *target.Info
targets, _ := chromedp.Targets(testContext)
for _, t := range targets {
  if t.Type == "iframe" && strings.Contains(t.URL, targetUrl) {
    tgt = t
    break
  }
}

Could someone please give me a hint about how I could fix my problem? Thanks in advance

about 4 years ago · Juan Pablo Isaza
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!