简体   繁体   中英

React-Native: Webview Javascript-Injection not working as expected

What I want to do: I make a fetch call, that gives me an API-token to login into a network. Now I want to inject a cookie (containing this api-token) into a Webview, so I should get logged in automatically.

What I tried: I set up a Webview like so:

<WebView
        source={{uri:this.state.url}}
        onNavigationStateChange={this._onNavigationStateChange.bind(this.url)}
        javaScriptEnabled = {true}
        injectedJavaScript={this.state.cookie}
      />

a little bit above I set cookie to:

cookie: 'document.cookie=\'apiToken=xxx; userId=1; expires=28799\'';

Also I loaded this chrome extension and injected the above line in Chrome and it works flawlessly..

I've read that the javascript gets injected after the view loaded, but this should still work, since I get redirected to 'domain/login', which should detect the cookie..

(I'm running react-native 0.29) Would appreciate any help.

上面的代码工作得很好-我的错误是在另一端(我不知情地更改了this.url ..,它调用了错误的url)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM