Knowledge Base Article

Launch Browser in Incognito/Private Mode

Question

Thought of sharing the code in the community for launching browsers in their incognito modes. The function is parameterized such a way to run for the browsers Internet Explorer, Edge, Chrome and Firefox.

Hope it will be useful for more people.

Answer

 

//JScript
function runIncognitoMode(browserName){
  //var browserName = "firefox" //iexplore,edge,chrome,firefox
  if (Sys.WaitBrowser(browserName).Exists){
    var browser = Sys.Browser(browserName);
    Log.Enabled = false // To disable the warning that might occur during closing of the browser
    browser.Close();
    Log.Enabled = true // enabling the logs back
  }
  if(browserName=="edge"){
    Browsers.Item(btEdge).RunOptions = "-inprivate"
    Delay(3000)
    Browsers.Item(btEdge).Run();
  }
  else if (browserName=="iexplore"){
    Browsers.Item(btIExplorer).RunOptions = "-private"
    Delay(3000)
    Browsers.Item(btIExplorer).Run();
  }
  else if (browserName=="chrome"){
    Browsers.Item(btChrome).RunOptions = "-incognito"
    Delay(3000)
    Browsers.Item(btChrome).Run();
  }
  else if (browserName=="firefox"){
    Browsers.Item(btFirefox).RunOptions = "-private"
    Delay(3000)
    Browsers.Item(btFirefox).Run();
  }
  Sys.Browser(browserName).BrowserWindow(0).Maximize()
}

 

Published 3 years ago
Version 1.0

Was this article helpful?

No CommentsBe the first to comment