Access local servers and Chrome instances with port forwarding

Meggin Kearney
Meggin Kearney
Sofia Emelianova
Sofia Emelianova

You can use port forwarding to:

  • Case 1. Debug a tab opened on a different Chrome instance.
  • Case 2. Host a site on a development machine web server, then access the content from an Android device through a USB cable.

In Case 2, port forwarding works through a listening TCP port on your Android device that maps to a TCP port on your development machine. Traffic between the ports travel through the USB connection between your Android device and development machine, so the connection doesn't depend on your network configuration.

Additionally, if your web server is using a custom domain, you can set up your Android device to access the content at that domain with custom domain mapping.

Set up port forwarding

Depending on your case, follow the next steps.

Case 1: Set up port forwarding to another Chrome instance

  1. Run another Chrome instance with the --remote-debugging-port=PORT parameter, for example:

    MacOS

    open -a "Google Chrome" --args --remote-debugging-port=PORT

    Windows

    start chrome --remote-debugging-port=PORT

    Linux

    google-chrome --remote-debugging-port=PORT
  2. In the Chrome instance you are debugging with:

    1. Open chrome://inspect/#devices.
    2. Make sure Checkbox. Discover network targets is checked.
    3. Click Configure next to the checkbox.
    4. In Target discovery settings, enter localhost:PORT, check Checkbox. Enable port forwarding, and click Done.