Skip to content

Commit 35e75c8

Browse files
Adam ComellaFacebook Github Bot
Adam Comella
authored and
Facebook Github Bot
committed
Android: Fix WebView crash for links of unknown schemes
Summary: When tapping on a link in a WebView with an unknown scheme, the app would crash. For example, if you have the link "something://example/" but your device doesn't have anything to handle the "something" scheme, the app would crash when the user clicks on the link. This change handles the exception to prevent the app from crashing. Instead, the click is a no-op and the WebView doesn't navigate anywhere. **Test plan (required)** Verified the app no longer crashes when clicking on unknown schemes in a test app. Also, my team uses this change in our app. Adam Comella Microsoft Corp. Closes #10903 Differential Revision: D4226371 Pulled By: mkonicek fbshipit-source-id: a6d3957806c6063e74fe055b0979cb9d1ce40e51
1 parent 4181000 commit 35e75c8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Locale;
1717
import java.util.Map;
1818

19+
import android.content.ActivityNotFoundException;
1920
import android.content.Intent;
2021
import android.graphics.Bitmap;
2122
import android.graphics.Picture;
@@ -136,9 +137,13 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
136137
url.startsWith("file://")) {
137138
return false;
138139
} else {
139-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
140-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
141-
view.getContext().startActivity(intent);
140+
try {
141+
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
142+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
143+
view.getContext().startActivity(intent);
144+
} catch (ActivityNotFoundException e) {
145+
FLog.w(ReactConstants.TAG, "activity not found to handle uri scheme for: " + url, e);
146+
}
142147
return true;
143148
}
144149
}

0 commit comments

Comments
 (0)