如何使用 NodeJS 和 Selenium 在私有模式下启动 Firefox?



我正在尝试使用TypeScript以私人模式启动Firefox。 我已经尝试过这个,它不会使用私人模式:

static async CreateFirefoxDriver():Promise<WebDriver>
{
//Create the firefox capabilities
var firefoxCapabilities = Capabilities.firefox();
//Use Private Window
var firefoxOptions = {
'args': ['-private']};
firefoxCapabilities.set('firefoxOptions', firefoxOptions);
var driver = await new Builder().withCapabilities(firefoxCapabilities).build();
//Maximize the window
await driver.manage().window().maximize();
return driver;
}

以下是正确配置它的方法:

static async CreateFirefoxDriver():Promise<WebDriver>
{
var options = new firefox.Options();
options.addArguments("-private");
var driver = await new Builder().forBrowser("firefox").setFirefoxOptions(options).build();
//Maximize the window
await driver.manage().window().maximize();
return driver;
}

最新更新