-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Provide extension points for custom BiDi modules #15420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
| { | ||
| await DisposeAsyncCore(); | ||
| GC.SuppressFinalize(this); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BiDi is not a sealed type, we have to implement the IAsyncDisposable pattern for types which users may extend.
|
|
||
| var message = JsonSerializer.Deserialize(new ReadOnlySpan<byte>(data), _jsonSerializerContext.Message); | ||
| var messageTypeInfo = (JsonTypeInfo<Message>)_jsonSerializerContext.GetTypeInfo(typeof(Message)); | ||
| var message = JsonSerializer.Deserialize(new ReadOnlySpan<byte>(data), messageTypeInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BiDiJsonSerializerContext is no longer "king".
We know that the Message JSON type info exists, but we must extract it manually now (AOT-safe).
| _jsonSerializerContext = jsonSerializerOptions; | ||
| } | ||
|
|
||
| public void ProvideCustomSerializationContext(JsonSerializerContext extensionContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guidance for users: do not call this method after Broker.ConnectAsync is called. Json serialization options becomes immutable and this method will throw..
public class PermissionsBiDi : BiDiIt it big mistake, meaning once I get I would say that |
|
With this PR, all the core Modules are still |
|
Ah, I see what you mean. I will try to make that vision a reality (will need to do something about |
|
Looking more into it, I'm not sure what having BiDi extensions without the core modules does. I have a follow-up PR up with a Permissions implementation #15421. If you look at the test, it uses core modules a well. Users should be free to use the modules without core BiDi, but I don't understand the use case there. |
|
Initially it was designed for continuation from EventArgs: bidi.Network.OnBeforeRequestSent(async args => await args.BiDi.DoSomethingAsync());We can revisit this design. Most likely it was motivated by network intercepting. |
|
I see the first step: |
|
Can you help me understand some design:
|
| new Json.Converters.Enumerable.GetClientWindowsResultConverter(), | ||
| new Json.Converters.Enumerable.GetRealmsResultConverter(), | ||
| }, | ||
| TypeInfoResolverChain = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think BiDi can construct his JsonSerializerContext, and then Broker will rely on it. So I am thinking on a way completely new own permissions json context rather than extending default. Why: probably having lighter json context is beneficial for serialization in terms of performance.
And Appium (who is most likely on top of Selenium), will also provide their own json context, they are still able to define it on top of our default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good idea. Then We can:
- internal Broker(BiDi bidi, Uri url)
+ internal Broker(SessionModule session, Uri url)Meaning be closer to BiDi -> Broker -> Transport


User description
Description
Enables the right extensibility for users to create their own Modules, and hook them into
BiDi.Example implementation of
Permissionsmodule:Or, if user does not care about AOT-safe JSON:
Sample Permissions module
Motivation and Context
Provides a roadmap for users to implement custom BiDi modules, such as in #15329.
Types of changes
Checklist
PR Type
Enhancement
Description
Added extensibility to
BiDifor custom modules.Introduced
ProvideCustomSerializationContextfor custom serialization.Enhanced
DisposeAsyncwith a virtual core method.Improved error handling and serialization in
Broker.Changes walkthrough 📝
BiDi.cs
Enhanced `BiDi` class for extensibility and disposaldotnet/src/webdriver/BiDi/BiDi.cs
Brokerproperty protected for extensibility.protected internalfor subclassing.Brokerdirectly.DisposeAsyncto include a virtual core method.Broker.cs
Enhanced `Broker` for custom serialization and error handlingdotnet/src/webdriver/BiDi/Communication/Broker.cs
ProvideCustomSerializationContextfor custom serializers.TypeInfoResolverChain.MessageErrorhandling.