Skip to content

Commit

Permalink
[dotnet] Add version-independent method for overriding user agent via…
Browse files Browse the repository at this point in the history
… CDP
  • Loading branch information
jimevans committed Sep 28, 2021
1 parent fe91134 commit a560c42
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dotnet/src/webdriver/DevTools/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ public abstract class Network
/// <returns>A task that represents the asynchronous operation.</returns>
public abstract Task EnableFetchForAllPatterns();

/// <summary>
/// Asynchronously sets the override of the user agent string.
/// </summary>
/// <param name="userAgent">The user agent string to set.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task SetUserAgentOverride(string userAgent)
{
await SetUserAgentOverride(new UserAgent() { UserAgentString = userAgent });
}

/// <summary>
/// Asynchronously sets the override of the user agent settings.
/// </summary>
/// <param name="userAgent">A <see cref="UserAgent"/> object containing the user agent values to override.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public abstract Task SetUserAgentOverride(UserAgent userAgent);

/// <summary>
/// Asynchronously diables the fetch domain.
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions dotnet/src/webdriver/DevTools/UserAgent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// <copyright file="Network.cs" company="WebDriver Committers">
// 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.
// </copyright>

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Represents a user agent string.
/// </summary>
public class UserAgent
{
public string UserAgentString { get; set; }
public string AcceptLanguage { get; set; }
public string Platform { get; set; }
}
}
15 changes: 15 additions & 0 deletions dotnet/src/webdriver/DevTools/v85/V85Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public override async Task DisableFetch()
await fetch.Disable();
}

/// <summary>
/// Asynchronously sets the override of the user agent settings.
/// </summary>
/// <param name="userAgent">A <see cref="UserAgent"/> object containing the user agent values to override.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task SetUserAgentOverride(UserAgent userAgent)
{
await network.SetUserAgentOverride(new SetUserAgentOverrideCommandSettings()
{
UserAgent = userAgent.UserAgentString,
AcceptLanguage = userAgent.AcceptLanguage,
Platform = userAgent.Platform
});
}

/// <summary>
/// Asynchronously continues an intercepted network request.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions dotnet/src/webdriver/DevTools/v93/V93Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public override async Task DisableFetch()
await fetch.Disable();
}

/// <summary>
/// Asynchronously sets the override of the user agent settings.
/// </summary>
/// <param name="userAgent">A <see cref="UserAgent"/> object containing the user agent values to override.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task SetUserAgentOverride(UserAgent userAgent)
{
await network.SetUserAgentOverride(new SetUserAgentOverrideCommandSettings()
{
UserAgent = userAgent.UserAgentString,
AcceptLanguage = userAgent.AcceptLanguage,
Platform = userAgent.Platform
});
}

/// <summary>
/// Asynchronously continues an intercepted network request.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions dotnet/src/webdriver/DevTools/v94/V94Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public override async Task DisableFetch()
await fetch.Disable();
}

/// <summary>
/// Asynchronously sets the override of the user agent settings.
/// </summary>
/// <param name="userAgent">A <see cref="UserAgent"/> object containing the user agent values to override.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
public override async Task SetUserAgentOverride(UserAgent userAgent)
{
await network.SetUserAgentOverride(new SetUserAgentOverrideCommandSettings()
{
UserAgent = userAgent.UserAgentString,
AcceptLanguage = userAgent.AcceptLanguage,
Platform = userAgent.Platform
});
}

/// <summary>
/// Asynchronously continues an intercepted network request.
/// </summary>
Expand Down

0 comments on commit a560c42

Please sign in to comment.