Commit 5ecf301
fix: open URL in browser on WSL (#128)
Here's a more elegant solution for opening URLs from WSL in your
favorite browser. It is based on `sensible-browser` which is included in
the default distribution for WSL. This avoids issues with the WSL
environment, `cmd.exe`. quoting parameters, etc.
In WSL, set the default browser using the `BROWSER` variable, for
example,
```sh
export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
or
export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
```
Note: To permanently set the default browser, add the appropriate entry
to your shell's RC file, e.g. .bashrc or .zshrc.
To launch a URL from the WSL command line:
```sh
sensible-browser https://google.com
```
To launch a URL using `promise-spawn`:
```js
const promiseSpawn = require('@npmcli/promise-spawn')
promiseSpawn.open('https://google.com')
```
Replaces #118
Closes #62
### Test
```
os: 5.15.153.1-microsoft-standard-WSL2
node: 20.18.0
npm: 10.8.2
```

---------
Co-authored-by: Gar <[email protected]>1 parent 6b0e577 commit 5ecf301
2 files changed
+59
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
134 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
135 | 141 | | |
136 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| |||
146 | 156 | | |
147 | 157 | | |
148 | 158 | | |
| 159 | + | |
| 160 | + | |
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
121 | | - | |
| 124 | + | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
133 | | - | |
| 137 | + | |
| 138 | + | |
134 | 139 | | |
135 | 140 | | |
136 | 141 | | |
| |||
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 162 | + | |
164 | 163 | | |
165 | 164 | | |
166 | 165 | | |
167 | 166 | | |
168 | 167 | | |
| 168 | + | |
| 169 | + | |
169 | 170 | | |
170 | | - | |
171 | | - | |
172 | | - | |
| 171 | + | |
173 | 172 | | |
174 | 173 | | |
175 | 174 | | |
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | 178 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | 179 | | |
187 | | - | |
| 180 | + | |
188 | 181 | | |
189 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
190 | 187 | | |
191 | 188 | | |
192 | 189 | | |
193 | 190 | | |
194 | 191 | | |
| 192 | + | |
| 193 | + | |
195 | 194 | | |
196 | | - | |
197 | | - | |
198 | | - | |
| 195 | + | |
199 | 196 | | |
200 | 197 | | |
201 | 198 | | |
202 | 199 | | |
203 | 200 | | |
204 | 201 | | |
205 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
206 | 207 | | |
207 | 208 | | |
208 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
209 | 232 | | |
210 | 233 | | |
211 | 234 | | |
| |||
0 commit comments