-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to start the system default browser. #17938
Comments
There's not a single call that will work on all platforms, but you can use something like this: public static void OpenBrowser(string url)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
...
}
} I haven't tried the OSX call above, but it seems to do what you want according to a google search. I've used the other two and they work as expected. |
|
I believe the main issue here is that UseShellExecute defaults to true in desktop (and presumably Mono, though I haven't verified), but false in corefx. It's false by default because the APIs necessary to support true on Windows aren't currently available in all target Windows platforms. It can be set to true on Unix. We should revisit this. |
Slight improvement on what @mellinoe suggested:
|
@gerardog Closing this issue, please reopen if the suggested methods don't work for you. |
Why are we closing this? Just because there's a workaround doesn't mean it's addressed. There's functionality that works in desktop and works in mono but doesn't in core: that's something to investigate further. Have we already done so? |
Leaving the issue open as a bug for investigation. |
FYI - this seemed to work fine on mac for me - El Capitan 10.11.6 |
This should work now (with useshellexecute=true) on Windows and work on Unix after https://github.com/dotnet/corefx/issues/19956 |
I'm going to close as it's fixed/covered elsewhere. |
|
You should not need to involve cmd.exe. If you set filename to the url and psi.useshellexecute =true it shoukd work. Including on Linux. Can you confirm? |
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start (psi); This does work on Windows but not on Linux. In Linux I can simply do: Process.Start ("xdg-open", url); which works. |
- On .NET Core 3.0 on Windows you will get a Win32Exception when you try to open any URL, because of this https://github.com/dotnet/corefx/issues/10361 - The proposed change was tested on .NET Core on Windows but should work anywhere.
- On .NET Core 3.0 on Windows you will get a Win32Exception when you try to open any URL, because of this https://github.com/dotnet/corefx/issues/10361 - The proposed change was tested on .NET Core on Windows but should work anywhere.
I'm seeing this now on Linux when trying
However, I'm confused because I'm running Mono and this used to work, so I must have installed or upgraded something at some point that exposed me to this (maybe Mono can use corefx libraries?). I've been trying to catch up on the network of related issues and pull requests to assess the impact, but it's a slog. Can anyone please summarize the scope of this issue, i.e. who is and is not affected by it? If I want my app to work on all of the available platforms and runtimes, do I need to implement a permanent workaround for launching URLs? |
.NET Core changes the default value of UseShellExecute when launching processes. dotnet/runtime#17938
The following line doesn't work:
Process.Start("http://localhost:5000");
Microsoft said that that was the official way to start a new browser, a long time ago, at:
https://support.microsoft.com/en-us/kb/305703
Is there any multiplatform way to do this now? Will it ever be?
The text was updated successfully, but these errors were encountered: