Skip to content

Conversation

@Delta456
Copy link
Member

@Delta456 Delta456 commented Dec 2, 2025

User description

🔗 Related Issues

💥 What does this PR do?

Implements emulation.setUserAgentOverride from https://w3c.github.io/webdriver-bidi/#command-emulation-setUserAgentOverride from W3C BiDi spec

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

PR Type

Enhancement


Description

  • Implements emulation.setUserAgentOverride BiDi command

  • Adds SetUserAgentOverrideParameters class for parameter handling

  • Supports context and user context targeting options

  • Includes comprehensive test coverage for override functionality


Diagram Walkthrough

flowchart LR
  A["Emulation.java"] -->|adds method| B["setUserAgentOverride"]
  C["SetUserAgentOverrideParameters.java"] -->|new class| D["Parameter handling"]
  E["SetUserAgentOverrideTest.java"] -->|new tests| F["Functional validation"]
  B -->|uses| D
  D -->|tested by| F
Loading

File Walkthrough

Relevant files
Enhancement
Emulation.java
Add setUserAgentOverride method to Emulation                         

java/src/org/openqa/selenium/bidi/emulation/Emulation.java

  • Adds setUserAgentOverride method to Emulation class
  • Accepts SetUserAgentOverrideParameters and sends BiDi command
  • Validates parameters with null check before sending
  • Returns Map response from BiDi command execution
+7/-0     
SetUserAgentOverrideParameters.java
New parameter class for user agent override                           

java/src/org/openqa/selenium/bidi/emulation/SetUserAgentOverrideParameters.java

  • New parameter class extending AbstractOverrideParameters
  • Constructor accepts required userAgent string parameter
  • Provides fluent contexts() method for targeting specific contexts
  • Provides fluent userContexts() method for targeting user contexts
+36/-0   
Tests
SetUserAgentOverrideTest.java
Comprehensive tests for user agent override                           

java/test/org/openqa/selenium/bidi/emulation/SetUserAgentOverrideTest.java

  • Test for setting user agent override with specific contexts
  • Test for setting user agent override with user contexts
  • Validates override takes effect and can be cleared by passing null
  • Uses Script module to verify navigator.userAgent changes
+114/-0 

@selenium-ci selenium-ci added C-java Java Bindings B-devtools Includes everything BiDi or Chrome DevTools related labels Dec 2, 2025
@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 2, 2025

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
🔴 Diagnose and fix repeated "Error: ConnectFailure (Connection refused)" when instantiating
multiple ChromeDriver instances on Ubuntu with specified versions.
Ensure subsequent ChromeDriver instantiations do not log ConnectFailure errors after the
first succeeds.
Provide steps or changes that prevent connection refusal in console for repeated driver
creation.
🟡
🎫 #1234
🔴 Ensure WebDriver 2.48 correctly triggers JavaScript in link href on click() in Firefox 42
(regression from 2.47.1).
Add test coverage or fixes to restore alert firing behavior when clicking anchors with
javascript: href.
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
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: 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: Comprehensive Audit Trails

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

Status:
No audit logs: The new method setUserAgentOverride performs a potentially sensitive environment change
without emitting any audit/log entry capturing who triggered it, when, and with what
parameters.

Referred Code
public Map<String, Object> setUserAgentOverride(SetUserAgentOverrideParameters parameters) {
  Require.nonNull("SetUserAgentOverride parameters", parameters);

  return bidi.send(
      new Command<>("emulation.setUserAgentOverride", parameters.toMap(), Map.class));
}

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:
Null handling: The public API accepts null userAgent to clear overrides but relies on parameters.toMap()
and downstream behavior without validating edge cases or providing contextual error
handling if the BiDi call fails.

Referred Code
public Map<String, Object> setUserAgentOverride(SetUserAgentOverrideParameters parameters) {
  Require.nonNull("SetUserAgentOverride parameters", parameters);

  return bidi.send(
      new Command<>("emulation.setUserAgentOverride", parameters.toMap(), Map.class));
}

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:
Input validation: The constructor accepts userAgent (including null in tests) and directly inserts it into
the map without validating type/length or sanitizing input, which may rely on downstream
enforcement and could allow invalid values.

Referred Code
public SetUserAgentOverrideParameters(String userAgent) {
  map.put("userAgent", userAgent);
}

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

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

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 2, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Use empty string to clear override

In the test, use an empty string ("") instead of null when creating
SetUserAgentOverrideParameters to clear the user agent override, aligning with
the BiDi specification.

java/test/org/openqa/selenium/bidi/emulation/SetUserAgentOverrideTest.java [65-67]

 // Clear the override
 emulation.setUserAgentOverride(
-    new SetUserAgentOverrideParameters(null).contexts(List.of(contextId)));
+    new SetUserAgentOverrideParameters("").contexts(List.of(contextId)));
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly points out that using an empty string to clear the override is more aligned with the BiDi specification than using null, improving the test's correctness and adherence to standards.

Medium
  • Update

@Delta456 Delta456 requested a review from asolntsev December 3, 2025 08:33
@Delta456 Delta456 merged commit 8a0b916 into SeleniumHQ:trunk Dec 3, 2025
38 checks passed
@Delta456 Delta456 deleted the emul_agentoverride branch December 3, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-devtools Includes everything BiDi or Chrome DevTools related C-java Java Bindings Review effort 2/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants