Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome: Ignores --window-size command line parameter

I am attempting to launch a new window of Chrome with an exact viewport size. I'm using this command on Windows command line:

chrome --window-size="500,500" http://whatismyviewport.com

This is the result, which is not 500x500 dimensions: enter image description here

Here is more about this version of Chrome (from chrome://version): enter image description here

How can I consistently, reliably get the viewport height & width supplied?

like image 883
aBlaze Avatar asked Mar 09 '26 17:03

aBlaze


1 Answers

The window-size argument has never worked, at least as far back as 2018 when I wrote a script to open Chrome in app mode for taking screenshots. I had a hacky workaround in place but that also broke recently.

Maybe somebody can fix my hack?

If run without the url="data:text/html part commented out Chrome just exits now.

https://gist.github.com/duffyjp/13a8f7a40cb4e43a240811c64235b25b

#!/bin/bash
url=${1:-http://localhost:3000}

# FYI: If your URL has an & you need to pass the argument in quotes.

# Chrome app mode doesn't work without the http/https part.
if [[ $url = *"http"* ]]; then
  echo $url
else
  url="http://${url}"
  echo $url
fi

# Hack to resize the window to 1024x768.
# url="data:text/html,<script>window.moveTo(0,0);window.resizeTo(1024,768);window.location='${url}';</script>"

# Launch Chrome from one of it's usual locations.
if [ -e "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then
  /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=$url 2>/dev/null
elif [ -e "~/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then
  ~/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=$url 2>/dev/null
else
  /usr/bin/google-chrome --app=$url 2>/dev/null
fi
like image 167
JP Duffy Avatar answered Mar 12 '26 04:03

JP Duffy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!