Open bigbigDreamer opened 2 years ago
In particular, you can install xdg-open
in your wsl in advance.
$ sudo apt-get update
$ sudo apt-get install xdg-open
Then, xdg-open
can automatically open the default browser on your host machine, provided that you have sufficient permissions.
you can try edit the source code in open
from node_modules:
if (app) {
command = app;
} else {
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
const isBundled = !__dirname || __dirname === '/';
// Check if local `xdg-open` exists and is executable.
let exeLocalXdgOpen = false;
try {
await fs.access(localXdgOpenPath, fsConstants.X_OK);
exeLocalXdgOpen = true;
} catch {}
// const useSystemXdgOpen = process.versions.electron ||
// platform === 'android' || isBundled || !exeLocalXdgOpen;
// command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
command = 'xdg-open';
}
Finally,u can use as follow:
const open = require('open');
open(url, { wait: true })
Don't add app
param!
In my case, I have given WSL restricted access to the host machine intentionally to work as a sandbox. It still tries to access Powershell. What should I do?
https://github.com/sindresorhus/open/blob/7579417bbd3b3fc155b10f9b9b2eb71381e13e9a/index.js#L123
Now I modified the source file in node modules and used
xdg-open
can work normal.Delete
|| (isWsl && !isDocker())
, becausewsl
also islinux
plateform.But, Note: You should give your current wsl system login user root privileges.
269