MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: WebView2 closing a window is not calling window.onunload

Open
#4,872 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.