@@ -131,9 +131,19 @@ const open = (_args, opts = {}, extra = {}) => {
131131
132132 let platform = process . platform
133133 // process.platform === 'linux' may actually indicate WSL, if that's the case
134- // we want to treat things as win32 anyway so the host can open the argument
134+ // open the argument with sensible-browser which is pre-installed
135+ // In WSL, set the default browser using, for example,
136+ // export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
137+ // or
138+ // export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
139+ // To permanently set the default browser, add the appropriate entry to your shell's
140+ // RC file, e.g. .bashrc or .zshrc.
135141 if ( platform === 'linux' && os . release ( ) . toLowerCase ( ) . includes ( 'microsoft' ) ) {
136- platform = 'win32'
142+ platform = 'wsl'
143+ if ( ! process . env . BROWSER ) {
144+ return Promise . reject (
145+ new Error ( 'Set the BROWSER environment variable to your desired browser.' ) )
146+ }
137147 }
138148
139149 let command = options . command
@@ -146,6 +156,8 @@ const open = (_args, opts = {}, extra = {}) => {
146156 // accidentally interpret the first arg as the title, we stick an empty
147157 // string immediately after the start command
148158 command = 'start ""'
159+ } else if ( platform === 'wsl' ) {
160+ command = 'sensible-browser'
149161 } else if ( platform === 'darwin' ) {
150162 command = 'open'
151163 } else {
0 commit comments