I have a C# WPF application that uses a WebView2 window running a React app for hosting video calls using the Azure Communications service. This works well, except if the user mutes the microphone or turns off the camera, when the app tries to close the WebView2 window after the call, the page reports that there are unsaved changes and displays a message saying "Leave site - The changes you made may not be saved". If the user doesn't touch the camera or mic controls, the "Leave site" message isn't displayed when they exit.
I have tried using the beforeunload
event, however I discovered from this question that Microsoft have blocked this feature from WebView2 windows.
Whilst the user could click on 'Leave', it gives a poor user experience. Plus, if they chose to ignore the dialog or click 'Cancel' then the WebView2 window stays hidden but active, using up resources and stopping a new WebView2 & ACS window being launched.
Is there another strategy I could use to either:
- Stop the message being shown
- Auto-select 'Leave' on behalf of the user.