From 2f4138aa437a1f46acbeef804db48de2c8ff0deb Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 00:56:30 +0300 Subject: [PATCH 1/7] Example for LogModule --- dotnet/src/webdriver/BiDi/Broker.cs | 22 ++++++++----------- .../BrowsingContextLogModule.cs | 16 ++++++++++---- dotnet/src/webdriver/BiDi/EventHandler.cs | 4 ++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Broker.cs b/dotnet/src/webdriver/BiDi/Broker.cs index f7e23c7d2f076..8ba9b3c8d7f56 100644 --- a/dotnet/src/webdriver/BiDi/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Broker.cs @@ -145,23 +145,21 @@ public async Task ExecuteCommandAsync(TCommand comma return (TResult)await tcs.Task.ConfigureAwait(false); } - public async Task SubscribeAsync(string eventName, Action action, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) + public Task SubscribeAsync(string eventName, Action action, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) where TEventArgs : EventArgs { - _eventTypesMap[eventName] = jsonTypeInfo; - - var handlers = _eventHandlers.GetOrAdd(eventName, (a) => []); - - var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false); - var eventHandler = new SyncEventHandler(eventName, action); + return SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo); + } - handlers.Add(eventHandler); - - return new Subscription(subscribeResult.Subscription, this, eventHandler); + public Task SubscribeAsync(string eventName, Func func, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) + where TEventArgs : EventArgs + { + var eventHandler = new AsyncEventHandler(eventName, func); + return SubscribeAsync(eventName, eventHandler, options, jsonTypeInfo); } - public async Task SubscribeAsync(string eventName, Func func, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) + private async Task SubscribeAsync(string eventName, EventHandler eventHandler, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) where TEventArgs : EventArgs { _eventTypesMap[eventName] = jsonTypeInfo; @@ -170,8 +168,6 @@ public async Task SubscribeAsync(string eventName, Fun var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = options?.Contexts, UserContexts = options?.UserContexts }).ConfigureAwait(false); - var eventHandler = new AsyncEventHandler(eventName, func); - handlers.Add(eventHandler); return new Subscription(subscribeResult.Subscription, this, eventHandler); diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs index 0327a48044dca..f4f32003d449c 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs @@ -27,23 +27,31 @@ public sealed class BrowsingContextLogModule(BrowsingContext context, LogModule { public Task OnEntryAddedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return logModule.OnEntryAddedAsync(async args => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + async Task OnContextMatch(Log.LogEntry args) { if (context.Equals(args.Source.Context)) { await handler(args).ConfigureAwait(false); } - }, new SubscriptionOptions() { Timeout = options?.Timeout }); // special case, don't scope to context, awaiting https://github.com/w3c/webdriver-bidi/issues/1032 + } + + return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } public Task OnEntryAddedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return logModule.OnEntryAddedAsync(args => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + void OnContextMatch(Log.LogEntry args) { if (context.Equals(args.Source.Context)) { handler(args); } - }, new SubscriptionOptions() { Timeout = options?.Timeout }); // special case, don't scope to context, awaiting https://github.com/w3c/webdriver-bidi/issues/1032 + } + + return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } } diff --git a/dotnet/src/webdriver/BiDi/EventHandler.cs b/dotnet/src/webdriver/BiDi/EventHandler.cs index b5d7ca9b3feac..4015a2f713ab4 100644 --- a/dotnet/src/webdriver/BiDi/EventHandler.cs +++ b/dotnet/src/webdriver/BiDi/EventHandler.cs @@ -32,7 +32,7 @@ internal abstract class EventHandler(string eventName) internal class AsyncEventHandler(string eventName, Func func) : EventHandler(eventName) where TEventArgs : EventArgs { - private readonly Func _func = func; + private readonly Func _func = func ?? throw new ArgumentNullException(nameof(func)); public override async ValueTask InvokeAsync(EventArgs args) { @@ -43,7 +43,7 @@ public override async ValueTask InvokeAsync(EventArgs args) internal class SyncEventHandler(string eventName, Action action) : EventHandler(eventName) where TEventArgs : EventArgs { - private readonly Action _action = action; + private readonly Action _action = action ?? throw new ArgumentNullException(nameof(action)); public override ValueTask InvokeAsync(EventArgs args) { From edea604810926299e3dc1b7a9d782d17edd4c623 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 01:10:26 +0300 Subject: [PATCH 2/7] Input --- .../BrowsingContextInputModule.cs | 16 ++++++++++++---- dotnet/src/webdriver/BiDi/EventHandler.cs | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs index da4666a6f3bfc..82ed31f22272a 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs @@ -43,23 +43,31 @@ public Task SetFilesAsync(Script.ISharedReference element, IEnum public Task OnFileDialogOpenedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return inputModule.OnFileDialogOpenedAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + async Task OnContextMatch(FileDialogInfo e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } + + return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } public Task OnFileDialogOpenedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return inputModule.OnFileDialogOpenedAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + void OnContextMatch(FileDialogInfo e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } + + return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } } diff --git a/dotnet/src/webdriver/BiDi/EventHandler.cs b/dotnet/src/webdriver/BiDi/EventHandler.cs index 4015a2f713ab4..12cde327e3601 100644 --- a/dotnet/src/webdriver/BiDi/EventHandler.cs +++ b/dotnet/src/webdriver/BiDi/EventHandler.cs @@ -32,7 +32,7 @@ internal abstract class EventHandler(string eventName) internal class AsyncEventHandler(string eventName, Func func) : EventHandler(eventName) where TEventArgs : EventArgs { - private readonly Func _func = func ?? throw new ArgumentNullException(nameof(func)); + private readonly Func _func = func ?? throw new ArgumentNullException(nameof(func), "Async event handler function cannot be null."); public override async ValueTask InvokeAsync(EventArgs args) { @@ -43,7 +43,7 @@ public override async ValueTask InvokeAsync(EventArgs args) internal class SyncEventHandler(string eventName, Action action) : EventHandler(eventName) where TEventArgs : EventArgs { - private readonly Action _action = action ?? throw new ArgumentNullException(nameof(action)); + private readonly Action _action = action ?? throw new ArgumentNullException(nameof(action), "Sync event handler action cannot be null."); public override ValueTask InvokeAsync(EventArgs args) { From 701b74700cce14a5d9dc1ffc1d69b4f36ab173ad Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 01:12:26 +0300 Subject: [PATCH 3/7] Network --- .../BrowsingContextNetworkModule.cs | 80 ++++++++++++++----- 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs index d3fdd49e31e8b..abeb82fc3fe27 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs @@ -92,112 +92,152 @@ public Task SetCacheBehaviorAsync(CacheBehavior behavior public Task OnBeforeRequestSentAsync(Func handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnBeforeRequestSentAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnBeforeRequestSentAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + async Task OnContextMatch(BeforeRequestSentEventArgs e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnBeforeRequestSentAsync(Action handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnBeforeRequestSentAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnBeforeRequestSentAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + void OnContextMatch(BeforeRequestSentEventArgs e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnResponseStartedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnResponseStartedAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnResponseStartedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + async Task OnContextMatch(ResponseStartedEventArgs e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnResponseStartedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnResponseStartedAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnResponseStartedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + void OnContextMatch(ResponseStartedEventArgs e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnResponseCompletedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnResponseCompletedAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnResponseCompletedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + async Task OnContextMatch(ResponseCompletedEventArgs e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnResponseCompletedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnResponseCompletedAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnResponseCompletedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + void OnContextMatch(ResponseCompletedEventArgs e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnFetchErrorAsync(Func handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnFetchErrorAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnFetchErrorAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + async Task OnContextMatch(FetchErrorEventArgs e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnFetchErrorAsync(Action handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnFetchErrorAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnFetchErrorAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + void OnContextMatch(FetchErrorEventArgs e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnAuthRequiredAsync(Func handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnAuthRequiredAsync(async e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnAuthRequiredAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + async Task OnContextMatch(AuthRequiredEventArgs e) { if (context.Equals(e.Context)) { await handler(e).ConfigureAwait(false); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } public Task OnAuthRequiredAsync(Action handler, ContextSubscriptionOptions? options = null) { - return networkModule.OnAuthRequiredAsync(e => + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnAuthRequiredAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + + void OnContextMatch(AuthRequiredEventArgs e) { if (context.Equals(e.Context)) { handler(e); } - }, ContextSubscriptionOptions.WithContext(options, context)); + } } } From 934940f090b10e3870077dae18107f5a8803a681 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 01:15:36 +0300 Subject: [PATCH 4/7] Unify --- .../BiDi/BrowsingContext/BrowsingContextInputModule.cs | 8 ++++---- .../BiDi/BrowsingContext/BrowsingContextLogModule.cs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs index 82ed31f22272a..fe8f5458c8dba 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs @@ -45,6 +45,8 @@ public Task OnFileDialogOpenedAsync(Func han { if (handler is null) throw new ArgumentNullException(nameof(handler)); + return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + async Task OnContextMatch(FileDialogInfo e) { if (context.Equals(e.Context)) @@ -52,14 +54,14 @@ async Task OnContextMatch(FileDialogInfo e) await handler(e).ConfigureAwait(false); } } - - return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } public Task OnFileDialogOpenedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); + return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + void OnContextMatch(FileDialogInfo e) { if (context.Equals(e.Context)) @@ -67,7 +69,5 @@ void OnContextMatch(FileDialogInfo e) handler(e); } } - - return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } } diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs index f4f32003d449c..463c4063ae937 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs @@ -29,6 +29,8 @@ public Task OnEntryAddedAsync(Func handler, Co { if (handler is null) throw new ArgumentNullException(nameof(handler)); + return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + async Task OnContextMatch(Log.LogEntry args) { if (context.Equals(args.Source.Context)) @@ -36,14 +38,14 @@ async Task OnContextMatch(Log.LogEntry args) await handler(args).ConfigureAwait(false); } } - - return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } public Task OnEntryAddedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); + return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + void OnContextMatch(Log.LogEntry args) { if (context.Equals(args.Source.Context)) @@ -51,7 +53,5 @@ void OnContextMatch(Log.LogEntry args) handler(args); } } - - return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); } } From 820a283f5cfa260e0330ad0cdae482e9e8655727 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 02:12:59 +0300 Subject: [PATCH 5/7] End up with private methods --- .../BrowsingContextInputModule.cs | 34 ++-- .../BrowsingContextLogModule.cs | 34 ++-- .../BrowsingContextNetworkModule.cs | 188 ++++++++++-------- 3 files changed, 142 insertions(+), 114 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs index fe8f5458c8dba..d8e991ce8c730 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs @@ -45,29 +45,33 @@ public Task OnFileDialogOpenedAsync(Func han { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - async Task OnContextMatch(FileDialogInfo e) - { - if (context.Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - } + return inputModule.OnFileDialogOpenedAsync( + e => HandleFileDialogOpenedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnFileDialogOpenedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return inputModule.OnFileDialogOpenedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + return inputModule.OnFileDialogOpenedAsync( + e => HandleFileDialogOpened(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } + + private async Task HandleFileDialogOpenedAsync(FileDialogInfo e, Func handler) + { + if (context.Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } - void OnContextMatch(FileDialogInfo e) + private void HandleFileDialogOpened(FileDialogInfo e, Action handler) + { + if (context.Equals(e.Context)) { - if (context.Equals(e.Context)) - { - handler(e); - } + handler(e); } } } diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs index 463c4063ae937..08296bd783fb0 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs @@ -29,29 +29,33 @@ public Task OnEntryAddedAsync(Func handler, Co { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - async Task OnContextMatch(Log.LogEntry args) - { - if (context.Equals(args.Source.Context)) - { - await handler(args).ConfigureAwait(false); - } - } + return logModule.OnEntryAddedAsync( + e => HandleEntryAddedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnEntryAddedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return logModule.OnEntryAddedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + return logModule.OnEntryAddedAsync( + e => HandleEntryAdded(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } + + private async Task HandleEntryAddedAsync(Log.LogEntry e, Func handler) + { + if (context.Equals(e.Source.Context)) + { + await handler(e).ConfigureAwait(false); + } + } - void OnContextMatch(Log.LogEntry args) + private void HandleEntryAdded(Log.LogEntry e, Action handler) + { + if (context.Equals(e.Source.Context)) { - if (context.Equals(args.Source.Context)) - { - handler(args); - } + handler(e); } } } diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs index abeb82fc3fe27..3517674956b91 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs @@ -94,149 +94,169 @@ public Task OnBeforeRequestSentAsync(Func HandleBeforeRequestSentAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnBeforeRequestSentAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnBeforeRequestSentAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - void OnContextMatch(BeforeRequestSentEventArgs e) - { - if (context.Equals(e.Context)) - { - handler(e); - } - } + return networkModule.OnBeforeRequestSentAsync( + e => HandleBeforeRequestSent(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnResponseStartedAsync(Func handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnResponseStartedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - async Task OnContextMatch(ResponseStartedEventArgs e) - { - if (context.Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - } + return networkModule.OnResponseStartedAsync(e + => HandleResponseStartedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnResponseStartedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnResponseStartedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - void OnContextMatch(ResponseStartedEventArgs e) - { - if (context.Equals(e.Context)) - { - handler(e); - } - } + return networkModule.OnResponseStartedAsync( + e => HandleResponseStarted(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnResponseCompletedAsync(Func handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnResponseCompletedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - async Task OnContextMatch(ResponseCompletedEventArgs e) - { - if (context.Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - } + return networkModule.OnResponseCompletedAsync( + e => HandleResponseCompletedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnResponseCompletedAsync(Action handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnResponseCompletedAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); - - void OnContextMatch(ResponseCompletedEventArgs e) - { - if (context.Equals(e.Context)) - { - handler(e); - } - } + return networkModule.OnResponseCompletedAsync( + e => HandleResponseCompleted(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); } public Task OnFetchErrorAsync(Func handler, ContextSubscriptionOptions? options = null) { if (handler is null) throw new ArgumentNullException(nameof(handler)); - return networkModule.OnFetchErrorAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + return networkModule.OnFetchErrorAsync( + e => HandleFetchErrorAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } + + public Task OnFetchErrorAsync(Action handler, ContextSubscriptionOptions? options = null) + { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnFetchErrorAsync( + e => HandleFetchError(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } + + public Task OnAuthRequiredAsync(Func handler, ContextSubscriptionOptions? options = null) + { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnAuthRequiredAsync( + e => HandleAuthRequiredAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } + + public Task OnAuthRequiredAsync(Action handler, ContextSubscriptionOptions? options = null) + { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + + return networkModule.OnAuthRequiredAsync( + e => HandleAuthRequired(e, handler), + ContextSubscriptionOptions.WithContext(options, context)); + } - async Task OnContextMatch(FetchErrorEventArgs e) + private async Task HandleBeforeRequestSentAsync(BeforeRequestSentEventArgs e, Func handler) + { + if (context.Equals(e.Context)) { - if (context.Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } + await handler(e).ConfigureAwait(false); } } - public Task OnFetchErrorAsync(Action handler, ContextSubscriptionOptions? options = null) + private void HandleBeforeRequestSent(BeforeRequestSentEventArgs e, Action handler) { - if (handler is null) throw new ArgumentNullException(nameof(handler)); + if (context.Equals(e.Context)) + { + handler(e); + } + } - return networkModule.OnFetchErrorAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + private async Task HandleResponseStartedAsync(ResponseStartedEventArgs e, Func handler) + { + if (context.Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } - void OnContextMatch(FetchErrorEventArgs e) + private void HandleResponseStarted(ResponseStartedEventArgs e, Action handler) + { + if (context.Equals(e.Context)) { - if (context.Equals(e.Context)) - { - handler(e); - } + handler(e); } } - public Task OnAuthRequiredAsync(Func handler, ContextSubscriptionOptions? options = null) + private async Task HandleResponseCompletedAsync(ResponseCompletedEventArgs e, Func handler) { - if (handler is null) throw new ArgumentNullException(nameof(handler)); + if (context.Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } - return networkModule.OnAuthRequiredAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + private void HandleResponseCompleted(ResponseCompletedEventArgs e, Action handler) + { + if (context.Equals(e.Context)) + { + handler(e); + } + } - async Task OnContextMatch(AuthRequiredEventArgs e) + private async Task HandleFetchErrorAsync(FetchErrorEventArgs e, Func handler) + { + if (context.Equals(e.Context)) { - if (context.Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } + await handler(e).ConfigureAwait(false); } } - public Task OnAuthRequiredAsync(Action handler, ContextSubscriptionOptions? options = null) + private void HandleFetchError(FetchErrorEventArgs e, Action handler) { - if (handler is null) throw new ArgumentNullException(nameof(handler)); + if (context.Equals(e.Context)) + { + handler(e); + } + } - return networkModule.OnAuthRequiredAsync(OnContextMatch, ContextSubscriptionOptions.WithContext(options, context)); + private async Task HandleAuthRequiredAsync(AuthRequiredEventArgs e, Func handler) + { + if (context.Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } - void OnContextMatch(AuthRequiredEventArgs e) + private void HandleAuthRequired(AuthRequiredEventArgs e, Action handler) + { + if (context.Equals(e.Context)) { - if (context.Equals(e.Context)) - { - handler(e); - } + handler(e); } } } From 2ee96cf75466ec3245e82b64ccc84b4bbed50a1d Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 02:23:34 +0300 Subject: [PATCH 6/7] Update BrowsingContext.cs --- .../BiDi/BrowsingContext/BrowsingContext.cs | 358 +++++++++++------- 1 file changed, 219 insertions(+), 139 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs index cb53464c2a247..80b5e60dbb8fa 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs @@ -128,222 +128,302 @@ public Task GetTreeAsync(ContextGetTreeOptions? options = null) public Task OnNavigationStartedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationStartedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationStartedAsync( + e => HandleNavigationStartedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationStartedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationStartedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationStartedAsync( + e => HandleNavigationStarted(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnFragmentNavigatedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnFragmentNavigatedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync( + e => HandleFragmentNavigatedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnFragmentNavigatedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnFragmentNavigatedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync( + e => HandleFragmentNavigated(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnHistoryUpdatedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnHistoryUpdatedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnHistoryUpdatedAsync( + e => HandleHistoryUpdatedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnHistoryUpdatedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnHistoryUpdatedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnHistoryUpdatedAsync( + e => HandleHistoryUpdated(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDomContentLoadedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDomContentLoadedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDomContentLoadedAsync( + e => HandleDomContentLoadedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDomContentLoadedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDomContentLoadedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDomContentLoadedAsync( + e => HandleDomContentLoaded(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnLoadAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnLoadAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnLoadAsync( + e => HandleLoad(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnLoadAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnLoadAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnLoadAsync( + e => HandleLoadAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDownloadWillBeginAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDownloadWillBeginAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync( + e => HandleDownloadWillBegin(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDownloadWillBeginAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDownloadWillBeginAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync( + e => HandleDownloadWillBeginAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDownloadEndAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDownloadEndAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDownloadEndAsync( + e => HandleDownloadEnd(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnDownloadEndAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnDownloadEndAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnDownloadEndAsync( + e => HandleDownloadEndAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationAbortedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationAbortedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationAbortedAsync( + e => HandleNavigationAborted(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationAbortedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationAbortedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationAbortedAsync( + e => HandleNavigationAbortedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationFailedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationFailedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationFailedAsync( + e => HandleNavigationFailed(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationFailedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationFailedAsync(async e => - { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationFailedAsync( + e => HandleNavigationFailedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationCommittedAsync(Action handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationCommittedAsync(e => - { - if (Equals(e.Context)) - { - handler(e); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + return BiDi.BrowsingContext.OnNavigationCommittedAsync( + e => HandleNavigationCommitted(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); } public Task OnNavigationCommittedAsync(Func handler, ContextSubscriptionOptions? options = null) { - return BiDi.BrowsingContext.OnNavigationCommittedAsync(async e => + return BiDi.BrowsingContext.OnNavigationCommittedAsync( + e => HandleNavigationCommittedAsync(e, handler), + ContextSubscriptionOptions.WithContext(options, this)); + } + + private async Task HandleNavigationStartedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleNavigationStarted(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleFragmentNavigatedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleFragmentNavigated(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleHistoryUpdatedAsync(HistoryUpdatedEventArgs e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleHistoryUpdated(HistoryUpdatedEventArgs e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleDomContentLoadedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleDomContentLoaded(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private void HandleLoad(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleLoadAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleDownloadWillBegin(DownloadWillBeginEventArgs e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleDownloadWillBeginAsync(DownloadWillBeginEventArgs e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleDownloadEnd(DownloadEndEventArgs e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleDownloadEndAsync(DownloadEndEventArgs e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleNavigationAborted(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleNavigationAbortedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleNavigationFailed(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleNavigationFailedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) + { + await handler(e).ConfigureAwait(false); + } + } + + private void HandleNavigationCommitted(NavigationInfo e, Action handler) + { + if (Equals(e.Context)) + { + handler(e); + } + } + + private async Task HandleNavigationCommittedAsync(NavigationInfo e, Func handler) + { + if (Equals(e.Context)) { - if (Equals(e.Context)) - { - await handler(e).ConfigureAwait(false); - } - }, ContextSubscriptionOptions.WithContext(options, this)); + await handler(e).ConfigureAwait(false); + } } public bool Equals(BrowsingContext? other) From ebe229993f72002af06f068ae1d77c00937dfc24 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 21 Jan 2026 02:25:29 +0300 Subject: [PATCH 7/7] Null guard --- .../BiDi/BrowsingContext/BrowsingContext.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs index 80b5e60dbb8fa..b03af60084a0b 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs @@ -128,6 +128,8 @@ public Task GetTreeAsync(ContextGetTreeOptions? options = null) public Task OnNavigationStartedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationStartedAsync( e => HandleNavigationStartedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -135,6 +137,8 @@ public Task OnNavigationStartedAsync(Func ha public Task OnNavigationStartedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationStartedAsync( e => HandleNavigationStarted(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -142,6 +146,8 @@ public Task OnNavigationStartedAsync(Action handle public Task OnFragmentNavigatedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync( e => HandleFragmentNavigatedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -149,6 +155,8 @@ public Task OnFragmentNavigatedAsync(Func ha public Task OnFragmentNavigatedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnFragmentNavigatedAsync( e => HandleFragmentNavigated(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -156,6 +164,8 @@ public Task OnFragmentNavigatedAsync(Action handle public Task OnHistoryUpdatedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnHistoryUpdatedAsync( e => HandleHistoryUpdatedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -163,6 +173,8 @@ public Task OnHistoryUpdatedAsync(Func OnHistoryUpdatedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnHistoryUpdatedAsync( e => HandleHistoryUpdated(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -170,6 +182,8 @@ public Task OnHistoryUpdatedAsync(Action public Task OnDomContentLoadedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDomContentLoadedAsync( e => HandleDomContentLoadedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -177,6 +191,8 @@ public Task OnDomContentLoadedAsync(Func han public Task OnDomContentLoadedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDomContentLoadedAsync( e => HandleDomContentLoaded(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -184,6 +200,8 @@ public Task OnDomContentLoadedAsync(Action handler public Task OnLoadAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnLoadAsync( e => HandleLoad(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -191,6 +209,8 @@ public Task OnLoadAsync(Action handler, ContextSub public Task OnLoadAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnLoadAsync( e => HandleLoadAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -198,6 +218,8 @@ public Task OnLoadAsync(Func handler, Contex public Task OnDownloadWillBeginAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync( e => HandleDownloadWillBegin(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -205,6 +227,8 @@ public Task OnDownloadWillBeginAsync(Action OnDownloadWillBeginAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDownloadWillBeginAsync( e => HandleDownloadWillBeginAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -212,6 +236,8 @@ public Task OnDownloadWillBeginAsync(Func OnDownloadEndAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDownloadEndAsync( e => HandleDownloadEnd(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -219,6 +245,8 @@ public Task OnDownloadEndAsync(Action handle public Task OnDownloadEndAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnDownloadEndAsync( e => HandleDownloadEndAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -226,6 +254,8 @@ public Task OnDownloadEndAsync(Func ha public Task OnNavigationAbortedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationAbortedAsync( e => HandleNavigationAborted(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -233,6 +263,8 @@ public Task OnNavigationAbortedAsync(Action handle public Task OnNavigationAbortedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationAbortedAsync( e => HandleNavigationAbortedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -240,6 +272,8 @@ public Task OnNavigationAbortedAsync(Func ha public Task OnNavigationFailedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationFailedAsync( e => HandleNavigationFailed(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -247,6 +281,8 @@ public Task OnNavigationFailedAsync(Action handler public Task OnNavigationFailedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationFailedAsync( e => HandleNavigationFailedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -254,6 +290,8 @@ public Task OnNavigationFailedAsync(Func han public Task OnNavigationCommittedAsync(Action handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationCommittedAsync( e => HandleNavigationCommitted(e, handler), ContextSubscriptionOptions.WithContext(options, this)); @@ -261,6 +299,8 @@ public Task OnNavigationCommittedAsync(Action hand public Task OnNavigationCommittedAsync(Func handler, ContextSubscriptionOptions? options = null) { + if (handler is null) throw new ArgumentNullException(nameof(handler)); + return BiDi.BrowsingContext.OnNavigationCommittedAsync( e => HandleNavigationCommittedAsync(e, handler), ContextSubscriptionOptions.WithContext(options, this));