Add some safety for webview window on windows and fix for mac#451
Merged
boyan01 merged 3 commits intoNov 11, 2025
Merged
Conversation
Contributor
|
Thanks for the contribution. LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix memory leaks, crashes, and bugs in desktop_webview_window
Summary
This PR addresses critical memory leaks, potential crashes, and bugs across Windows and macOS implementations of the desktop_webview_window package. The changes improve stability, prevent memory leaks, and fix incorrect behavior.
Changes
Commit 1: Fix critical memory leaks and crashes in Windows webview implementation
File:
packages/desktop_webview_window/windows/web_view.ccIssues Fixed:
LPWSTR user_agent[256]and memory leak by usingwil::unique_cotaskmem_stringICoreWebView2Settings *settingstowil::com_ptrfor automatic COM reference managementNewWindowRequestedandNavigationStartinghandlers by usingwil::unique_cotaskmem_stringGetAllCookiesmethod for all cookie string fields (name, value, domain, path)get_CoreWebView2(),get_Settings(), and all cookie operations to prevent crashesstd::holds_alternative<bool>()before accessing variant value to prevent exceptionsExecuteScriptresult to prevent crashesTechnical Details:
wil::com_ptrfor automatic lifetime managementLPWSTRallocations withwil::unique_cotaskmem_stringfor automatic memory cleanupImpact: Prevents memory leaks that could accumulate over time and crashes from invalid COM objects or null pointers.
Commit 2: Add removeAllWebMessageReceivedCallback method and improve code formatting
Files:
packages/desktop_webview_window/lib/src/webview.dartpackages/desktop_webview_window/lib/src/webview_impl.dartChanges:
removeAllWebMessageReceivedCallback()method to clear all web message callbacks at onceImpact: Provides better control over web message callbacks and improves code maintainability.
Commit 3: Fix macOS JavaScript interface removal bug
File:
packages/desktop_webview_window/macos/Classes/DesktopWebviewWindowPlugin.swiftIssue Fixed:
unregisterJavaScriptMessageHandler- was callingaddJavascriptInterfaceinstead ofremoveJavascriptInterfaceImpact: JavaScript interface removal now works correctly on macOS, preventing potential memory leaks and incorrect behavior.
Testing
Breaking Changes
None - all changes are bug fixes and improvements that maintain backward compatibility.
Related Issues
Fixes memory leaks and crashes that could occur during: