Skip to content

Conversation

nvborisenko
Copy link
Member

@nvborisenko nvborisenko commented Oct 4, 2025

User description

https://w3c.github.io/webdriver-bidi/#module-emulation

💥 What does this PR do?

Implements entire emulation module.

🔄 Types of changes

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

PR Type

Enhancement


Description

  • Implements complete WebDriver BiDi emulation module

  • Adds 7 emulation commands for browser behavior control

  • Includes timezone, user agent, locale, and geolocation overrides

  • Provides screen orientation and scripting control features


Diagram Walkthrough

flowchart LR
  BiDi["BiDi Main Class"] --> EmulationModule["Emulation Module"]
  EmulationModule --> Commands["7 Override Commands"]
  Commands --> Timezone["Timezone Override"]
  Commands --> UserAgent["User Agent Override"]
  Commands --> Locale["Locale Override"]
  Commands --> Colors["Forced Colors Theme"]
  Commands --> Scripting["Scripting Control"]
  Commands --> Orientation["Screen Orientation"]
  Commands --> Geolocation["Geolocation Override"]
  Broker["Communication Broker"] --> Serialization["JSON Serialization"]
  Serialization --> Converter["Screen Orientation Converter"]
Loading

File Walkthrough

Relevant files
Enhancement
10 files
BiDi.cs
Add emulation module property and initialization                 
+14/-0   
ScreenOrientationTypeConverter.cs
Custom JSON converter for screen orientation types             
+55/-0   
EmulationModule.cs
Main emulation module with all override methods                   
+92/-0   
SetForcedColorsModeThemeOverrideCommand.cs
Command for forced colors mode theme override                       
+42/-0   
SetGeolocationOverrideCommand.cs
Command for geolocation coordinates and position error override
+61/-0   
SetLocaleOverrideCommand.cs
Command for locale override functionality                               
+36/-0   
SetScreenOrientationOverrideCommand.cs
Command for screen orientation override with enums             
+52/-0   
SetScriptingEnabledCommand.cs
Command for enabling or disabling scripting                           
+36/-0   
SetTimezoneOverrideCommand.cs
Command for timezone override functionality                           
+36/-0   
SetUserAgentOverrideCommand.cs
Command for user agent string override                                     
+36/-0   
Configuration changes
2 files
Broker.cs
Register screen orientation type converter                             
+1/-0     
BiDiJsonSerializerContext.cs
Add JSON serialization for emulation commands                       
+7/-0     
Tests
1 files
EmulationTest.cs
Unit tests for all emulation module commands                         
+76/-0   

@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Oct 4, 2025
Copy link
Contributor

qodo-merge-pro bot commented Oct 4, 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
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

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

Copy link
Member Author

@nvborisenko nvborisenko left a comment

Choose a reason for hiding this comment

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

Review tests, ignore some browsers if needed.

Copy link
Contributor

qodo-merge-pro bot commented Oct 4, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Consolidate duplicated command option classes

To reduce code duplication, create a reusable base class for the multiple new
command Options classes that share identical properties for targeting browsing
contexts and user contexts.

Examples:

dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs [31-36]
public sealed class SetTimezoneOverrideOptions : CommandOptions
{
    public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

    public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}
dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs [31-36]
public sealed class SetLocaleOverrideOptions : CommandOptions
{
    public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

    public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}

Solution Walkthrough:

Before:

// In SetTimezoneOverrideCommand.cs
public sealed class SetTimezoneOverrideOptions : CommandOptions
{
    public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
    public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}

// In SetLocaleOverrideCommand.cs
public sealed class SetLocaleOverrideOptions : CommandOptions
{
    public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
    public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}

// ... and 4 other identical classes

After:

// In a new shared file or a relevant existing one
public class ContextOptions : CommandOptions
{
    public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
    public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
}

// In SetTimezoneOverrideCommand.cs
public sealed class SetTimezoneOverrideOptions : ContextOptions { }

// In SetLocaleOverrideCommand.cs
public sealed class SetLocaleOverrideOptions : ContextOptions { }

// ... and so on for other option classes
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies significant code duplication across multiple new Options classes and proposes a valid solution that improves maintainability by using a shared base class.

Medium
Possible issue
Ensure correct enum JSON serialization

To ensure ForcedColorsModeTheme enum values serialize to lowercase strings as
per the WebDriver BiDi specification, add the [JsonStringEnumConverter]
attribute to the enum definition.

dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs [38-42]

+[JsonStringEnumConverter]
 public enum ForcedColorsModeTheme
 {
     Light,
     Dark
 }
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that the ForcedColorsModeTheme enum will be serialized incorrectly as an integer, but the proposed fix using [JsonStringEnumConverter] is incomplete as it would serialize to "Light" and "Dark" instead of the required "light" and "dark".

Medium
  • Update

@nvborisenko nvborisenko merged commit 565459e into SeleniumHQ:trunk Oct 4, 2025
10 checks passed
@nvborisenko nvborisenko deleted the bidi-emulation-module branch October 4, 2025 19:27
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.

2 participants