dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 667 forks source link

[blazor-wasm] Not launching correct OS specific browser #4108

Open ar0311 opened 3 years ago

ar0311 commented 3 years ago

Issue Description

When specifying browser to launch using "blazorwasm" debug type, it is only respected when using the root "browser" option. It is not respected when using stanza under OS such as "windows".

Steps to Reproduce

On windows, make sure Chrome is installed and set as default browser. Also make sure Edge is installed.

Edit launch.json in project using "blazorwasm" debug type, add

"browser": "edge"

Launch and confirm Edge was launched.

Stop debugging, edit launch.json:

"windows": { "browser": "edge" }

Launch and Chrome (default browser) is launched.

Expected Behavior

Edge is launched.

Actual Behavior

Chrome is launched.

Environment information

VSCode version: 1.50.0 C# Extension: 1.23.3

Dotnet Information .NET SDK (reflecting any global.json): Version: 5.0.100-rc.2.20480.7 Commit: 53e0c8c7f9 Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.100-rc.2.20480.7\ Host (useful for support): Version: 5.0.0-rc.2.20475.5 Commit: c5a3f49c88 .NET SDKs installed: 3.1.402 [C:\Program Files\dotnet\sdk] 5.0.100-rc.2.20480.7 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.0-rc.2.20475.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.0-rc.2.20475.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.0-rc.2.20475.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-dotnettools|1.23.3| |dotnet-test-explorer|formulahendry|0.7.4| |git-graph|mhutchie|1.26.0| |gitlens|eamodio|10.2.2| |html-css-class-completion|Zignd|1.19.0| |msbuild-project-tools|tintoy|0.3.8| |razor-plus|austincummings|0.1.4| |remote-ssh|ms-vscode-remote|0.55.0| |remote-ssh-edit|ms-vscode-remote|0.55.0| |vscode-sqlite|alexcvzz|0.9.0|;
gregg-miskelly commented 3 years ago

CC @captainsafia

captainsafia commented 3 years ago

Thanks for reporting this, @ar0311.

The blazorwasm type doesn't support OS-specific configuration types for the browser to launch.

@gregg-miskelly Is this something the JS debugger supports? I don't believe so but I might be incorrect here.

gregg-miskelly commented 3 years ago

I know that the C# extension supports it for launching a browser without debugging when using the somewhat-deprecated launchBrowser launch.json syntax, but I am not sure about scenarios when launching the browser under a debugger. @connor4312 do you know?

connor4312 commented 3 years ago

js-debug supports this if you toggle the runtimeExecutable, but it doesn't have a browser field (chrome and edge are distinct launch types).

captainsafia commented 3 years ago

Took a look at this.

The OS-specific options are supported by the O# configuration and allow a user to override what command is used to launch the browser, for example how to use open Google Chrome.app in macOS.

Given that the blazorwasm debug configuration type uses the vscode-js-debug under the hood, I don't think it's applicable for us to expose this option.

jtsom commented 3 years ago

I have a default Blazor-wasm application and, on Windows, when I try to run I get an error dialog: image

My default system browser is set to Brave, but I do have Chrome installed: image

The error dialog says to add an item to the launch.json specifying the "runtimeExecutable", but that setting is not recognized in the launch.json for a blazorwasm type.

If I set the "browser" field to "edge", it will correctly find and launch MS Edge browser.

connor4312 commented 3 years ago

Where is chrome.exe located on your systems?

jtsom commented 3 years ago

"C:\Program Files (x86)\Google\Chrome Dev\Application\chrome.exe"

jtsom commented 3 years ago

If I change the name of the folder from "Chrome Dev" to "Chrome", the error message does not appear, and my Chrome does launch. Guessing that could cause other problems if I do that though.

connor4312 commented 3 years ago

Thanks, fixed in the linked commit. It'll ship in the next nightly js debugger.

jtsom commented 3 years ago

Has this been released? I believe I'm on the latest nightly: image

connor4312 commented 3 years ago

Yes, it's been published -- works for me by setting the runtimeExecutable: dev

Are you still running into issues?

jtsom commented 3 years ago

Yes, still having the same error.

However, this is my launch.json, created from the ".Net Generate Assets for Build and Debug" command: image

connor4312 commented 3 years ago

We should be able to detect that if the PROGRAMFILES(X86) environment variable is set to C:\Program Files (x86) in your extension host. You can check process.env in the console when running the Toggle Developer Tools command.

If it's not set you might be hitting https://github.com/microsoft/vscode/issues/106537

jtsom commented 3 years ago

Looks like it is set correctly:

image

jtsom commented 3 years ago

I'm also seeing this in the console, not sure if it's relevant : image

connor4312 commented 3 years ago

That means the built-in extension is still installed (and probably stealing launches, which explains the issue). Make sure to do steps 1 and 2 here! https://github.com/microsoft/vscode-js-debug#nightly-extension

jtsom commented 3 years ago

Ok getting this now: image and when I try to add that item, I get: image

connor4312 commented 3 years ago

Ok, that makes more sense.

@captainsafia is there a way to pass the runtimeExecutable through the blazor launch to js-debug?

captainsafia commented 3 years ago

@connor4312 Nope, we can add this if enough people express interest in it.

@jtsom As an alternative, you can try falling back to a two-step launch configuration by launching the application server via the .NET debugger and the front-end client by using the JS debugger.

connor4312 commented 3 years ago

@jtsom here's another alternative that will arrive in the next js-debug nightly https://github.com/microsoft/vscode-js-debug/issues/836

jtsom commented 3 years ago

I will give it a try when it drops. Though will it work with the standard launch.json, created by default with the .Net Generate Assets command, given your comment:

This can now be done via the debug.javascript.defaultRuntimeExecutable setting. Note that this happens at config resolution time, so for the moment only works with pwa- prefixed configs (e.g. if you have a launch type named node, then rename it to pwa-node)

connor4312 commented 3 years ago

It will since blazor launches pwa-chrome internally