go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.

Home Page:https://go-rod.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Tomichi opened this issue · comments

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?

Thank you