chrome-devtools-mcp icon indicating copy to clipboard operation
chrome-devtools-mcp copied to clipboard

Access chrome while in WSL environment

Open ljmerza opened this issue 1 year ago • 55 comments

Is your feature request related to a problem? Please describe.

Codex works far better in a linux based environment thus it's generally recommended if yo are on windows to use WSL. The problem here is this MCP only tries to look for chrome inside the WSL instead of the host system.

Describe the solution you'd like

The MCP server would know it's in WSL and use the host system's chrome

Describe alternatives you've considered

Can use codex for windows but it's not officially supported.

Additional context Add any other context or screenshots about the feature request here.

ljmerza avatar Sep 25 '25 00:09 ljmerza

@OrKoN @jackfranklin It is indeed necessary to consider supporting the windows subsystem.

Image

yuwenlong avatar Sep 25 '25 04:09 yuwenlong

@ljmerza Could you try to use the --executable-path argument in the MCP server config to pass a custom path to where Chrome is installed?

OrKoN avatar Sep 25 '25 05:09 OrKoN

@OrKoN I just tried it and it didn't work. The wsl subsystem is Ubuntu. If I configure it with this parameter, it's equivalent to using windows chrome across systems. Does the code logic support it? You need to look at the code.

Image Image

yuwenlong avatar Sep 25 '25 05:09 yuwenlong

Thanks for checking! I would have expected the ability to run Windows binaries to be a feature of the WSL :) In this case a few other options are possible:

  1. Starting Chrome manually with --remote-debugging-port=9222 and a custom --user-data-dir outside of WSL and connecting to the running Chrome by specifying --browser-url=http://127.0.0.1:9222 in the args for the MCP server.
  2. Installing a Linux Chrome version in WSL (https://support.google.com/chrome/a/answer/9025903?hl=en).
  3. Installing a Chrome for Testing build in WSL and pointing to it via --executable-path. npx @puppeteer/browsers install chrome@stable would install the latest stable build.

We will look into WSL support in general but in code we are just launching sub-processes (and we cannot do much if the environment does not support it) and locating Chrome at the well-known path per OS reported by Node.

OrKoN avatar Sep 25 '25 06:09 OrKoN

@yuwenlong also Chrome is not started in the MCP discovery phase (it is started on the first tool call). The error could be something else. Which gemini-cli version do you use and which node version is it?

OrKoN avatar Sep 25 '25 06:09 OrKoN

Hello, I'm also trying to use the MCP through a DevContainer, can be the same solution for WSL and DevContainer I guess.

I already tried to launch a Chrome instance by using the --browserUrl=http://host.docker.internal:9222, but I got a connection refused that my header isn't an IP with a curl.

So I tried the solution with Puppeteer installation, I give the executable path to the MCP with this configuration:

"chrome-devtools": {
    "type": "stdio",
    "command": "npx",
    "args": [
        "chrome-devtools-mcp@latest",
        "--executable-path=/workspaces/xxx/chrome/linux_arm-140.0.7339.207/chrome-linux64/chrome",
        "--headless",
        "--isolated",
        "--no-sandbox"
        // "--browserUrl=http://host.docker.internal:9222"
    ]
}

When I'm not using the isolated parameter, I got this error:

Image

When I'm using it, I've got now:

Image

When I'm checking the output of the MCP Server, I don't see any errors :

2025-09-25 08:49:35.039 [info] Discovered 26 tools
2025-09-25 08:50:23.874 [info] Stopping server chrome-devtools
2025-09-25 08:50:23.910 [info] Connection state: Stopped
2025-09-25 08:50:27.460 [info] Starting server chrome-devtools
2025-09-25 08:50:27.461 [info] Connection state: Starting
2025-09-25 08:50:27.467 [info] Starting server from Remote extension host
2025-09-25 08:50:27.493 [info] Connection state: Starting
2025-09-25 08:50:27.494 [info] Connection state: Running
2025-09-25 08:50:28.231 [warning] [server stderr] chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
2025-09-25 08:50:28.231 [warning] [server stderr] debug, and modify any data in the browser or DevTools.
2025-09-25 08:50:28.231 [warning] [server stderr] Avoid sharing sensitive or personal information that you do want to share with MCP clients.
2025-09-25 08:50:28.244 [info] Discovered 26 tools

Let me know If I need to open an other issue specifically for DevContainer

ThomasRumasLM avatar Sep 25 '25 07:09 ThomasRumasLM

If you use containers you should also have required system dependencies installed to run Chrome in the container https://pptr.dev/guides/system-requirements

OrKoN avatar Sep 25 '25 07:09 OrKoN

@yuwenlong also Chrome is not started in the MCP discovery phase (it is started on the first tool call). The error could be something else. Which gemini-cli version do you use and which node version is it?

Image

yuwenlong avatar Sep 25 '25 07:09 yuwenlong

Thanks for checking. Node 20 is not supported (see https://github.com/ChromeDevTools/chrome-devtools-mcp?tab=readme-ov-file#requirements).

OrKoN avatar Sep 25 '25 07:09 OrKoN

If you use containers you should also have required system dependencies installed to run Chrome in the container https://pptr.dev/guides/system-requirements

I've already installed the needed package but still got the Protocol error (Target.setDiscoverTargets): Target closed

ThomasRumasLM avatar Sep 25 '25 07:09 ThomasRumasLM

感谢您的检查。Node 20 不受支持(请参阅https://github.com/ChromeDevTools/chrome-devtools-mcp?tab=readme-ov-file#requirements)。

@OrKoN Thank you. node has been upgraded.

Image Image

It seems to be okay. The mcp configuration is as follows. Let others who have encountered problems take a look:

"chrome-devtools": {
                        "command": "npx",
                        "args": [
                                "-y",
                                "chrome-devtools-mcp@latest",
                                "--executable-path=/mnt/c/Program\\ Files/Google/Chrome/Application/chrome.exe"
                        ]
                }

yuwenlong avatar Sep 25 '25 07:09 yuwenlong

@OrKoN I'm still not sure if it can work in actual operation? After all, this is an exe run by ubuntu on windows. It should still not work. After all, it's cross-system!

yuwenlong avatar Sep 25 '25 07:09 yuwenlong

@yuwenlong please see other possible options in https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/131#issuecomment-3332300428

OrKoN avatar Sep 25 '25 08:09 OrKoN

@yuwenlong please see other possible options in #131 (comment)

Ok. Thank you.

yuwenlong avatar Sep 25 '25 08:09 yuwenlong

Note that we will still investigate how we can solve it in a better way without extra manual steps, so thanks a lot for reporting and sharing the details about the setup.

OrKoN avatar Sep 25 '25 08:09 OrKoN

You can use this guide about WSL and GUI apps - https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps#install-support-for-linux-gui-apps It shows how to install Chrome and run it from WSL.

One you install it, the MCP should be able to pick it up automatically. Reminder you need to call at least one tool for the browser to start.

Tested with the following WSL version

From wsl --version

// Version
WSL version: 2.6.1.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.66
MSRDC version: 1.2.6353
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: **10.0.26100.6584**

From wsl --status:

Default Distribution: Ubuntu
Default Version: 2

Lightning00Blade avatar Sep 25 '25 19:09 Lightning00Blade

Launching chrome with these options is the only way to get the chrome-devtools-mcp to function in a dev container. google-chrome --headless --remote-debugging-port=9222 --no-sandbox disable-dev-shm-usage --disable-gpu Combined with: { "mcpServers": { "chrome-devtools": { "command": "npx", "args": [ "chrome-devtools-mcp@latest", "--browserUrl", "http://127.0.0.1:9222" ] } } }

Unfortunately, the chrome-devtools mcp doesn't appear to pass along any of those options to chrome.

trafflux avatar Sep 26 '25 05:09 trafflux

Thanks for checking! I would have expected the ability to run Windows binaries to be a feature of the WSL :) In this case a few other options are possible:

  1. Starting Chrome manually with --remote-debugging-port=9222 and a custom --user-data-dir outside of WSL and connecting to the running Chrome by specifying --browser-url=http://127.0.0.1:9222 in the args for the MCP server.
  2. Installing a Linux Chrome version in WSL (https://support.google.com/chrome/a/answer/9025903?hl=en).
  3. Installing a Chrome for Testing build in WSL and pointing to it via --executable-path. npx @puppeteer/browsers install chrome@stable would install the latest stable build.

We will look into WSL support in general but in code we are just launching sub-processes (and we cannot do much if the environment does not support it) and locating Chrome at the well-known path per OS reported by Node.

Hi @OrKoN, I am in the same case and have tried for 3 days several alternatives, including those you mention. And it did not work, having a chrome exe in the wsl is useless as we cant launch it within the wsl. I cant even run on windows as my repo are Linux only librairies.

nelyajizi avatar Sep 26 '25 06:09 nelyajizi

@nelyajizi did you try the suggestion in https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/131#issuecomment-3335699730 ?

Lightning00Blade avatar Sep 26 '25 10:09 Lightning00Blade

Update: success!

[!TIP] REQUIREMENTS: single Chrome instance + new profile (--user-data-dir) + remote debugging port

No matter whether your Chrome is installed on Windows or in WSL2, both work well.

Use Windows as an example:

  1. Kill all Chrome instances
  2. Start Chrome with a new profile and enable the remote debugging port
  3. Access http://127.0.0.1:9222/json/version in the opened Chrome window and check the result
  • Kill the Chrome instance and start a new one:
taskkill /F /IM chrome.exe
$chrome = "$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe"
if (-not (Test-Path $chrome)) { $chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe" }
& $chrome --user-data-dir="$env:TEMP\chrome-mcp" --remote-debugging-port=9222 --remote-debugging-address=127.0.0.1 --no-first-run --no-default-browser-check
  • Gemini CLI ~/.gemini/settings.json Requires --browserUrl=http://localhost:9222 and --isolated=true (If Chrome has already been manually started, this parameter is unnecessary):
{
  "mcpServers": {
    "chrome-devtools": {
      "command": "npx",
      "args": [
        "chrome-devtools-mcp@latest",
        "--browserUrl=http://localhost:9222",
        "--isolated=true" // MCP starts Chrome with a new profile. If you start Chrome manually, that's not required.
      ]
    }
  }
}

Thanks for the help ♥️ https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/99#issuecomment-3327349975


[!NOTE] below history

Still struggling :(

Tried installing google-chrome in WSL2, then ran it with google-chrome --no-sandbox --remote-debugging-port=9222.

All we got the Protocol error (Target.setDiscoverTargets): Target closed error.

  • Codex:
[mcp_servers.chrome-devtools]
command = "npx"
args = ["chrome-devtools-mcp@latest", "--isolated=true", "--executable-path=/usr/bin/google-chrome"]
Image
  • Gemini CLI
Image

Loongphy avatar Sep 26 '25 14:09 Loongphy