How to launch Chrome browser from command line?

By Gulshan Saini
Published in Browser
September 10, 2020
1 min read

For one of my projects, I had to manually open the browser and resize it to the 9:16 aspect ratio. Doing this task manually and hitting those 9:16 aspect ratio numbers was time-consuming and prone to errors. Trust me it was also boring to resize the window. Another challenge was to position the browser every time perfectly at the same position on the screen.

I thought to automate the steps by automatically opening the Chrome browser from the command line and resize it by passing arguments to the startup command line

Lets see how we can automate these steps easily

  1. Open a new file and name it as automation.sh
  2. Type "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome". Make sure you put command inn double quotes as the path is having spaces.
  3. Next, we can instruct Chrome to launch in particular size by passing command line arguments --window-size=502,984,
  4. To position Chrome on the launch, you can additionally pass --window-position=100,100as an argument. This will position the Chrome browser at 100 pixels from the left and 100 pixels from the top
  5. Save the file and open terminal
  6. Change to the directory where the file was saved and execute sh automation.sh and wait for the magic to happen

You might also want to get rid of notification “Google API Keys are missing…“. To disable notification add below environment variables just above the command to launch Chrome

Google API Keys are missing
Google API Keys are missing

Final Script


Previous Article
(Solved) How to fix UnauthorizedError invalid algorithm?

Gulshan Saini

Fullstack Developer

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Related Posts

How to enable or disable experimental web platform features in chrome browser?

August 04, 2020
1 min
© 2020, All Rights Reserved.

Quick Links

Advertise with usContact Us

Social Media