1

I am using an external url to handle the authentication for my react-native app. I send the user to a webview with a loginurl. Following is a snippet from my Signin.tsx code: -

 <WebView
            cacheEnabled={false}
            source={{uri: this.state.loginUri}}
            onNavigationStateChange={this.onNavigationStateChange}
            incognito={true}
/>

The 'incognito' property works perfectly on iOS but doesnt seem to work at all for Android. My goal is for the Webview to not save any data during its lifetime. There are multiple pages in the login and after entering one detail, it automatically takes the previously logged in account's details and autologs in with the older credentials.

I have tried updating react-native-webview to the latest(v11.3.1) and have also tried CookieManager.clearAll(){used from react-native-community/cookies}. Nothing seems to work. Can someone help me in understanding why its working for iOS and not Android?

sc344
  • 11
  • 2
  • I have the opposite problem - I want to log out a user, which I accomplished with incognito prop on Android, but cannot get it to work on iOS. Also used CookieManager, nothing – borgmater Aug 10 '21 at 11:37
  • If you check the code WebView code, you can see that there are 2 different sets of props, for Android and iOS. Try to play around with cacheMode prop for Android: https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int) – borgmater Aug 10 '21 at 11:43

1 Answers1

0

We had similar issue and after googling around found Tapani's answer so according to him the actual implementation is different so they act differently depending on the OS. Unfortunately this is not mentioned in the API docs.

In our case the app wasn't working properly if on Android the incognito prop was set true nor it was working on iOS if set to false so if that's your case also you could check the platform and set the prop accordingly:

<WebView
   cacheEnabled={false}
   source={{uri: this.state.loginUri}}
   onNavigationStateChange={this.onNavigationStateChange}
   incognito={Platform.OS === 'ios'}
/>
Luis Paulo Pinto
  • 5,578
  • 4
  • 21
  • 35
Mikko
  • 1