Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 646
dv3 Avatar asked Jul 14 '16 20:07

dv3


1 Answers

The above code works just fine - my error was on a different end (I not knowingly changed this.url.. which called the wrong url)

like image 103
dv3 Avatar answered Nov 10 '22 17:11

dv3