vscode-extensions-open-in-browser
vscode-extensions-open-in-browser copied to clipboard
Support WSL
Currently, it seems this extension doesn't work in WSL.
Here is an example for the error message:
Windows can't find '\mnt\c\ {some path} \index.html'. Make sure you typed the name correctly, and then try agian.
This should be replace to 'C:/ {some path}/ index.html'.
This is a "hacky" solution, but it got me going using this extension onWSL2 and Windows 10 Pro 19041.685.
In index.ts I made the following changes, compiled and manually replaced the contents in %USERPROFILE%\.vscode\extensions\techer.open-in-browser-2.0.0\out\index.js
Import child process to run commands against cmd prompt in windows.
import * as cp from 'child_process';
Added a const to convert windows path into unix friendly.
const convertPath = (windowsPath) => windowsPath.replace(/^\\\\\?\\/,"").replace(/\\/g,'\/').replace(/\/\/+/g,'\/')
Added helper function to run shell commands against cmd prompt
const execShell = (cmd: string) =>
new Promise<string>((resolve, reject) => {
cp.exec(cmd, (err, out) => {
if (err) {
return reject(err);
}
return resolve(out);
});
});
Converted openDefault to async and used wsl.exe to run the wslpath command from a dos prompt and return the output.
- This now opens files from the WSL sub system directly in host windows browser.
export const openDefault = async (path: any): Promise<void> => {
let uri;
if (path) {
uri = await execShell('wsl wslpath -w ' + convertPath(path.fsPath));
} else {
const _path = currentPageUri();
uri = _path && _path.fsPath;
}
const browser = standardizedBrowserName(defaultBrowser());
open(uri, browser);
};
please add support by default, it is needed
Would love to have this as well
what about this issue?