question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mailto: and tel: links do not work in webview

See original GitHub issue

Bug description:

If the page opened in the webview has any mailto: or tel: links, pressing them causes the webview to return the generic android page and fire the error events.

I believe the error is: net::ERR_UNKNOWN_URL_SCHEME (android) and unsupported URL (iOS)

Happens on both iOS and Android

To Reproduce:

Load any page with mailto and/or tel links.

Expected behavior:

Other schemas should be working

Screenshots/Videos:

Environment:

  • OS: Android and iOS
  • OS version: 8.1, 10, 13.2.3
  • react-native version: 0.61.5
  • react-native-webview version: 7.6.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

24reactions
cristianoccazinspcommented, Jan 12, 2020

@Visakeswaran not really, I just handled the links case by case with the onShouldStartLoadWithRequest prop and something like this:

function onShouldStartLoadWithRequest(request){

  // short circuit these
  if (!request.url ||
    request.url.startsWith('http') ||
    request.url.startsWith("/") ||
    request.url.startsWith("#") ||
    request.url.startsWith("javascript") ||
    request.url.startsWith("about:blank")
  ) {
    return true;
  }

  // blocked blobs
  if(request.url.startsWith("blob")){
    Alert.alert("Link cannot be opened.");
    return false;
  }

  // list of schemas we will allow the webview
  // to open natively
  if(request.url.startsWith("tel:") ||
    request.url.startsWith("mailto:") ||
    request.url.startsWith("maps:") ||
    request.url.startsWith("geo:") ||
    request.url.startsWith("sms:")
    ){

    Linking.openURL(request.url).catch(er => {
      Alert.alert("Failed to open Link: " + er.message);
    });
    return false;
  }

  // let everything else to the webview
  return true;
}
5reactions
sbycroszcommented, Apr 21, 2020

Does this still work? We found that when we open an intent:// link, onShouldStartLoadWithRequest prop is not called anymore (An error Can't open url: intent://xxx is displayed instead)

It used to work on 5.x.x 😢

Read more comments on GitHub >

github_iconTop Results From Across the Web

MailTo does not working in Android WebView - Stack Overflow
I solve my issue by using this : public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.startsWith("tel:")) { Intent ...
Read more >
Handling 'mailto' And 'tel' Links Inside Android ... - C# Corner
Today, we will see how to integrate those wrappers into our Android app to respond to a user clicking mailto and tel links....
Read more >
Handling 'mailto' and 'tel' Links inside Android WebView
By inspecting WebView class you can find that there's no direct way to subscribe to events of user clicking a link or navigating...
Read more >
Proper way to do mailto: and tel: links | Telerik Forums
I've got a Kendo UI Mobile listview and each item has a phone number and email address, both of which should be clickable/touchable...
Read more >
WebView mailto links don't work on android - MSDN
Figured this out myself. In the android project on the MainActivity.cs I added code below. Would also need to handle the other mailto...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found