Skip to content

[dotnet] [bidi] SetMediaFeaturesOverride command in Emulation module - #17953

Merged
nvborisenko merged 3 commits into
SeleniumHQ:trunkfrom
nvborisenko:bidi-media-features
Aug 27, 2026
Merged

nvborisenko merged 3 commits into
SeleniumHQ:trunkfrom
nvborisenko:bidi-media-features

Conversation

@nvborisenko

Copy link
Copy Markdown
Member

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

💥 What does this PR do?

Add support of emulation.setMediaFeaturesOverride command.

🤖 AI assistance

  • No substantial AI assistance used
  • AI assisted (complete below)
    • Tool(s):
    • What was generated:
    • I reviewed all AI output and can explain the change

💡 Additional Considerations

Optional<> and KebabCaseConverter works nicely here.

🔄 Types of changes

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

@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Aug 26, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Add BiDi media feature overrides to .NET emulation

✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Adds .NET BiDi support for overriding CSS media features by context or user context.
• Models protocol features with optional nullable values and kebab-case enum serialization.
• Verifies applying selected overrides and restoring browser defaults.
Diagram

graph TD
  Tests["Integration Tests"] --> API["Emulation API"] --> Module["Emulation Module"] --> Model["Media Features"] --> Serializer["JSON Serializer"] --> Browser["BiDi Browser"]
Loading
High-Level Assessment

The implementation follows the established .NET BiDi emulation-command pattern and uses typed records, Optional values, existing converters, and source-generated JSON metadata. A string-based feature map would reduce declarations but sacrifice protocol discoverability and compile-time safety, so the current approach is preferable.

Files changed (4) +376 / -0

Enhancement (3) +350 / -0
EmulationModule.csWire the media-features override command +11/-0

Wire the media-features override command

• Registers emulation.setMediaFeaturesOverride, builds its scoped parameters, and executes it through the existing module pipeline. Adds parameter and result types to the source-generated JSON serializer context.

dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs

IEmulationModule.csExpose media-feature overrides in the emulation API +1/-0

Expose media-feature overrides in the emulation API

• Adds SetMediaFeaturesOverrideAsync to the public emulation module contract with optional context and cancellation settings.

dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs

SetMediaFeaturesOverride.csModel BiDi media-feature override payloads +338/-0

Model BiDi media-feature override payloads

• Defines command parameters, scoping options, result type, and the full typed MediaFeatures surface. Optional nullable values distinguish omitted features from explicit null resets, while converters emit protocol-compatible property and enum names.

dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs

Tests (1) +26 / -0
EmulationTests.csCover setting and resetting media-feature overrides +26/-0

Cover setting and resetting media-feature overrides

• Adds integration tests that submit representative enum and numeric media features for a browsing context. Also verifies that a null feature set restores browser defaults without errors.

dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs

@qodo-code-review

qodo-code-review Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. features uses wrong shape ✗ Dismissed 📘 Rule violation ≡ Correctness
Description
SetMediaFeaturesOverrideParameters.Features serializes as a single object keyed by CSS feature
names, such as {"any-hover":"none","color":8}, instead of the protocol-required nullable array of
{name, value} records, such as
[{"name":"any-hover","value":"none"},{"name":"color","value":"8"}]. Non-null overrides therefore
have both an incompatible container shape and, for numeric features, the wrong JSON value type,
which can cause conforming endpoints to reject or misread emulation.setMediaFeaturesOverride.
Code

dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[R25-26]

+internal sealed record SetMediaFeaturesOverrideParameters(
+    [property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] MediaFeatures? Features,
Evidence
Rule 2 requires equivalent language bindings to remain behaviorally aligned, and the repository's
Ruby BiDi protocol schema defines features as a nullable list of MediaFeature records whose
name and value fields are strings. In contrast, the added .NET parameter uses a single
MediaFeatures object with feature names mapped directly to JSON properties, including numeric
values declared as long; because OptionalConverter serializes the underlying values unchanged,
those values become JSON numbers rather than the required strings, proving that the .NET wire model
conflicts with the applicable binding and protocol schema.

AGENTS.md: Maintain Consistent User-Visible Behavior Across Language Bindings: AGENTS.md: Maintain Consistent User-Visible Behavior Across Language Bindings
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-42]
rb/lib/selenium/webdriver/bidi/protocol/emulation.rb[122-134]
rb/sig/lib/selenium/webdriver/bidi/protocol/emulation.rbs[81-91]
rb/lib/selenium/webdriver/bidi/protocol/emulation.rb[121-134]
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-29]
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[38-58]
dotnet/src/webdriver/BiDi/Json/Converters/OptionalConverter.cs[39-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`SetMediaFeaturesOverrideParameters.Features` is modeled as a single `MediaFeatures` object, producing a wire object keyed by CSS media-feature names instead of the protocol-required nullable array of `{name, value}` records. Numeric feature values are also serialized as JSON numbers rather than strings.
## Issue Context
Replace the object-based `MediaFeatures` wire model with a list-valued model whose records contain string `name` and `value` fields. Update the public .NET signature, parameter model, serialization metadata, and tests together; preserve explicit JSON `null` for resetting the override, and ensure numeric and enum feature values are represented as protocol strings within each record.
## Fix Focus Areas
- dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-155]
- dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs[27-27]
- dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs[81-84]
- dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[86-109]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Media tests are always ignored ✗ Dismissed 📘 Rule violation ☼ Reliability
Description
Both new media-feature tests are marked to ignore Chrome, Edge, and Firefox, so the added coverage
never executes on the supported browser matrix. This leaves the new command without applicable
regression coverage and can allow serialization or protocol regressions to pass unnoticed.
Code

dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[R87-89]

+    [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")]
+    [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")]
+    [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")]
Evidence
The checklist requires changed behavior to have focused regression coverage. The first new test is
ignored for Chrome, Edge, and Firefox, and the second test has the same all-browser ignore
configuration, meaning neither test runs in the current browser matrix.

AGENTS.md: Prefer Small Realistic Tests and Avoid Contract-Distorting Mocks: AGENTS.md: Prefer Small Realistic Tests and Avoid Contract-Distorting Mocks
dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[87-89]
dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[106-108]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new media-feature tests are ignored for every listed browser, so they provide no executable regression coverage.
## Issue Context
The test methods exercise `SetMediaFeaturesOverrideAsync`, but all supported browser entries are disabled with `IgnoreBrowser` attributes. Keep browser skips only where required by a documented capability gap, and add an executable lower-level serialization/command test if no current browser supports the feature.
## Fix Focus Areas
- dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[87-115]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🚀 Fast: The latest push only renames a public method parameter and its local use in two closely related declarations, with no behavioral or high-risk logic change.

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit aabbe45 🚀 Fast

Results up to commit 57dd288 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. features uses wrong shape ✗ Dismissed 📘 Rule violation ≡ Correctness
Description
SetMediaFeaturesOverrideParameters.Features serializes as a single object keyed by CSS feature
names, such as {"any-hover":"none","color":8}, instead of the protocol-required nullable array of
{name, value} records, such as
[{"name":"any-hover","value":"none"},{"name":"color","value":"8"}]. Non-null overrides therefore
have both an incompatible container shape and, for numeric features, the wrong JSON value type,
which can cause conforming endpoints to reject or misread emulation.setMediaFeaturesOverride.
Code

dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[R25-26]

+internal sealed record SetMediaFeaturesOverrideParameters(
+    [property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] MediaFeatures? Features,
Evidence
Rule 2 requires equivalent language bindings to remain behaviorally aligned, and the repository's
Ruby BiDi protocol schema defines features as a nullable list of MediaFeature records whose
name and value fields are strings. In contrast, the added .NET parameter uses a single
MediaFeatures object with feature names mapped directly to JSON properties, including numeric
values declared as long; because OptionalConverter serializes the underlying values unchanged,
those values become JSON numbers rather than the required strings, proving that the .NET wire model
conflicts with the applicable binding and protocol schema.

AGENTS.md: Maintain Consistent User-Visible Behavior Across Language Bindings
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-42]
rb/lib/selenium/webdriver/bidi/protocol/emulation.rb[122-134]
rb/sig/lib/selenium/webdriver/bidi/protocol/emulation.rbs[81-91]
rb/lib/selenium/webdriver/bidi/protocol/emulation.rb[121-134]
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-29]
dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[38-58]
dotnet/src/webdriver/BiDi/Json/Converters/OptionalConverter.cs[39-47]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description

`SetMediaFeaturesOverrideParameters.Features` is modeled as a single `MediaFeatures` object, producing a wire object keyed by CSS media-feature names instead of the protocol-required nullable array of `{name, value}` records. Numeric feature values are also serialized as JSON numbers rather than strings.

## Issue Context

Replace the object-based `MediaFeatures` wire model with a list-valued model whose records contain string `name` and `value` fields. Update the public .NET signature, parameter model, serialization metadata, and tests together; preserve explicit JSON `null` for resetting the override, and ensure numeric and enum feature values are represented as protocol strings within each record.

## Fix Focus Areas

- dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs[25-155]
- dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs[27-27]
- dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs[81-84]
- dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[86-109]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit a21a4c4 🚀 Fast


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Media tests are always ignored ✗ Dismissed 📘 Rule violation ☼ Reliability
Description
Both new media-feature tests are marked to ignore Chrome, Edge, and Firefox, so the added coverage
never executes on the supported browser matrix. This leaves the new command without applicable
regression coverage and can allow serialization or protocol regressions to pass unnoticed.
Code

dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[R87-89]

+    [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")]
+    [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")]
+    [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")]
Evidence
The checklist requires changed behavior to have focused regression coverage. The first new test is
ignored for Chrome, Edge, and Firefox, and the second test has the same all-browser ignore
configuration, meaning neither test runs in the current browser matrix.

AGENTS.md: Prefer Small Realistic Tests and Avoid Contract-Distorting Mocks
dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[87-89]
dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[106-108]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new media-feature tests are ignored for every listed browser, so they provide no executable regression coverage.

## Issue Context
The test methods exercise `SetMediaFeaturesOverrideAsync`, but all supported browser entries are disabled with `IgnoreBrowser` attributes. Keep browser skips only where required by a documented capability gap, and add an executable lower-level serialization/command test if no current browser supports the feature.

## Fix Focus Areas
- dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs[87-115]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs
Comment thread dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs
@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit a21a4c4

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit aabbe45

@nvborisenko
nvborisenko merged commit 2183264 into SeleniumHQ:trunk Aug 27, 2026
23 checks passed
@nvborisenko
nvborisenko deleted the bidi-media-features branch August 27, 2026 16:57
This was referenced Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-dotnet .NET Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants