Run javascript inside a webview source

Does anyone know how (if possible) to execute JS "inside" a WebView in React Native?

Scenario: I have this remote login page (website) displayed in my WebView, and this website has a sequence of events that occur according to the user's actions. All events fire one callback each, which WebView should listen to (no problem).
Inside each callback there is a link to a JavaScript function that must be called inside the WebView (what a problem!).
Therefore, from my React Native application, I need to call this JavaScript function, located on the website page (source), loaded into my WebView.

What I have: I listen to callbacks with onShouldStartLoadWithRequest and manipulate the behavior of the WebView using this and it is excellent. Regarding JavaScript execution, I tried the getWebViewHandle method, but at least I didnโ€™t do it from my place.
I also looked at the injectedJavaScript property, but the problem is that I donโ€™t know which JavaScript to execute before the callbacks are executed.

Does anyone know how to solve this?

+5
source share
2 answers

Calling javascript methods inside a webview is possible with iOS and Android source components. But the required API for javascript execution is not currently provided by response-native. You can see the discussion on this github issue .

However, there is a third-party module that provides bi-directional communication between your application and web browsing. You can start using it after integrating some code into your project.

+4
source

There is currently a good article on how to communicate with content through React Native Webview using the injection API as well as onMessage / postMessage.

+1
source

All Articles