Skip to content

Commit

Permalink
[rb] Fully support Chrome 120+ old headless mode (#13271)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
neilvcarvalho authored Dec 11, 2023
1 parent 6f37dba commit e586190
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class << self

def for(browser, opts = {})
case browser
when :chrome
when :chrome, :chrome_headless_shell
Chrome::Driver.new(**opts)
when :internet_explorer, :ie
IE::Driver.new(**opts)
Expand Down Expand Up @@ -329,7 +329,7 @@ def screenshot

def add_extensions(browser)
extensions = case browser
when :chrome, :msedge
when :chrome, :chrome_headless_shell, :msedge
Chromium::Driver::EXTENSIONS
when :firefox
Firefox::Driver::EXTENSIONS
Expand Down
4 changes: 2 additions & 2 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_session(capabilities)
@capabilities = Capabilities.json_create(capabilities)

case @capabilities[:browser_name]
when 'chrome'
when 'chrome', 'chrome-headless-shell'
extend(WebDriver::Chrome::Features)
when 'firefox'
extend(WebDriver::Firefox::Features)
Expand All @@ -82,7 +82,7 @@ def session_id
def browser
@browser ||= begin
name = @capabilities.browser_name
name ? name.tr(' ', '_').downcase.to_sym : 'unknown'
name ? name.tr(' -', '_').downcase.to_sym : 'unknown'
end
end

Expand Down

0 comments on commit e586190

Please sign in to comment.