10

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?

Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
  • 1
    Browsing Chromium source codes, I'm affraid it appears that the `--window-position` and `--window-size` options only really work properly when you're creating a new popup window, not a tabbed window. I didn't find a way to force Chrome to create the new windows as a popup, sadly. – Luaan Nov 29 '13 at 12:16
  • I haven't had time to check, but I know Chrome supports the `--app` argument, that creates a "tabless" window. Could this be the popup you're referring to? – DTI-Matt Nov 29 '13 at 15:12
  • That doesn't seem to do it, at least not on my computer. I remember a lot of checks for window type application, which ignored the position and size, so that's probably a dead end. – Luaan Nov 29 '13 at 15:25
  • you can check the similar implementation in Chrome Window Positioner plugin source code located at https://github.com/s-haines/chrome-window-positioner/blob/master/src/main.js – vCillusion Jul 16 '14 at 06:36
  • You may want to check out this Google Chrome extension: https://chrome.google.com/webstore/detail/window-seat/ffapagmeaendpngophdffbjjcobilago – Hans Jan 23 '16 at 22:20
  • See the answer [here](http://stackoverflow.com/a/26962811/429982) – Gerrat Apr 12 '16 at 21:25
  • @Gerrat very interesting, going to give this a try in the coming days. Thanks! Looks promising! – DTI-Matt Apr 13 '16 at 03:19
  • @Gerrat nope. No dice. It moves it but it behaves very oddly. I have two monitors and setting "moveTo(1920,0)" places it 3/4 of the way in my main monitor, not top-left of monitor 2 as would be expected. It seems even to change randomly if I run the same shortcut again and again. Thanks anyway! – DTI-Matt Apr 13 '16 at 15:51
  • Anyone managed to find more "native" way for this? I am using mac terminal with open command @DTI-Matt – M. A. Feb 27 '21 at 09:32

2 Answers2

1

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.

jnm2
  • 7,960
  • 5
  • 61
  • 99
0

I have another idea for you, why not use a chrome extension for handling the positioning.

Background: We had related difficulties. Internal webapp that opens multiple documents in windows, and need to be placed in other monitors. The javascript does not support this, for security reasons and only a native extension can properly work with the tabs/windows objects.

Therefore, we have created an open source chrome extension for doing exactly that: flexible windows position across multi-monitor setups.

Perhaps more interest to you would be the feature to use predefine templates. The template file is located in any webserver you like and therefore can be easily share across different users.

The chrome extension is called "MultiWindow Positioner" and its complete free. You can get it at the chrome store here

The actual source code you find in github in the project chrome-multiwindow-positioner

Disclaimer: I am the maintainer of the open source (MIT) github project. If there any interesting idea, or comments feel free to share them here.

Igor Lino
  • 532
  • 7
  • 10