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:

Here is more about this version of Chrome (from chrome://version):

How can I consistently, reliably get the viewport height & width supplied?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With