docker - How to Get Browser ID when running chromium-browser command - Stack Overflow

admin2025-04-18  3

I use the zenika/alpine-chrome Docker image in one of my projects. Another container connects to it using a web socket, and I have been able to use it successfully.

The problem is that the browser ID (shown below when the container starts) changes each initialization, and I can’t find a good way to fetch or extract this ID.

Here is the excerpt from my docker-compose.yml file:


....
    chromium:
        image: zenika/alpine-chrome
        command:
          [
              chromium-browser,
              "--headless",
              "--disable-gpu",
              "--remote-debugging-address=0.0.0.0",
              "--remote-debugging-port=9222",
              " --remote-allow-origins=*",
              "--no-sandbox"
          ]
        cap_add:
            - SYS_ADMIN
        networks:
            - sail
        ports:
            - '${FORWARD_CHROMIUM_PORT:-9222}:9222'

....

I was hoping that I could do one of the following:

  1. Use a flag with the chromium-browser command to hard code this ID (this is just used for local development)
  2. Hit an endpoint to get the browser ID.
  3. Extract the ID from the command and pass it to the other container.
  4. Use a "generic" endpoint that doesn't rely upon a browser ID (I've tried, but I get a 404 instead of a 101 response.

UPDATE

I just discovered this endpoint: :9222/json, which does get me what I need; it's not as clean as just the ID, but it will work for now.

转载请注明原文地址:http://anycun.com/QandA/1744955065a89984.html