ITADN

Cannot detect default browser correctly when app.name is set to browser or browserPrivate in WSL environment.

#357Closedsukjuhong 创建于 2025-04-29
S
sukjuhongcommented
Currently, when `app.name` is set to browser or browserPrivate, the default-browser library is used to detect the system's default browser. ```js // in 'default-browser' library if (process.platform === 'linux') { const {stdout} = await execFileAsync('xdg-mime', ['query', 'default', 'x-scheme-handler/http']); const id = stdout.trim(); const name = titleize(id.replace(/.desktop$/, '').replace('-', ' ')); return {name, id}; } ``` Since WSL reports process.platform as linux, it uses xdg-mime to detect the default browser. However, in WSL, the Windows-installed default browser is usually not set properly for x-scheme-handler/http, leading to incorrect or missing results. In my testing with a fresh Ubuntu installation on WSL: - x-scheme-handler/http is often unset. - If wslu is installed, the result might be { name: 'Wslview', id: 'wslview.desktop' }. - Sometimes it even defaults to Firefox even when Firefox isn't installed. This leads to runtime errors like: ```log Error: Wslview is not supported as a default browser at baseOpen (file:///home/***/dev/test-open-browser/node_modules/open/index.js:143:9) at async file:///home/***/dev/test-open-browser/index.js:4:1 ``` Since Wslview isn't an actual browser, the open operation fails. ```js import open from "open"; await open("https://google.com", { wait: true }); // Works fine await open("https://google.com", { app: { name: "browser" } }); // Fails ``` When `app.name` is not set, it falls back to using PowerShell's Start command, and the URL correctly opens in the default browser. However, to use features like private/incognito mode, setting `app.name` is necessary. Is there a good way to handle this situation in WSL? Maybe it would be possible to detect WSL specifically and fall back to the Windows behavior instead of using xdg-mime? Any advice would be appreciated!
关闭于 2025-05-01 0 条评论