Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome --new-window switch ignores --window-position and --window-size

I'm trying to control the size and position of newly spawned Google Chrome windows via the command line (through C#.)

My command line ends up looking like:

--new-window --window-position=100,100 --window-size=800,600 www.UrlToOpen.com

However, the new window just opens over top of where the last Chrome window was started.

The end result I'm looking for is to be able to start multiple instances of Google Chrome, in separate windows, with a specific location and size. The only way I've been able to do this so far is by specifying that each instance is to have it's own --user-data-dir. However, this is not ideal given how many extensions a user may have installed, and it would not be the best user experience.

Does anyone have any suggestions?

like image 564
DTI-Matt Avatar asked Jan 29 '13 20:01

DTI-Matt


1 Answers

If Chrome is not programmed to allow this, you only have one option.

  1. Create the process and keep the process object.
  2. Use Process.MainWindowHandle to get the newly created window (you might need to use a loop and Process.Refresh, or Process.WaitForInputIdle)
  3. Use the SetWindowPos native function to position the window wherever you want it.

Native hooks could be used to detect creation of the window, but that requires you to create an unmanaged DLL.

like image 163
jnm2 Avatar answered Oct 12 '22 23:10

jnm2