Comments (11)
Does this work?
for i := 0; i < 4; i++ {
time.Sleep(time.Second)
from rod.
This is useful for me, can you help me explain the reason for this?
Does this work?
for i := 0; i < 4; i++ { time.Sleep(time.Second)
from rod.
Does this work?
for i := 0; i < 4; i++ { time.Sleep(time.Second)
不行,我这边依旧会卡住,测试平台是win11,浏览器是google chrome ,版本号120.0.6099.130,强制停止时我看到了3个leakless的cmd窗口
from rod.
确实,你单独试试 leakless 呢?不用 rod,这样很容易定位问题在哪。用 leakless 启动一个空服务。看看 leakless 的文档。 有可能是 Windows 的某种兼容问题。
from rod.
linux环境相同结果,排除win的问题
from rod.
mac 也是这样的 应该和环境无关
from rod.
package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
"github.com/samber/lo"
"log"
"os"
"strconv"
"time"
)
func main() {
err := os.RemoveAll("tmp")
if err != nil {
fmt.Println(err)
}
launcher.NewManager()
for i := 0; i < 4; i++ {
userDir := fmt.Sprintf("tmp/%s", lo.RandomString(12, lo.LettersCharset))
u, err := launcher.NewUserMode().Bin("/Applications/Chromium.app/Contents/MacOS/Chromium").
UserDataDir(userDir).
Headless(false).
Leakless(true).
Set("remote-debugging-port", strconv.Itoa(9222+i)). // 使用不同的端口
Set("no-default-browser-check").
Set("no-sandbox").
Set("disable-gpu").
Set("start-maximized").
Launch()
if err != nil {
log.Fatalln("launch:", err)
}
print(u, "\t", userDir, "\n")
b := rod.New().ControlURL(u).MustConnect()
b.Page(proto.TargetCreateTarget{URL: "https://www.baidu.com"})
fmt.Println("browser:", i, "started")
}
}
似乎和启动参数有关系, 如果指定不同的"remote-debugging-port" 端口 也将正常启动.
用同一个端口时我发现, 指定不同的UserDataDir 页面会在同一个浏览器进程里面打开, 而且他们的cookie 是共用的
from rod.
package main import ( "fmt" "github.com/go-rod/rod" "github.com/go-rod/rod/lib/launcher" "github.com/go-rod/rod/lib/proto" "github.com/samber/lo" "log" "os" "strconv" "time" ) func main() { err := os.RemoveAll("tmp") if err != nil { fmt.Println(err) } launcher.NewManager() for i := 0; i < 4; i++ { userDir := fmt.Sprintf("tmp/%s", lo.RandomString(12, lo.LettersCharset)) u, err := launcher.NewUserMode().Bin("/Applications/Chromium.app/Contents/MacOS/Chromium"). UserDataDir(userDir). Headless(false). Leakless(true). Set("remote-debugging-port", strconv.Itoa(9222+i)). // 使用不同的端口 Set("no-default-browser-check"). Set("no-sandbox"). Set("disable-gpu"). Set("start-maximized"). Launch() if err != nil { log.Fatalln("launch:", err) } print(u, "\t", userDir, "\n") b := rod.New().ControlURL(u).MustConnect() b.Page(proto.TargetCreateTarget{URL: "https://www.baidu.com"}) fmt.Println("browser:", i, "started") } }
似乎和启动参数有关系, 如果指定不同的"remote-debugging-port" 端口 也将正常启动. 用同一个端口时我发现, 指定不同的UserDataDir 页面会在同一个浏览器进程里面打开, 而且他们的cookie 是共用的
确实,如果随机端口号的同时随机userdir,则一个浏览器也启动不了
from rod.
命令行同时启动3个不同dir不同端口headless的chrome没有问题
from rod.
那可能是 chrome 在竞争某个端口导致的,我 mac 跑 rod 的单元测试,同时启动 12 个浏览器都没有问题。你可以看看 rod 的单元测试的 setup_test.go
因为 UserMode 会使用同一个端口:
Line 135 in ced12b5
而默认的模式使用的是随机端口:
Line 74 in c945d86
from rod.
那可能是 chrome 在竞争某个端口导致的,我 mac 跑 rod 的单元测试,同时启动 12 个浏览器都没有问题。你可以看看 rod 的单元测试的 setup_test.go
因为 UserMode 会使用同一个端口:
Line 135 in ced12b5
原来如此,感谢您的解答,设置参数RemoteDebuggingPort后没有问题
from rod.
Related Issues (20)
- How run multiple instances of chrome and have one manager go rod which handle this instances HOT 2
- ElementX stuck if you specify a non-existent element HOT 2
- Repeat login HOT 2
- 如何模拟鼠标滚动向下拉取加载数据? HOT 10
- Leakless feature problems... HOT 1
- 当浏览器关闭时,chrome_crashpad_handler和Chromium Helper两个进程没有被关闭。 HOT 3
- Is it possible to improve Screenshot's fullPage implementation? HOT 1
- Why doesn't it remember the window size now? HOT 11
- How to cancel the timeout for Elements (not just one)? HOT 1
- Intercept DevTools disconnection HOT 3
- How to ignore cert errors when HijackRequests is used? HOT 3
- Proxy auth dialog handler is not working in another tab HOT 4
- Is there a way to change or get download directory of browser? HOT 8
- page.Elements result have cache? HOT 1
- navigation failed: net::ERR_INVALID_AUTH_CREDENTIALS HOT 11
- chromium can't login gmail account HOT 11
- Alert Trojan Virus HOT 2
- After setting the default system device, the viewport display height and width are reversed. HOT 2
- hijack无法加载Other类型请求 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rod.