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

[rb] Fully support Chrome 120+ old headless mode #13271

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

neilvcarvalho
Copy link
Contributor

@neilvcarvalho neilvcarvalho commented Dec 8, 2023

Motivation and Context

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.

This change is explained on the Chrome for Developers blog: Download old Headless Chrome as chrome-headless-shell

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.

Description

This commit introduces chrome-headless-shell as an alternative Chrome browser name, fixing this issue.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Fixes #13112

@CLAassistant
Copy link

CLAassistant commented Dec 8, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@titusfortner titusfortner left a comment

Choose a reason for hiding this comment

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

Thanks for this PR.

Let's leave the test files alone, those get toggled off of the values we pass in, not what comes back from the browser. (also we just aren't going to be running tests with the old headless).

rb/CHANGES Outdated Show resolved Hide resolved
rb/lib/selenium/webdriver/remote/bridge.rb Show resolved Hide resolved
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 SeleniumHQ#13112
@neilvcarvalho
Copy link
Contributor Author

Let's leave the test files alone, those get toggled off of the values we pass in, not what comes back from the browser. (also we just aren't going to be running tests with the old headless).

@titusfortner I removed the specs changes, amending on the same commit. Thank you for the explanation!

@titusfortner titusfortner merged commit e586190 into SeleniumHQ:trunk Dec 11, 2023
25 of 30 checks passed
@neilvcarvalho neilvcarvalho deleted the nc-chrome-120 branch December 11, 2023 17:34
@ryanb
Copy link

ryanb commented Dec 12, 2023

I'm running into this issue and having trouble with the new headless. Do you know when the next release will be that contains this fix?

@titusfortner
Copy link
Member

The current plan is to release about as often as Google does https://chromiumdash.appspot.com/schedule
The recommendation is to use --headless=new

@ryanb
Copy link

ryanb commented Dec 13, 2023

Thanks. I'm having trouble migrating to --headless=new so for now I'll stick to Chrome v119 until this PR is released.

For those who may be facing the same issue, you can set the version like this.

Selenium::WebDriver::Chrome::Options.new(
  args: ["headless=old"],
  browser_version: "119",
),

cbliard added a commit to opf/openproject that referenced this pull request Dec 15, 2023
`./modules/my_page/spec/features/my/my_spent_time_widget_with_a_negative_time_zone_spec.rb`
is failing with error `undefined method `execute_cdp'
for #<Selenium::WebDriver::Chrome::Driver:0x..fe768862b9701efbc browser=:"chrome-headless-shell">`.

The `--headless` flag uses the old headless mode of Chrome. Since
version 120, this version's name is "chrome-headless-shell". This name
is not properly recognized in selenium-webdriver 4.16.0 and some
extensions are not loaded, like the one allowing to use execute_cdp.

This will be fixed in next selenium-webdriver with this PR: SeleniumHQ/selenium#13271

In the meantime, using the new headless mode with `--headless=new` fixes the issue.
cbliard added a commit to opf/openproject that referenced this pull request Dec 15, 2023
`./modules/my_page/spec/features/my/my_spent_time_widget_with_a_negative_time_zone_spec.rb`
is failing with error `undefined method `execute_cdp'
for #<Selenium::WebDriver::Chrome::Driver:0x..fe768862b9701efbc browser=:"chrome-headless-shell">`.

The `--headless` flag uses the old headless mode of Chrome. Since
version 120, this version's name is "chrome-headless-shell". This name
is not properly recognized in selenium-webdriver 4.16.0 and some
extensions are not loaded, like the one allowing to use execute_cdp.

This will be fixed in next selenium-webdriver with this PR: SeleniumHQ/selenium#13271

In the meantime, using the new headless mode with `--headless=new` fixes the issue.
@jeppester
Copy link

jeppester commented Dec 18, 2023

The current plan is to release about as often as Google does https://chromiumdash.appspot.com/schedule The recommendation is to use --headless=new

I think a lot of projects will need to implement this temporary workaround in order to get their CI to pass.
Many of hours will be spent investigating the problem and eventually implementing the workaround, and then after the next release, the workaround will become obsolete code in those projects.

@titusfortner
Is it completely out of question to make a bugfix release containing this fix?

@titusfortner
Copy link
Member

Using --headless=new is not a temporary workaround. It is the recommendation going forward. And maybe on a patch release, I've got other things on my plate right now, so haven't looked at what's feasible.

@ryanb
Copy link

ryanb commented Dec 18, 2023

@titusfortner a couple questions that might help those migrating to the new headless.

  1. Should we file a bug if we find an inconsistency between old and new headless?
  2. If old and new headless has intentional differences, are those differences documented somewhere?

Thanks for your time.

@titusfortner
Copy link
Member

Should we file a bug if we find an inconsistency between old and new headless?

Probably. It depends on if it was actually a bug in the old headless. :)
Old Headless was essentially a stripped down fake browser.
New Headless is an actual headless implementation of Real Chrome.

@ryanb
Copy link

ryanb commented Dec 20, 2023

@titusfortner thanks for the reply.

Probably. It depends on if it was actually a bug in the old headless. :)

I guess a better check is if it works in non headless chrome but not in new headless chrome. In my case drag & drop isn't working in new headless but it does work in old headless and non headless Chrome. I'll look into it further and file a bug once I've isolated the issue.

@titusfortner
Copy link
Member

Oh that's interesting. Drag and Drop with HTML 5 draggable / droppable elements hasn't actually ever worked with the drivers as far as I know. (perpetual complaints as you may have guessed).

@runephilosof-abtion
Copy link

Using --headless=new is not a temporary workaround. It is the recommendation going forward.

It is a temporary workaround in projects that use selenium, because it is only necessary until this commit is released.

Just see the linked pull requests
Shopify Shopify/maintenance_tasks#936

Instead of waiting for a new release of selenium-webdriver that includes the fix to continue using the old headless, or configuring Selenium to use an older version of Chrome, this moves to the new headless Chrome.

Openproject opf/openproject#14426

This will be fixed in next selenium-webdriver with this PR: #13271

In the meantime, using the new headless mode with --headless=new fixes the issue.

They are working around the problem that this pull request fixes. It seems they would have preferred to just update to a selenium-webdriver version that included this fix.

If it is the recommendation going forward to add --headless=new, then that should be more prominent in the documentation. The only place it is mentioned is https://www.selenium.dev/documentation/webdriver/browsers/edge/#arguments

There are probably also a lot of frameworks that need to catch up and add --headless=new to their templates, so it would be a nice Christmas gift for a lot of people that they would not have to use a lot of time to figure out that they need to add --headless=new.

If you release a patch version, everyone can upgrade to --headless=new when they are ready, or when it becomes the default.

@titusfortner
Copy link
Member

titusfortner commented Dec 21, 2023

It is a temporary workaround in projects that use selenium, because it is only necessary until this commit is released.

We're arguing semantics. Encouraging people to use the recommended settings shouldn't include the baggage of the term "workaround," even if it entails "extra work," but I think we each get the other's point here.

Google will soon(?) be switching --headless to use --headless=new instead of --headless=old as it is now. I wish they had done this at the same time as making a backwards incompatible name change, or at least given us a heads up about it, but they didn't.

There is code in trunk that for /reasons/ cannot be released, yet, so doing a patch release is no longer an option. The next minor release will be for all languages when Chrome 121 comes out in January.

dgmstuart added a commit to dgmstuart/swing-out-london that referenced this pull request Dec 28, 2023
Looks like there was some change in headless chrome where some features
were removed, including execute_cdp, which we rely on for the tests
which exercise the clipboard. There's an old mode which is faster but
doesn't have all the features of a real browser, and a new mode which
does.

  SeleniumHQ/selenium#13112
  SeleniumHQ/selenium#13271

Maybe a better approach would be to keep the old mode for fast tests
which don't need these features and use new mode for tests which do.
dgmstuart added a commit to dgmstuart/swing-out-london that referenced this pull request Dec 29, 2023
3.40 will use the new headless chrome, but it hasn't been merged yet.

As far as I can gather there was some change in Chrome where they split
headless into two versions: old and new. The old one is used by default,
but is missing some features were removed, including execute_cdp, which
we rely on for the tests which exercise the clipboard This PR explains
it pretty well:

  SeleniumHQ/selenium#13271

What makes this confusing is that the headless browser is provided by
the selenium-webdrivers gem, but driver is specified by Capybara:

  teamcapybara/capybara@e2f9f6c

The result was that we got failures on some environments saying that
execute_cdp is not defined - this is presumably due to the Chrome
version being updated - independent of the codebase.

Note that unfortunately the "new" headless browser is slower, but I
think it's probably worth it for keeping the config simple and using a
more realistic browser.
@neilvcarvalho
Copy link
Contributor Author

For folks who were following this and want to use the old headless mode: this was released this week 🎉

dgmstuart added a commit to dgmstuart/swing-out-london that referenced this pull request Feb 25, 2024
Looks like there was some change in headless chrome where some features
were removed, including execute_cdp, which we rely on for the tests
which exercise the clipboard. There's an old mode which is faster but
doesn't have all the features of a real browser, and a new mode which
does.

  SeleniumHQ/selenium#13112
  SeleniumHQ/selenium#13271

Maybe a better approach would be to keep the old mode for fast tests
which don't need these features and use new mode for tests which do.
dgmstuart added a commit to dgmstuart/swing-out-london that referenced this pull request Feb 26, 2024
Looks like there was some change in headless chrome where some features
were removed, including execute_cdp, which we rely on for the tests
which exercise the clipboard. There's an old mode which is faster but
doesn't have all the features of a real browser, and a new mode which
does.

  SeleniumHQ/selenium#13112
  SeleniumHQ/selenium#13271

Maybe a better approach would be to keep the old mode for fast tests
which don't need these features and use new mode for tests which do.
dgmstuart added a commit to dgmstuart/swing-out-london that referenced this pull request Feb 26, 2024
Looks like there was some change in headless chrome where some features
were removed, including execute_cdp, which we rely on for the tests
which exercise the clipboard. There's an old mode which is faster but
doesn't have all the features of a real browser, and a new mode which
does.

  SeleniumHQ/selenium#13112
  SeleniumHQ/selenium#13271

Maybe a better approach would be to keep the old mode for fast tests
which don't need these features and use new mode for tests which do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants