From c7143e3dc4ee07bbafe4bbeae8a62f2b2636e035 Mon Sep 17 00:00:00 2001
From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com>
Date: Mon, 18 Aug 2025 22:48:38 +0300
Subject: [PATCH 1/3] [dotnet] [bidi] Make cookie expiry as TimeSpan
---
.../webdriver/BiDi/Communication/Broker.cs | 1 +
.../Json/Converters/TimeSpanConverter.cs | 44 +++++++++++++++++++
dotnet/src/webdriver/BiDi/Network/Cookie.cs | 2 +-
3 files changed, 46 insertions(+), 1 deletion(-)
create mode 100644 dotnet/src/webdriver/BiDi/Communication/Json/Converters/TimeSpanConverter.cs
diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs
index db2058224749b..f0c0f2c279f91 100644
--- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs
+++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs
@@ -84,6 +84,7 @@ internal Broker(BiDi bidi, Uri url)
new RealmConverter(_bidi),
new RealmTypeConverter(),
new DateTimeOffsetConverter(),
+ new TimeSpanConverter(),
new PrintPageRangeConverter(),
new InputOriginConverter(),
new WebExtensionConverter(_bidi),
diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/TimeSpanConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/TimeSpanConverter.cs
new file mode 100644
index 0000000000000..8bb6717f2391c
--- /dev/null
+++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/TimeSpanConverter.cs
@@ -0,0 +1,44 @@
+//
+// 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;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
+
+internal class TimeSpanConverter : JsonConverter
+{
+ public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ if (reader.TryGetInt64(out long milliseconds) is false)
+ {
+ var doubleValue = reader.GetDouble();
+
+ milliseconds = Convert.ToInt64(doubleValue);
+ }
+
+ return TimeSpan.FromMilliseconds(milliseconds);
+ }
+
+ public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
+ {
+ writer.WriteNumberValue(value.TotalMilliseconds);
+ }
+}
diff --git a/dotnet/src/webdriver/BiDi/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Network/Cookie.cs
index 226f03ec36e64..99d1cd997e001 100644
--- a/dotnet/src/webdriver/BiDi/Network/Cookie.cs
+++ b/dotnet/src/webdriver/BiDi/Network/Cookie.cs
@@ -25,7 +25,7 @@ namespace OpenQA.Selenium.BiDi.Network;
public sealed record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite)
{
[JsonInclude]
- public DateTimeOffset? Expiry { get; internal set; }
+ public TimeSpan? Expiry { get; internal set; }
}
public enum SameSite
From 79916bc09d704cdee3bdd223e0674507a69d63d4 Mon Sep 17 00:00:00 2001
From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com>
Date: Mon, 18 Aug 2025 22:52:57 +0300
Subject: [PATCH 2/3] Simplify
---
dotnet/src/webdriver/BiDi/Network/Cookie.cs | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/dotnet/src/webdriver/BiDi/Network/Cookie.cs b/dotnet/src/webdriver/BiDi/Network/Cookie.cs
index 99d1cd997e001..972e02541f1d8 100644
--- a/dotnet/src/webdriver/BiDi/Network/Cookie.cs
+++ b/dotnet/src/webdriver/BiDi/Network/Cookie.cs
@@ -18,15 +18,10 @@
//
using System;
-using System.Text.Json.Serialization;
namespace OpenQA.Selenium.BiDi.Network;
-public sealed record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite)
-{
- [JsonInclude]
- public TimeSpan? Expiry { get; internal set; }
-}
+public sealed record Cookie(string Name, BytesValue Value, string Domain, string Path, long Size, bool HttpOnly, bool Secure, SameSite SameSite, TimeSpan? Expiry);
public enum SameSite
{
From c41bc7970864f23bfe15b82b6ef32340b06823b0 Mon Sep 17 00:00:00 2001
From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com>
Date: Mon, 18 Aug 2025 23:18:07 +0300
Subject: [PATCH 3/3] Remove chromium workaround for datetime
---
.../Json/Converters/DateTimeOffsetConverter.cs | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs
index 4ffa57f627bba..e3b2b57ffe4f4 100644
--- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs
+++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/DateTimeOffsetConverter.cs
@@ -27,16 +27,7 @@ internal class DateTimeOffsetConverter : JsonConverter
{
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
- // Workaround: it should be Int64, chrome uses double for `expiry` like "expiry":1737379944.308351
-
- if (reader.TryGetInt64(out long unixTime) is false)
- {
- var doubleValue = reader.GetDouble();
-
- unixTime = Convert.ToInt64(doubleValue);
- }
-
- return DateTimeOffset.FromUnixTimeMilliseconds(unixTime);
+ return DateTimeOffset.FromUnixTimeMilliseconds(reader.GetInt64());
}
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)