Skip to content
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

[Problem/Bug]: how to cancel a navigate event ? #4660

Closed
fforjan opened this issue Jul 3, 2024 · 1 comment
Closed

[Problem/Bug]: how to cancel a navigate event ? #4660

fforjan opened this issue Jul 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@fforjan
Copy link

fforjan commented Jul 3, 2024

What happened?

We are using a virtual host and we would like to open the regular webbrowser when the navigation goes to a different website.
(The virtual host content point to our regular internet website for support and we would prefer the user to use his regular web browser for SSO purpose).
note: we are providing our content in both virtual host and internet hosted for some internal reasons and we would like to avoid any modification for the virtual host mode.

I have tried:

@this.CoreWebView2.NavigationStarting += CoreWebView2_NavigationStarting;

void CoreWebView2_NavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
{
    if(!hostName.Equals(new Uri(e.Uri).Authority, StringComparison.InvariantCultureIgnoreCase))
    {
        Process.Start(new ProcessStartInfo(e.Uri.Replace("&", "^&")) { UseShellExecute = true });             
        e.Cancel = true;                
    }
}

The link is correctly opened into the external web browser BUT the navigation is not cancelled, i.e. the WebView2 displays an empty web page.

Is there a way we cancel the navigation, meaning the current page will be displayed ?

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

126.0.2592.81

SDK Version

1.0.2535.41

Framework

WPF

Operating System

Windows 11

OS Version

No response

Repro steps

Create a virtual host and try to cancel the navigation using the following code:

@this.CoreWebView2.NavigationStarting += CoreWebView2_NavigationStarting;

void CoreWebView2_NavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
{
    if(!hostName.Equals(new Uri(e.Uri).Authority, StringComparison.InvariantCultureIgnoreCase))
    {
        Process.Start(new ProcessStartInfo(e.Uri.Replace("&", "^&")) { UseShellExecute = true });             
        e.Cancel = true;                
    }
}

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

@fforjan fforjan added the bug Something isn't working label Jul 3, 2024
@fforjan
Copy link
Author

fforjan commented Jul 4, 2024

I think it is my mistake, the reason being that the request was coming to a new indow but we redirected to ourself.
bt moving the URI check into the new window, everything works as expected.

@fforjan fforjan closed this as completed Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant