MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Hololens + Unity : Prevent WebView2 to open NewWindow on Edge
@michaelfarnsworth is already working on this.
Since Sep 7, 2023.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Hi I'm trying to implement webview2 using the latest library for hololens and unity, but I'm having an issue where pages invoke a new window and this is catched by default Browser on the Hololens2 and openning an Edge window.
I saw other examples that explain how to prevent this but this examples differs from what I have on the unity library, I can catch the string of the url, but it doesn't prevent to open a new window.
Like this:
private void Start()
{
webViewComponent.GetWebViewWhenReady((IWebView webView) =>
{
_webView = webView;
webView.NewWindowRequested += OnNewWindow;
});
}
private void OnNewWindow(string url)
{
Debug.Log($"New window url: {url}");
}
But in other examples from UWP .Net the method is like this, and they suggest to set the Handled to true, but this is not available on Unity library
Something like this:
WebView2 webView21 = new WebView2();
private async void Form1_Load(object sender, EventArgs e)
{
webView21.Dock = DockStyle.Fill;
this.Controls.Add(webView21);
webView21.Source = new Uri("Https://stackoverflow.com");
await webView21.EnsureCoreWebView2Async();
webView21.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
}
private void CoreWebView2_NewWindowRequested(object sender,
CoreWebView2NewWindowRequestedEventArgs e)
{
//e.NewWindow = (CoreWebView2)sender;
e.Handled = true; //Prevent new window to open
}
PD. Im using this page from micrsoft as reference
https://learn.microsoft.com/en-us/microsoft-edge/webview2/get-started/hololens2#step-7---extending-webview2-functionality
Any have any clue on how to prevent from opening new windows on edge on unity with hololens 2?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.