Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Get LocalStorage from WebView react native

import { WebView } from 'react-native-webview';

const INJECTED_JAVASCRIPT = `(function() {
  const tokenLocalStorage = window.localStorage.getItem('token');
  window.ReactNativeWebView.postMessage(tokenLocalStorage);
})();`;

export default function App() {
  const onMessage = (payload) => {
    console.log('payload', payload);
  };

  return (
    <View style={styles.container}>
      <StatusBar style="auto" />
      <WebView
        source={{ uri: 'https://somewebsite.com/login' }}
        injectedJavaScript={INJECTED_JAVASCRIPT}
        onMessage={onMessage}
      />
    </View>
  );
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Get #LocalStorage #WebView #react #native
ADD COMMENT
Topic
Name
8+6 =