Developing and testing features or extensions for Microsoft Edge
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am working on a WebView2 project, a new HTML browser based on Edge Chromium and a real step forward compared to the old IE based component.
However, when I click a URL in this control, it always opens a new Webview2 Runtime component (without menu's) showing the URL. I want a click executed in an existing window and e.g. a Ctrl or Shift click should open in my default browser (Firefox).
Several webpages refer to NewWindowRequested. This event does not seem to be fired when I click an URL in a page. Why not? I use this code:
public MainWindow()
// From: https://learn.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/wpf
{
InitializeComponent();
InitializeAsync();
}
async void InitializeAsync()
{
await webView.EnsureCoreWebView2Async(null);
webView.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
}
private void CoreWebView2_NewWindowRequested(object sender,CoreWebView2NewWindowRequestedEventArgs e)
{
// BELOW SOME CODE SAMPLES I FOUND WHICH COULD CHANGE A URL CLICK BEHAVIOR BUT THIS METHOD IS NEVER CALLED
e.NewWindow = (CoreWebView2)sender;
e.Handled = true;
}
Developing and testing features or extensions for Microsoft Edge
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.