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

Unexpected window.close() behavior #119

Closed
nnemkin opened this issue Feb 4, 2020 · 8 comments
Closed

Unexpected window.close() behavior #119

nnemkin opened this issue Feb 4, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@nnemkin
Copy link

nnemkin commented Feb 4, 2020

When a script calls window.close(), WebView2 destroys itself, leaving an empty black window behind.

I think the reasonable behavior for embedded WebViews would be to fire an event (new API) and do nothing.

@david-risney david-risney added the bug Something isn't working label Feb 4, 2020
@david-risney
Copy link
Contributor

Thanks! Yes it looks like if we inject 'close()' the renderer process will end although the browser, GPU, and utility processes remain.

@douglas-jordan
Copy link

I have a background watchdog thread that monitors for this condition and posts a quit message to the main thread, where everything is released.

@pagoe-msft
Copy link

@nnemkin and @douglas-jordan,

In our previous SDK release, we added the WindowCloseRequested event that should resolve your scenario. You can check it out here: https://docs.microsoft.com/en-us/microsoft-edge/hosting/webview2/reference/icorewebview2#add_windowcloserequested

@douglas-jordan
Copy link

@pagoe-msft
The watchdog thread also has the advantage of handling browser crash recovery and only needed to be slightly augmented to handle WebView2.

@shyjusachin
Copy link

Hi @pagoe-msft @douglas-jordan I wanted to get trigger WindowCloseRequested event in one of my WebView2 use case scenario. I have attempted multiple ways but WindowCloseRequested event/event handler is not listing in my WebView2 core libraries. It is a VB.NET application and installed latest nuget version of WebView2 (1.0.1020.30). Could you please let me know how to implement or enable this functionality. Thanks in advance & much appreciated

@champnic
Copy link
Member

WindowCloseRequested is fired when the page calls window.close(). How have you tried to do this so far? I've confirmed that WindowCloseRequested is available in Microsoft.Web.WebView2.Core.dll in the 1.0.1020.30 package:
image

@shyjusachin
Copy link

@champnic Thank you for the quick response. In my case I have been using WinForms and events are registered like this

Friend WithEvents WebView21 As Microsoft.Web.WebView2.WinForms.WebView2

And I can able to use some events like this
image

But here I couldn't use same for WindowCloseRequested. So could you please let me know same is available in WinForms or may I am wrong with some event usage ?. If then could you please provide me sample code of WindowCloseRequested event usage.

@champnic
Copy link
Member

champnic commented Nov 30, 2021

@shyjusachin The WindowCloseRequested event is on the WebView2.CoreWebView2 object, and not the WebView2 Winforms control itself. The WebView2 control only contains a subset of the most common events. Thanks!

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

6 participants