Skip to content

Chrome Headless affected by switch_to.alert #15273

Open
@MrSerth

Description

@MrSerth

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

  1. Download steps_to_reproduce.zip and extract it

  2. 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'
  3. In another terminal, launch the provided script

    cd <folder>
    ruby bug.rb
  4. 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:

  1. Either remove the headless switch (and keep the alert)
    options.add_argument("--headless")
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-rbRuby Bindings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions