23

I'm trying to remote debugg a chrome instance using the remote debug option in chrome:

chrome.exe --remote-debugging-port=1337

as described on google page: http://code.google.com/chrome/devtools/docs/remote-debugging.html

the problem is when i try to access it using IP it doesn't work, while testing it with localhost:1337 does work.

any idea?

Amir
  • 1,109
  • 3
  • 14
  • 30

7 Answers7

32

You can setup an SSH tunnel in order to debug remotely. On the source machine execute:

ssh -L 0.0.0.0:9223:localhost:9222 localhost -N 

Then on the other machine point Chrome browser to http://source-machine-ip:9223

Adam V.
  • 1,597
  • 1
  • 15
  • 17
18

I don't think Chrome accepts connections from outside of localhost (for security reasons). I would suggest you have to build small proxy on the same host where Chrome is.

beefeather
  • 1,028
  • 5
  • 8
  • because they created for mobile devices that you can debug from your desktop and not from a smartphone – Azd325 Aug 25 '11 at 14:50
  • What resource would be recommended to create a proxy? I imagine for most cases this is more trouble than it's worth, but I've thought this several times in the last couple of months. – Chris May Jan 19 '12 at 18:47
  • Sorry, Chris, I have no recommendation here. I wrote Java from scratch for myself and you probably could also. I know that some flavor of 'nc' (netcat) utility already support proxying (not openbsd). – beefeather Jan 22 '12 at 00:36
  • I could recommend Charles Web Debugging Proxy. – izogfif Mar 21 '13 at 16:23
  • Solved: See my answer for complete solution on Windows without installing any third party software. – Philip Bulley Nov 12 '14 at 12:10
17

The following worked for me when running a Chrome remote debugging host on Windows 8.

  1. Add an Inbound Rule to Windows Firewall
    • Search for "Windows Firewall" and select the "Windows Firewall" result
    • On the left of the "Windows Firewall" control panel window, click "Advanced Settings". This will open up "Windows Firewall with Advanced Security".
    • In the tree view on the left, click "Inbound Rules"
    • On the far right, click "New Rule..."
    • Select "Port" (Click Next)
    • Select TCP and set "Specific local ports" to 9222 (Click Next)
    • Select "Allow the connection" (Click Next)
    • Choose the profile access (Domain, Private, Public) to suit your needs (Click Next)
    • Give it a name like Chrome Remote Debugging (9222) (Click Finish)
  2. Follow user3445047's instructions on port forwarding:

Run Chrome on the Windows host:

chrome.exe --remote-debugging-port=9222

Set up port forwarding on the Windows host:

Open up a cmd window. You must "Run as administrator".

Enter the following into the cmd window:

netsh
interface
portproxy
add v4tov4 listenport=9222 connectaddress=127.0.0.1

On the client, navigate to http://THE_HOST_IP_ADDRESS:9222 and you should be presented with a list of "Inspectable Pages".

Community
  • 1
  • 1
Philip Bulley
  • 8,224
  • 3
  • 29
  • 44
15

The easiest way of sharing your debugging session with another computer is with socat. For example, if you've enabled the remote debugging protocol on port 1337 using

chromium --remote-debugging-port=1337

Then, you can create a tunnel using socat,

socat tcp-listen:5656,fork tcp:localhost:1337

After doing this, anyone can just visit http://<YOUR_IP_OR_HOSTNAME>:5656/ and immediately use the debugger.

When you're done, press Ctrl + C to terminate socat and thus stop the tunneling.
If the previous code does not work, check whether the firewall (e.g. iptables) is blocking access. If the firewall is OK, check whether the IP address or host name is actually correct. To see whether the traffic is correctly forwarded/tunnelled, visit http://localhost:5656/ and verify that there's a Webkit debugger instance running.

Rob W
  • 315,396
  • 71
  • 752
  • 644
  • I get `Host header is specified and is not an IP address or localhost` when trying to access it with another hostname than `localhost` – Mathieu Apr 02 '21 at 13:03
9
  1. Start the headless server

    chrome.exe --remote-debugging-port=9222
    
  2. Set up Port forwarding on windows

    netsh interface portproxy add v4tov4^
        listenport=9222 listenaddress=0.0.0.0^
        connectaddress=127.0.0.1 connectport=9222 
    
jpaugh
  • 5,719
  • 4
  • 33
  • 83
vlpro
  • 91
  • 1
  • 3
  • On Windows, this in conjunction with adding an Inbound Rule to Windows Firewall works well without the need to install any extra port forwarding utils. See my answer for complete instructions... – Philip Bulley Nov 12 '14 at 12:08
  • Note that the [line continuation character](https://stackoverflow.com/a/69079/712526) is (`^`) for `cmd.exe` (as I've added above), but is backtick (`\``) for PowerShell, instead. – jpaugh Dec 18 '17 at 23:45
  • Chome gives an error if you try this: `Host header is specified and is not an IP address or localhost.` – Samuel Thompson Nov 09 '18 at 20:30
6

recent Chrome versions support the commandline switch "--remote-debugging-address" so the workarounds listed above should no longer be necessary.

Here the description: "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 re-mote debugging protocol does not perform any authentica-tion, so exposing it too widely can be a security risk."

Michael Dreher
  • 801
  • 6
  • 14
  • Do you know how to use this? I've tried all sorts of things and I cannot access the debug tools remotely. Is it asking for the remote clients IP? Or is it asking for a DNS name that will resolve to my machine? – Sean256 Nov 10 '16 at 19:13
  • @Sean256 did you figure this out? No matter what incantation I use I can't make this work.. – Marcus Stade Nov 24 '16 at 18:19
  • 2
    @MarcusStade I have not. I have since resorted to creating an ssh tunnel. It must be broken. – Sean256 Nov 24 '16 at 18:41
  • I'm running Chrome under Docker container and adding --remote-debugging-address=0.0.0.0 to the command line allowed me to connect from outside. Easy way to test is to check the version page: http://localhost:9222/json/version – Juha Palomäki Jul 21 '17 at 20:40
  • https://stackoverflow.com/questions/40538197/chrome-remote-debugging-from-another-machine States that this only works in headless mode. – Tamir Daniely Apr 23 '19 at 11:38
  • Yes --headless binds the port to the specified IP, but it still looks broke, devtools only partially loads and then halts. – OrdinaryOrange Sep 05 '19 at 12:14
0

You can create simple TCP proxy with netcat:

EXTERNAL_PORT=1338
CHROME_DEBUG_PORT=1337 # This is the port specified with --remote-debugging-port

nc -l -p ${EXTERNAL_PORT} -c "nc 127.0.0.1 ${CHROME_DEBUG_PORT}"
Mikalai Parafeniuk
  • 1,118
  • 13
  • 10