We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Rod Version: v0.116.2
通过开启多协程来访问网站并截图时,截图会失败,如果协程数量为1则不会。
package main import ( "errors" "fmt" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/proto" "github.com/remeh/sizedwaitgroup" "github.com/ysmood/leakless/pkg/utils" "log" "strings" "time" ) func main() { url := []string{ "https://cn.bing.com/", "https://www.baidu.com/", "https://www.qq.com/", "https://www.163.com/", "https://www.sohu.com/", "https://www.sogou.com/", "https://www.youku.com/"} b, err := New() if err != nil { log.Fatal(err) } defer b.Close() wg := sizedwaitgroup.New(3) for _, u := range url { wg.Add() go func(u string) { defer wg.Done() page, err := b.Page(proto.TargetCreateTarget{}) if err != nil { log.Printf("could not create target, url=%s, err=%s", u, err) } defer page.Close() //hijack //do something timeout := 30 * time.Second page = page.Timeout(timeout) waitNavigation := page.WaitNavigation(proto.PageLifecycleEventNameFirstMeaningfulPaint) err = page.Navigate(u) if err != nil { log.Printf("could not navigate target, url=%s, err=%s", u, err) } else { waitNavigation() } page.WaitLoad() w := page.WaitRequestIdle(1*time.Second, nil, nil, nil) w() println(u) println("TargetID: " + page.TargetID) println("FrameID: " + page.FrameID) println("SessionID: " + page.SessionID) bin, err := page.Screenshot(true, nil) if err != nil { log.Printf("could not take screenshot, url=%s, err=%s", u, err) } path := fmt.Sprintf("screenshots/%s.png", strings.SplitN(u, "/", 4)[2]) err = utils.OutputFile(path, bin, nil) if err != nil { log.Printf("could not save screenshot, url=%s, err=%s", u, err) } }(u) } wg.Wait() } func New() (*rod.Browser, error) { chromeLauncher := launcher.New(). Leakless(false). Append("disable-infobars", ""). Append("disable-extensions", ""). Set("disable-web-security"). Set("allow-running-insecure-content"). Set("reduce-security-for-testing"). Set("disable-gpu", "true"). Set("ignore-certificate-errors", "true"). Set("ignore-certificate-errors", "1"). Set("disable-crash-reporter", "true"). Set("disable-breakpad", "true"). Set("disable-notifications", "true"). //Set("window-size", fmt.Sprintf("%d,%d", 1080, 1920)). Set("hide-scrollbars", "true"). Set("mute-audio", "true"). Set("incognito", "true"). Bin("/chrome-mac/Chromium.app/Contents/MacOS/Chromium") chromeLauncher.Headless(false) //chromeLauncher.Set("engine", "new") launcherURL, launcherErr := chromeLauncher.Launch() if launcherErr != nil { return nil, launcherErr } browser := rod.New().NoDefaultDevice().ControlURL(launcherURL) if browserErr := browser.Connect(); browserErr != nil { return nil, browserErr } incognito, err := browser.Incognito() if err != nil { chromeLauncher.Kill() return nil, errors.New("failed to create incognito browser") } return incognito, nil }
协程为1时,截图正常 wg := sizedwaitgroup.New(1)
协程为3时,部分截图失败,并且每次截图失败的网站不同
The text was updated successfully, but these errors were encountered:
Please fix the format of your markdown:
139:1 MD033/no-inline-html Inline HTML [Element: img] 142:1 MD033/no-inline-html Inline HTML [Element: img]
generated by check-issue
Sorry, something went wrong.
建议开启 headlless model 截图试试
headlless model
在 headless 模式下应该使得页面中的元素具备了“可见性”“可交互性”等,即使用户不处于当前页面 但是当处于 headful 模式下只有用户处于的这个页面中可视区域的元素才具有“可见性”和“可交互性”
No branches or pull requests
Rod Version: v0.116.2
问题描述
通过开启多协程来访问网站并截图时,截图会失败,如果协程数量为1则不会。
示例代码
协程为1时,截图正常
wg := sizedwaitgroup.New(1)
协程为3时,部分截图失败,并且每次截图失败的网站不同
The text was updated successfully, but these errors were encountered: