Description
Problem description
Since a few days, we experience a weird issue with Chrome in headless mode. To me, it seems like interacting with a browser alert is affecting the "performance" or causing some other race-condition like issue. Since I found it extremely difficult to identify a potential root cause, I've tried to minimize the example. Below is my current state, that shows some undesired side effect when using the alert feature with a headless version of Chrome. Removing the alert or using a non-headless version of Chrome avoids the issue.
Steps to reproduce
-
Download steps_to_reproduce.zip and extract it
-
Within the folder, start a webserver. For example, use Webrick listening on port 8000:
cd <folder> ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start'
-
In another terminal, launch the provided script
cd <folder> ruby bug.rb
-
Observe the script output.
Actual output
Modal is visible
-----------------
Modal is visible
Expected output
Modal is visible
-----------------
Modal is hidden
Potential changes
To demonstrate the unpleasant interaction between headless Chrome and the alert, you can change one of the following two:
- Either remove the headless switch (and keep the alert)
options.add_argument("--headless")
- Or remove the alert (and keep the headless switch)
driver.execute_script('alert("hi");') driver.switch_to.alert.accept
When either of these changes is performed, the expected output is shown:
Modal is visible
-----------------
Modal is hidden
Environment
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +YJIT +PRISM [arm64-darwin24]
selenium-webdriver (4.28.0)
Google Chrome Version 133.0.6943.54 (Official Build) (arm64)
chromedriver (downloaded through selenium): 133.0.6943.53