0

I'm trying to use my Firefox v109 with Selenium using Chrome Devtools Protocol. I started Firefox like this:

$ firefox --remote-debugging-port=2137
/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
[GFX1-]: glxtest: VA-API test failed: failed to initialise VAAPI connection.
WebDriver BiDi listening on ws://127.0.0.1:2137
DevTools listening on ws://127.0.0.1:2137/devtools/browser/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Then I used the following code:

import logging
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--session-id", required=True)
parser.add_argument("-p", "--port", type=int, required=True)
args = parser.parse_args()


logging.basicConfig(level=logging.DEBUG)

import selenium.webdriver


# https://stackoverflow.com/q/37963785/1091116
class SessionRemote(selenium.webdriver.Remote):
    def start_session(self, desired_capabilities, browser_profile=None):
        # Skip the NEW_SESSION command issued by the original driver
        # and set only some required attributes
        self.w3c = True


caps = selenium.webdriver.DesiredCapabilities.FIREFOX
command_executor = f"127.0.0.1:{args.port}"
driver = SessionRemote(command_executor=command_executor, desired_capabilities=caps)
driver.session_id = args.session_id
driver.get("https://google.com")

Here's how I executed it and what the output was:

> python3 a.py -p 2137 --session-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
/tmp/strace/a.py:24: DeprecationWarning: desired_capabilities has been deprecated, please pass in an Options object with options kwarg
  driver = SessionRemote(command_executor=command_executor, desired_capabilities=caps)
DEBUG:selenium.webdriver.remote.remote_connection:POST 127.0.0.1:2137/session/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/url {"url": "https://google.com"}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1:2137
DEBUG:urllib3.connectionpool:http://127.0.0.1:2137 "POST /session/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/url HTTP/1.1" 404 611
DEBUG:selenium.webdriver.remote.remote_connection:Remote response: status=404 | data=<html>                    <head><title>404 Not Found</title></head>                    <body>                      <h1>404 Not Found</h1>                      <p>                        <span style='font-family: monospace;'>&#47;&#115;&#101;&#115;&#115;&#105;&#111;&#110;&#47;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#47;&#117;&#114;&#108;</span> was not found.                      </p>                    </body>                  </html> | headers=HTTPHeaderDict({'content-type': 'text/html;charset=utf-8', 'connection': 'close', 'server': 'httpd.js', 'date': 'Tue, 31 Jan 2023 15:58:52 GMT', 'content-length': '611'})
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
Traceback (most recent call last):
  File "/tmp/strace/a.py", line 26, in <module>
    driver.get("https://google.com")
  File "/home/d33tah/virtualenv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 449, in get
    self.execute(Command.GET, {"url": url})
  File "/home/d33tah/virtualenv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "/home/d33tah/virtualenv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 209, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <html>                    <head><title>404 Not Found</title></head>                    <body>                      <h1>404 Not Found</h1>                      <p>                        <span style='font-family: monospace;'>&#47;&#115;&#101;&#115;&#115;&#105;&#111;&#110;&#47;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#45;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#120;&#47;&#117;&#114;&#108;</span> was not found.                      </p>                    </body>                  </html>

What am I doing wrong? One thing that's confusing to me is that Firefox passes a websocket URI while selenium is trying to use HTTP instead.

d33tah
  • 10,999
  • 13
  • 68
  • 158

0 Answers0