15

Chrome has a really awesome feature that allows you to open the dev tools from another browser or window. It works by starting chrome with this flag:

--remote-debugging-port=9222

Then from another window/browser you can go to http://localhost:9222 and open dev tools for any running tab in Chrome. For security reasons Chrome will not allow access from another machine by IP, lets say http://192.168.1.2:9222.

However there is an additional flag that indicates it opens this ability, here is what Chrome has to say for it:

--remote-debugging-address 

Use the given address instead of the default loopback for accepting remote debugging connections. Should be used together with --remote-debugging-port. Note that the remote debugging protocol does not perform any authentication, so exposing it too widely can be a security risk.

Either it's not working or I have no idea how to format it. I have tried the following:

--remote-debugging-port=9222 --remote-debugging-address=http://192.168.1.2:9222
--remote-debugging-port=9222 --remote-debugging-address=http://192.168.1.2
--remote-debugging-port=9222 --remote-debugging-address=192.168.1.2:9222
--remote-debugging-port=9222 --remote-debugging-address=192.168.1.3 //maybe thinking its supposed to be the IP of the remote machine

The target machine a Mac

Sean256
  • 2,849
  • 4
  • 30
  • 39
  • Should probably just be the IP address the other machine can connect by. Adding a port would be redundant. – Alexander O'Mara Nov 10 '16 at 22:38
  • In example 4 you can see I tried that – Sean256 Nov 10 '16 at 23:34
  • Example 4 actually shows you tried specifying the address of the remote machine. Not the local one... I believe Alex meant this: --remote-debugging-port=9222 --remote-debugging-address=192.168.1.2 and I want to suggest this as a possibility too: --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 – JoshG Feb 28 '17 at 08:09
  • Nothing works also here (chromium in debug mode is in raspberry / linux), remote browser on a mac, through a VPN – Damien C Jan 13 '21 at 10:03

3 Answers3

28

it turned out, that the option "--remote-debugging-address" can only be used for the headless mode ("--headless") and is intended to be used for tests when the browser runs in a docker container and not for remote debugging.

The parameter of "remote-debugging-address" must be the numeric ip-adress of a local network interface of the machine where you start Chrome with "--remote-debugging-address". When using any non-local ip-address you will get the following errors:

[0526/132024.480654:ERROR:socket_posix.cc(137)] bind() returned an error, errno=49: Can't assign requested address
[0526/132024.480766:ERROR:devtools_http_handler.cc(226)] Cannot start http server for devtools. Stop devtools.

On my Mac I can start the Chrome Canary version from today using this command line (the current stable version just crashes with "--headless"):

/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary  --remote-debugging-port=9222 --remote-debugging-address=192.168.1.20 --headless

In another shell you can see, that this address is used to listen on the socket:

netstat -a -n | grep 9222
tcp4       0      0  192.168.1.20.9222      *.*                    LISTEN   

Without "--headless" the output will look like this:

tcp4       0      0  127.0.0.1.9222         *.*                    LISTEN

Michael

Michael Dreher
  • 1,369
  • 11
  • 17
  • 22
    Note to others... If you want to run in windowed mode (headed mode?), an SSH tunnel gets the job done. Specify the port with --remote-debugging-port and use ssh to forward a local port to the host. Example: `--remote-debugging-port=9222` on the remote machine and `ssh -L 9222:localhost:9222 user@host` on the local machine. Then you would connect to localhost:9222 on local to access remote's Dev Tools. – musicin3d Mar 18 '18 at 16:56
  • @musicin3d I am getting curl "Empty reply from server" when using ssh tunner however its working properly on host machine. – Shashwat Kumar May 25 '21 at 08:46
  • instead of using "localhost" you can explicitly use "127.0.0.1" to force ipv4 instead of ipv6 connection for the ssh forward – Michael Dreher May 27 '21 at 09:46
4

--remote-debugging-address is semantically different from chromedriver's --whitelisted-ips

The remote debugging address must specify the address to bind to. So what you want in there is your machine's IP address not the address you will be connecting from. Try binding to all interfaces with --remote-debugging-address=0.0.0.0

Declan Shanaghy
  • 2,314
  • 2
  • 18
  • 19
2

Try create a HTTP-proxy in your target machine.

httpProxy
    .createServer({
      target: wsurl,
      ws: true,
      localAddress: host
    })
    .listen(port);

works for me.

Abdelsalam Shahlol
  • 1,621
  • 1
  • 20
  • 31
王镇佳
  • 111
  • 1
  • 1
  • 3
    Works for me too, though the answer could be a bit more clear. Perhaps this link can help some: https://github.com/http-party/node-http-proxy – barney765 Sep 29 '20 at 06:58