4

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.

Tim
  • 95
  • 3
  • 7
  • What browser are you using? – mjz19910 Jan 23 '16 at 04:41
  • @mjz19910 Edited title, sorry for the confusion. – Tim Jan 23 '16 at 04:43
  • 3
    If you have an extension with the permission to open tabs you can use `chrome.windows.create({"url": url, "incognito": true})` – mjz19910 Jan 23 '16 at 04:45
  • 1
    dupe of http://stackoverflow.com/questions/2228118/how-to-open-new-incognito-window-with-javascript-google-chrome – pvg Jan 23 '16 at 04:47
  • probably should have typed the title in to search first – pvg Jan 23 '16 at 04:48
  • I did find that but I've never messed with extensions before; I just wanted to write it in a standalone Java or Javascript executable, because I've worked with both of those. – Tim Jan 23 '16 at 04:51

1 Answers1

5

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();
jmarrero
  • 221
  • 3
  • 8