wsl-chrome-bridge 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README-zh.md ADDED
@@ -0,0 +1,270 @@
1
+ # wsl-chrome-bridge
2
+
3
+ 本專案主要提供一支 CLI `wsl-chrome-bridge`。
4
+
5
+ 在 [chrome-devtools-mcp](https://github.com/ChromeDevTools/chrome-devtools-mcp) 眼中,`wsl-chrome-bridge` 將會是一個可執行的 Chrome。
6
+ `wsl-chrome-bridge` 會在 WSL 端提供 DevTools 連線入口,並把 CDP 訊息橋接到 Windows Chrome。
7
+
8
+ 原有 `chrome-devtools-mcp` 的設定方式,只需調整 `--executablePath` 並增加特定參數,即可讓 WSL 下的 Agent 調用 Windows Chrome,且無須做任何系統層級的設定(如 portproxy 轉發 , WSL2 Mirrored Mode)。
9
+
10
+ 此構想是看到 [wsl-chrome-mcp](https://github.com/477174/wsl-chrome-mcp) 實作方式是利用 `powershell` 繞過限制,但由於此專案是以 MCP Server 方式提供服務,但我想繼續使用比較多人維護的 `chrome-devtools-mcp`,所以才寫了本專案作為橋接手段。
11
+
12
+ ## 0.2.0 重大變更(支援 Playwright)
13
+
14
+ `0.2.0` 新增對 `playwright-mcp` 的支援,並且調整多項 bridge 參數行為與設定方式。
15
+
16
+ 若你是從 `0.1.0` 升級,請先閱讀升級說明文件:[UPGRADE-zh.md](./UPGRADE-zh.md)。
17
+
18
+ ## 基本運作方式
19
+
20
+ ```text
21
+ [Chrome DevTools MCP] [Playwright MCP]
22
+ | |
23
+ stdio pipe remote-debugging-port
24
+ | |
25
+ +------[wsl-chrome-bridge]-----+
26
+ |
27
+ PowerShell websocket relay
28
+ |
29
+ [Windows Chrome]
30
+ ```
31
+
32
+ wsl-chrome-bridge 會:
33
+
34
+ - 接收 `chrome-devtools-mcp` 與 `playwright-mcp` 傳入的 Chrome 啟動參數
35
+ - 啟動 Windows Chrome(透過PowerShell)
36
+ - 在 `chrome-devtools-mcp` 模式下,透過 stdio pipe(OS pipe)接收/回傳 CDP 訊息
37
+ - 在 `playwright-mcp` 模式下,於本機建立對應 port 的 WebSocket proxy 後轉發 CDP 訊息
38
+ - 透過 PowerShell WebSocket relay 雙向轉發 CDP 訊息到 Windows Chrome
39
+
40
+
41
+ ## 使用環境需求
42
+ - Windows 11 安裝最新版 chrome。
43
+ - Windows 11 需要有 powershell.exe 可供 WSL2 執行。
44
+ - WSL2 需要有 Node 20+
45
+
46
+
47
+ ## 安裝與使用方式
48
+
49
+ ### 安裝方式
50
+
51
+ 於 WSL 環境下用以下方式擇一安裝 :
52
+
53
+ 1. 透過 `npm install -g wsl-chrome-bridge` 安裝。
54
+ 2. 下載原始碼後自行編譯,再以 `npm link` 安裝:
55
+
56
+ ```bash
57
+ git clone https://github.com/pigochu/wsl-chrome-bridge.git
58
+ cd wsl-chrome-bridge
59
+ npm install
60
+ npm run build
61
+ npm link
62
+ ```
63
+
64
+ ### 使用方式 (以 codex 為例子)
65
+
66
+ 1. 找出 wsl-chrome-bridge 實際位置 , 假設是 `/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge`。
67
+ 2. 設定檔撰寫,如以下範例 `.codex/config.toml`。
68
+
69
+ `chrome-devtools-mcp` 最小可運作設定:
70
+
71
+ ```toml
72
+ [sandbox_workspace_write]
73
+ network_access = true
74
+
75
+ [mcp_servers.chrome-devtools]
76
+ command = "npx"
77
+ args = [
78
+ "-y",
79
+ "chrome-devtools-mcp@latest",
80
+ "--executablePath",
81
+ "/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge"
82
+ ]
83
+ enabled = true
84
+ ```
85
+
86
+ 這是最小可運作設定。`wsl-chrome-bridge` 會啟動 Windows Chrome,並為 `chrome-devtools-mcp` 橋接 CDP 流量,不需要額外 bridge 專用參數。
87
+
88
+ `playwright-mcp` 最小可運作設定(含 sandbox):
89
+
90
+ ```toml
91
+ [sandbox_workspace_write]
92
+ network_access = true
93
+
94
+ [mcp_servers.playwright]
95
+ command = "npx"
96
+ args = [
97
+ "-y",
98
+ "@playwright/mcp@latest",
99
+ "--browser",
100
+ "chrome",
101
+ "--sandbox",
102
+ "--executable-path",
103
+ "/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge"
104
+ ]
105
+ enabled = true
106
+
107
+ [mcp_servers.playwright.env]
108
+ DISPLAY = ":9999"
109
+ ```
110
+
111
+ 在 bridge + Windows 系統 Chrome 的情境下,加上 `--browser chrome` 可避免常見的上游 `--no-sandbox` 警告行為,並維持 Playwright 啟動行為穩定。
112
+
113
+ > [!NOTE]
114
+ > FAQ 章節有介紹 `--executablePath` 的路徑尋找的方式。
115
+ > 其他設定寫法可參考 `agent-config-sample/.codex/`。
116
+
117
+ ## 安裝與建置
118
+
119
+ ```bash
120
+ npm install
121
+ npm run build
122
+ ```
123
+
124
+ ## 本地測試
125
+
126
+ ```bash
127
+ npm test
128
+ ```
129
+
130
+ 測試分成兩層:
131
+
132
+ - 單元測試:路徑轉換、參數標準化、bridge 啟動規劃
133
+ - 情境測試:CLI 對 bridge runner 的參數傳遞整合
134
+
135
+
136
+ ## FAQ
137
+
138
+ ### `--executablePath` 如何找
139
+
140
+ `chrome-devtools-mcp` 的 `--executablePath` 必須是「檔案路徑」,不能只填指令名(例如 `wsl-chrome-bridge`)。
141
+
142
+ #### 情境 A: 未使用 Node 版本管理工具(僅系統 Node)
143
+
144
+ 這種情境下,通常就是用 `command` 找出絕對路徑再填入設定:
145
+
146
+ ```bash
147
+ command -v wsl-chrome-bridge
148
+ ```
149
+
150
+ 把輸出結果直接填進 `--executablePath`。
151
+
152
+ #### 情境 B: 使用 mise 管理多版本 Node(建議做法)
153
+
154
+ 若你使用 [mise](https://mise.jdx.dev/) 且可能切換多個 Node 版本,不建議把 `command -v` 找到的版本化路徑(例如 `.../installs/node/<version>/bin/...`)直接寫死在設定檔。
155
+
156
+ 建議改用 mise shim 固定入口:
157
+
158
+ 如以下命令所印出的絕對路徑
159
+ ```bash
160
+ echo $HOME/.local/share/mise/shims/wsl-chrome-bridge
161
+ ```
162
+ 或直接檢查:
163
+
164
+ ```bash
165
+ ls -la ~/.local/share/mise/shims/wsl-chrome-bridge
166
+ ```
167
+
168
+ #### 差異總結
169
+
170
+ - 不使用版本管理工具時,透過 `command -v` 找絕對路徑是可行且直接的方法。
171
+ - 使用 mise 多版本 Node 時,建議使用 `/home/<user>/.local/share/mise/shims/wsl-chrome-bridge`,避免 Node 版本切換後路徑失效。
172
+
173
+ ### 為什麼 Playwright 需要設定 `DISPLAY`
174
+
175
+ 在 WSL/Linux 環境下,`playwright-mcp` 啟動瀏覽器時會先判斷圖形顯示環境。
176
+ 若 `DISPLAY` 沒有設定,Playwright 通常會改成 headless 行為(即使你沒有手動指定 `--headless`)。
177
+
178
+ 而這個判斷是在 bridge 之前就完成,所以 `wsl-chrome-bridge` 無法在後段覆蓋該決策。
179
+ 如果你希望在 Windows 看到實際 Chrome 視窗,請於 MCP `env` 額外設定 `DISPLAY`(例如 `DISPLAY=:999`)。
180
+
181
+ ### 上游 MCP 結束時,Headless 與非 Headless 行為
182
+
183
+ `wsl-chrome-bridge` 在上游 MCP(例如 `chrome-devtools-mcp` / `playwright-mcp`)結束時,採用以下生命週期策略:
184
+
185
+ - 若 Chrome 是以 headless 啟動,bridge 一律會結束該 Chrome 行程。
186
+ - 若 Chrome 不是以 headless 啟動(headed / non-headless),bridge 一律保留該 Chrome 行程。
187
+
188
+ 這是刻意設計的行為,與原生 Playwright 在部分流程下的預設行為可能不同。
189
+
190
+ ### 為什麼 Playwright 可能出現 `--no-sandbox` 警告
191
+
192
+ `playwright-mcp` 若未明確指定 browser channel,可能會產生含 `--no-sandbox` 的啟動參數。
193
+ 在有視窗的 Chrome 中,會看到這類警告列:
194
+ `你正在使用不受支援的命令列標幟: --no-sandbox`
195
+
196
+ 建議在 Playwright MCP args 明確加入:
197
+
198
+ ```text
199
+ --browser chrome
200
+ ```
201
+
202
+ 這樣在常見 bridge 設定下可避免上游傳入 `--no-sandbox`。
203
+
204
+
205
+ ### `--user-data-dir` 說明
206
+
207
+ `wsl-chrome-bridge` 現在支援上游 MCP 直接傳入 `--user-data-dir` / `--userDataDir`。
208
+
209
+ Playwright 可能會把原本的 Windows 風格路徑先 resolve 成 Linux 路徑,並在本地先建立一個空目錄再交給 bridge。
210
+ bridge 目前會檢查該路徑,且僅在「空目錄」時才會安全刪除;非空目錄不會刪除。
211
+
212
+ `chrome-devtools-mcp` 一般不會有這個本地空目錄副作用。
213
+
214
+ 另外,bridge 只會把「Windows 風格」的 user-data-dir 傳給 Windows Chrome。像 `/cwd/%TEMP%\\...` 這種被 resolve 過的形式會先嘗試還原。
215
+
216
+ 若上游沒有送出 `--user-data-dir`,或送出的值最後無法還原為 Windows 風格路徑(被過濾),bridge 會自動使用預設值:
217
+
218
+ ```text
219
+ %TEMP%\wsl-chrome-bridge\profile-default
220
+ ```
221
+
222
+ 這可確保 Windows Chrome 啟動時一律有可用的 profile 目錄,避免因未帶 profile 導致的啟動行為差異。
223
+
224
+ 為了避免 Playwright 差異,並統一 `chrome-devtools-mcp` / `playwright-mcp` 的設定風格,建議優先使用:
225
+
226
+ ```toml
227
+ WSL_CHROME_BRIDGE_USER_DATA_DIR = "%TEMP%\\wsl-chrome-bridge\\chrome-profile-xxx"
228
+ ```
229
+
230
+ `--user-data-dir` 仍可使用,但建議把 `WSL_CHROME_BRIDGE_USER_DATA_DIR` 當成預設寫法。
231
+
232
+
233
+ ## 設定參數重要說明
234
+
235
+ - `--user-data-dir` / `--userDataDir` : 僅當最終值為 Windows 風格(包含 `%TEMP%\\...` 還原成功)才會帶入啟動參數。
236
+ - 若 `--user-data-dir` 未提供,或被過濾(非 Windows 風格),bridge 會回退到 `%TEMP%\\wsl-chrome-bridge\\profile-default`。
237
+ - `playwright-mcp --browser chrome` : 建議搭配 bridge 使用,可避免上游送出 `--no-sandbox` 警告列。
238
+
239
+ ## 環境變數重要說明
240
+
241
+ - `WSL_CHROME_BRIDGE_USER_DATA_DIR=%TEMP%\\...` : 建議預設使用。可固定指定 Windows Chrome profile 路徑,且優先於上游 `--user-data-dir`,可避開 Playwright 本地空目錄副作用,並統一兩種 MCP 設定風格。
242
+ - `WSL_CHROME_BRIDGE_EXECUTABLE_PATH=C:\\...` : 可選環境變數,用於覆蓋 Windows Chrome 的執行檔路徑。
243
+ - `WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT=9222` : 以環境變數指定 Windows Chrome debug port。若都沒指定,bridge 改為隨機 port,不再固定 9222。
244
+ - bridge 會在 Windows 端先探測 port 可用性。若是固定 port 模式且該 port 已被占用,會在啟動前直接報錯。
245
+ - `WSL_CHROME_BRIDGE_DEBUG_FILE=/tmp/xxx.log` : 以環境變數指定 bridge debug log 輸出路徑。
246
+ - `WSL_CHROME_BRIDGE_DEBUG_LEVEL=all|important` : 可選 debug 詳細度。`important`(預設)只記錄 session / 開頁導覽 / 斷線相關的重要 method 與錯誤回應;`all` 會記錄全部 CDP relay 訊息。
247
+ - `WSL_CHROME_BRIDGE_DEBUG_RAW_DIR=/tmp/wsl-chrome-bridge-raw` : 以環境變數指定 raw CDP 內容輸出目錄。每筆 request/response/event 會獨立寫入一個 `raw-<timestamp>.log` 檔案,且 `WSL_CHROME_BRIDGE_DEBUG_FILE` 的 relay log 會包含對應的 `rawPath`。
248
+
249
+ ### 已確認無法使用的參數
250
+
251
+ 以下列表為搭配本程式確定無法使用 `chrome-devtools-mcp` 原始參數
252
+
253
+ - `--browser-url` : 這是遠端連線設定,一旦啟用就會讓 `chrome-devtools-mcp` 走 remote mode 而非 pipe mode,無法與 `wsl-chrome-bridge` 配合。
254
+
255
+
256
+ > 其他 `chrome-devtools-mcp` 提供的原始參數未必全部能使用,本程式尚在開發中,也沒有完全測試過所有原始參數,故只列出目前已經測試過的。
257
+
258
+ ## For Developer
259
+
260
+ 開發者可參考 bridge 連線生命週期與恢復策略文件:
261
+
262
+ - [docs/BRIDGE_CONNECTION_LIFECYCLE-zh.md](./docs/BRIDGE_CONNECTION_LIFECYCLE-zh.md)
263
+
264
+ 開發時所用技術棧:
265
+
266
+ - Node 24
267
+ - TypeScript v6
268
+ - Commander v14
269
+ - ws v8.20
270
+ - 測試框架: Vitest v4.1
package/README.md CHANGED
@@ -8,51 +8,70 @@
8
8
 
9
9
  This project provides a CLI tool: `wsl-chrome-bridge`.
10
10
 
11
- From `chrome-devtools-mcp`'s perspective, `wsl-chrome-bridge` behaves like a Chrome executable.
11
+ From [`chrome-devtools-mcp`](https://github.com/ChromeDevTools/chrome-devtools-mcp)'s perspective, `wsl-chrome-bridge` behaves like a Chrome executable.
12
12
  It provides a DevTools connection entry in WSL and bridges CDP messages to Windows Chrome.
13
13
 
14
14
  With the original `chrome-devtools-mcp` setup, you only need to change `--executablePath` and add a few bridge-specific arguments to let WSL agents control Windows Chrome, without system-level setup (for example `netsh interface portproxy` forwarding or WSL2 mirrored mode).
15
15
 
16
16
  This idea came from [wsl-chrome-mcp](https://github.com/477174/wsl-chrome-mcp), which uses PowerShell to work around the same limitation. That project provides MCP server capability itself, while this project keeps using the widely maintained `chrome-devtools-mcp` and adds a bridge layer.
17
17
 
18
+ ## Breaking Changes in 0.2.0 (Playwright Support)
19
+
20
+ `0.2.0` adds `playwright-mcp` compatibility and includes multiple bridge argument/configuration adjustments.
21
+
22
+ If you are upgrading from `0.1.0`, read the upgrade guide first: [UPGRADE.md](./UPGRADE.md).
23
+
18
24
  ## How It Works
19
25
 
20
26
  ```text
21
- [chrome-devtools-mcp]
22
- |
23
- stdio pipe
24
- |
25
- [wsl-chrome-bridge]
26
- |
27
- PowerShell websocket relay
28
- |
29
- [Windows Chrome]
27
+ [Chrome DevTools MCP] [Playwright MCP]
28
+ | |
29
+ stdio pipe remote-debugging-port
30
+ | |
31
+ +------[wsl-chrome-bridge]-----+
32
+ |
33
+ PowerShell websocket relay
34
+ |
35
+ [Windows Chrome]
30
36
  ```
31
37
 
32
38
  `wsl-chrome-bridge` will:
33
39
 
34
- - Accept Chrome launch arguments from `chrome-devtools-mcp`
40
+ - Accept Chrome launch arguments from both `chrome-devtools-mcp` and `playwright-mcp`
35
41
  - Launch Windows Chrome via PowerShell
36
- - Receive/return CDP messages through stdio pipe (OS pipe)
42
+ - In `chrome-devtools-mcp` mode, receive/return CDP messages through stdio pipe (OS pipe)
43
+ - In `playwright-mcp` mode, create a local WebSocket proxy on the mapped port and forward CDP traffic through it
37
44
  - Relay CDP messages bidirectionally to Windows Chrome through PowerShell websocket relay
38
45
 
39
46
  ## Requirements
40
47
 
41
48
  - Windows 11 with the latest Chrome installed
42
49
  - `powershell.exe` available for WSL2
43
- - Node 20+
50
+ - WSL2 with Node 20+
44
51
 
45
52
  ## Install and Use
46
53
 
47
54
  ### Install
48
55
 
56
+ In WSL, choose one of the following installation methods:
57
+
49
58
  1. Install globally with `npm install -g wsl-chrome-bridge`.
50
- 2. Or clone source and install with `npm link`.
59
+ 2. Or clone source, build it, then install with `npm link`:
60
+
61
+ ```bash
62
+ git clone https://github.com/pigochu/wsl-chrome-bridge.git
63
+ cd wsl-chrome-bridge
64
+ npm install
65
+ npm run build
66
+ npm link
67
+ ```
51
68
 
52
69
  ### Example (Codex)
53
70
 
54
71
  1. Find the actual path of `wsl-chrome-bridge`, for example `/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge`.
55
- 2. Configure `.codex/config.toml` like this:
72
+ 2. Configure `.codex/config.toml` like this.
73
+
74
+ Minimal working `chrome-devtools-mcp` setup:
56
75
 
57
76
  ```toml
58
77
  [sandbox_workspace_write]
@@ -64,28 +83,41 @@ args = [
64
83
  "-y",
65
84
  "chrome-devtools-mcp@latest",
66
85
  "--executablePath",
67
- "/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge",
68
- "--chrome-arg=--window-size=720,400",
69
- "--chrome-arg=--new-window",
70
- "--chrome-arg=--user-data-dir=%TEMP%\\wsl-chrome-bridge\\chrome-profile-test",
71
- "--chrome-arg=--bridge-remote-debugging-port=9222",
72
- "--chrome-arg=--bridge-debug-file=/tmp/wsl-chrome-bridge-debug.log",
73
- "--no-sandbox"
86
+ "/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge"
74
87
  ]
75
88
  enabled = true
76
89
  ```
77
90
 
78
- In this example, Windows Chrome is launched with port `9222`, and `wsl-chrome-bridge` relays traffic between Windows Chrome and `chrome-devtools-mcp`.
91
+ This is the minimum working setup. `wsl-chrome-bridge` launches Windows Chrome and relays CDP traffic for `chrome-devtools-mcp` without extra bridge-specific arguments.
79
92
 
80
- > See the FAQ for how to locate `--executablePath`.
93
+ Minimal working `playwright-mcp` setup (with sandbox):
81
94
 
82
- ## Development Stack
95
+ ```toml
96
+ [sandbox_workspace_write]
97
+ network_access = true
83
98
 
84
- - Node 24
85
- - TypeScript v6
86
- - Commander v14
87
- - ws v8.20
88
- - Test framework: Vitest v4.1
99
+ [mcp_servers.playwright]
100
+ command = "npx"
101
+ args = [
102
+ "-y",
103
+ "@playwright/mcp@latest",
104
+ "--browser",
105
+ "chrome",
106
+ "--sandbox",
107
+ "--executable-path",
108
+ "/home/pigochu/.local/share/mise/shims/wsl-chrome-bridge"
109
+ ]
110
+ enabled = true
111
+
112
+ [mcp_servers.playwright.env]
113
+ DISPLAY = ":9999"
114
+ ```
115
+
116
+ In bridge + system Chrome usage, `--browser chrome` helps avoid upstream `--no-sandbox` warning behavior while keeping Playwright launch behavior stable.
117
+
118
+ > [!NOTE]
119
+ > See the FAQ for how to locate `--executablePath`.
120
+ > For more configuration patterns, see `agent-config-sample/.codex/`.
89
121
 
90
122
  ## Build
91
123
 
@@ -123,7 +155,7 @@ Then paste that output into `--executablePath`.
123
155
 
124
156
  #### Scenario B: Using mise for multiple Node versions (recommended)
125
157
 
126
- If you use mise and switch Node versions, do not hardcode a versioned path from `command -v` (for example `.../installs/node/<version>/bin/...`).
158
+ If you use [mise](https://mise.jdx.dev/) and switch Node versions, do not hardcode a versioned path from `command -v` (for example `.../installs/node/<version>/bin/...`).
127
159
 
128
160
  Prefer the mise shim entry:
129
161
 
@@ -142,23 +174,97 @@ ls -la ~/.local/share/mise/shims/wsl-chrome-bridge
142
174
  - Without a version manager, `command -v` is a direct and valid way to get an absolute path.
143
175
  - With mise multi-version Node, prefer `/home/<user>/.local/share/mise/shims/wsl-chrome-bridge` so path does not break when Node versions change.
144
176
 
145
- ### Why `--user-data-dir` is not recommended
177
+ ### Why Playwright needs `DISPLAY`
178
+
179
+ In WSL/Linux, `playwright-mcp` checks display availability before launching the browser.
180
+ If `DISPLAY` is not set, Playwright often switches to headless behavior (even when you did not explicitly pass `--headless`).
181
+
182
+ That decision happens upstream before bridge logic starts, so `wsl-chrome-bridge` cannot override it later.
183
+ If you want to see a visible Chrome window on Windows, set `DISPLAY` in MCP `env` (for example `DISPLAY=:999`).
184
+
185
+ ### Headless vs headed behavior on upstream MCP exit
186
+
187
+ `wsl-chrome-bridge` applies the following lifecycle policy when upstream MCP exits (for example `chrome-devtools-mcp` / `playwright-mcp`):
188
+
189
+ - If Chrome was started in headless mode, bridge always terminates that Chrome process.
190
+ - If Chrome was started in headed mode (non-headless), bridge always keeps that Chrome process.
146
191
 
147
- `chrome-devtools-mcp` checks whether `--user-data-dir` is an absolute path (starts with `/`). If not, it may be treated as relative, which does not work well with `%TEMP%\\...` style values. Use `--chrome-arg=--user-data-dir=...` instead.
192
+ This behavior is intentional and can differ from native Playwright defaults in some workflows.
193
+
194
+ ### Why Playwright may show `--no-sandbox` warning
195
+
196
+ When `playwright-mcp` is launched without an explicit browser channel, it may resolve to launch args that include `--no-sandbox`. In headed Chrome, this shows the warning banner:
197
+ `You are using an unsupported command-line flag: --no-sandbox`.
198
+
199
+ For bridge usage with system Chrome, recommend adding:
200
+
201
+ ```text
202
+ --browser chrome
203
+ ```
204
+
205
+ This keeps Playwright on the Chrome channel and avoids passing `--no-sandbox` in the common setup.
206
+
207
+ ### About `--user-data-dir`
208
+
209
+ `wsl-chrome-bridge` accepts direct `--user-data-dir` / `--userDataDir` values from upstream MCP.
210
+
211
+ Playwright may resolve a Windows-style path into a Linux path and pre-create a local empty directory before bridge logic starts.
212
+ Bridge checks that local path and removes it only when it is an empty directory. Non-empty directories are never removed.
213
+
214
+ `chrome-devtools-mcp` typically does not create this local empty-directory artifact.
215
+
216
+ Bridge only passes Windows-style user-data-dir values to Windows Chrome. Path-resolved forms like `/cwd/%TEMP%\\...` are restored back to the original Windows-style path when possible.
217
+
218
+ If upstream does not send `--user-data-dir`, or the final value cannot be restored as a Windows-style path (and gets filtered), bridge automatically falls back to:
219
+
220
+ ```text
221
+ %TEMP%\wsl-chrome-bridge\profile-default
222
+ ```
223
+
224
+ This ensures Windows Chrome always starts with a usable profile directory and avoids launch behavior differences when no profile is provided.
225
+
226
+ To avoid Playwright-specific differences and keep a unified config style across `chrome-devtools-mcp` and `playwright-mcp`, prefer setting:
227
+
228
+ ```toml
229
+ WSL_CHROME_BRIDGE_USER_DATA_DIR = "%TEMP%\\wsl-chrome-bridge\\chrome-profile-xxx"
230
+ ```
231
+
232
+ `--user-data-dir` still works, but `WSL_CHROME_BRIDGE_USER_DATA_DIR` is recommended as the default style.
148
233
 
149
234
  ## Important Argument Notes
150
235
 
151
- - `--user-data-dir`: this original `chrome-devtools-mcp` option is not recommended here. It may pass an unexpected path and should be avoided.
152
- - `--chrome-arg=--user-data-dir=...`: set Chrome profile path.
153
- - `--chrome-arg=--bridge-chrome-executablePath=...`: optionally set the Chrome executable absolute path (Windows format required, for example `C:\\...`).
154
- - `--chrome-arg=--bridge-remote-debugging-port=9222`: optionally set the Windows Chrome debug port. Default is `9222` if omitted. This is a bridge-only argument, not a native Chrome flag.
155
- - `--chrome-arg=--bridge-debug-file=/tmp/xxx.log`: optional debug output file in WSL.
236
+ - `--user-data-dir` / `--userDataDir`: Bridge only forwards this flag when the final value is Windows-style (including restored `%TEMP%\\...` forms).
237
+ - If `--user-data-dir` is missing or filtered (non-Windows-style), bridge falls back to `%TEMP%\\wsl-chrome-bridge\\profile-default`.
238
+ - `playwright-mcp --browser chrome`: recommended for bridge usage to avoid upstream `--no-sandbox` banner in headed Chrome.
239
+
240
+ ## Important Environment Variables
241
+
242
+ - `WSL_CHROME_BRIDGE_USER_DATA_DIR=%TEMP%\\...`: recommended default profile setting. It forces the Windows Chrome profile path, takes precedence over upstream `--user-data-dir`, avoids Playwright local empty-dir artifacts, and keeps a unified config style across MCP servers.
243
+ - `WSL_CHROME_BRIDGE_EXECUTABLE_PATH=C:\\...`: optional environment variable to override the Windows Chrome executable path.
244
+ - `WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT=9222`: optional environment variable for Windows Chrome debug port. If no port is specified, bridge uses a random port instead of fixed `9222`.
245
+ - Bridge now probes port availability on Windows before launching Chrome. In fixed-port mode, startup fails fast if that port is already occupied.
246
+ - `WSL_CHROME_BRIDGE_DEBUG_FILE=/tmp/xxx.log`: optional debug output file in WSL.
247
+ - `WSL_CHROME_BRIDGE_DEBUG_LEVEL=all|important`: optional debug verbosity level. `important` (default) logs only important session/navigation/disconnect-related CDP methods and error responses. `all` logs all CDP relay traffic.
248
+ - `WSL_CHROME_BRIDGE_DEBUG_RAW_DIR=/tmp/wsl-chrome-bridge-raw`: optional directory to store full raw CDP payload files. Each request/response/event payload is written as a separate `raw-<timestamp>.log` file, and `WSL_CHROME_BRIDGE_DEBUG_FILE` includes the corresponding `rawPath` for each relay log entry.
156
249
 
157
250
  ### Known incompatible original arguments
158
251
 
159
- The following original `chrome-devtools-mcp` options are currently known as incompatible in this bridge setup:
252
+ The following original `chrome-devtools-mcp` option is currently known as incompatible in this bridge setup:
160
253
 
161
- - `--user-data-dir`: internal handling in `chrome-devtools-mcp` may turn an intended Windows-style path into Linux-style behavior, so this option is filtered out by this bridge and is not recommended for profile path configuration.
162
- - `--browser-url`: this enables remote-connection mode in `chrome-devtools-mcp` instead of pipe mode, so it cannot work with `wsl-chrome-bridge`. Use `--chrome-arg=--bridge-remote-debugging-port=...` instead.
254
+ - `--browser-url`: this enables remote-connection mode in `chrome-devtools-mcp` instead of pipe mode, so it cannot work with `wsl-chrome-bridge`.
163
255
 
164
256
  > Other original `chrome-devtools-mcp` arguments are not all fully validated yet. This project is still under development, so only currently tested limitations are listed here.
257
+
258
+ ## For Developer
259
+
260
+ Developer lifecycle and recovery reference:
261
+
262
+ - [docs/BRIDGE_CONNECTION_LIFECYCLE.md](./docs/BRIDGE_CONNECTION_LIFECYCLE.md)
263
+
264
+ Development stack:
265
+
266
+ - Node 24
267
+ - TypeScript v6
268
+ - Commander v14
269
+ - ws v8.20
270
+ - Test framework: Vitest v4.1
package/UPGRADE-zh.md ADDED
@@ -0,0 +1,122 @@
1
+ # Upgrade Guide: 0.1.0 -> 0.2.0
2
+
3
+ 本文件說明從 `wsl-chrome-bridge` `0.1.0` 升級到 `0.2.0` 需要調整的設定。
4
+
5
+ ## 1. 必做變更
6
+
7
+ ### 1.1 改用環境變數設定 debug log
8
+
9
+ `0.2.0` 開始,以下舊寫法已棄用且會報錯:
10
+
11
+ - `--chrome-arg=--bridge-debug-file=/tmp/xxx.log`
12
+
13
+ 請改為 MCP `env`:
14
+
15
+ ```toml
16
+ WSL_CHROME_BRIDGE_DEBUG_FILE = "/tmp/debug-bridge.log"
17
+ ```
18
+
19
+ ### 1.2 改用環境變數設定 Chrome 執行檔路徑
20
+
21
+ `0.2.0` 開始,以下舊寫法已棄用且會報錯:
22
+
23
+ ```text
24
+ --bridge-chrome-executablePath=C:\Custom\Chrome\chrome.exe
25
+ ```
26
+
27
+ 若你是透過 `chrome-devtools-mcp` 包一層傳入,常見會是:
28
+
29
+ ```text
30
+ --chrome-arg=--bridge-chrome-executablePath=C:\Custom\Chrome\chrome.exe
31
+ ```
32
+
33
+ 請改為 MCP `env`:
34
+
35
+ ```toml
36
+ WSL_CHROME_BRIDGE_EXECUTABLE_PATH = "C:\\Custom\\Chrome\\chrome.exe"
37
+ ```
38
+
39
+ ### 1.3 正式支援 `--user-data-dir`,並新增建議環境變數
40
+
41
+ `0.2.0` 會只把「Windows 風格」路徑帶給 Windows Chrome。
42
+ 像 `/cwd/%TEMP%\\...` 這種被 resolve 過的形式會嘗試還原回 Windows 路徑。
43
+
44
+ 另外,Playwright 可能先建立本地端目錄(Linux 路徑)再交給 bridge。
45
+ bridge 現在會檢查該路徑,若是空目錄就安全刪除;非空目錄則保留。
46
+ `chrome-devtools-mcp` 一般不會有這個空目錄副作用。
47
+
48
+ 因此,雖然 `--user-data-dir` 仍可用,仍建議優先在 MCP `env` 設定:
49
+
50
+ ```toml
51
+ WSL_CHROME_BRIDGE_USER_DATA_DIR = "%TEMP%\\wsl-chrome-bridge\\chrome-profile-xxx"
52
+ ```
53
+
54
+ `--user-data-dir` 仍可使用,但建議作為次要方式,並以 `WSL_CHROME_BRIDGE_USER_DATA_DIR` 統一兩種 MCP 的設定風格。
55
+
56
+ 若你原本使用舊寫法:
57
+
58
+ ```text
59
+ --chrome-arg=--user-data-dir=%TEMP%\wsl-chrome-bridge\chrome-profile-xxx
60
+ ```
61
+
62
+ 升級到 `0.2.0` 建議改成上方 `WSL_CHROME_BRIDGE_USER_DATA_DIR`。
63
+
64
+ ## 2. 建議變更
65
+
66
+ ### 2.1 以環境變數指定固定 debug port(可選)
67
+
68
+ 若你需要固定 port(例如防火牆、除錯工具綁定),可設定:
69
+
70
+ ```toml
71
+ WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT = "9222"
72
+ ```
73
+
74
+ 若你原本使用舊寫法:
75
+
76
+ ```text
77
+ --chrome-arg=--bridge-remote-debugging-port=9222
78
+ ```
79
+
80
+ 升級到 `0.2.0` 建議改成 MCP `env` 的 `WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT`。
81
+ 建議統一用環境變數管理,避免不同 MCP 設定方式造成混用。
82
+
83
+ 若未指定,`0.2.0` 預設改為「隨機可用 port」,不再固定 `9222`。
84
+
85
+ ### 2.2 chrome-devtools 與 playwright 請用不同 profile(可選但強烈建議)
86
+
87
+ 若兩者共用同一個 profile(不論是 `--user-data-dir` 或 `WSL_CHROME_BRIDGE_USER_DATA_DIR`),可能互相影響同一個 Windows Chrome 實例。
88
+ 建議各自指定不同 profile 目錄。
89
+
90
+ ### 2.3 Playwright 建議加上 `--browser chrome`
91
+
92
+ 在 bridge + Windows Chrome 情境下,`playwright-mcp` 若未明確指定 browser channel,可能出現上游傳入 `--no-sandbox`,並在 Chrome 顯示警告列。
93
+
94
+ 建議於 Playwright MCP args 額外加入:
95
+
96
+ ```text
97
+ --browser chrome
98
+ ```
99
+
100
+ 這是設定層級的建議,不影響 bridge 功能,但可避免常見的 `--no-sandbox` UI 警告。
101
+
102
+ ## 3. 驗證清單
103
+
104
+ 升級後可用以下方式快速驗證:
105
+
106
+ 1. 啟動 `chrome-devtools-mcp`,確認 bridge 可正常開頁。
107
+ 2. 啟動 `playwright-mcp`,確認可正常導頁(例如 `https://www.google.com`)。
108
+ 3. 檢查 debug log(`WSL_CHROME_BRIDGE_DEBUG_FILE`):
109
+ - 有 `launchPlan` / `windowsArgs` 記錄
110
+ - `windowsUserDataDir` 或 `windowsArgs` 中的 `--user-data-dir` 為預期 Windows 路徑
111
+
112
+ ## 4. 範例(MCP env)
113
+
114
+ ```toml
115
+ env = {
116
+ WSL_CHROME_BRIDGE_DEBUG_FILE = "/tmp/debug-bridge.log",
117
+ WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT = "9222",
118
+ WSL_CHROME_BRIDGE_USER_DATA_DIR = "%TEMP%\\wsl-chrome-bridge\\chrome-profile-bridge"
119
+ }
120
+ ```
121
+
122
+ `WSL_CHROME_BRIDGE_REMOTE_DEBUG_PORT` 可省略;省略時 bridge 會自動使用隨機可用 port。