Before proceeding with the solution, we need to understand the problem. If you read carefully the documentation of Chromium or use a list of all the options that you can setup on Chromium in the command line, you will quickly find that you can launch Chrome (chromium) with a specific window size using the
--window-size flag, for example, to open chrome with a custom size, you would simply run the following command in the command prompt:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --window-size=800,600
Pitifully, with a default installation of Chrome, when it starts, it will have the last window size that the last user had, not the one we're specifying on the command 🤔. This happen because we're not changing the default user-data-dir property on the command as well. The user data directory contains profile data such as history, bookmarks, and cookies, as well as other per-installation local state. Each profile is a subdirectory (often Default) within the user data directory. This can be changed with the
--user-data-dir flag on the command.
Opening a URL
Now, let's explain what you came for, ideally, the command should just open a new URL in a window with a custom size. We would simply change the
--user-data-dir to a custom directory that we will create in the desktop in this case, specify a framed window using the
--chrome-frame flag and the URL with
REM where: REM --chrome-frame: specifies that the website should be opened in a single frame, without tabs. REM --user-data-dir: a custom directory that stores the configuration of your new options (window-size) REM --window-size: specify the width and height of the new window. REM --app: the URL of the website that you are trying to show "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --user-data-dir="C:\Users\your-username\Desktop\tmp-chrome" --window-size=800,600 --app=https://bestfreehtmlcsstemplates.com
This will run Google Chrome with the desired window size (800x600) and opening the specified URL (bestfreehtmlcsstemplates.com). It's worth to mention that you shouldn't modify the size of the frame with the mouse, instead, close chrome and run the command again with a new size.
Note that after running for the first time, in the
user-data-dir directory, some new files will be created:
You can delete them, but everytime that you run the command, the files appear again and again, so you can simply ignore the existence of this directory. Alternatively, you can run the command using a random temporary directory of the system like this:
REM where "%tmp%\chrome_tmp_user_dir~%RANDOM%" REM translates basically to a new random temporary directory REM for example: "C:\Users\your-user\AppData\Local\Temp\chrom_tmp_user_dir~15034" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --chrome-frame --user-data-dir="%tmp%\chrome_tmp_user_dir~%RANDOM%" --window-size=800,600 --app=https://bestfreehtmlcsstemplates.com
In this way, you'll never see a directory that stores tmp data of chrome, it will run always as a brand new chrome instance!
Happy coding ❤️!