@dbalabka/chrome-wsl 0.2.4 → 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.md +37 -3
- package/chrome-wsl +97 -4
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -17,7 +17,9 @@ A small WSL helper to open Google Chrome on Windows with remote debugging (port
|
|
|
17
17
|
- Windows Chrome installed at `C:\Program Files\Google\Chrome\Application\chrome.exe` (adjust the path in the script if different).
|
|
18
18
|
- Network/apt access to install `socat` on first run (or preinstall manually).
|
|
19
19
|
|
|
20
|
-
## Usage
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### with NPX
|
|
21
23
|
```sh
|
|
22
24
|
npx @dbalabka/chrome-wsl
|
|
23
25
|
```
|
|
@@ -25,10 +27,42 @@ npx @dbalabka/chrome-wsl
|
|
|
25
27
|
- The script logs `socat` output to `/tmp/socat-9222.log`.
|
|
26
28
|
- To stop the `socat` forwarder:
|
|
27
29
|
```sh
|
|
28
|
-
npx @dbalabka/chrome-wsl --
|
|
30
|
+
npx @dbalabka/chrome-wsl --stop
|
|
31
|
+
```
|
|
32
|
+
- To uninstall (prompts before removing the firewall rule and socat):
|
|
33
|
+
```sh
|
|
34
|
+
npx @dbalabka/chrome-wsl --uninstall
|
|
29
35
|
```
|
|
30
36
|
- Runs directly via npm without cloning; default entrypoint is `chrome-wsl` (matching the package name).
|
|
31
|
-
|
|
37
|
+
|
|
38
|
+
#### Example
|
|
39
|
+
```sh
|
|
40
|
+
❯ npx @dbalabka/chrome-wsl
|
|
41
|
+
✅ Detected Windows host IP: 172.18.112.1
|
|
42
|
+
✅ Portproxy 172.18.112.1:9222 -> 127.0.0.1:9222 is configured.
|
|
43
|
+
✅ Firewall rule "Chrome Remote Debug" exists.
|
|
44
|
+
✅ socat is already installed.
|
|
45
|
+
✅ Started socat (logging to /tmp/socat-9222.log).
|
|
46
|
+
✅ Launched Chrome (pid 32408) with remote debugging.
|
|
47
|
+
✅ Chrome is listening on port 9222.
|
|
48
|
+
```
|
|
49
|
+
```sh
|
|
50
|
+
❯ npx @dbalabka/chrome-wsl --stop
|
|
51
|
+
✅ Stopped tracked Chrome process (pid 32408).
|
|
52
|
+
✅ Stopped socat forwarding for port 9222.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### with NPM
|
|
56
|
+
To install globally instead of npx:
|
|
57
|
+
```sh
|
|
58
|
+
npm install -g @dbalabka/chrome-wsl
|
|
59
|
+
```
|
|
60
|
+
Then run:
|
|
61
|
+
```sh
|
|
62
|
+
chrome-wsl
|
|
63
|
+
chrome-wsl --stop
|
|
64
|
+
chrome-wsl --uninstall
|
|
65
|
+
```
|
|
32
66
|
|
|
33
67
|
## Notes
|
|
34
68
|
- Portproxy check expects forwarding from the detected Windows host IP to `127.0.0.1:9222`.
|
package/chrome-wsl
CHANGED
|
@@ -64,8 +64,37 @@ stop_socat() {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
run_powershell() {
|
|
67
|
-
# Runs a PowerShell command from WSL.
|
|
68
|
-
|
|
67
|
+
# Runs a PowerShell command from WSL. If RUN_AS_ADMIN=1, invoke via Start-Process -Verb RunAs
|
|
68
|
+
# and capture output through a temp script/output file to mirror direct execution.
|
|
69
|
+
local ps_cmd="$*"
|
|
70
|
+
|
|
71
|
+
if [[ "${RUN_AS_ADMIN:-}" == "1" ]]; then
|
|
72
|
+
local out_file ps_file win_out win_ps
|
|
73
|
+
mkdir -p /mnt/c/Temp
|
|
74
|
+
out_file=$(mktemp -p /mnt/c/Temp chrome-wsl-out-XXXXXX)
|
|
75
|
+
ps_file=$(mktemp -p /mnt/c/Temp --suffix=.ps1 chrome-wsl-XXXXXX)
|
|
76
|
+
win_out=$(wslpath -w "$out_file")
|
|
77
|
+
win_ps=$(wslpath -w "$ps_file")
|
|
78
|
+
|
|
79
|
+
{
|
|
80
|
+
echo "& {"
|
|
81
|
+
echo " ${ps_cmd}"
|
|
82
|
+
echo "} | Out-File -FilePath \"${win_out}\" -Encoding UTF8"
|
|
83
|
+
} >"$ps_file"
|
|
84
|
+
|
|
85
|
+
powershell.exe -NoLogo -NoProfile -NonInteractive -Command "Start-Process -FilePath 'powershell' -Verb RunAs -ArgumentList '-NoLogo','-NoProfile','-NonInteractive','-File','\"${win_ps}\"' -WindowStyle Hidden -Wait"
|
|
86
|
+
cat "$out_file"
|
|
87
|
+
rm -f "$out_file" "$ps_file"
|
|
88
|
+
else
|
|
89
|
+
powershell.exe -NoLogo -NoProfile -NonInteractive -Command "$ps_cmd"
|
|
90
|
+
fi
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
confirm() {
|
|
94
|
+
local prompt=$1
|
|
95
|
+
local reply
|
|
96
|
+
read -r -p "${prompt} [y/N] " reply
|
|
97
|
+
[[ "${reply}" =~ ^[Yy]$ ]]
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
chrome_running() {
|
|
@@ -89,6 +118,10 @@ port_listening_info() {
|
|
|
89
118
|
run_powershell "\$conns = Get-NetTCPConnection -LocalPort ${PORT} -ErrorAction SilentlyContinue | Select-Object -Property LocalAddress,LocalPort,RemoteAddress,RemotePort,State,OwningProcess; foreach (\$c in \$conns) { \$p = Get-Process -Id \$c.OwningProcess -ErrorAction SilentlyContinue; \$name = if (\$p) { \$p.Name } else { 'unknown' }; Write-Output (\"{0}:{1} owner={2} pid={3} state={4}\" -f \$c.LocalAddress, \$c.LocalPort, \$name, \$c.OwningProcess, \$c.State) }"
|
|
90
119
|
}
|
|
91
120
|
|
|
121
|
+
port_in_use_by_non_chrome() {
|
|
122
|
+
run_powershell "if (Get-NetTCPConnection -LocalPort ${PORT} -ErrorAction SilentlyContinue | Where-Object { \$p = Get-Process -Id \_.OwningProcess -ErrorAction SilentlyContinue; -not (\$p -and \$p.Name -eq 'chrome') }) { exit 0 } else { exit 1 }"
|
|
123
|
+
}
|
|
124
|
+
|
|
92
125
|
get_wsl_host_ip() {
|
|
93
126
|
local host_ip
|
|
94
127
|
host_ip=$(ip route | awk '/^default via / {print $3; exit}')
|
|
@@ -118,19 +151,68 @@ EOF
|
|
|
118
151
|
}
|
|
119
152
|
|
|
120
153
|
check_firewall_rule() {
|
|
121
|
-
|
|
154
|
+
local rule_check_cmd="\$rule='${FIREWALL_RULE_NAME}'; if (Get-NetFirewallRule -DisplayName \$rule -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"
|
|
155
|
+
|
|
156
|
+
if run_powershell "${rule_check_cmd}"; then
|
|
122
157
|
ok "Firewall rule \"${FIREWALL_RULE_NAME}\" exists."
|
|
123
158
|
return 0
|
|
124
159
|
fi
|
|
125
160
|
|
|
161
|
+
err "Firewall rule \"${FIREWALL_RULE_NAME}\" is missing; attempting to create it (may prompt for admin)."
|
|
162
|
+
if RUN_AS_ADMIN=1 run_powershell "New-NetFirewallRule -DisplayName \"${FIREWALL_RULE_NAME}\" -Direction Inbound -LocalPort ${PORT} -Protocol TCP -Action Allow" \
|
|
163
|
+
&& run_powershell "${rule_check_cmd}"; then
|
|
164
|
+
ok "Created firewall rule \"${FIREWALL_RULE_NAME}\"."
|
|
165
|
+
return 0
|
|
166
|
+
fi
|
|
167
|
+
|
|
126
168
|
cat <<EOF
|
|
127
|
-
${ERR_MARK}
|
|
169
|
+
${ERR_MARK} Failed to create firewall rule "${FIREWALL_RULE_NAME}" automatically.
|
|
128
170
|
Run this in an **admin PowerShell** window:
|
|
129
171
|
New-NetFirewallRule -DisplayName "${FIREWALL_RULE_NAME}" -Direction Inbound -LocalPort ${PORT} -Protocol TCP -Action Allow
|
|
130
172
|
EOF
|
|
131
173
|
return 1
|
|
132
174
|
}
|
|
133
175
|
|
|
176
|
+
uninstall_firewall_rule() {
|
|
177
|
+
local rule_check_cmd="\$rule='${FIREWALL_RULE_NAME}'; if (Get-NetFirewallRule -DisplayName \$rule -ErrorAction SilentlyContinue) { exit 0 } else { exit 1 }"
|
|
178
|
+
|
|
179
|
+
if ! run_powershell "${rule_check_cmd}"; then
|
|
180
|
+
ok "Firewall rule \"${FIREWALL_RULE_NAME}\" is already absent."
|
|
181
|
+
return 0
|
|
182
|
+
fi
|
|
183
|
+
|
|
184
|
+
if ! confirm "Remove firewall rule \"${FIREWALL_RULE_NAME}\"?"; then
|
|
185
|
+
ok "Skipped firewall rule removal."
|
|
186
|
+
return 0
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if RUN_AS_ADMIN=1 run_powershell "Remove-NetFirewallRule -DisplayName \"${FIREWALL_RULE_NAME}\"" \
|
|
190
|
+
&& ! run_powershell "${rule_check_cmd}"; then
|
|
191
|
+
ok "Removed firewall rule \"${FIREWALL_RULE_NAME}\"."
|
|
192
|
+
else
|
|
193
|
+
err "Failed to remove firewall rule \"${FIREWALL_RULE_NAME}\"."
|
|
194
|
+
fi
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
uninstall_socat() {
|
|
198
|
+
if ! command -v socat >/dev/null 2>&1; then
|
|
199
|
+
ok "socat is not installed; nothing to remove."
|
|
200
|
+
return 0
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
if ! confirm "Remove socat package (sudo apt-get remove -y socat)?"; then
|
|
204
|
+
ok "Skipped socat removal."
|
|
205
|
+
return 0
|
|
206
|
+
fi
|
|
207
|
+
|
|
208
|
+
stop_socat
|
|
209
|
+
if sudo apt-get remove -y socat; then
|
|
210
|
+
ok "Removed socat package."
|
|
211
|
+
else
|
|
212
|
+
err "Failed to remove socat package."
|
|
213
|
+
fi
|
|
214
|
+
}
|
|
215
|
+
|
|
134
216
|
ensure_socat() {
|
|
135
217
|
if command -v socat >/dev/null 2>&1; then
|
|
136
218
|
ok "socat is already installed."
|
|
@@ -185,6 +267,11 @@ start_chrome() {
|
|
|
185
267
|
fi
|
|
186
268
|
fi
|
|
187
269
|
|
|
270
|
+
if port_in_use_by_non_chrome; then
|
|
271
|
+
err "Port ${PORT} is already in use by another process (not Chrome); details:"
|
|
272
|
+
port_listening_info
|
|
273
|
+
fi
|
|
274
|
+
|
|
188
275
|
local chrome_pid
|
|
189
276
|
chrome_pid=$(run_powershell "$chrome_cmd" | tr -d '\r' | head -n 1)
|
|
190
277
|
if [[ -n "${chrome_pid:-}" ]]; then
|
|
@@ -203,6 +290,12 @@ start_chrome() {
|
|
|
203
290
|
}
|
|
204
291
|
|
|
205
292
|
main() {
|
|
293
|
+
if [[ "${1-}" == "--uninstall" ]]; then
|
|
294
|
+
uninstall_firewall_rule
|
|
295
|
+
uninstall_socat
|
|
296
|
+
exit 0
|
|
297
|
+
fi
|
|
298
|
+
|
|
206
299
|
if [[ "${1-}" == "--stop" ]]; then
|
|
207
300
|
stop_chrome
|
|
208
301
|
stop_socat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbalabka/chrome-wsl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "WSL helper to start Windows Chrome with remote debugging and socat port forwarding.",
|
|
5
5
|
"bin": "./chrome-wsl",
|
|
6
6
|
"files": [
|
|
@@ -18,11 +18,14 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/dbalabka/
|
|
21
|
+
"url": "git+https://github.com/dbalabka/chrome-wsl.git"
|
|
22
22
|
},
|
|
23
23
|
"author": "Dmitry Balabka",
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/dbalabka/
|
|
25
|
+
"url": "https://github.com/dbalabka/chrome-wsl/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/dbalabka/
|
|
27
|
+
"homepage": "https://github.com/dbalabka/chrome-wsl#readme",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
28
31
|
}
|