I want to listen a click event triggered inside a webapp , this webapp loads in react-native webview. So need to listen the click event and then run an async function in react-native.
My use-case is to download a file once save button clicked (This save button is inside webapp).
But nothing gets triggered or listened inside handleNavigationStateChange
and onMessage
. please find the below code.
render() {
const url = 'https://www.takeselfie.com/#';
return (
<WebView
useWebKit
originWhitelist={['*']}
allowsInlineMediaPlayback
bounces={true}
source={{
uri: url,
}}
startInLoadingState={true}
scalesPageToFit
javaScriptEnabledAndroid={true}
javaScriptEnabled={true}
injectedJavaScript={`document.body.addEventListener('click', function(e){
window.postMessage("Message from WebView","*");
console.log(e)
})`}
onMessage={e => console.log("message==", e)}
mixedContentMode={'always'}
allowUniversalAccessFromFileURLs={true}
onNavigationStateChange={this.handleNavigationStateChange}
style={{ flex: 1 }}
/>
);
}