Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium CDP compatibility #424

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Selenium CDP compatibility #424

wants to merge 1 commit into from

Conversation

krichprollsch
Copy link
Member

Mimic Chrome's endpoints to enable Selenium CDP connection.

Selenium requires:

On /json/version, Browser with a Chrome version and WebkitVersion.
On json/list, at least one item containing id, url and type.

⚠️ This PR blocks on WS connection.

Mimic Chrome's endpoints to enable Selenium CDP connection.
@krichprollsch krichprollsch self-assigned this Feb 13, 2025
@krichprollsch krichprollsch changed the title server: implement /json/list Selenium CDP comaptibility Feb 13, 2025
@krichprollsch
Copy link
Member Author

Script example can be found here: lightpanda-io/demo#22

@karlseguin
Copy link
Collaborator

karlseguin commented Feb 14, 2025

After establishing the connection, the first thing it does is issue this CDP command which we don't support:

{
    "id": 1,
    "method": "Target.getTargets",
    "params": {
        "filter": [
            { "exclude": true, "type": "browser" },
            { "exclude": true, "type": "page" },
            { "exclude": false}
        ]
    }
}

fn buildJSONVersionResponse(
allocator: Allocator,
address: net.Address,
) ![]const u8 {
const body_format = "{{\"webSocketDebuggerUrl\": \"ws://{}/\"}}";
const body_format = "{{\"Browser\": \"Chrome/132.0.6834.110\", \"WebKit-Version\": \"537.36 (@df453a35f099772fdb954e33551388add2ca3cde)\", \"webSocketDebuggerUrl\": \"ws://{}/\"}}";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the branch for the demo project, I followed the instructions and ran pip install trio selenium. When I tried to run the selenium script against this PR, I got this error:

Message: session not created: cannot connect to chrome at 127.0.0.1:9222 from session not created: This version of ChromeDriver only supports Chrome version 133 Current browser version is 132.0.6834.110.

I wonder if this version response should be optionally loaded from the command line argument / a config file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.
It looks like selenium is running a chrome --version command to select the right webdriver version.
So I guess it expects the same version is returned by the endpoint.

chromedriver not found in PATH                          
chrome detected at /usr/bin/google-chrome                                                                       
Running command: /usr/bin/google-chrome --version                                                               
Output: "Google Chrome 132.0.6834.110 "                                                                         
Detected browser: chrome 132.0.6834.110                                                                         
Required driver: chromedriver 132.0.6834.159                                                                    
chromedriver 132.0.6834.159 already in the cache                                                                
Driver path: /home/pierre/.cache/selenium/chromedriver/linux64/132.0.6834.159/chromedriver                                                                                                                                       
Browser path: /usr/bin/google-chrome                                                                            
Started executable: `/home/pierre/.cache/selenium/chromedriver/linux64/132.0.6834.159/chromedriver` in a child process with pid: 993207 using 0 to output -3

I would be better to configure selenium with the websocket url to connect to.
But Idk if it's possible.
Here It looks like it can either use an se:cdp capability or retrieve it from the /json/version endpoint. But I wasn't able to configure it properly for now.

Copy link
Collaborator

@karlseguin karlseguin Feb 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out that you can force which version it will download:

options = webdriver.ChromeOptions()
options.browser_version = '132';  # add this
# ...

It downloaded 132 instead of 133 with this, and it didn't complain about the version when I ran it.

@krichprollsch krichprollsch changed the title Selenium CDP comaptibility Selenium CDP compatibility Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants