4

I want to set my Chrome with socks5 proxy.

chrome://linux-proxy-config/

To input the chrome://linux-proxy-config/ in Chrome, I'm presented with a page with this content:

When running Google Chrome under a supported desktop environment, the system proxy settings will be used. However, either your system is not supported or there was a problem launching your system configuration.

But you can still configure via the command line. Please see man google-chrome for more information on flags and environment variables.

I input the command in console:

google-chrome-stable  --proxy-server="socks5://127.0.0.1:1080

Two effects for the above command:

  • effect1: I can go surfing now via socks5 proxy.

  • effect2: So many warnings info:

    "Fontconfig warning: "/etc/fonts/fonts.conf", line 100: unknown element "blank"
    [3873:3960:0808/102301.399211:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.Notifications.GetCapabilities: object_path= /org/freedesktop/Notifications: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files
    [7:13:0808/102302.782729:ERROR:command_buffer_proxy_impl.cc(107)] ContextResult::kTransientFailure: Shared memory region is not valid
    [3873:4069:0808/102302.788747:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
    [3873:4069:0808/102302.789045:ERROR:object_proxy.cc(619)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
    

I want to fix effect2, that is to say, make the command run in background silently.

google-chrome-stable  --proxy-server="socks5://127.0.0.1:1080  &

Effect2 still exist, it can't run in background, warning info still pop out in the console.

Try other way:

sudo gvim /usr/share/applications/google-chrome.desktop
#replace the  `Exec=/usr/bin/google-chrome-stable --incognito` with 
Exec=/usr/bin/google-chrome-stable  --proxy-server="socks5://127.0.0.1:1080"

Run Chrome with its logo, Chrome can open, now I can't go surfing with the proxy socks5://127.0.0.1:1080. How to fix it?

fra-san
  • 10,205
  • 2
  • 22
  • 43
showkey
  • 323
  • 1
    try run it with this:

    --proxy-server="socks5://127.0.0.1:1080" --host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE 127.0.0.1"

    – Dominik Matis Aug 10 '19 at 08:29
  • Not a real answer, since I cannot test these suggestions; but 1) In google-chrome.desktop you likely have more than one Exec line; the one that takes effect when you start Chrome—and that you should try editing—is that in the [Desktop Entry] section, while the one you edited (with the --incognito option) likely is in the [Desktop Action new-private-window] section and only takes effect when you select the New Incognito Window entry from a context menu. 2) To silence a background job you may just redirect its output, e.g. google-chrome-stable --proxy... 1>/dev/null 2>&1 &. – fra-san Aug 12 '19 at 13:01
  • @fra-san,please write it as a formal answer,it is tested ,feasible,i give you the 300 points. – showkey Aug 12 '19 at 13:36
  • @fra-san - Now I see your comment. It runs along the same line as my answer... – sancho.s ReinstateMonicaCellio Aug 17 '19 at 07:44
  • @it_is_a_literature - Do you feel your question was not fully addressed? It has been answered by drawing from credible and/or official sources. – sancho.s ReinstateMonicaCellio Aug 17 '19 at 07:45

4 Answers4

4

If you found a way to make things work, and your only concern is getting too many warnings, you may do things your way discarding the messages:

<your command> 2> /dev/null

You would be redirecting file descriptor (FD) #2, which is stderr, to a "black hole". You may also want to discard messages sent to stdout (FD #1), although this is less common in cases like yours. You have to check how much clutter you get. So, you would have (redirecting only stderr):

google-chrome-stable --proxy-server="socks5://127.0.0.1:1080" 2> /dev/null &

or (redirecting stderr and stdout; these are alternative forms of the same command)

google-chrome-stable --proxy-server="socks5://127.0.0.1:1080" 2> /dev/null 1>&2 &
google-chrome-stable --proxy-server="socks5://127.0.0.1:1080" > /dev/null 2>&1 &

The syntax 2>&1 means redirecting FD #2 to wherever FD #1 goes. The default FD is #1, so > is equivalent to 1>.


For the rare cases you need more info than above, or for the sake of curiosity:

https://stackoverflow.com/questions/5256599/what-are-file-descriptors-explained-in-simple-terms

In Bash, what is file descriptor 255 for, can I use it?

https://en.wikipedia.org/wiki/File_descriptor

3

Most likely, your attempt at editing google-chrome.desktop didn't work because that file has more than one Exec entry, and the one you changed wasn't the one that is actually used.

Using the Chrome package for Debian from Google's repository, google-chrome.desktop shows three Exec entries in three distinct sections (groups, in freedesktop.org's nomenclature):

$ grep -E '^Exec|^\[|^Name=' /usr/share/applications/google-chrome.desktop 
[Desktop Entry]
Name=Google Chrome
Exec=/usr/bin/google-chrome-stable %U
[Desktop Action new-window]
Name=New Window
Exec=/usr/bin/google-chrome-stable
[Desktop Action new-private-window]
Name=New Incognito Window
Exec=/usr/bin/google-chrome-stable --incognito

The one with the --incognito option—likely the one you edited—is only executed when you select "New Incognito Window" from a context menu (e.g. after right clicking on Chrome's icon in GNOME Activities).

Unless your goal was to change the configuration for every user on your system, I suggest you to create your own, customized version of google-chrome.desktop:

$ cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications/

And then edit the Exec entry, at least in the [Desktop Entry] group (you may want to keep the other Exec entries aligned to ensure Chrome will behave the same way no matter what menu entry you used to start it):

Exec=/usr/bin/google-chrome-stable --proxy-server="socks5://proxyURL:proxyPORT" --host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE proxyURL" %U

As noted by Dominik Matis in a comment, you may want to add the --host-resolver-rules option to prevent Chrome's DNS prefetcher from circumventing your proxy settings, as explained in the Chromium documentation.

Adjust proxyURL and proxyPORT as needed; don't forget to set proxyURL for both the --proxy-server and --host-resolver-rules options.

If you want the default opening action to run Chrome without setting any proxy, you may leave the main [Desktop Entry]'s Exec entry untouched and add an action instead. It requires you to

  1. add a name for a new action to the Actions key in the [Desktop Entry] group;
  2. add a new action group.
[Desktop Entry]
...
Actions=new-window;new-private-window;new-proxied-window;

...

[Desktop Action new-proxied-window]
Name=New Proxied Window
Exec=/usr/bin/google-chrome-stable --proxy-server="socks5://proxyURL:proxyPORT" --host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE proxyURL" %U

"New Proxied Window" will then appear as an option when you right click on Chrome's icon (it may require a logout/login). Note that all the concurrently running instances of Chrome will share the same proxy settings of the first one you opened, unless you start them with the --user-data-dir option.

fra-san
  • 10,205
  • 2
  • 22
  • 43
2

I wrote about the various ways Google Chrome is affected by proxy settings. Rather than setting the proxy within Chrome, use the OS' settings instead.

If you are using GNOME, try using gsettings

gsettings set org.gnome.system.proxy.http host "myproxy.server.com"
gsettings set org.gnome.system.proxy.http port "3128"

Can you download a file from the Internet using wget or curl? Does the following command create an index.html file from Google's homepage?

wget https://www.google.com

If your problem is connecting to the SOCKS proxy and it is affecting other applications, try using proxychains or pacproxy.

$ proxychains4 google-chrome
hanxue
  • 591
0

cat /usr/share/applications/google-chrome.desktop

[Desktop Entry]
Name=Google Chrome
Icon=/usr/share/icons/hicolor/16x16/apps/google-chrome.png
Terminal=false
Type=Application
Categories=Network;WebBrowser;
Exec=/usr/bin/google-chrome-stable --proxy-server="socks5://127.0.0.1:1080"  2> /dev/null 1>&2 &
showkey
  • 323
  • Why are you redirecting Chrome's output in your desktop file? Are you seeing messages from Chrome somewhere when you start it by clicking on its icon? (Redirection should have a visible effect when you start Chrome from the command line only). – fra-san Aug 17 '19 at 09:20