Created
December 1, 2020 11:50
-
-
Save wobsoriano/cfdbd5e89c011317f4acdaa6c879e2a4 to your computer and use it in GitHub Desktop.
Get localStorage value from Webview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { View } from '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> | |
| <WebView | |
| source={{ uri: 'https://coil.com/login' }} | |
| injectedJavaScript={INJECTED_JAVASCRIPT} | |
| onMessage={onMessage} | |
| /> | |
| </View> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment