go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.25k stars 345 forks source link

How run multiple instances of chrome and have one manager go rod which handle this instances #1000

Closed Tomichi closed 8 months ago

Tomichi commented 8 months ago

Rod Version: v0.114.5

Question

Hi, I would like to ask or point you in the right direction. I would like to run several instances of ghcr.io/go-rod/rod chrome browsers in Docker containers and have one Docker container that would manage sending requests to individual Docker instances of Google chrome something like "Load balancer" or "SeleniumGrid". I don't know how to link calls to multiple Google chrome instances in a target driving container. Can you give me some advice on how to do this?

docker-compose.yml

 chrome-01:
    container_name: chrome-01
    image: ghcr.io/go-rod/rod
    command: ["chrome", "--headless", "--disable-dev-shm-usage", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=9222", "--remote-debugging-address=0.0.0.0"]
      ...
chrome-0n:
    container_name: chrome-0n
    image: ghcr.io/go-rod/rod
    command: ["chrome", "--headless", "--disable-dev-shm-usage", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=9222", "--remote-debugging-address=0.0.0.0"]

and in main.go

connectURL := launcher.MustResolveURL("ws://chrome-01:9222")
browser := rod.New().ControlURL(connectURL).MustConnect()

Is there any better idea than have it counter and static array of name of docker-chrome instances? Is it possible to hide instances to one url like load balance?

ysmood commented 8 months ago

https://go-rod.github.io/#/custom-launch?id=remotely-manage-the-launcher

Tomichi commented 8 months ago

Thank you