Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page.MustExpose not work in launcher.NewAppMode() #1038

Closed
hktalent opened this issue Apr 14, 2024 · 2 comments
Closed

page.MustExpose not work in launcher.NewAppMode() #1038

hktalent opened this issue Apr 14, 2024 · 2 comments
Labels
enhance New feature or request

Comments

@hktalent
Copy link

hktalent commented Apr 14, 2024

@ysmood
Rod Version: v0.114.8
go version go1.21.4 darwin/amd64

page.MustExpose can not work in launcher.NewAppMode()

chromeLauncher := launcher.New().
		Headless(false).
		Set(flags.Env, "GOOGLE_API_KEY=no").
		Delete("no-startup-window").
		Delete("enable-automation").
		Set(flags.App, szUrl).
...
launcherURL, err := chromeLauncher.Launch()
	if err != nil {
		log.Println(err)
		return
	}
	browser := rod.New().ControlURL(launcherURL)
	if err = browser.Connect(); err != nil {
		log.Println(err)
		return
	}
var page *rod.Page
	if p, err := browser.Pages(); nil == err && 0 < len(p) {
		page = p[0]
		page.MustEvalOnNewDocument(`console.log=window.confirm=window.alert=()=>{}`)
		// 封装的 Go 方法,供浏览器的 JavaScript 调用
		page.MustExpose("SaveMp4", func(s gson.JSON) (interface{}, error) {
log.Println("SaveMp4 now work")
....
return nil, nil
		})

page.MustNavigate(szUrl)

page.MustWaitLoad()

time.Sleep(time.Duration(nMxt) * time.Second)
	// 等待浏览器关闭
	browser.MustClose()

@hktalent hktalent added the enhance New feature or request label Apr 14, 2024
Copy link

Please fix the format of your markdown:

1:8 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
6 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
6 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]

generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Apr 15, 2024

Could you provide more details?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants