Skip to content

Conversation

@msamoeed
Copy link

Description

This PR improves the handling of authentication challenges in WKWebView when no handler is implemented in Flutter. Instead of throwing an error when receiving a null response, it now returns a default cancel response, matching WKWebView's standard behavior.

Changes

  • Modified didReceiveAuthenticationChallenge to handle null responses gracefully
  • Added proper type checking for non-null responses
  • Improved error messages for invalid response types
  • Updated documentation

Why?

Previously, the code would crash when no authentication challenge handler was implemented in Flutter. This change makes the behavior more idiomatic by following WKWebView's default patterns.

Related Issues

Fixes flutter/flutter#163213

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

…e responses to follow WKWebView's default behavior, When no authentication challenge handler is implemented in Flutter, return the default WKWebView cancel response instead of throwing an error. This makes the behavior more idiomatic and prevents crashes

When no authentication challenge handler is implemented in Flutter,
return the default WKWebView cancel response instead of throwing an error.

Fixes flutter/flutter#163213
@msamoeed msamoeed requested a review from cbracken as a code owner February 13, 2025 14:11
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@stuartmorgan-g
Copy link
Collaborator

Closing in favor of #8564, which is already reviewed.

In the future, please don't indiscriminately check all the boxes in the checklist; the reason the checklist is there is to make sure all the required steps have been done, and checking the boxes without doing the steps doesn't accomplish that goal:

  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes].

These were not done.

  • All existing and new tests are passing.

The PR as submitted does not compile.

let details: String? = nilOrValue(listResponse[2])
completion(.failure(PigeonError(code: code, message: message, details: details)))
} else if listResponse[0] == nil {
} else if listResponse[0] == nil || firstElement is NSNull {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also for reference in case you plan to contribute to webview_flutter in the future: Per the comment at the top of this file, it cannot be edited like this.

// Autogenerated from Pigeon (v22.7.2), do not edit directly.

@msamoeed msamoeed deleted the fix_auth_challenge_null_handling branch February 13, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[webview_flutter_wkwebview] iOS crash: NSNull to AuthenticationChallengeResponse cast failure in didReceiveAuthenticationChallenge

2 participants