Skip to content

[javascript] Add headless flag to internal Chrome tests#17079

Open
ElliotNewtonMiller wants to merge 1 commit intoSeleniumHQ:trunkfrom
ElliotNewtonMiller:internal-chrome-headless
Open

[javascript] Add headless flag to internal Chrome tests#17079
ElliotNewtonMiller wants to merge 1 commit intoSeleniumHQ:trunkfrom
ElliotNewtonMiller:internal-chrome-headless

Conversation

@ElliotNewtonMiller
Copy link

🔗 Related Issues

💥 What does this PR do?

Make internal javascript testing on Chrome headless because Chromedriver will otherwise not connect with Chrome.
This change was implimented in the internal testing Environment object.

🔧 Implementation Notes

I used the Environment object in the "testing/index.js" file because it seemed to be solely used for internal testing (in Bazel), which is the only place this bug exists.

I considered trying to add environment flags via Bazel commands.

💡 Additional Considerations

The tests don't all pass. Hopefully fixing them can be my focus in future PRs.

🔄 Types of changes

  • Bug fix (backwards compatible)

@qodo-code-review
Copy link
Contributor

PR Type

Bug fix


Description

  • Add headless flag to Chrome in internal Bazel tests

  • Enables Chromedriver to connect with Chrome during testing

  • Conditionally applies flag only when running under Bazel


File Walkthrough

Relevant files
Bug fix
index.js
Add Chrome headless flag for Bazel test environment           

javascript/selenium-webdriver/testing/index.js

  • Added conditional logic to set Chrome headless mode when running under
    Bazel
  • Retrieves existing Chrome options or creates new Options instance
  • Appends --headless=new argument to Chrome options for Bazel test
    environment
  • Includes explanatory comment about necessity for driver-browser
    connection
+10/-0   

@selenium-ci selenium-ci added the C-nodejs JavaScript Bindings label Feb 11, 2026
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #5678
🔴 Address the ChromeDriver "ConnectFailure (Connection refused)" error that occurs on
subsequent ChromeDriver instantiations (not the first) on Ubuntu/Chrome/ChromeDriver as
described.
Provide a fix or workaround that allows ChromeDriver to reliably connect to Chrome in the
affected environment.
🟡
🎫 #1234
🔴 Restore or ensure that clicking a link with JavaScript in its href triggers the expected
JavaScript in Selenium 2.48+ (regression vs 2.47.1) on Firefox 42.
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Always create and set new Chrome options

Remove the call to the non-existent builder.getChromeOptions() method and always
instantiate a new chrome.Options() instance.

javascript/selenium-webdriver/testing/index.js [347-354]

 if (browser.name === Browser.CHROME && process.env.BAZEL_TEST) {
-  let options = builder.getChromeOptions()
-  if (!options) {
-    options = new chrome.Options()
-  }
+  const options = new chrome.Options()
   options.addArguments('--headless=new')
   builder.setChromeOptions(options)
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This suggestion correctly identifies that builder.getChromeOptions() does not exist on the Builder API, simplifying the code by removing the unnecessary check and API call.

Medium
  • More

@cgoldberg
Copy link
Member

cgoldberg commented Feb 11, 2026

Why is this needed? Isn't there already a --headless option when calling bazel that works with all browsers?

Copy link
Member

@cgoldberg cgoldberg left a comment

Choose a reason for hiding this comment

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

There is an option when running bazel that sets headless for any browser (--headless). If that doesn't work in JS, it should be fixed. This PR forces headless (for Chrome only), which is not what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants