Skip to content

Selenium CDP compatibility #424

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/server.zig
Original file line number Diff line number Diff line change
@@ -578,6 +578,16 @@ fn Client(comptime S: type) type {
return self.send(self.server.json_version_response, false);
}

const json_list_response =
"HTTP/1.1 200 OK\r\n" ++
"Content-Length: 47\r\n" ++
"Content-Type: application/json; charset=UTF-8\r\n\r\n" ++
"[{\"id\":\"1\",\"type\":\"page\",\"url\":\"abount:blank\"}]";

if (std.mem.eql(u8, url, "/json/list")) {
return self.send(json_list_response, false);
}

return error.NotFound;
}

@@ -1123,12 +1133,12 @@ pub fn run(

// Utils
// --------

//
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.

const body_len = std.fmt.count(body_format, .{address});

const response_format =