We are using WebView to open an authentication process via a third-party provider. During this process they will redirect to a custom URL scheme. This URL scheme contains a parameter that we need to intercept in the javascript code.
This would normally throw an error on iOS, but we are able to handle that by implementing onShouldStartLoadWithRequest on the WebView, retrieving the parameter and return false.
But on Android, I get the following error:
W/System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=myscheme://id/615563 flg=0x10000000 }
W/System.err: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
W/System.err: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3917)
W/System.err: at android.app.Activity.startActivityForResult(Activity.java:3877)
W/System.err: at android.app.Activity.startActivity(Activity.java:4200)
W/System.err: at android.app.Activity.startActivity(Activity.java:4168)
W/System.err: at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
W/System.err: at com.facebook.react.views.webview.ReactWebViewManager$ReactWebViewClient.shouldOverrideUrlLoading(ReactWebViewManager.java:123)
W/System.err: at com.android.webview.chromium.WebViewContentsClientAdapter.shouldOverrideUrlLoading(WebViewContentsClientAdapter.java:331)
W/System.err: at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:265)
W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:148)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
As far as I understand, this should not normally throw an error on Android. But in RN 0.31 this commit for shouldOverrideUrlLoading was introduced.
I've tested this with RN 0.33.
Load a HTML page in the WebView with the following javascript-snippet included:
<script language="javascript">
window.location = 'myscheme://id/123';
</script>
It would be nice if we could get something similar to onShouldStartLoadWithRequest on Android. But that seems unlikely to happen following the discussion in #6478
I'd prefer it not crashing, and being able to intercept the navigation (with url/parameter).
I have the same problem, does anyone has solution for it?
likewise ^
check if my PR #9668 fixes your issue.
I'd accept a PR which prevents the cash
@andy9775 that only fixes the the file scheme. So it doesn't fix my issue, but maybe other peoples here?
@satya164 I'll take a look into making a PR with a general fix for this issue. Would you also mind looking at my other PR #10105? It provides more extensibility for WebView.
I'll take look tomorrow
Assigning myself so that I remember
Have the same situation/issue, would be very grateful if someone fixed it!
Hi. There's still one more scenario where app can crash. Before lunching implicit intent we should check whether there are activities that can handle it. In my case app crashes because it tries to launch an activity which doesn't exist.
From ReactWebViewManager.java
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://") || url.startsWith("https://")) {
return false;
} else {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
view.getContext().startActivity(intent);
return true;
}
}
@reinisseredzins that's the same problem as in the issue description.
@satya164 did you get a chance to checkout my PR? I can CC you there as well, since it's gone a bit stale.
I have a potential fix for this issue in my PR #10654. Have to see if it is accepted.
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
This issue should remain open in my opinion.
It's accepted practice for Mobile Webview implementations to use custom url schemas as callbacks. This is a fairly large functionality gap for Android here.
Most helpful comment
Assigning myself so that I remember