我们可以从webview注入的脚本中获取数据吗?

时间:2018-08-03 15:14:49

标签: react-native wkwebview

我在ios上使用WKWebView from 'react-native-wkwebview-reborn'; Webview,但是我无法使用“ react-native-cookies”或“ react-native-cookie”来获取Cookie值。

我尝试了

<WKWebView
    injectedJavaScript={'alert(document.cookie);'}
    ref={webViewRef}
    allowsBackForwardNavigationGestures={true}
    bounces={false}
    automaticallyAdjustContentInsets={false}
    dataDetectorTypes={'all'}
    source={{uri: defaultUrl}}
    javaScriptEnabled={true}
    domStorageEnabled={true}
    decelerationRate={'normal'}
    startInLoadingState={true}
    scalesPageToFit={true}
    onNavigationStateChange={this._onHomeNavigationStateChange}
    renderLoading={()=>{return (null)}}
    onLoadStart={()=>{
        this.props.navigation.setParams({fade: true});
        this.setState({loading: true});
    }}
    onLoadEnd={(event)=>{
        // const { data } = event.nativeEvent;
        // const cookies  = data.split(';'); 
        // `csrftoken=...; rur=...; mid=...; somethingelse=...`
        // console.log(cookies);
        this.props.navigation.setParams({fade: false});
        this.setState({loading: false});
    }}
/>

我从jectedJavaScript收到了cookie,但问题是:如何传递这些cookie来响应本机?

0 个答案:

没有答案