diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs index e1c0419a1d71c..7420e4dcb4ab7 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs @@ -113,141 +113,141 @@ public async Task HandleUserPromptAsync(BrowsingContext context, Ha public async Task OnNavigationStartedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationStarted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationStarted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationStartedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationStarted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationStarted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnFragmentNavigatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnFragmentNavigatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnHistoryUpdatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options, JsonContext.HistoryUpdatedEventArgs).ConfigureAwait(false); } public async Task OnHistoryUpdatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options, JsonContext.HistoryUpdatedEventArgs).ConfigureAwait(false); } public async Task OnDomContentLoadedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.domContentLoaded", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.domContentLoaded", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnDomContentLoadedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.domContentLoaded", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.domContentLoaded", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnLoadAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.load", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.load", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnLoadAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.load", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.load", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnDownloadWillBeginAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.downloadWillBegin", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.downloadWillBegin", handler, options, JsonContext.DownloadWillBeginEventArgs).ConfigureAwait(false); } public async Task OnDownloadWillBeginAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.downloadWillBegin", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.downloadWillBegin", handler, options, JsonContext.DownloadWillBeginEventArgs).ConfigureAwait(false); } public async Task OnDownloadEndAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.downloadEnd", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.downloadEnd", handler, options, JsonContext.DownloadEndEventArgs).ConfigureAwait(false); } public async Task OnDownloadEndAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.downloadEnd", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.downloadEnd", handler, options, JsonContext.DownloadEndEventArgs).ConfigureAwait(false); } public async Task OnNavigationAbortedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationAborted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationAborted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationAbortedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationAborted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationAborted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationFailedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationFailed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationFailed", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationFailedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationFailed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationFailed", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationCommittedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationCommitted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationCommitted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnNavigationCommittedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.navigationCommitted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.navigationCommitted", handler, options, JsonContext.NavigationInfo).ConfigureAwait(false); } public async Task OnContextCreatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.contextCreated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.contextCreated", handler, options, JsonContext.BrowsingContextInfo).ConfigureAwait(false); } public async Task OnContextCreatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.contextCreated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.contextCreated", handler, options, JsonContext.BrowsingContextInfo).ConfigureAwait(false); } public async Task OnContextDestroyedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.contextDestroyed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.contextDestroyed", handler, options, JsonContext.BrowsingContextInfo).ConfigureAwait(false); } public async Task OnContextDestroyedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.contextDestroyed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.contextDestroyed", handler, options, JsonContext.BrowsingContextInfo).ConfigureAwait(false); } public async Task OnUserPromptOpenedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.userPromptOpened", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.userPromptOpened", handler, options, JsonContext.UserPromptOpenedEventArgs).ConfigureAwait(false); } public async Task OnUserPromptOpenedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.userPromptOpened", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.userPromptOpened", handler, options, JsonContext.UserPromptOpenedEventArgs).ConfigureAwait(false); } public async Task OnUserPromptClosedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.userPromptClosed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.userPromptClosed", handler, options, JsonContext.UserPromptClosedEventArgs).ConfigureAwait(false); } public async Task OnUserPromptClosedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.userPromptClosed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.userPromptClosed", handler, options, JsonContext.UserPromptClosedEventArgs).ConfigureAwait(false); } } diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 449715c3f47ef..e5946ba349394 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -24,7 +24,6 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json; -using System.Text.Json.Serialization; using System.Text.Json.Serialization.Metadata; using System.Threading; using System.Threading.Tasks; @@ -40,7 +39,7 @@ public sealed class Broker : IAsyncDisposable private readonly ConcurrentDictionary _pendingCommands = new(); private readonly BlockingCollection _pendingEvents = []; - private readonly Dictionary _eventTypesMap = []; + private readonly Dictionary _eventTypesMap = []; private readonly ConcurrentDictionary> _eventHandlers = new(); @@ -157,10 +156,10 @@ public async Task ExecuteCommandAsync(TCommand comma return JsonSerializer.Deserialize(resultJson, jsonResultTypeInfo)!; } - public async Task SubscribeAsync(string eventName, Action action, SubscriptionOptions? options, JsonSerializerContext jsonContext) + public async Task SubscribeAsync(string eventName, Action action, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) where TEventArgs : EventArgs { - _eventTypesMap[eventName] = (typeof(TEventArgs), jsonContext); + _eventTypesMap[eventName] = jsonTypeInfo; var handlers = _eventHandlers.GetOrAdd(eventName, (a) => []); @@ -186,10 +185,10 @@ public async Task SubscribeAsync(string eventName, Act } } - public async Task SubscribeAsync(string eventName, Func func, SubscriptionOptions? options, JsonSerializerContext jsonContext) + public async Task SubscribeAsync(string eventName, Func func, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo) where TEventArgs : EventArgs { - _eventTypesMap[eventName] = (typeof(TEventArgs), jsonContext); + _eventTypesMap[eventName] = jsonTypeInfo; var handlers = _eventHandlers.GetOrAdd(eventName, (a) => []); @@ -317,7 +316,7 @@ private void ProcessReceivedMessage(byte[]? data) if (_eventTypesMap.TryGetValue(method, out var eventInfo)) { - var eventArgs = (EventArgs)JsonSerializer.Deserialize(ref paramsReader, eventInfo.EventType, eventInfo.JsonContext)!; + var eventArgs = (EventArgs)JsonSerializer.Deserialize(ref paramsReader, eventInfo)!; var messageEvent = new MessageEvent(method, eventArgs); _pendingEvents.Add(messageEvent); @@ -350,8 +349,6 @@ class CommandInfo(long id, Type resultType, TaskCompletionSource ta { public long Id { get; } = id; - public Type ResultType { get; } = resultType; - public TaskCompletionSource TaskCompletionSource { get; } = taskCompletionSource; }; } diff --git a/dotnet/src/webdriver/BiDi/Log/LogModule.cs b/dotnet/src/webdriver/BiDi/Log/LogModule.cs index d6e36263c1117..a3887d7f052cf 100644 --- a/dotnet/src/webdriver/BiDi/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Log/LogModule.cs @@ -27,11 +27,11 @@ public sealed class LogModule : Module { public async Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("log.entryAdded", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("log.entryAdded", handler, options, JsonContext.LogEntry).ConfigureAwait(false); } public async Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("log.entryAdded", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("log.entryAdded", handler, options, JsonContext.LogEntry).ConfigureAwait(false); } } diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs index acbb737c307de..ceb132784b13c 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs @@ -126,51 +126,51 @@ public async Task ContinueWithAuthAsync(Request request, ContinueWi public async Task OnBeforeRequestSentAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.beforeRequestSent", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.beforeRequestSent", handler, options, JsonContext.BeforeRequestSentEventArgs).ConfigureAwait(false); } public async Task OnBeforeRequestSentAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.beforeRequestSent", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.beforeRequestSent", handler, options, JsonContext.BeforeRequestSentEventArgs).ConfigureAwait(false); } public async Task OnResponseStartedAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.responseStarted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.responseStarted", handler, options, JsonContext.ResponseStartedEventArgs).ConfigureAwait(false); } public async Task OnResponseStartedAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.responseStarted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.responseStarted", handler, options, JsonContext.ResponseStartedEventArgs).ConfigureAwait(false); } public async Task OnResponseCompletedAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.responseCompleted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.responseCompleted", handler, options, JsonContext.ResponseCompletedEventArgs).ConfigureAwait(false); } public async Task OnResponseCompletedAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.responseCompleted", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.responseCompleted", handler, options, JsonContext.ResponseCompletedEventArgs).ConfigureAwait(false); } public async Task OnFetchErrorAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.fetchError", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.fetchError", handler, options, JsonContext.FetchErrorEventArgs).ConfigureAwait(false); } public async Task OnFetchErrorAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.fetchError", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.fetchError", handler, options, JsonContext.FetchErrorEventArgs).ConfigureAwait(false); } public async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.authRequired", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.authRequired", handler, options, JsonContext.AuthRequiredEventArgs).ConfigureAwait(false); } public async Task OnAuthRequiredAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("network.authRequired", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("network.authRequired", handler, options, JsonContext.AuthRequiredEventArgs).ConfigureAwait(false); } } diff --git a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs index e5968f76bdef0..3ebd7912638d9 100644 --- a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs @@ -78,31 +78,31 @@ public async Task RemovePreloadScriptAsync(PreloadScript script, Re public async Task OnMessageAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.message", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.message", handler, options, JsonContext.MessageEventArgs).ConfigureAwait(false); } public async Task OnMessageAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.message", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.message", handler, options, JsonContext.MessageEventArgs).ConfigureAwait(false); } public async Task OnRealmCreatedAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.realmCreated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.realmCreated", handler, options, JsonContext.RealmInfo).ConfigureAwait(false); } public async Task OnRealmCreatedAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.realmCreated", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.realmCreated", handler, options, JsonContext.RealmInfo).ConfigureAwait(false); } public async Task OnRealmDestroyedAsync(Func handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.realmDestroyed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.realmDestroyed", handler, options, JsonContext.RealmDestroyedEventArgs).ConfigureAwait(false); } public async Task OnRealmDestroyedAsync(Action handler, SubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("script.realmDestroyed", handler, options, JsonContext).ConfigureAwait(false); + return await Broker.SubscribeAsync("script.realmDestroyed", handler, options, JsonContext.RealmDestroyedEventArgs).ConfigureAwait(false); } }