How to work with Google Chrome CLI
Google Chrome CLI

Google CLI

How to work with Google Chrome CLI

Open Google Chrome from the Linux terminal.

Rajdeep Singh
The Linux
Published in
5 min readMay 27, 2024

--

Google Chrome is a famous browser among the other browsers. Google Chrome comes with CLI. Especially for Linux users, chrome CLI is the best option when sometimes the desktop icon does not work or is available. In that case, you can use Chrome CLI To open Google Chrome and the website in Chrome from the terminal.

This article explains how to use Chrome CLI. First, install Google Chrome in the Linux distro.

Google Chrome CLI command changes based on your installation process.

The most common are two syntaxes I found when I used Chrome in different distro.

  1. google-chrome
  2. google-chrome-stable

If you use a beta or an unstable version of Chrome, your Chrome CLI syntax also changes.

For Beta:

  • google-chrome-beta

For Unstable:

  • google-chrome-unstable

I used nixos in my case; I used Chrome stable version, and the command is this: google-chrome-stable

The google-chrome-stable — help command output looks like this.

$ google-chrome-stable --help

google-chrome(1) USER COMMANDS google-chrome(1)

NAME
google-chrome - the web browser from Google

SYNOPSIS
google-chrome [OPTION] [PATH|URL]

DESCRIPTION
See the Google Chrome help center for help on using the browser.

<https://support.google.com/chrome/>

This manpage only describes invocation, environment, and arguments.

OPTIONS
Google Chrome has hundreds of undocumented command-line flags that are added and removed at the whim of the developers. Here, we docu‐
ment relatively stable flags.

--user-data-dir=DIR
Specifies the directory that user data (your "profile") is kept in. Defaults to $HOME/.config/google-chrome . Separate in‐
stances of Google Chrome must use separate user data directories; repeated invocations of google-chrome will reuse an existing
process for a given user data directory.

--incognito
Open in incognito mode.

--new-window
If PATH or URL is given, open it in a new window.

--proxy-server=host:port
Specify the HTTP/SOCKS4/SOCKS5 proxy server to use for requests. This overrides any environment variables or settings picked
via the options dialog. An individual proxy server is specified using the format:

[<proxy-scheme>://]<proxy-host>[:<proxy-port>]

Where <proxy-scheme> is the protocol of the proxy server, and is one of:

"http", "socks", "socks4", "socks5".

If the <proxy-scheme> is omitted, it defaults to "http". Also note that "socks" is equivalent to "socks5".

Examples:

--proxy-server="foopy:99"
Use the HTTP proxy "foopy:99" to load all URLs.

--proxy-server="socks://foobar:1080"
Use the SOCKS v5 proxy "foobar:1080" to load all URLs.

--proxy-server="socks4://foobar:1080"
Use the SOCKS v4 proxy "foobar:1080" to load all URLs.

--proxy-server="socks5://foobar:66"
Use the SOCKS v5 proxy "foobar:66" to load all URLs.

It is also possible to specify a separate proxy server for different URL types, by prefixing the proxy server specifier with a
URL specifier:

Example:

--proxy-server="https=proxy1:80;http=socks4://baz:1080"
Load https://* URLs using the HTTP proxy "proxy1:80". And load http://*
URLs using the SOCKS v4 proxy "baz:1080".

--no-proxy-server
Disables the proxy server. Overrides any environment variables or settings picked via the options dialog.

--proxy-auto-detect
Autodetect proxy configuration. Overrides any environment variables or settings picked via the options dialog.

--proxy-pac-url=URL
Specify proxy autoconfiguration URL. Overrides any environment variables or settings picked via the options dialog.

--password-store=<basic|gnome|kwallet>
Set the password store to use. The default is to automatically detect based on the desktop environment. basic selects the
built in, unencrypted password store. gnome selects Gnome keyring. kwallet selects (KDE) KWallet. (Note that KWallet may not
work reliably outside KDE.)

--version
Show version information.

As a GTK+ app, Google Chrome also obeys GTK+ command-line flags, such as --display. See the GTK documentation for more:

<http://library.gnome.org/devel/gtk/stable/gtk-running.html>

<http://library.gnome.org/devel/gtk/stable/gtk-x11.html>

ENVIRONMENT
Google Chrome obeys the following environment variables:

all_proxy
Shorthand for specifying all of http_proxy, https_proxy, ftp_proxy

http_proxy, https_proxy, ftp_proxy
The proxy servers used for HTTP, HTTPS, and FTP. Note: because Gnome/KDE proxy settings may propagate into these variables in
some terminals, this variable is ignored (in preference for actual system proxy settings) when running under Gnome or KDE. Use
the command-line flags to set these when you want to force their values.

auto_proxy
Specify proxy autoconfiguration. Defined and empty autodetects; otherwise, it should be an autoconfig URL. But see above note
about Gnome/KDE.

SOCKS_SERVER
SOCKS proxy server (defaults to SOCKS v4, also set SOCKS_VERSION=5 to use SOCKS v5).

no_proxy
Comma separated list of hosts or patterns to bypass proxying.

FILES
$HOME/.config/google-chrome
Default directory for configuration data.

$HOME/.cache/google-chrome
Default directory for cache data. (Why? See <http://standards.freedesktop.org/basedir-spec/latest/> .)

BUGS
Bug tracker:

http://code.google.com/p/chromium/issues/list

Be sure to do your search within "All Issues" before reporting bugs, and be sure to pick the "Defect on Linux" template when filing a
new one.

AUTHOR
The Chromium team - <http://www.chromium.org> google-chrom

With Google Chrome CLI, you achieve a few tasks as a beginner. Let’s discuss them.

How to open Chrome from a terminal?

You can open Google Chrome with the following command from your terminal.

google-chrome-stable

How to open a website in Chrome with a terminal?

To open any website in Chrome from your terminal, you need to follow the syntax below.

google-chrome-stable https://officialrajdeepsingh.dev

It opens the website in the current window, and otherwise, it creates a new window.

How to open a website in incognito mode in Chrome with a terminal?

You can use the inbuilt incognito flag option to open the website in Chrome from your terminal.

google-chrome-stable https://officialrajdeepsingh.dev --incognito

How to change the user data directory in Chrome with a terminal?

You can use the user-data-dir flag in Google Chrome CLI to change the user data directory.

google-chrome-stable --user-data-dir your-directory

How to run Chrome in the background without showing any output in the terminal?

The output is shown in the terminal whenever you use Chrome CLI by default.

➜  ~ google-chrome-stable https://officialrajdeepsingh.dev
[71040:71040:0527/181710.883811:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.ScreenSaver.GetActive: object_path= /org/freedesktop/ScreenSaver: org.freedesktop.DBus.Error.NotSupported: This method is not part of the idle inhibition specification: https://specifications.freedesktop.org/idle-inhibit-spec/latest/
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.

There is no option or flag available in Chrome CLI to hide output in the terminal and run Chrome CLI in the background in your distro.

You can run Chrome in the background using another command such as bg, nohup, ampersand, etc.

I’m familiar with nohup, so I used nohup. There are other commands also available. You can try to google or read this article to learn about other commands.

nohup google-chrome-stable https://officialrajdeepsingh.dev --new-window

The command output looks like this.

➜  ~ nohup google-chrome-stable https://officialrajdeepsingh.dev --new-window
nohup: ignoring input and appending output to 'nohup.out'
➜ ~

Now, your Chrome is running in the background without showing any output in the terminal.

To learn more about Nixos and Linux stuff, follow the Linux publication on Medium and other updates. Follow me on Twitter (X) and Medium.

--

--

Rajdeep Singh
The Linux

JavaScript | TypeScript | Reactjs | Nextjs | Rust | Biotechnology | Bioinformatic | Frontend Developer | Author | https://linktr.ee/officialrajdeepsingh