Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a link in an Incognito Window in Google Chrome

Is there any way to do this through Java or Javascript, given the link as a String? I've been looking but I've only found topics about Android devices, I'm asking for a Windows PC.

I hadn't planned on learning how to write an extension with the proper permissions for Chrome for this, but if that's the only way then so be it.

like image 887
Tim Avatar asked Sep 16 '25 11:09

Tim


1 Answers

To run any executable including Chrome in JAVA:

If the path to the application is a system variable:

String location = System.getenv("APPVARIAVLE");
Process process = new ProcessBuilder(location).start(); 

Or if you want to use the fully qualified path:

Process process = new ProcessBuilder("C:\\location\\MyApp.exe").start();

The JavaDoc for the process builder say that you can add parameters like this:

new ProcessBuilder("myCommand", "myArg1", "myArg2");

The argument for incognito looks like it is: "-incognito" and to open a url just add the url: "example.com".

Which means that you can most likely can add the url and incognito arguments the following way to chrome in the arguments:

Process process = new ProcessBuilder("C:\\YourChrome\\Location\\chrome.exe","-incognito","http://stackoverflow.com").start();
like image 115
jmarrero Avatar answered Sep 19 '25 01:09

jmarrero