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.

[SOLVED] Linking.openURL [Possible Unhandled Promise Rejection]

See original GitHub issue

Bug description: My website has a WhatsApp floating button and when clicking it, I was able to open the WhatsApp native application from that button, but I’m getting a warning in the metro console.

Trying to open Linking.openURL(url) from onNavigationStateChange WebView prop, I get warning Possible Unhandled Promise Rejection

The URL I’m trying to open is whatsapp://send?phone=XXXXXXXXX

      <WebView
            ref={(ref) => (this.webview = ref)}
            originWhitelist={['https://', 'whatsapp://']}
            source={{ uri: 'https://xxx.xxxx.xxx/' }}
            onNavigationStateChange={this.handleWebViewNavigationStateChange}
            onMessage={(event: WebViewMessageEvent) => {
              alert(event.nativeEvent.data);
            }}
      />

handleWebViewNavigationStateChange = (newNavState: WebViewNavigation) => {
    console.log('nav state changed');

    if (url.startsWith('whatsapp://')) {
      this.webview.stopLoading();
      Linking.openURL(url);
    }
  };

Environment:

  • OS: Linux Mint 20.3
  • react-native version: 0.64.3
  • react-native-webview version: 11.15.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
TheAlmightyBobcommented, Jan 14, 2022

However you like dealing with promises. You could use async/await and wrap it in a try/catch, or use .then/.catch.

I’m personally a fan of using no-floating-promises to help avoid these types of issues.

0reactions
github-actions[bot]commented, Mar 16, 2022

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: Linking.openUrl throwing "Possible Unhandled ...
I am trying to create a Audio/Video Calling app using React Native. There's a screen in the app where calling happens using WebRTC....
Read more >
Fixing the React Native Error: "Unable to open URL: telprompt"
If the user cancels the call, the Promise is rejected. This triggers the error you see in the screenshot. As you can see,...
Read more >
unhandled promise about:blank in IOS-React Native
How to save Firestore response, after I add a doc, in React Native (Possible Unhandled Promise Rejection (id: 1): TypeError: "res" is read-only)?...
Read more >
React Native Auth0 Possible Unhandled Promise Rejection
In setting up samples, I've made some progress with the docs, but I've come into this error. Possible Unhandled Promise Rejection (id: 1): ......
Read more >
Linking - React Native
You can handle these events with Linking.getInitialURL() - it returns a Promise that resolves to the URL, if there is one. Example​. Open...
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