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.

In iOS 14 Updated devices injectedJavascript callBack not receiving Webview onMessage Method

See original GitHub issue

Bug description: Hi We are doing a payment integration app using react-native-webview. After the payment has been processed there will be a call back received on message Webview. But In iOS 14 Updated devices this injectedJavascript callBack has not triggered.

In iOS 14 Updated devices InjectedJavascript callback not receiving Webview onMessage Method. The other iOS lower version (< 14 )of devices it working as expected and the android device also it working five.

Expected behavior: Need to work on all latest iOS version updated devices.

My Code:

const INJECTEDJAVASCRIPT = const meta = document.createElement('meta'); window.checkoutError = function(){ window.ReactNativeWebView.postMessage('checkout-error') }; window.checkoutSuccess = function(){ window.ReactNativeWebView.postMessage('checkout-success') }; const script = document.createElement("script"); script.setAttribute("data-error", "checkoutError"); script.setAttribute("data-success", "checkoutSuccess"); script.onload = function() { checkOut() }; document.getElementsByTagName('head')[0].appendChild(script); ;

<WebView
      source={{ html }}
      originWhitelist={['*']}
      javaScriptEnabled={true}
      onNavigationStateChange={this._onNavigationStateChange}
      onMessage={this.handleMessage}
      injectedJavaScript={INJECTEDJAVASCRIPT}
      mixedContentMode={'always'}
    />

handleMessage = (d) => { const { navigation } = this.props; const msg = d.nativeEvent.data; switch (msg) { case ‘checkout-success’: return his.paymentSuccess(); case ‘checkout-error’: return navigation.goBack(); default: return console.log(ONMESSAGE: , msg); } }

Environment:

  • OS: iOS
  • OS version: iOS 14
  • react-native version: 0.63.3
  • react-native-webview version: 11.0.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

6reactions
danielfx90commented, Jan 11, 2021

Hi, I tried it out on iOS 14 and it works fine.

const INJECTED_JAVASCRIPT = `(function() {
  window.ReactNativeWebView.postMessage(JSON.stringify(window.location));
})();`;
<WebView
  source={{ uri: 'https://google.com' }}
  injectedJavaScript={INJECTED_JAVASCRIPT}
  onMessage={(msg) => console.log(msg)}
/>
"dependencies": {
    "react": "16.13.1",
    "react-native": "0.63.3",
    "react-native-webview": "11.0.2"
  },
0reactions
github-actions[bot]commented, May 4, 2021

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 WebView onMessage doesn't do anything
The website is executing a postMessage ( window.postMessage("Post message from web"); ) but react native's webview onMessage listener is not ...
Read more >
React Native WebView: A complete guide - LogRocket Blog
In this post, we are going to look at the most common use cases of React Native WebView, including: Getting started; Creating the...
Read more >
Communicating between React Native and the WebView
The first and most basic task we had was to find a way to communicate between the React Native code and the web...
Read more >
How to use Webview in React Native? - The Wirescript
Here's how you can use WebView inside React Native to display websites or entire web apps natively inside your application.
Read more >
react native webview download pdf - You.com | The AI Search ...
The problem is that when users try to download an invoice in pdf format, iOS shows the preview and it's not possible to...
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