From 5e7dd3b00c979d240c018bacef8303b9ee179d05 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 19 Jun 2025 17:41:13 +0300 Subject: [PATCH 1/3] Add OnHistoryUpdated event --- .../BiDi/BrowsingContext/BrowsingContext.cs | 10 ++++++++ .../BrowsingContext/BrowsingContextModule.cs | 10 ++++++++ .../HistoryUpdatedEventArgs.cs | 25 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 dotnet/src/webdriver/BiDi/BrowsingContext/HistoryUpdatedEventArgs.cs diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs index 70ca21320de23..81f03ffb59134 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs @@ -147,6 +147,16 @@ public Task OnFragmentNavigatedAsync(Action handle return BiDi.BrowsingContext.OnFragmentNavigatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); } + public Task OnHistoryUpdatedAsync(Func handler, SubscriptionOptions? options = null) + { + return BiDi.BrowsingContext.OnHistoryUpdatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + } + + public Task OnHistoryUpdatedAsync(Action handler, SubscriptionOptions? options = null) + { + return BiDi.BrowsingContext.OnHistoryUpdatedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); + } + public Task OnDomContentLoadedAsync(Func handler, SubscriptionOptions? options = null) { return BiDi.BrowsingContext.OnDomContentLoadedAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [this] }); diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs index e3c8ec83d87b3..a39709f10ccac 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs @@ -134,6 +134,16 @@ public async Task OnFragmentNavigatedAsync(Action return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options).ConfigureAwait(false); } + public async Task OnHistoryUpdatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options).ConfigureAwait(false); + } + + public async Task OnHistoryUpdatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) + { + return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options).ConfigureAwait(false); + } + public async Task OnDomContentLoadedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { return await Broker.SubscribeAsync("browsingContext.domContentLoaded", handler, options).ConfigureAwait(false); diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/HistoryUpdatedEventArgs.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/HistoryUpdatedEventArgs.cs new file mode 100644 index 0000000000000..6611f37bd684d --- /dev/null +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/HistoryUpdatedEventArgs.cs @@ -0,0 +1,25 @@ +// +// Licensed to the Software Freedom Conservancy (SFC) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The SFC licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +using System; + +namespace OpenQA.Selenium.BiDi.BrowsingContext; + +public record HistoryUpdatedEventArgs(BiDi BiDi, BrowsingContext Context, DateTimeOffset Timestamp, string Url) + : BrowsingContextEventArgs(BiDi, Context); From 74e4b6e04af5b4ab4b569df1977c1c1ab97d1918 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 19 Jun 2025 17:54:11 +0300 Subject: [PATCH 2/3] Fix method name --- .../webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs index a39709f10ccac..4f966c4df46a8 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs @@ -136,12 +136,12 @@ public async Task OnFragmentNavigatedAsync(Action public async Task OnHistoryUpdatedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options).ConfigureAwait(false); } public async Task OnHistoryUpdatedAsync(Action handler, BrowsingContextsSubscriptionOptions? options = null) { - return await Broker.SubscribeAsync("browsingContext.fragmentNavigated", handler, options).ConfigureAwait(false); + return await Broker.SubscribeAsync("browsingContext.historyUpdated", handler, options).ConfigureAwait(false); } public async Task OnDomContentLoadedAsync(Func handler, BrowsingContextsSubscriptionOptions? options = null) From bf26249300f87abfc4b2db32a9d64834fbdeca07 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Thu, 19 Jun 2025 18:16:32 +0300 Subject: [PATCH 3/3] Add event into bidi json context --- .../BiDi/Communication/Json/BiDiJsonSerializerContext.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 0803f13404c3c..5b2a0b803ff7a 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -111,9 +111,10 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(BrowsingContext.SetViewportCommand))] [JsonSerializable(typeof(BrowsingContext.TraverseHistoryCommand))] [JsonSerializable(typeof(BrowsingContext.TraverseHistoryResult))] + [JsonSerializable(typeof(BrowsingContext.BrowsingContextInfo))] +[JsonSerializable(typeof(BrowsingContext.HistoryUpdatedEventArgs))] [JsonSerializable(typeof(BrowsingContext.NavigationInfo))] - [JsonSerializable(typeof(BrowsingContext.UserPromptOpenedEventArgs))] [JsonSerializable(typeof(BrowsingContext.UserPromptClosedEventArgs))]