rod: Can't access iframe on some websites

Rod Version: v0.102.0

The code to demonstrate your question

package main

import (
	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/defaults"
)

func main() {
	defaults.Show = true

	page := rod.New().MustConnect().NoDefaultDevice().MustPage("https://captcha.website")
	f := page.MustElement("div:not([style*='display:']) > iframe[data-hcaptcha-widget-id]").MustFrame()
	f.MustElement("#checkbox")
}

The code above will panic. It works fine on headless mode.

About this issue

Commits related to this issue

Most upvoted comments

A temp solution is to use PageFromTargetID to create a standalone page for the iframe:

package main

import (
	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/defaults"
	"github.com/go-rod/rod/lib/proto"
	"github.com/go-rod/rod/lib/utils"
)

func main() {
	defaults.Show = true

	page := rod.New().MustConnect().NoDefaultDevice().MustPage("https://captcha.website")
	f := page.MustElement("div:not([style*='display:']) > iframe[data-hcaptcha-widget-id]").MustFrame()
	p := page.Browser().MustPageFromTargetID(proto.TargetTargetID(f.FrameID))
	p.MustElement("#checkbox").MustClick()
	utils.Pause()
}

I will take some time to redesign how the js runtime works to completely resolve this issue.

A temp solution is to download an older version of Chromium and replace the current version of Chromium. I successfuly tested my code with on version 884014

Any update on this?

Your temp solution didn’t work on it me.

I’m getting “Command can only be executed on top-level targets” error when PageFromTarget(proto.TargetTargetID(f.FrameID)) which f is what I got from calling el.Frame(). Wondering is this a same issue? then why the error is so different? BTW, no success with other suggested solutions (not tried old Chromium version though as I don’t see it as a sustainable solution). FYI, I’m trying to create a test that needs filling credit card information in Stripe iframe form.

@tlopo I have opened an issue on puppeteer, but no update yet