|
19 | 19 |
|
20 | 20 | using OpenQA.Selenium.BiDi.Communication; |
21 | 21 | using System.Collections.Generic; |
| 22 | +using System.Text.Json; |
22 | 23 | using System.Text.Json.Serialization; |
23 | 24 | using System.Threading.Tasks; |
24 | 25 |
|
25 | 26 | namespace OpenQA.Selenium.BiDi.Browser; |
26 | 27 |
|
27 | 28 | public sealed class BrowserModule : Module |
28 | 29 | { |
| 30 | + private BrowserModuleJsonSerializerContext _context = null!; |
29 | 31 | public async Task<EmptyResult> CloseAsync(CloseOptions? options = null) |
30 | 32 | { |
31 | | - return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options).ConfigureAwait(false); |
| 33 | + return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _context).ConfigureAwait(false); |
32 | 34 | } |
33 | 35 |
|
34 | 36 | public async Task<UserContextInfo> CreateUserContextAsync(CreateUserContextOptions? options = null) |
35 | 37 | { |
36 | 38 | var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior); |
37 | 39 |
|
38 | | - return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options).ConfigureAwait(false); |
| 40 | + return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _context).ConfigureAwait(false); |
39 | 41 | } |
40 | 42 |
|
41 | 43 | public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null) |
42 | 44 | { |
43 | | - return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options).ConfigureAwait(false); |
| 45 | + return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _context).ConfigureAwait(false); |
44 | 46 | } |
45 | 47 |
|
46 | 48 | public async Task<EmptyResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null) |
47 | 49 | { |
48 | 50 | var @params = new RemoveUserContextParameters(userContext); |
49 | 51 |
|
50 | | - return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options).ConfigureAwait(false); |
| 52 | + return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _context).ConfigureAwait(false); |
51 | 53 | } |
52 | 54 |
|
53 | 55 | public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null) |
54 | 56 | { |
55 | | - return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options).ConfigureAwait(false); |
| 57 | + return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _context).ConfigureAwait(false); |
56 | 58 | } |
57 | 59 |
|
58 | 60 | public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null) |
59 | 61 | { |
60 | 62 | var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts); |
61 | 63 |
|
62 | | - return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false); |
| 64 | + return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false); |
63 | 65 | } |
64 | 66 |
|
65 | 67 | public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null) |
66 | 68 | { |
67 | 69 | var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts); |
68 | 70 |
|
69 | | - return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false); |
| 71 | + return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false); |
70 | 72 | } |
71 | 73 |
|
72 | 74 | public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null) |
73 | 75 | { |
74 | 76 | var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts); |
75 | 77 |
|
76 | | - return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false); |
| 78 | + return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false); |
77 | 79 | } |
78 | 80 |
|
79 | | - protected internal override void Initialize(Broker broker) |
| 81 | + protected internal override void Initialize(JsonSerializerOptions options) |
80 | 82 | { |
81 | | - broker.ConfigureJsonContext(opts => opts.TypeInfoResolverChain.Add(BrowserModuleJsonSerializerContext.Default)); |
| 83 | + _context = new BrowserModuleJsonSerializerContext(options); |
82 | 84 | } |
83 | 85 | } |
84 | 86 |
|
| 87 | +[JsonSerializable(typeof(Command))] |
| 88 | +[JsonSerializable(typeof(EmptyResult))] |
| 89 | + |
85 | 90 | [JsonSerializable(typeof(CloseCommand))] |
86 | 91 | [JsonSerializable(typeof(CreateUserContextCommand))] |
87 | 92 | [JsonSerializable(typeof(GetUserContextsCommand))] |
|
0 commit comments