Skip to content

[dotnet] [bidi] Statically declare commands#17330

Merged
nvborisenko merged 12 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-command-descriptor
Apr 10, 2026
Merged

[dotnet] [bidi] Statically declare commands#17330
nvborisenko merged 12 commits intoSeleniumHQ:trunkfrom
nvborisenko:bidi-command-descriptor

Conversation

@nvborisenko
Copy link
Copy Markdown
Member

@nvborisenko nvborisenko commented Apr 9, 2026

Commands declaration without allocation.

🔗 Related Issues

Contributes to #16095

💥 What does this PR do?

This pull request refactors the BiDi (Bi-Directional) WebDriver command execution pipeline to simplify command handling, improve type safety, and streamline serialization logic. The main changes include replacing the generic ExecuteCommandAsync method with a more type-safe ExecuteAsync method, centralizing command definitions, and cleaning up command class structure. Additionally, the handling of pending commands and serialization is improved for reliability and maintainability.

Refactoring of command execution and handling:

  • Replaced the generic ExecuteCommandAsync method with a more type-safe ExecuteAsync method in Broker.cs, which now uses a Command<TParameters, TResult> descriptor and parameters, improving clarity and reducing boilerplate. (dotnet/src/webdriver/BiDi/Broker.cs, [1] [2] [3] [4]
  • Updated the handling of pending commands to use TryRemove instead of TryGetValue, ensuring commands are removed as soon as they are processed, preventing potential memory leaks or double-removal. (dotnet/src/webdriver/BiDi/Broker.cs, [1] [2] [3]

Centralization and simplification of command definitions:

  • Removed individual command classes (e.g., CloseCommand, CreateUserContextCommand) and replaced them with static command descriptors in BrowserModule.cs, reducing duplication and centralizing command logic. (dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs, [1]; dotnet/src/webdriver/BiDi/Browser/Close.cs, [2]; dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs, [3]; dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs, [4]; dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs, [5]; dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs, [6]; dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs, [7]; dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs, [8]

Module and visibility adjustments:

  • Changed several module classes from public sealed to internal sealed to restrict their visibility and clarify their intended usage within the assembly. (dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs, [1]; dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs, [2]; dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs, [3]

These changes collectively improve maintainability, type safety, and the overall structure of the BiDi WebDriver implementation.

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • New feature (non-breaking change which adds functionality and tests!)

Copilot AI review requested due to automatic review settings April 9, 2026 22:08
@selenium-ci selenium-ci added the C-dotnet .NET Bindings label Apr 9, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

[dotnet] [bidi] Refactor to statically declare commands using CommandDescriptor

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Replace concrete command classes with static CommandDescriptor instances for cleaner command
  definition
• Refactor ExecuteCommandAsync to ExecuteAsync method accepting CommandDescriptor and
  parameters
• Update JSON serialization to use parameter types instead of command wrapper classes
• Change module visibility from public to internal for better encapsulation
• Simplify command execution by removing intermediate command object allocation

Grey Divider

File Changes

1. dotnet/src/webdriver/BiDi/Command.cs ✨ Enhancement +8/-18

Replace Command classes with CommandDescriptor generic type

dotnet/src/webdriver/BiDi/Command.cs


2. dotnet/src/webdriver/BiDi/Broker.cs ✨ Enhancement +13/-8

Update ExecuteAsync to compose commands from descriptor and parameters

dotnet/src/webdriver/BiDi/Broker.cs


3. dotnet/src/webdriver/BiDi/Module.cs ✨ Enhancement +3/-3

Update ExecuteAsync method signature to use CommandDescriptor

dotnet/src/webdriver/BiDi/Module.cs


View more (79)
4. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs ✨ Enhancement +89/-54

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs


5. dotnet/src/webdriver/BiDi/Network/NetworkModule.cs ✨ Enhancement +74/-38

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs


6. dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs ✨ Enhancement +58/-40

Replace command classes with static CommandDescriptor instances

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


7. dotnet/src/webdriver/BiDi/Script/ScriptModule.cs ✨ Enhancement +37/-20

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Script/ScriptModule.cs


8. dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs ✨ Enhancement +31/-16

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs


9. dotnet/src/webdriver/BiDi/Input/InputModule.cs ✨ Enhancement +18/-10

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Input/InputModule.cs


10. dotnet/src/webdriver/BiDi/Session/SessionModule.cs ✨ Enhancement +24/-11

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Session/SessionModule.cs


11. dotnet/src/webdriver/BiDi/Storage/StorageModule.cs ✨ Enhancement +16/-8

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Storage/StorageModule.cs


12. dotnet/src/webdriver/BiDi/Log/LogModule.cs ✨ Enhancement +4/-5

Change visibility to internal and use static context alias

dotnet/src/webdriver/BiDi/Log/LogModule.cs


13. dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs ✨ Enhancement +11/-6

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs


14. dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs ✨ Enhancement +4/-5

Change visibility to internal and use static context alias

dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs


15. dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs ✨ Enhancement +6/-4

Replace command classes with static CommandDescriptor instances

dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs


16. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs ✨ Enhancement +1/-1

Change visibility from public to internal

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs


17. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs ✨ Enhancement +1/-1

Change visibility from public to internal

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs


18. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs ✨ Enhancement +1/-1

Change visibility from public to internal

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs


19. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs ✨ Enhancement +1/-1

Change visibility from public to internal

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs


20. dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs ✨ Enhancement +1/-1

Change visibility from public to internal

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs


21. dotnet/test/webdriver/BiDi/Session/SessionTests.cs 🧪 Tests +5/-5

Update test to use CommandDescriptor pattern

dotnet/test/webdriver/BiDi/Session/SessionTests.cs


22. dotnet/src/webdriver/BiDi/Browser/Close.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/Close.cs


23. dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs


24. dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs


25. dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs


26. dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs


27. dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs


28. dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs


29. dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs


30. dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs


31. dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs


32. dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs


33. dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs


34. dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs


35. dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs


36. dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs


37. dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs


38. dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs


39. dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs


40. dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverride.cs Additional files +0/-3

...

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


41. dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs Additional files +0/-3

...

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


42. dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverride.cs Additional files +0/-3

...

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


43. dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditions.cs Additional files +0/-3

...

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


44. dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverride.cs Additional files +0/-3

...

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


45. dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverride.cs Additional files +0/-3

...

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


46. dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabled.cs Additional files +0/-3

...

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


47. dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverride.cs Additional files +0/-3

...

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


48. dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverride.cs Additional files +0/-3

...

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


49. dotnet/src/webdriver/BiDi/Emulation/SetTouchOverride.cs Additional files +0/-3

...

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


50. dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverride.cs Additional files +0/-3

...

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


51. dotnet/src/webdriver/BiDi/Input/PerformActions.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Input/PerformActions.cs


52. dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs


53. dotnet/src/webdriver/BiDi/Input/SetFiles.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Input/SetFiles.cs


54. dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs


55. dotnet/src/webdriver/BiDi/Network/AddIntercept.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/AddIntercept.cs


56. dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs


57. dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs


58. dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs


59. dotnet/src/webdriver/BiDi/Network/FailRequest.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/FailRequest.cs


60. dotnet/src/webdriver/BiDi/Network/GetData.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/GetData.cs


61. dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs


62. dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs


63. dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs


64. dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs


65. dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs


66. dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs


67. dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs


68. dotnet/src/webdriver/BiDi/Script/CallFunction.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/CallFunction.cs


69. dotnet/src/webdriver/BiDi/Script/Disown.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/Disown.cs


70. dotnet/src/webdriver/BiDi/Script/Evaluate.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/Evaluate.cs


71. dotnet/src/webdriver/BiDi/Script/GetRealms.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/GetRealms.cs


72. dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs


73. dotnet/src/webdriver/BiDi/Session/End.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Session/End.cs


74. dotnet/src/webdriver/BiDi/Session/New.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Session/New.cs


75. dotnet/src/webdriver/BiDi/Session/Status.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Session/Status.cs


76. dotnet/src/webdriver/BiDi/Session/Subscribe.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Session/Subscribe.cs


77. dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs


78. dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs


79. dotnet/src/webdriver/BiDi/Storage/GetCookies.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Storage/GetCookies.cs


80. dotnet/src/webdriver/BiDi/Storage/SetCookie.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/Storage/SetCookie.cs


81. dotnet/src/webdriver/BiDi/WebExtension/Install.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/WebExtension/Install.cs


82. dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs Additional files +0/-3

...

dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Apr 9, 2026

Code Review by Qodo

🐞 Bugs (1)   📘 Rule violations (1)   📎 Requirement gaps (0)   🎨 UX Issues (0)
🐞\ ☼ Reliability (1)
📘\ ⚙ Maintainability (1)

Grey Divider


Action required

1. No deprecation for modules 📘
Description
Public module types were effectively removed from the public API (made internal) without being
deprecated first or providing a guided migration path. This can cause abrupt compile breaks for
users upgrading.
Code

dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[25]

+internal sealed partial class NetworkModule : Module, INetworkModule
Evidence
PR Compliance ID 20 requires deprecating public functionality before removal and pointing to
alternatives. The diff shows NetworkModule (and other modules) moved from public to internal
with no deprecation step in the changed code.

AGENTS.md
dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[25-25]
dotnet/src/webdriver/BiDi/Input/InputModule.cs[25-25]

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

## Issue description
Public module types were removed from the public surface by changing them to `internal` without a deprecation period or guidance.

## Issue Context
If these types must be hidden, they should remain public for at least one release with `[Obsolete(...)]` messages and a documented alternative (e.g., use `IBiDi.<Module>` interface properties, or another supported entry point).

## Fix Focus Areas
- dotnet/src/webdriver/BiDi/Network/NetworkModule.cs[25-25]
- dotnet/src/webdriver/BiDi/Input/InputModule.cs[25-25]
- dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs[25-25]

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



Remediation recommended

2. Descriptor nulls crash broker 🐞
Description
CommandDescriptor is public and is the key building block for custom modules via BiDi.AsModule<T>(),
but it does not validate constructor arguments. A null/invalid Method or JsonTypeInfo will cause
late NullReferenceExceptions inside Broker.ExecuteAsync during serialization, making failures harder
to diagnose.
Code

dotnet/src/webdriver/BiDi/Command.cs[R24-34]

+public sealed class CommandDescriptor<TParameters, TResult>(
+    string method,
+    JsonTypeInfo<TParameters> paramsTypeInfo,
+    JsonTypeInfo<TResult> resultTypeInfo)
    where TParameters : Parameters
    where TResult : EmptyResult
{
-    [JsonPropertyOrder(2)]
-    public TParameters Params { get; } = @params;
+    public string Method { get; } = method;
+    public JsonTypeInfo<TParameters> ParamsTypeInfo { get; } = paramsTypeInfo;
+    public JsonTypeInfo<TResult> ResultTypeInfo { get; } = resultTypeInfo;
}
Evidence
CommandDescriptor stores method/typeinfo values without validation, while Broker.ExecuteAsync
immediately dereferences descriptor.Method and descriptor.ParamsTypeInfo when composing the JSON
request. Since BiDi.AsModule<T>() is public, external consumers can implement custom modules and
construct their own descriptors, so this is a real public-API footgun.

dotnet/src/webdriver/BiDi/Command.cs[24-34]
dotnet/src/webdriver/BiDi/Broker.cs[117-150]
dotnet/src/webdriver/BiDi/BiDi.cs[96-99]
dotnet/src/webdriver/BiDi/Module.cs[28-33]

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

### Issue description
`CommandDescriptor<TParameters, TResult>` does not validate its constructor inputs. If `method`, `paramsTypeInfo`, or `resultTypeInfo` are null/invalid, the failure occurs later in `Broker.ExecuteAsync` as a NullReferenceException during JSON write/serialization.

### Issue Context
`BiDi.AsModule<T>()` is public and enables custom module implementations outside this assembly, which will need to create `CommandDescriptor` instances.

### Fix Focus Areas
- dotnet/src/webdriver/BiDi/Command.cs[24-34]
- dotnet/src/webdriver/BiDi/Broker.cs[117-150]

### Suggested fix
- In `CommandDescriptor` constructor, throw `ArgumentNullException` for null `paramsTypeInfo`/`resultTypeInfo`, and validate `method` (non-null, non-empty).
- Optionally add `ArgumentNullException.ThrowIfNull(descriptor);` at the top of `Broker.ExecuteAsync` for extra safety and clearer error messages.

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


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the .NET BiDi implementation to define commands statically (via CommandDescriptor) and execute them through a single Broker.ExecuteAsync pathway, reducing per-call allocations and simplifying JSON source-generation requirements.

Changes:

  • Introduces CommandDescriptor<TParameters, TResult> and updates command execution to serialize { id, method, params } directly in Broker.
  • Replaces numerous concrete *Command classes with static CommandDescriptor fields + parameter records across modules.
  • Updates JSON source-generation attributes to reference parameter/result types and narrows visibility of several module implementations.

Reviewed changes

Copilot reviewed 82 out of 82 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/test/webdriver/BiDi/Session/SessionTests.cs Updates custom module test to use CommandDescriptor + ExecuteAsync.
dotnet/src/webdriver/BiDi/Broker.cs Implements ExecuteAsync and manual request JSON serialization using descriptors.
dotnet/src/webdriver/BiDi/Command.cs Replaces Command hierarchy with CommandDescriptor; keeps Parameters/EmptyResult.
dotnet/src/webdriver/BiDi/Module.cs Switches base module execution helper to ExecuteAsync(descriptor, params, ...).
dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs Converts browser commands to static descriptors; changes module implementation visibility.
dotnet/src/webdriver/BiDi/Browser/Close.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs Removes concrete command class, leaving options/result types.
dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs Removes concrete command class, leaving options/result types.
dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs Converts browsingContext commands to static descriptors; updates subscribe contexts.
dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs Narrows wrapper module visibility while keeping interface-based surface.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs Narrows wrapper module visibility while keeping interface-based surface.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs Narrows wrapper module visibility while keeping interface-based surface.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs Narrows wrapper module visibility while keeping interface-based surface.
dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs Narrows wrapper module visibility while keeping interface-based surface.
dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs Converts emulation commands to static descriptors; updates source-gen types.
dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs Removes concrete command class, leaving polymorphic params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditions.cs Removes concrete command class, leaving polymorphic params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabled.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetTouchOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverride.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Input/InputModule.cs Converts input commands to static descriptors; updates subscribe contexts.
dotnet/src/webdriver/BiDi/Input/PerformActions.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Input/SetFiles.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Log/LogModule.cs Updates subscription serialization references and narrows module visibility.
dotnet/src/webdriver/BiDi/Network/NetworkModule.cs Converts network commands to static descriptors; updates subscribe contexts.
dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/AddIntercept.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs Removes concrete command class, leaving polymorphic params/result types.
dotnet/src/webdriver/BiDi/Network/FailRequest.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/GetData.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs Converts permissions command to a static descriptor; updates source-gen types.
dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/ScriptModule.cs Converts script commands to static descriptors; updates subscribe contexts and source-gen.
dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/CallFunction.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/Disown.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/Evaluate.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/GetRealms.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Session/SessionModule.cs Converts session commands to static descriptors; updates source-gen types.
dotnet/src/webdriver/BiDi/Session/End.cs Removes concrete command class, leaving options/result types.
dotnet/src/webdriver/BiDi/Session/New.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Session/Status.cs Removes concrete command class, leaving options/result types.
dotnet/src/webdriver/BiDi/Session/Subscribe.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs Updates subscription serialization references and narrows module visibility.
dotnet/src/webdriver/BiDi/Storage/StorageModule.cs Converts storage commands to static descriptors; updates source-gen types.
dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Storage/GetCookies.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/Storage/SetCookie.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs Converts webExtension commands to static descriptors; updates source-gen types.
dotnet/src/webdriver/BiDi/WebExtension/Install.cs Removes concrete command class, leaving params/result types.
dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs Removes concrete command class, leaving params/result types.

Copilot AI review requested due to automatic review settings April 9, 2026 22:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 82 out of 82 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings April 10, 2026 17:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 83 out of 83 changed files in this pull request and generated 1 comment.

@nvborisenko nvborisenko merged commit f710cf2 into SeleniumHQ:trunk Apr 10, 2026
19 checks passed
@nvborisenko nvborisenko deleted the bidi-command-descriptor branch April 10, 2026 18:15
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.

3 participants