Skip to content

Commit e586190

Browse files
[rb] Fully support Chrome 120+ old headless mode (#13271)
When Chrome's new headless mode was announced, it was mentioned that they intended to remove the old headless mode from the Chrome binary. Some people still want to use the old headless mode, as it's more lightweight, performant, and has fewer dependencies - at the expense of having fewer features. Chrome 120+ has a standalone `chrome-headless-shell` binary to keep the old headless mode working for those who wish to use it. If your Ruby code sets up the Chrome driver with `--headless` (which currently defaults to `old`) or `--headless=old` explicitly, you will lose capabilities such as setting permissions, fetching the logs and using the CDP API. That happens because the new binary has a browser name of `chrome-headless-shell`, instead of `chrome`. That makes it be recognized as something other than Chrome, not setting its capabilities. This commit introduces `chrome-headless-shell` as an alternative Chrome browser name, fixing this issue. Fixes #13112
1 parent 6f37dba commit e586190

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class << self
4343

4444
def for(browser, opts = {})
4545
case browser
46-
when :chrome
46+
when :chrome, :chrome_headless_shell
4747
Chrome::Driver.new(**opts)
4848
when :internet_explorer, :ie
4949
IE::Driver.new(**opts)
@@ -329,7 +329,7 @@ def screenshot
329329

330330
def add_extensions(browser)
331331
extensions = case browser
332-
when :chrome, :msedge
332+
when :chrome, :chrome_headless_shell, :msedge
333333
Chromium::Driver::EXTENSIONS
334334
when :firefox
335335
Firefox::Driver::EXTENSIONS

rb/lib/selenium/webdriver/remote/bridge.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_session(capabilities)
6060
@capabilities = Capabilities.json_create(capabilities)
6161

6262
case @capabilities[:browser_name]
63-
when 'chrome'
63+
when 'chrome', 'chrome-headless-shell'
6464
extend(WebDriver::Chrome::Features)
6565
when 'firefox'
6666
extend(WebDriver::Firefox::Features)
@@ -82,7 +82,7 @@ def session_id
8282
def browser
8383
@browser ||= begin
8484
name = @capabilities.browser_name
85-
name ? name.tr(' ', '_').downcase.to_sym : 'unknown'
85+
name ? name.tr(' -', '_').downcase.to_sym : 'unknown'
8686
end
8787
end
8888

0 commit comments

Comments
 (0)