首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于Kameleo的无头模式的额外铬合金选项

用于Kameleo的无头模式的额外铬合金选项
EN

Stack Overflow用户
提问于 2021-10-05 10:14:06
回答 1查看 81关注 0票数 1

我已经测试了Kameleo.LocalApiClient一整天了。注意到一些奇怪的事情。

代码语言:javascript
复制
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浏览器仍然会弹出并且不会以无头模式运行。

如何添加我的附加选项?

EN

回答 1

Stack Overflow用户

发布于 2021-10-06 11:57:21

  • 浏览器由Kameleo
  • 启动RemoteWebDriver不启动任何浏览器,只是连接到已启动的browser

因此,您不能使用RemoteWebDriver的选项向浏览器传递任何参数。

有办法提供额外的web驱动程序选项。当Kameleo启动浏览器时,有一个POST /profiles/{guid}/start端点可以处理额外的参数、选项和首选项。请参阅documentationexample code

代码语言:javascript
复制
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"),
    }
});

有些论点不受支持,可能会导致问题,因此最好就这些论点与团队联系。

例如:

代码语言:javascript
复制
opts.AddArgument("--disable-extensions");

这不能添加,因为浏览器中需要Kameleo的扩展。如果您将其删除,欺骗将不起作用。

我看你也想用这个标志:

代码语言:javascript
复制
opts.AddArgument("disable-gpu");

您可以简单地将WebGL设置为Block。这将导致相同的结果。

目前,没有机会以无头模式启动浏览器。但很快就会有解决方案。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69448636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档