MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: WebView2 closing a window is not calling window.onunload
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
I am using WebView2 control (latest stable release 1.0.2651.64, WebView2 Runtime 127.0.2651.105) in WPF app.
Within the WebView2 control a html form with javascript is loaded, the form uses window.onunload and some other html forms I use window.onbeforeunload to call unlock methods on C# Host objects.
The issue happens when the WPF window is closed and onunload/onbeforeunload javascript methods are not getting called.
I have attached sample application where i launch Test.html inside WebView2, in this form i have subscribed to load, unload and beforeunload. Only load method gets executed which calls a method from HostObject, but on close of the form beforeunload nor unload are getting called.
WebViewEx1.zip
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
127.0.2651.105
SDK Version
1.0.2651.64
Framework
WPF
Operating System
Windows 11
OS Version
10.0.22631
Repro steps
A html form with javascript is loaded in webview2 control hosted inside WPF window, the html form uses js window.onunload and some other html forms I use js window.onbeforeunload to call unlock methods on C# Host objects.
The issue happens when the WPF window is closed and onunload/onbeforeunload javascript methods are not getting called.
Repros in Edge Browser
Yes, issue can be reproduced in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
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.
Research direction
Start by running the attached WebViewEx1.zip sample and inspect Test.html, focusing on the load, unload, and beforeunload handlers when the WPF window closes. Compare the behavior with the corresponding Edge version as described; done requires determining why the close lifecycle callbacks are absent and identifying an appropriate resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, html, javascript
- Domain
- desktop, web-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100