我已经测试了Kameleo.LocalApiClient一整天了。注意到一些奇怪的事情。
var client = new KameleoLocalApiClient(new Uri(KameleoBaseUrl));
client.SetRetryPolicy(null);
// Search Chrome Base Profiles
var baseProfileList = await client.SearchBaseProfilesAsync("desktop", "windows", "chrome", "ru-ru");
Random rnd = new Random();
var baseId = rnd.Next(1, baseProfileList.Count);
// Create a new profile with recommended settings
// Choose one of the Firefox BaseProfiles
// You can set your proxy up in the setProxy method
var requestBody = BuilderForCreateProfile
.ForBaseProfile(baseProfileList[baseId].Id)
.SetRecommendedDefaults()
.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-zone2", "5inhblkgrzxj"))
//.SetProxy("http", new Server("zproxy.lum-superproxy.io", 22225, "lum-customer-joshua901-zone-russiashared-ip-181.214.180.215", "lqoz0ee2hbvb"))
.SetLauncher("chrome")
//.SetScreen("--window-size", 500, 783)
.Build();
var profile = await client.CreateProfileAsync(requestBody);
// Start the browser
await client.StartProfileAsync(profile.Id);
// Connect to the running browser instance using WebDriver
var uri = new Uri($"{KameleoBaseUrl}/webdriver");
var opts = new ChromeOptions();
opts.AddAdditionalOption("kameleo:profileId", profile.Id.ToString());
opts.AddExcludedArgument("enable-automation");
opts.AddArgument("--window-size=500,783");
opts.AddArgument("disable-infobars");
opts.AddArgument("--incongito");
opts.AddArgument("--disable-extensions");
opts.AddArgument("disable-gpu");
opts.AddArgument("headless");
opts.AddArgument("--ignore-certificate-errors");
opts.AddArgument("no-sandbox");
opts.AddArgument("--silent-launch");
opts.AddArgument("--no-startup-window");
//var webdriver = new RemoteWebDriver(uri, opts);
_driver = new RemoteWebDriver(uri, opts)我想把我的额外的ChromeOptions添加到我的驱动程序中,特别是能够在“无头”模式下运行。
即使我定义了上面的ChromeOptions并使用这些选项创建了RemoteWebDriver,chrome浏览器仍然会弹出并且不会以无头模式运行。
如何添加我的附加选项?
发布于 2021-10-06 11:57:21
RemoteWebDriver不启动任何浏览器,只是连接到已启动的browser因此,您不能使用RemoteWebDriver的选项向浏览器传递任何参数。
有办法提供额外的web驱动程序选项。当Kameleo启动浏览器时,有一个POST /profiles/{guid}/start端点可以处理额外的参数、选项和首选项。请参阅documentation或example code。
await client.StartProfileWithWebDriverSettingsAsync(profile.Id, new WebDriverSettings
{
Arguments = new List<string> { "mute-audio" },
Preferences = new List<Preference>
{
new Preference("profile.managed_default_content_settings.images", 2),
new Preference("profile.password_manager_enabled.images", 2),
},
AdditionalOptions = new List<Preference>
{
new Preference("pageLoadStrategy", "eager"),
}
});有些论点不受支持,可能会导致问题,因此最好就这些论点与团队联系。
例如:
opts.AddArgument("--disable-extensions");这不能添加,因为浏览器中需要Kameleo的扩展。如果您将其删除,欺骗将不起作用。
我看你也想用这个标志:
opts.AddArgument("disable-gpu");您可以简单地将WebGL设置为Block。这将导致相同的结果。
目前,没有机会以无头模式启动浏览器。但很快就会有解决方案。
https://stackoverflow.com/questions/69448636
复制相似问题