Skip to content

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

@rajusn273

Description

@rajusn273

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions