diff --git a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs index 6da9665233c3d..4963f6d037dd7 100644 --- a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs @@ -79,9 +79,9 @@ public async Task SetDownloadBehaviorDeniedAsync(SetD return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi)); _jsonContext = new BrowserJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs index 002fc87520495..24300fb820bc3 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs @@ -253,12 +253,12 @@ public async Task OnUserPromptClosedAsync(Action InterceptRequestAsync(Func await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator, req.Intercepts)), @@ -53,7 +53,7 @@ public async Task InterceptResponseAsync(Func await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response, res.Intercepts)), @@ -71,7 +71,7 @@ public async Task InterceptAuthAsync(Func h var interceptResult = await networkModule.AddInterceptAsync([InterceptPhase.AuthRequired], addInterceptOptions).ConfigureAwait(false); - Interception interception = new(context.BiDi, interceptResult.Intercept); + Interception interception = new(networkModule, interceptResult.Intercept); await interception.OnAuthRequiredAsync( async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response, auth.Intercepts)), diff --git a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs index 41d2c03ac5a5c..865ef8d6fb5a0 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs @@ -100,10 +100,10 @@ public async Task SetGeolocationPositionErrorOverr return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, _jsonContext.SetGeolocationOverrideCommand, _jsonContext.SetGeolocationOverrideResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi)); + jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi)); _jsonContext = new EmulationJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Input/InputModule.cs index 8157a6f7031f5..f9d4ad2ae4a67 100644 --- a/dotnet/src/webdriver/BiDi/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Input/InputModule.cs @@ -61,10 +61,10 @@ public async Task OnFileDialogOpenedAsync(Action h return await SubscribeAsync("input.fileDialogOpened", handler, options, _jsonContext.FileDialogInfo).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi)); + jsonSerializerOptions.Converters.Add(new HandleConverter(bidi)); _jsonContext = new InputJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/Log/LogModule.cs b/dotnet/src/webdriver/BiDi/Log/LogModule.cs index f994cbbe8f2f2..0c825e0d7bfba 100644 --- a/dotnet/src/webdriver/BiDi/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Log/LogModule.cs @@ -39,12 +39,12 @@ public async Task OnEntryAddedAsync(Action handler, Subs return await SubscribeAsync("log.entryAdded", handler, options, _jsonContext.LogEntry).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new RealmConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new InternalIdConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new HandleConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi)); + jsonSerializerOptions.Converters.Add(new RealmConverter(bidi)); + jsonSerializerOptions.Converters.Add(new InternalIdConverter(bidi)); + jsonSerializerOptions.Converters.Add(new HandleConverter(bidi)); _jsonContext = new LogJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/Module.cs b/dotnet/src/webdriver/BiDi/Module.cs index ed5baead1a588..f5e679aac978e 100644 --- a/dotnet/src/webdriver/BiDi/Module.cs +++ b/dotnet/src/webdriver/BiDi/Module.cs @@ -26,8 +26,6 @@ namespace OpenQA.Selenium.BiDi; public abstract class Module { - protected BiDi BiDi { get; private set; } = null!; - private Broker Broker { get; set; } = null!; protected Task ExecuteCommandAsync(TCommand command, CommandOptions? options, JsonTypeInfo jsonCommandTypeInfo, JsonTypeInfo jsonResultTypeInfo) @@ -51,18 +49,17 @@ public Task SubscribeAsync(string eventName, Func(BiDi bidi, Broker broker, JsonSerializerOptions jsonSerializerOptions) where TModule : Module, new() { TModule module = new() { - BiDi = bidi, Broker = broker }; - module.Initialize(jsonSerializerOptions); + module.Initialize(bidi, jsonSerializerOptions); return module; } diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs index 54324e11cf8f2..e95f121cbb8db 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.HighLevel.cs @@ -30,7 +30,7 @@ public async Task InterceptRequestAsync(Func await handler(new(req.BiDi, req.Context, req.IsBlocked, req.Navigation, req.RedirectCount, req.Request, req.Timestamp, req.Initiator, req.Intercepts))).ConfigureAwait(false); @@ -41,7 +41,7 @@ public async Task InterceptResponseAsync(Func await handler(new(res.BiDi, res.Context, res.IsBlocked, res.Navigation, res.RedirectCount, res.Request, res.Timestamp, res.Response, res.Intercepts))).ConfigureAwait(false); @@ -52,7 +52,7 @@ public async Task InterceptAuthAsync(Func h { var interceptResult = await AddInterceptAsync([InterceptPhase.AuthRequired], options).ConfigureAwait(false); - Interception interception = new(BiDi, interceptResult.Intercept); + Interception interception = new(this, interceptResult.Intercept); await interception.OnAuthRequiredAsync(async auth => await handler(new(auth.BiDi, auth.Context, auth.IsBlocked, auth.Navigation, auth.RedirectCount, auth.Request, auth.Timestamp, auth.Response, auth.Intercepts))).ConfigureAwait(false); @@ -128,7 +128,7 @@ public Task ContinueAsync(ContinueWithAuthCancelCredentialsOptions? options = nu } } -public sealed record Interception(BiDi BiDi, Intercept Intercept) : IAsyncDisposable +public sealed record Interception(NetworkModule Network, Intercept Intercept) : IAsyncDisposable { IList OnBeforeRequestSentSubscriptions { get; } = []; IList OnResponseStartedSubscriptions { get; } = []; @@ -136,7 +136,7 @@ public sealed record Interception(BiDi BiDi, Intercept Intercept) : IAsyncDispos public async Task RemoveAsync() { - await BiDi.Network.RemoveInterceptAsync(Intercept).ConfigureAwait(false); + await Network.RemoveInterceptAsync(Intercept).ConfigureAwait(false); foreach (var subscription in OnBeforeRequestSentSubscriptions) { @@ -156,21 +156,21 @@ public async Task RemoveAsync() public async Task OnBeforeRequestSentAsync(Func handler, SubscriptionOptions? options = null) { - var subscription = await BiDi.Network.OnBeforeRequestSentAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); + var subscription = await Network.OnBeforeRequestSentAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); OnBeforeRequestSentSubscriptions.Add(subscription); } public async Task OnResponseStartedAsync(Func handler, SubscriptionOptions? options = null) { - var subscription = await BiDi.Network.OnResponseStartedAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); + var subscription = await Network.OnResponseStartedAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); OnResponseStartedSubscriptions.Add(subscription); } public async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) { - var subscription = await BiDi.Network.OnAuthRequiredAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); + var subscription = await Network.OnAuthRequiredAsync(async args => await Filter(args, handler), options).ConfigureAwait(false); OnAuthRequiredSubscriptions.Add(subscription); } diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs index e11cc05d7930c..2cad7bc13c569 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs @@ -174,12 +174,12 @@ public async Task OnAuthRequiredAsync(Action SetPermissionAsync(PermissionDescriptor d return await ExecuteCommandAsync(new SetPermissionCommand(@params), options, _jsonContext.SetPermissionCommand, _jsonContext.SetPermissionResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi)); _jsonContext = new PermissionsJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs index 829ca972f19d2..a4b94d9fa436c 100644 --- a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs @@ -117,13 +117,13 @@ public async Task OnRealmDestroyedAsync(Action EndAsync(EndOptions? options = null) return await ExecuteCommandAsync(new EndCommand(), options, _jsonContext.EndCommand, _jsonContext.EndResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi)); + jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi)); _jsonContext = new SessionJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs b/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs index a17bb632c8661..97458a28a2cff 100644 --- a/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs @@ -49,10 +49,10 @@ public async Task SetCookieAsync(PartialCookie cookie, SetCooki return await ExecuteCommandAsync(new SetCookieCommand(@params), options, _jsonContext.SetCookieCommand, _jsonContext.SetCookieResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(BiDi)); - jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new BrowsingContextConverter(bidi)); + jsonSerializerOptions.Converters.Add(new BrowserUserContextConverter(bidi)); _jsonContext = new StorageJsonSerializerContext(jsonSerializerOptions); } diff --git a/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs b/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs index c49f89fe09556..bab8d9a25d246 100644 --- a/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs +++ b/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs @@ -42,9 +42,9 @@ public async Task UninstallAsync(Extension extension, Uninstall return await ExecuteCommandAsync(new UninstallCommand(@params), options, _jsonContext.UninstallCommand, _jsonContext.UninstallResult).ConfigureAwait(false); } - protected override void Initialize(JsonSerializerOptions jsonSerializerOptions) + protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions) { - jsonSerializerOptions.Converters.Add(new WebExtensionConverter(BiDi)); + jsonSerializerOptions.Converters.Add(new WebExtensionConverter(bidi)); _jsonContext = new WebExtensionJsonSerializerContext(jsonSerializerOptions); }