Skip to content

[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567

Merged
auto-submit[bot] merged 8 commits intoflutter:mainfrom
bparrishMines:wkwebview_terminate2
Apr 29, 2026
Merged

[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate#11567
auto-submit[bot] merged 8 commits intoflutter:mainfrom
bparrishMines:wkwebview_terminate2

Conversation

@bparrishMines
Copy link
Copy Markdown
Contributor

@bparrishMines bparrishMines commented Apr 22, 2026

Relands #11484

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@bparrishMines bparrishMines changed the title Wkwebview terminate2 [webview_flutter_wkwebview] Prevent message calls when application will terminate Apr 22, 2026
@bparrishMines bparrishMines changed the title [webview_flutter_wkwebview] Prevent message calls when application will terminate [webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in applicationWillTerminate Apr 22, 2026
@bparrishMines bparrishMines added the CICD Run CI/CD label Apr 22, 2026
@bparrishMines bparrishMines marked this pull request as ready for review April 22, 2026 21:40
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the webview_flutter_wkwebview plugin to version 3.24.6, increases the minimum supported SDK versions to Flutter 3.38 and Dart 3.10, and implements logic to tear down the ProxyAPIRegistrar when the application terminates or a scene disconnects on iOS. Review feedback notes that PlatformViewImplTests.swift is referenced in the project file but missing from the PR, warns that sceneDidDisconnect might prematurely destroy state in multi-scene applications, suggests safer handling of optional scenes in tests, and identifies redundant setup calls in the new test file.

8F1488FF2D2DE27000191744 /* NavigationActionProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488CB2D2DE27000191744 /* NavigationActionProxyAPITests.swift */; };
8F1489012D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1489002D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift */; };
8F63D06B2F8812E400EC5076 /* WebViewFlutterPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F63D06A2F8812E400EC5076 /* WebViewFlutterPluginTests.swift */; };
8F63D06C2F8812E400EC5076 /* PlatformViewImplTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F63D0692F8812E400EC5076 /* PlatformViewImplTests.swift */; };
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The project file has been updated to include PlatformViewImplTests.swift, but this file is missing from the pull request patches. This will result in a build error in Xcode due to a missing file reference. Please ensure all new test files are included in the commit.

Comment on lines +60 to +62
public func sceneDidDisconnect(_ scene: UIScene) {
tearDownProxyAPIRegistrar()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Tearing down the ProxyAPIRegistrar in sceneDidDisconnect may be problematic for applications that support multiple scenes (e.g., on iPad). If one scene is disconnected while others remain active and share the same Flutter engine, the plugin's state will be destroyed for all scenes, potentially breaking the remaining webviews. Since applicationWillTerminate and detachFromEngine already handle cleanup for the app and engine respectively, consider if sceneDidDisconnect is necessary or if it should be removed to avoid side effects in multi-window scenarios.

expectation.fulfill()
}

let scene = UIApplication.shared.connectedScenes.first!
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a forced unwrap on UIApplication.shared.connectedScenes.first can lead to a crash during test execution if the test environment does not have any active scenes. It is safer to use a guard statement or an optional binding to handle cases where no scenes are connected.

Suggested change
let scene = UIApplication.shared.connectedScenes.first!
guard let scene = UIApplication.shared.connectedScenes.first else {
XCTFail("No connected scenes found.")
return
}

#if os(iOS)
func testInstanceManagerIsDeallocatedInApplicationWillTerminate() {
let plugin = WebViewFlutterPlugin(binaryMessenger: TestBinaryMessenger())
plugin.proxyApiRegistrar!.setUp()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to plugin.proxyApiRegistrar!.setUp() is redundant because the WebViewFlutterPlugin initializer already calls setUp() on the registrar. This can be removed to avoid unnecessary re-initialization of the ProxyAPI.


func testInstanceManagerIsDeallocatedInSceneDidDisconnect() {
let plugin = WebViewFlutterPlugin(binaryMessenger: TestBinaryMessenger())
plugin.proxyApiRegistrar!.setUp()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to plugin.proxyApiRegistrar!.setUp() is redundant here as well, as the plugin's initializer already handles the setup of the registrar.

Comment thread packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this is being added to the iOS project but not the macOS project, even though it sounds generic. Someone will almost certainly add tests here in the future thinking they will run on macOS, so the file should be added to both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and added all the tests files not added on macOS.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 28, 2026
@bparrishMines bparrishMines added the CICD Run CI/CD label Apr 28, 2026
Copy link
Copy Markdown
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 29, 2026
@bparrishMines bparrishMines added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Apr 29, 2026
@auto-submit auto-submit Bot merged commit e212d61 into flutter:main Apr 29, 2026
83 checks passed
@bparrishMines bparrishMines deleted the wkwebview_terminate2 branch April 30, 2026 18:53
pull Bot pushed a commit to Klomgor/flutter that referenced this pull request May 1, 2026
…r#185897)

flutter/packages@cde5b36...daf30f8

2026-04-30 mdebbar@google.com [url_launcher_web] Re-enable flaky test
(not flaky anymore) (flutter/packages#11478)
2026-04-30 stuartmorgan@google.com [in_app_purchase] Switch to Kotlin
Pigeon (flutter/packages#11608)
2026-04-29 katelovett@google.com [two_dimensional_scrollables] Fix mouse
event loop when calling setState in TableSpan.onEnter
(flutter/packages#11606)
2026-04-29 katelovett@google.com [two_dimensional_scrollables] trailing
pinned row/col for TableView (flutter/packages#11519)
2026-04-29 10687576+bparrishMines@users.noreply.github.com
[webview_flutter_wkwebview] Tear down ProxyAPIRegistrar in
`applicationWillTerminate` (flutter/packages#11567)
2026-04-29 stuartmorgan@google.com [google_maps_flutter] Replace use of
zIndex in examples and tests (flutter/packages#11572)
2026-04-29 stuartmorgan@google.com [tool] Remove --against-pub flag
(flutter/packages#11550)
2026-04-29 47866232+chunhtai@users.noreply.github.com [ci] Update branch
management for batch release (flutter/packages#11575)
2026-04-29 spkhalad@gmail.com [webview_flutter] Platform implementations
for getCookies flutter#11037 (flutter/packages#11386)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: webview_flutter platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants