Search code examples
node.jsseleniumselenium-webdriverwebdrivergeckodriver

Selenium driver.manage().deleteAllCookies() doesn't work when using Browser options


I have noticed that when using browser Options in selenium, driver.manage().deleteAllCookies() doesn't work. Not sure why but here is a snippet of the code.

var profile = new firefox.Profile('./fProfile');
profile.setPreference("browser.privatebrowsing.autostart",true);
var fOptions = new firefox.Options();
fOptions.setProfile(profile); 

var driver = new Builder()
    .withCapabilities({'browserName': 'firefox'})
    .setFirefoxOptions(fOptions)    
    .build();
driver.get("https://google.com");

In the above driver setup the driver.manage().deleteAllCookies() doesn't work and driver.manage().getCookies().then((cookies)=>{console.log(cookies)}) returns an empty array

However when using this to create the driver the above functions work.

driver= new Builder()
    .withCapabilities({'browserName': 'firefox'})    
    .build();

Though I cant use the above code since I require the use of a firefox profile.

Platform : Node.Js Selenium using geckodriver


Solution

  • Turns out turning off private browsing did the trick.Removing the line works too.

    profile.setPreference("browser.privatebrowsing.autostart",false);