Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start Edge from WSL2?

I can run code to start VSCode from inside WSL2.

How would I start Edge (the current Chromium based one)?

I have tried:

~/Code/company/workshops-website$ cmd.exe /c 'start microsoft-edge:\\wsl$\Ubuntu\home\mike\Code\company\workshops-website\index.html'
'\\wsl$\Ubuntu\home\mike\Code\company\workshops-website'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

It starts Edge but doesn't open index.html (instead Edge searches for it)

How would I start Edge (the Windows app) from inside WSL2?

I'm comfortable making bash aliases, functions, etc.

like image 211
mikemaccana Avatar asked May 08 '20 18:05

mikemaccana


3 Answers

$ wslview index.html

Will open the file in your default browser on Windows.

wslview is packaged in wslutilities which comes pre-installed on Ubuntu on WSL and some other WSL distros.

like image 131
Hayden Barnes Avatar answered Sep 21 '22 10:09

Hayden Barnes


If you wish to use the default Windows browser automatically, e.g. when using 'az login', add these lines to your shell's RC e.g. .bashrc or .zshrc:

export DISPLAY=:0
export BROWSER=/usr/bin/wslview
like image 34
Marko V Avatar answered Sep 25 '22 10:09

Marko V


I think the best way to do this is to use explorer.exe. You can use explorer.exe to open anything web related in your default browser.

So edit your .bash_aliases (or create it) to add this line:

alias browser="explorer.exe"

Then you can open your HTML files in your default browser like this:

$ browser index.html
like image 44
HadiAlqattan Avatar answered Sep 25 '22 10:09

HadiAlqattan