[webview_flutter] Fix crash in iOS external native API#10959
Conversation
Fixes a crash if `FWFWebViewFlutterWKWebViewExternalAPI`'s `webView(forIdentifier:withPluginRegistry:)` is called with a registry that doesn't contain a published webview plugin value. This can happen if the wrong object is passed in (e.g., the FlutterAppDelegate in an app that has adopted UIScene). Fixes flutter/flutter#181865
There was a problem hiding this comment.
Code Review
This pull request addresses a crash in the iOS external native API by replacing a force-cast with a safe optional cast. This correctly handles cases where the webview plugin isn't found in the provided registry. The change is accompanied by a new unit test to verify the fix, along with corresponding updates to the changelog and package version. The implementation is sound, but I've noted a minor issue in the new test code that will cause a compilation error.
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
The registrar(forPlugin:) method for macOS in EmptyRegistry is declared to return a non-optional FlutterPluginRegistrar, but the implementation returns nil. This will cause a compilation error on macOS because the protocol requires a non-optional return value.
To resolve this, you can return the registrar property, which will satisfy the protocol requirement without altering the test's behavior.
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | |
| return nil | |
| } | |
| func registrar(forPlugin pluginKey: String) -> FlutterPluginRegistrar { | |
| return registrar | |
| } |
flutter/packages@3bddf2c...c197455 2026-02-05 [email protected] Roll Flutter from bf701fe to f916dd6 (44 revisions) (flutter/packages#10967) 2026-02-05 [email protected] [webview_flutter] Fix crash in iOS external native API (flutter/packages#10959) 2026-02-04 8014077[email protected] [google_fonts] Fix file type priority in asset path lookup (flutter/packages#10907) 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 [email protected] 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
…r#181962) flutter/packages@3bddf2c...c197455 2026-02-05 [email protected] Roll Flutter from bf701fe to f916dd6 (44 revisions) (flutter/packages#10967) 2026-02-05 [email protected] [webview_flutter] Fix crash in iOS external native API (flutter/packages#10959) 2026-02-04 8014077[email protected] [google_fonts] Fix file type priority in asset path lookup (flutter/packages#10907) 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 [email protected] 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
…r#181962) flutter/packages@3bddf2c...c197455 2026-02-05 [email protected] Roll Flutter from bf701fe to f916dd6 (44 revisions) (flutter/packages#10967) 2026-02-05 [email protected] [webview_flutter] Fix crash in iOS external native API (flutter/packages#10959) 2026-02-04 8014077[email protected] [google_fonts] Fix file type priority in asset path lookup (flutter/packages#10907) 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 [email protected] 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
…r#181962) flutter/packages@3bddf2c...c197455 2026-02-05 [email protected] Roll Flutter from bf701fe to f916dd6 (44 revisions) (flutter/packages#10967) 2026-02-05 [email protected] [webview_flutter] Fix crash in iOS external native API (flutter/packages#10959) 2026-02-04 8014077[email protected] [google_fonts] Fix file type priority in asset path lookup (flutter/packages#10907) 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 [email protected] 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
…r#181962) flutter/packages@3bddf2c...c197455 2026-02-05 [email protected] Roll Flutter from bf701fe to f916dd6 (44 revisions) (flutter/packages#10967) 2026-02-05 [email protected] [webview_flutter] Fix crash in iOS external native API (flutter/packages#10959) 2026-02-04 8014077[email protected] [google_fonts] Fix file type priority in asset path lookup (flutter/packages#10907) 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 [email protected] 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
Fixes a crash if
FWFWebViewFlutterWKWebViewExternalAPI'swebView(forIdentifier:withPluginRegistry:)is called with a registry that doesn't contain a published webview plugin value. This can happen if the wrong object is passed in (e.g., the FlutterAppDelegate in an app that has adopted UIScene).Fixes flutter/flutter#181865
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
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 ↩3