Cap-go / capacitor-inappbrowser

Capacitor plugin in app browser with urlChangeEvent
MIT License
55 stars 33 forks source link

Webview and Ionic Communication #114

Open jeanpfs opened 1 month ago

jeanpfs commented 1 month ago

Hello, is there any way to capture a message from the webview?

In React Native, I can do something like the code below, but I couldn't find a solution for this in your library.

const INJECTED_JAVASCRIPT = `(function() {
    window.ReactNativeWebView.postMessage(JSON.stringify({key : "value"}));
})();`;

<WebView
  source={{ uri: 'https://reactnative.dev' }}
  injectedJavaScript={INJECTED_JAVASCRIPT}
  onMessage={(event) => {
       const data = JSON.parse(event.nativeEvent.data);
       alert(data.key);
  }}
/>;
korenskoy commented 1 month ago

Hi. This plugin doesn't know how to work with postMessage. Here is a similar issue https://github.com/Cap-go/capacitor-inappbrowser/issues/84