Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda