Replies: 1 comment 6 replies
-
If you CefSharp/CefSharp/DevTools/DevToolsDomainEntityBase.cs Lines 131 to 234 in 94fb457 So currently it only works when setting Complete Testcase with OffScreen Browser: [Fact]
public async Task CanSetUserAgentOverride()
{
using (var browser = new ChromiumWebBrowser("about:blank"))
{
await browser.LoadPageAsync();
using (var devToolsClient = browser.GetDevToolsClient())
{
var brandsList = new List<UserAgentBrandVersion>();
var uab = new UserAgentBrandVersion();
uab.Brand = "Google Chrome";
uab.Version = "89";
brandsList.Add(uab); // comment this out to make it work
var uab2 = new UserAgentBrandVersion();
uab2.Brand = "Chromium";
uab2.Version = "89";
brandsList.Add(uab2); // comment this out to make it work
var ua = new UserAgentMetadata();
ua.Brands = brandsList;
ua.Architecture = "";
ua.Model = "Nexus 7";
ua.Platform = "Android";
ua.PlatformVersion = "6.0.1";
ua.FullVersion = "89.0.4389.114";
ua.Mobile = true;
await devToolsClient.Emulation.SetUserAgentOverrideAsync("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/5(KHTML,likeGeckoChrome/89.0.4389.114Safari/537.36", null, null, ua);
}
await browser.LoadPageAsync("https://httpbin.org/user-agent");
var html = await browser.GetTextAsync();
Assert.Contains("Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/5(KHTML,likeGeckoChrome/89.0.4389.114Safari/537.36", html);
}
} |
Beta Was this translation helpful? Give feedback.
-
I am trying to set user agent.But the following code doesn't work.
code:
using (CefSharp.DevTools.DevToolsClient dtc = this.browser.GetDevToolsClient())
{
IList brandsList = new List();
UserAgentBrandVersion uab = new UserAgentBrandVersion();
uab.Brand = "Google Chrome";
uab.Version = "89";
brandsList.Add(uab);
}
Os: windows 10
Cefsharp version: 89.0.4389.114
Platform: winforms
Cpu: x86
Beta Was this translation helpful? Give feedback.
All reactions