In my React Native code, I'm try to call my webpage inside WebView component. In that webpage I'm passing some data using window.postMessage() method from injectedJavascript attribute of React Native WebView. Based upon the data that I've passed to my web page, I'm displaying some console.log() on that page. So, my requirement is to capture those console logs from my webpage inside WebView component and display it in my React Native Code.
Below is my WebView Code:
<WebView source={{ uri: 'https://www.example.com/', }} javaScriptEnabled={true} injectedJavaScript={`window.postMessage({...}, '*')`} onMessage={(event) => { const { data } = event.nativeEvent; console.log('MESSAGE >>>>'+ JSON.stringify(data)); }}/>
In short, whatever is print in the console of my webpage, I want to print that in my React Native's console, so that I can able to debug my webpage from WebView component by passing the data using window.postMessage().