From 5d3c959d38fb1c679288a0cc25e0b0f8834a8cab Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 5 Oct 2025 15:28:06 +0300 Subject: [PATCH 1/3] SetExtraHeaders --- .../Json/BiDiJsonSerializerContext.cs | 1 + .../webdriver/BiDi/Network/NetworkModule.cs | 7 ++++ .../BiDi/Network/SetExtraHeadersCommand.cs | 35 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 4a74468315f4c..aeac1520eb6b0 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -131,6 +131,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Network.RemoveDataCollectorCommand))] [JsonSerializable(typeof(Network.RemoveInterceptCommand))] [JsonSerializable(typeof(Network.SetCacheBehaviorCommand))] +[JsonSerializable(typeof(Network.SetExtraHeadersCommand))] [JsonSerializable(typeof(Network.BeforeRequestSentEventArgs))] [JsonSerializable(typeof(Network.ResponseStartedEventArgs))] diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs index 95e38245af4b5..74136bfc03bb0 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs @@ -65,6 +65,13 @@ public async Task SetCacheBehaviorAsync(CacheBehavior behavior, Set return await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false); } + public async Task SetExtraHeadersAsync(IEnumerable
headers, SetExtraHeadersOptions? options = null) + { + var @params = new SetExtraHeadersParameters(headers, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetExtraHeadersCommand(@params), options).ConfigureAwait(false); + } + public async Task ContinueRequestAsync(Request request, ContinueRequestOptions? options = null) { var @params = new ContinueRequestParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url); diff --git a/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs b/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs new file mode 100644 index 0000000000000..f0229cfb34fa4 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs @@ -0,0 +1,35 @@ +// +// 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.Collections.Generic; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Network; + +internal sealed class SetExtraHeadersCommand(SetExtraHeadersParameters @params) + : Command(@params, "network.setExtraHeaders"); + +internal sealed record SetExtraHeadersParameters(IEnumerable
Headers, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetExtraHeadersOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} From db69774bd50b452fc8a22ca83b481fdf38e1c0e3 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 5 Oct 2025 15:32:43 +0300 Subject: [PATCH 2/3] Test --- dotnet/test/common/BiDi/Network/NetworkTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index 8aa1c07601d1f..813fe06017223 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -251,4 +251,12 @@ public void CanSetCacheBehavior() Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing); Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing); } + + [Test] + public async Task CanSetExtraHeaders() + { + var result = await bidi.Network.SetExtraHeadersAsync([new Header("x-test-header", "test-value")]); + + Assert.That(result, Is.Not.Null); + } } From 083d636ecf7d54c0bb70488aea28101d7952a844 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 5 Oct 2025 15:35:04 +0300 Subject: [PATCH 3/3] Ignore test --- dotnet/test/common/BiDi/Network/NetworkTest.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index 813fe06017223..577e79a419515 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -253,6 +253,9 @@ public void CanSetCacheBehavior() } [Test] + [IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] public async Task CanSetExtraHeaders() { var result = await bidi.Network.SetExtraHeadersAsync([new Header("x-test-header", "test-value")]);