-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[webview_flutter_wkwebview] Fix crash when calling setOnConsoleMessage multiple times #10922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 introduces two separate and valuable improvements. The main change fixes a crash in webview_flutter_wkwebview when setOnConsoleMessage is called multiple times by correctly removing any existing script message handler before adding a new one. This is accompanied by a solid test case. The second change improves error handling in camera_avfoundation by checking the result of AVAssetWriter.startWriting() and propagating errors, also with a corresponding test. Both changes are correct and well-implemented. For future contributions, consider submitting unrelated changes in separate pull requests to improve review focus and maintain a clean commit history.
6adc861 to
754ec75
Compare
|
Please see this comment, which applies here as well. |
| ) throws { | ||
| // WKUserContentController will crash if a script message handler with the same name | ||
| // is added twice. We remove the existing one (if any) to ensure the new one replaces it. | ||
| pigeonInstance.removeScriptMessageHandler(forName: name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a high-level review, this is not consistent with the design of this plugin, which is to use intentionally minimal native wrappers, and implement as much logic as possible in Dart. We would not add remove logic to the add wrapper when removing can be done from Dart.
There was a problem hiding this 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 fixes a crash that occurs when setOnConsoleMessage is called multiple times by ensuring any existing script message handler is removed before adding a new one. The change is correct and is accompanied by a new test case that properly verifies the fix. I have one minor suggestion regarding code formatting consistency in the new test.
...view_flutter/webview_flutter_wkwebview/darwin/Tests/UserContentControllerProxyAPITests.swift
Outdated
Show resolved
Hide resolved
|
@stuartmorgan-g I've refactored the fix to be purely in Dart as requested. The native changes have been reverted, and the fix is now implemented in |
The first entry here is no longer accurate, and it's not clear how the second is a test.
These changes don't appear to have been pushed to the PR. |
Fixes flutter/flutter#180914
Description
This PR fixes a crash that occurs when
setOnConsoleMessageis called multiple times. TheWKUserContentControllerthrows an exception if a script message handler with the same name is added more than once. This change ensures that any existing handler is removed before adding the new one.Tests
testAddScriptMessageHandlerHandlesDuplicatestoUserContentControllerProxyAPITests.swift.xcodebuild(Exit Code 0).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.///).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-assistbot 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
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