Skip to content

Commit a832596

Browse files
committed
Revert to one big json context
Fix
1 parent 3b2f9f4 commit a832596

File tree

13 files changed

+332
-350
lines changed

13 files changed

+332
-350
lines changed

dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private BiDi(string url)
6060

6161
public TModule AsModule<TModule>() where TModule : Module, new()
6262
{
63-
return (TModule)_modules.GetOrAdd(typeof(TModule), _ => Module.Create<TModule>(this, _broker));
63+
return (TModule)_modules.GetOrAdd(typeof(TModule), _ => Module.Create<TModule>(_broker));
6464
}
6565

6666
public Task<Session.StatusResult> StatusAsync()

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,61 +27,59 @@ namespace OpenQA.Selenium.BiDi.Browser;
2727

2828
public sealed class BrowserModule : Module
2929
{
30-
private BrowserModuleJsonSerializerContext _jsonContext = null!;
31-
3230
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
3331
{
34-
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _jsonContext).ConfigureAwait(false);
32+
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, JsonContext).ConfigureAwait(false);
3533
}
3634

3735
public async Task<UserContextInfo> CreateUserContextAsync(CreateUserContextOptions? options = null)
3836
{
3937
var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior);
4038

41-
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _jsonContext).ConfigureAwait(false);
39+
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
4240
}
4341

4442
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
4543
{
46-
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _jsonContext).ConfigureAwait(false);
44+
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, JsonContext).ConfigureAwait(false);
4745
}
4846

4947
public async Task<EmptyResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
5048
{
5149
var @params = new RemoveUserContextParameters(userContext);
5250

53-
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _jsonContext).ConfigureAwait(false);
51+
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
5452
}
5553

5654
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
5755
{
58-
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _jsonContext).ConfigureAwait(false);
56+
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, JsonContext).ConfigureAwait(false);
5957
}
6058

6159
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
6260
{
6361
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
6462

65-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
63+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
6664
}
6765

6866
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
6967
{
7068
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);
7169

72-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
70+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
7371
}
7472

7573
public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
7674
{
7775
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
7876

79-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _jsonContext).ConfigureAwait(false);
77+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
8078
}
8179

82-
protected internal override void Initialize(JsonSerializerOptions options)
80+
protected internal override JsonSerializerContext ConfigureJson(JsonSerializerOptions options)
8381
{
84-
_jsonContext = new(options);
82+
return new BrowserModuleJsonSerializerContext(options);
8583
}
8684
}
8785

0 commit comments

Comments
 (0)