Skip to content
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

fix: handle webview provider missing exception #34456

Closed
wants to merge 5 commits into from

Conversation

rachitmishra
Copy link
Contributor

@rachitmishra rachitmishra commented Aug 19, 2022

Summary

The existing fix to handle missing WebView provider uses string comparison based checks to handle the exception gracefully, or otherwise simply throw the exception. This ends up crashing the app for the end user.

Screenshot 2022-08-19 at 4 33 31 PM

Fatal exceptions are bad in any case and not good user experience, we can gracefully handle this by returning null for all cases when WebView provider is not found.

Changelog

[Android] [Fixed] - Gracefully handle crash if no WebView provider is found on the device

Test Plan

IMO no testing is required as we were already returning null in certain cases after handling the exception message, also ForwardingCookieManager::getCookieManager is already marked @Nullable so we are safe there.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Aug 19, 2022
@react-native-bot react-native-bot added Bug Platform: Android Android applications. labels Aug 19, 2022
@analysis-bot
Copy link

analysis-bot commented Aug 19, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,698,513 -27,445
android hermes armeabi-v7a 7,102,105 -26,248
android hermes x86 8,001,264 -30,580
android hermes x86_64 7,973,833 -31,366
android jsc arm64-v8a 9,569,022 -27,259
android jsc armeabi-v7a 8,336,040 -26,058
android jsc x86 9,509,448 -30,380
android jsc x86_64 10,101,129 -31,184

Base commit: 2fc44ac
Branch: main

} else {
throw exception;
}
// fatal exception is no good for the user experience,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm generally against this change as we would blindly catch all the exceptions and return null here while we want to distinguish between MissingWebViewPackageException and other type of exceptions

Copy link
Contributor Author

@rachitmishra rachitmishra Aug 20, 2022

Choose a reason for hiding this comment

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

@cortinico i totally agree. this is not a best practice, or in principal good code.

Although the thought here is that, for any case when the CookieManager instance is not available, returning a null is better than the fatal exception.

@Pajn
Copy link
Contributor

Pajn commented Aug 23, 2022

I opened #34483 but IMHO this is better. It's very weird to me that not having a webview at all is fine but having one that can't be loaded for whatever reason is a fatal crash

@analysis-bot
Copy link

analysis-bot commented Sep 22, 2022

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 2fc44ac
Branch: main

@cortinico
Copy link
Contributor

I opened #34483 but IMHO this is better. It's very weird to me that not having a webview at all is fine but having one that can't be loaded for whatever reason is a fatal crash

I've looked again at this PR and I believe we should merge it as the scope is limited to only the CookieManager. @rachitmishra Can you update the comment before the return null as it's currently stale, explaining why we do this?

@rachitmishra
Copy link
Contributor Author

@cortinico I have updated the comment and our reasoning, let me know if we can improve this more :)

…ForwardingCookieHandler.java

Co-authored-by: Nicola Corti <corti.nico@gmail.com>
@facebook-github-bot
Copy link
Contributor

@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @rachitmishra in 3f3394a.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 26, 2022
@rachitmishra rachitmishra deleted the patch-2 branch September 27, 2022 20:06
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
The [existing fix](https://github.com/facebook/react-native/blob/fb936dfffb3ca2d9bc0969dfe36a70bdf66783e0/ReactAndroid/src/main/java/com/facebook/react/modules/network/ForwardingCookieHandler.java#L151) to handle missing WebView provider uses string comparison based checks to handle the exception gracefully, or otherwise simply throw the exception. This ends up crashing the app for the end user.

<img width="1319" alt="Screenshot 2022-08-19 at 4 33 31 PM" src="https://user-images.githubusercontent.com/933314/185605137-24757dad-806e-4cca-b000-7d6ce2d191e1.png">

Fatal exceptions are bad in any case and not good user experience, we can gracefully handle this by [returning](facebook/react-native@main...rachitmishra:react-native-1:patch-2#diff-f7ca1976002c4612051e4949395e64511b6f769e347c488e9a0d15cb5331fe76R141) `null` for all cases when WebView provider is not found.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Fixed] - Gracefully handle crash if no WebView provider is found on the device

Pull Request resolved: facebook#34456

Test Plan: IMO no testing is required as we were already returning null in certain cases after handling the exception message, also `ForwardingCookieManager::getCookieManager` is already marked `Nullable` so we are safe there.

Reviewed By: lunaleaps

Differential Revision: D39809020

Pulled By: cortinico

fbshipit-source-id: 54b290ad7740859bdc84401904236c32761a4631
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants