Running Selenium in a Docker instance on an Apple M1 Pro

60 Views Asked by At

I am trying to run Selenium Standalone Chrome on docker. The idea is to connect to it with a Python program using webdriver.Remote(url, options).

Unfortunately I bump into issues. I also read quite some pages explaining AMD64 vs. ARM64. Hence, I already switched to using the seleniarm/standalone-chromium image. I start up the instance with the following command:

$ docker run --rm -it -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-chromium:latest 

This runs happily, and when going to http://localhost:4444 I do see the UI with one available session.

However, when I now try to connect to this instance in my local Python program, it keeps hanging

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Remote(command_executor=f"http://localhost:4444", options=chrome_options)

I am running my program locally (not in a Docker), so the URL should be fine.

When I try to connect to a Selenium container which I span up on my Qnap Container Station (but using the image selenium/standalone-chrome:latest), it just works (indicating this is an issue with my local M1 Pro setup).

When diving into the Selenium log files (fcr. below), I see things like "browserVersion": "." and Driver info: driver.version: unknown. Sounds fudgy to me, and after searching quite a while, I don't see other people with the same issue or logs with a browserVersion that's just a dot. All logs I find on the web, all have a browserVersion defined. Already tried with different images (instead of only :latest), but without luck, they all show the same behaviour.

Searching for the issue DevToolsActivePort file doesn't exist (which appears when trying to connect with my Python program) gives me a few threads indicating I have to set arguments like --headless, --no-sandbox etc., none of those solves my issue though (they do cause that specific message to no longer appear, but they end up in a different failure chrome not reachable).

 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [--no-sandbox, --headless, --disable-gpu, --disable-dev-shm-usage, --remote-debugging-port=9222], extensions: []}, pageLoadStrategy: normal}]
16:14:43.056 WARN [DriverServiceSessionFactory.apply] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: chrome not reachable

If anybody could give me some hints what to try next, would be great!

(.venv) ➜  utils git:(main) ✗ docker run --rm -it -p 4444:4444 -p 5900:5900 -p 7900:7900 --shm-size 2g seleniarm/standalone-chromium:latest 
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
2024-03-10 15:48:44,890 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2024-03-10 15:48:44,903 INFO RPC interface 'supervisor' initialized
2024-03-10 15:48:44,903 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2024-03-10 15:48:44,905 INFO supervisord started with pid 12
2024-03-10 15:48:45,938 INFO spawned: 'xvfb' with pid 15
2024-03-10 15:48:45,950 INFO spawned: 'vnc' with pid 17
2024-03-10 15:48:45,960 INFO spawned: 'novnc' with pid 19
2024-03-10 15:48:45,978 INFO spawned: 'selenium-standalone' with pid 21
2024-03-10 15:48:46,070 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2024-03-10 15:48:46,070 INFO success: vnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2024-03-10 15:48:46,070 INFO success: novnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2024-03-10 15:48:46,071 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
Appending Selenium options: --heartbeat-period 30
Appending Selenium options: --reject-unsupported-caps false
Setting up SE_NODE_GRID_URL...
Selenium Grid Standalone configuration: 
[network]
relax-checks = true

[node]
session-timeout = "300"
override-max-sessions = false
detect-drivers = false
drain-after-session-count = 0
max-sessions = 1

[[node.driver-configuration]]
display-name = "chrome"
stereotype = '{"browserName": "chrome", "browserVersion": ".", "platformName": "Linux", "goog:chromeOptions": {"binary": "/usr/bin/chromium"}}'
max-sessions = 1

Starting Selenium Grid Standalone...
Tracing is disabled
15:48:49.669 INFO [LoggingOptions.configureLogEncoding] - Using the system default encoding
15:48:49.700 INFO [OpenTelemetryTracer.createTracer] - Using OpenTelemetry for tracing
15:48:54.317 INFO [NodeOptions.getSessionFactories] - Detected 6 available processors
15:48:55.011 INFO [NodeOptions.report] - Adding chrome for {"browserName": "chrome","browserVersion": ".","goog:chromeOptions": {"binary": "\u002fusr\u002fbin\u002fchromium"},"platformName": "linux","se:noVncPort": 7900,"se:vncEnabled": true} 1 times
15:48:55.136 INFO [Node.<init>] - Binding additional locator mechanisms: relative
15:48:55.260 INFO [GridModel.setAvailability] - Switching Node 4f1545f2-33a6-4e2f-8397-91f7db14c420 (uri: http://172.17.0.2:4444) from DOWN to UP
15:48:55.265 INFO [LocalDistributor.add] - Added node 4f1545f2-33a6-4e2f-8397-91f7db14c420 at http://172.17.0.2:4444. Health check every 120s
15:48:55.842 INFO [Standalone.execute] - Started Selenium Standalone 4.18.0 (revision b6bf9de7cc): http://172.17.0.2:4444
15:53:26.121 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, pageLoadStrategy: normal}]
15:54:30.110 WARN [DriverServiceSessionFactory.apply] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist 
Host info: host: 'e1a9df0410e2', ip: '172.17.0.2'
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
15:54:50.334 WARN [SeleniumSpanExporter$1.lambda$export$1] - Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist 
Host info: host: 'e1a9df0410e2', ip: '172.17.0.2'
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
15:54:50.338 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist 
Host info: host: 'e1a9df0410e2', ip: '172.17.0.2'
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:139)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:95)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:162)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:72)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:464)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

15:54:50.347 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "149c361fb75196b874b2c489e41ab3c1","eventTime": 1710086070115490654,"eventName": "exception","attributes": {"driver.url": "http:\u002f\u002flocalhost:6357","exception.message": "Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist \nHost info: host: 'e1a9df0410e2', ip: '172.17.0.2'\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist \nHost info: host: 'e1a9df0410e2', ip: '172.17.0.2'\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:139)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:95)\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:162)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:72)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:464)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat java.base\u002fjava.lang.Thread.run(Unknown Source)\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.node.config.DriverServiceSessionFactory","session.capabilities": "{\"browserName\": \"chrome\",\"browserVersion\": \".\",\"goog:chromeOptions\": {\"args\": [],\"extensions\": [],\"binary\": \"\\u002fusr\\u002fbin\\u002fchromium\"},\"pageLoadStrategy\": \"normal\",\"platformName\": \"linux\",\"se:noVncPort\": 7900,\"se:vncEnabled\": true}\n"}}

15:54:50.351 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "149c361fb75196b874b2c489e41ab3c1","eventTime": 1710086090349286039,"eventName": "Unable to create session with the driver","attributes": {"current.session.count": 0,"logger": "org.openqa.selenium.grid.node.local.LocalNode","session.request.capabilities": "Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, pageLoadStrategy: normal}","session.request.downstreamdialect": "[W3C]"}}

15:54:50.363 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "149c361fb75196b874b2c489e41ab3c1","eventTime": 1710086006119961500,"eventName": "Session request received by the Distributor","attributes": {"logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, pageLoadStrategy: normal}]"}}

15:54:50.365 WARN [SeleniumSpanExporter$1.lambda$export$1] - Unable to create session: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist 
Host info: host: 'e1a9df0410e2', ip: '172.17.0.2'
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
15:54:50.367 WARN [SeleniumSpanExporter$1.lambda$export$1] - org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist 
Host info: host: 'e1a9df0410e2', ip: '172.17.0.2'
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
Build info: version: '4.18.0', revision: 'b6bf9de7cc'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'
Driver info: driver.version: unknown
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:223)
        at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:72)
        at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)
        at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:464)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)
        at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

15:54:50.370 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "149c361fb75196b874b2c489e41ab3c1","eventTime": 1710086090361378706,"eventName": "exception","attributes": {"exception.message": "Unable to create session: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist \nHost info: host: 'e1a9df0410e2', ip: '172.17.0.2'\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown","exception.stacktrace": "org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: session not created: DevToolsActivePort file doesn't exist \nHost info: host: 'e1a9df0410e2', ip: '172.17.0.2'\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown\nBuild info: version: '4.18.0', revision: 'b6bf9de7cc'\nSystem info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '11.0.22'\nDriver info: driver.version: unknown\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:223)\n\tat org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply(DriverServiceSessionFactory.java:72)\n\tat org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)\n\tat org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:464)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession(LocalDistributor.java:651)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession(LocalDistributor.java:570)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest(LocalDistributor.java:830)\n\tat org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1(LocalDistributor.java:790)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.base\u002fjava.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat java.base\u002fjava.lang.Thread.run(Unknown Source)\n","exception.type": "org.openqa.selenium.SessionNotCreatedException","logger": "org.openqa.selenium.grid.distributor.local.LocalDistributor","request.payload": "[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, pageLoadStrategy: normal}]"}}

15:54:50.410 WARN [SeleniumSpanExporter$1.lambda$export$3] - {"traceId": "149c361fb75196b874b2c489e41ab3c1","eventTime": 1710086090407235622,"eventName": "HTTP request execution complete","attributes": {"http.flavor": 1,"http.handler_class": "org.openqa.selenium.grid.sessionqueue.local.LocalNewSessionQueue","http.host": "localhost:4444","http.method": "POST","http.request_content_length": "164","http.scheme": "HTTP","http.status_code": 500,"http.target": "\u002fsession","http.user_agent": "selenium\u002f4.18.1 (python mac)"}}

15:54:55.542 INFO [LocalDistributor.newSession] - Session request received by the Distributor: 
 [Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}, pageLoadStrategy: normal}]
  • Tried with image selenium/standalone-chrome image (using platform=linux/amd64)
  • Tried with image seleniarm/standalone-chromium image
  • Tried adding diverse arguments in my webdriver.ChromeOptions
  • Tried connecting to another Selenium container (which works)
0

There are 0 best solutions below