React-Native: Webview Javascript-Injection does not work as expected

What I want to do: I am making a fetch call that gives me an API token to enter the network. Now I want to enter a cookie (containing this api token) in Webview, so I have to log in automatically.

What I tried: I created a web view as follows:

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

A little higher, I set a cookie for:

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

I also downloaded this chrome extension and entered the above line in Chrome and it works flawlessly.

I read that javascript is entered after the view is loaded, but this should still work, as I am redirecting to the "domain / login" that the cookie should detect ..

(I run response-native 0.29) Would thank for any help.

+4
1

- ( this.url.., URL-)

+2

All Articles