react-native-inappbrowser icon indicating copy to clipboard operation
react-native-inappbrowser copied to clipboard

Android API Level 25 and below: Promise returned from open function occasionally does not resolve until user interaction.

Open stevenrein20 opened this issue 4 years ago • 7 comments

Which platform(s) does your issue occur on?

  • Android
  • API Level <=25
  • emulator, Google Pixel 2

Please, provide the following version numbers that your issue occurs with:

  • 3.6.3

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

  • Build an app using the open function from this library and run on Android emulator with API level 25 or below.
  • Open the InAppBrowser
  • Close browser with X button.
  • Occasionally (not consistently reproduced), promise will not resolve until the user interacts with the app again after closing InAppBrowser.

Is there any code involved?

InAppBrowser.open(url).then((success) => {
 console.log("Resolved.");
});

stevenrein20 avatar Aug 19 '21 15:08 stevenrein20

Having a very simaler issue on 3.6.3 but API levels are higher than 25 apart from minSDK. Running on Pixel 3 emulator on API 30

        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "20.1.5948944"

When authenticating with google/facebook the authentication process starts and completes but the browser never closes

            await InAppBrowser.isAvailable();
            console.log(`urlOpener: calling url: ${url}, redirectsignIn: ${redirectSignIn}`)
            const response = await InAppBrowser.openAuth(url, redirectSignIn, {
              dismissButtonStyle: 'cancel',
              showTitle: false,
              enableUrlBarHiding: true,
              enableDefaultShare: false,
              ephemeralWebSession: false,
            });
            console.log('urlOpener: response: ', JSON.stringify(response));

The line that logs out the response never logs out. If close the browser tab then the app appears to sign in ok possibly because the user is signed in when the authentication process starts again

markl-vesper avatar Oct 03 '21 23:10 markl-vesper

Tried a slightly different approach based on current examples

urlOpener is now

        urlOpener: async (url, redirectSignIn) => {
          try {
            await InAppBrowser.isAvailable();
            console.log(`urlOpener: calling url: ${url}, redirectsignIn: ${redirectSignIn}`)
            InAppBrowser.openAuth(url, redirectSignIn, {
              dismissButtonStyle: 'cancel',
              showTitle: false,
              enableUrlBarHiding: true,
              enableDefaultShare: false,
              ephemeralWebSession: false,
              forceCloseOnRedirection: true
            }).then((response) => {
              console.log('urlOpener: response: ', JSON.stringify(response));
              if (response.type === 'cancel') {
                console.log('urlOpener: cancel:');
                AuthStore.setIsFedratedSignIn(false);
              } else if (response.type === 'success' && response.url) {
                console.log('urlOpener: success: url: ', response.url);
                Linking.openURL(response.url);
              }
            })
          } catch (err) {
            console.log('urlOpener: error: ', JSON.stringify(err));
          }
        }

When we test the authentication we see

urlOpener: calling url: https://auth.vespercortex.com/oauth2/authorize?redirect_uri=cortexmonitorapp%3A%2F%2Fsignin&response_type=code&client_id=***&identity_provider=Google&scope=phone%20email%20profile%20openid%20aws.cognito.signin.user.admin&state=***&code_challenge=***&code_challenge_method=S256, redirectsignIn: cortexmonitorapp://signin

authentication appears to succeed but the app sits there and no response received and nothing logged out

closing the tab and starting auth again results in following

 WARN  EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
urlOpener: response:  {"message":"chrome tabs activity closed","type":"cancel"}

urlOpener: calling url: https://auth.vespercortex.com/oauth2/authorize?redirect_uri=cortexmonitorapp%3A%2F%2Fsignin&response_type=code&client_id=***&identity_provider=Google&scope=phone%20email%20profile%20openid%20aws.cognito.signin.user.admin&state=***&code_challenge=***&code_challenge_method=S256, redirectsignIn: cortexmonitorapp://signin
(via Hub.listen logs) SocialSignIn: FederatedEvent = ["parsingCallbackUrl"] Data = [{"url":"cortexmonitorapp://signin?code=***&state=***"}] message= The callback url is being parsed
SocialSignIn: FederatedEvent = ["codeFlow"] Data = [{}] message= Retrieving tokens from https://auth.vespercortex.com/oauth2/token
 WARN  EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
urlOpener: response:  {"url":"cortexmonitorapp://signin?code=***&state=***","type":"success"}
 WARN  EventEmitter.removeListener('appStateDidChange', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
 WARN  EventEmitter.removeListener('appStateDidChange', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
 SocialSignIn: FederatedEvent = ["signIn"] Data = [{"username":"google_***","pool":{"userPoolId":"us-east-1_***","clientId":"***","client":{"endpoint":"https://cognito-idp.us-east-1.amazonaws.com/","fetchOptions":{}},"advancedSecurityDataCollectionFlag":true},"Session":null,"client":{"endpoint":"https://cognito-idp.us-east-1.amazonaws.com/","fetchOptions":{}},"signInUserSession":{"idToken":{"jwtToken":"***","payload":{"at_hash":"***","sub":"***","cognito:groups":["us-east-***_Google"],"email_verified":false,"iss":"https://cognito-idp.us-east-1.amazonaws.com/us-east-***","cognito:username":"google_***","aud":"***","identities":[{"userId":"***","providerName":"Google","providerType":"Google","issuer":null,"primary":"true","dateCreated":"1632878004858"}],"token_use":"id","auth_time":1633308355,"name":"Mark","exp":1633394755,"iat":1633308355,"family_name":"***","email":"***"}},"refreshToken":{"token":"***"},"accessToken":{"jwtToken":"***,"payload":{"sub":"***","cognito:groups":["us-east-1_***_Google"],"token_use":"access","scope":"aws.cognito.signin.user.admin phone openid profile email","auth_time":1633308355,"iss":"https://cognito-idp.us-east-1.amazonaws.com/us-east-1_***","exp":1633394755,"iat":1633308355,"version":2,"jti":"***","client_id":"***","username":"google_***"}},"clockDrift":0},"authenticationFlowType":"USER_SRP_AUTH","keyPrefix":"CognitoIdentityServiceProvider.***","userDataKey":"CognitoIdentityServiceProvider.***.google_***.userData"}] message= A user google_*** has been signed in

markl-vesper avatar Oct 04 '21 01:10 markl-vesper

also just noticed that the first attempt that fails does not log this line that the second attempt that works fine does log out

I ActivityTaskManager: START u0 {act=android.intent.action.VIEW cat=[android.intent.category.BROWSABLE] dat=cortexmonitorapp://signin?code=b3bbf90f-5b8c-4b94-97c0-a2a9bcaedbc1&state=hF8xky8sYKMaTSA06j1X2IsKhaqDtJ7r flg=0x14000000 cmp=com.cortexmonitoring/.MainActivity (has extras)} from uid 10116

So it would appear in the 1st attempt that the browser is either not receiving anything from the hosted UI or not passing it on

markl-vesper avatar Oct 04 '21 02:10 markl-vesper

Hello folks, thanks for reporting this issue!

I'm not working with React Native recently, but any pull request is welcome in the meantime! <3

jdnichollsc avatar Oct 05 '21 15:10 jdnichollsc

Hi @jdnichollsc

If I knew how to fix I would help. I have next to zero skills on native side of things as my background is purely JS and cloud etc

Have no idea where to even start

markl-vesper avatar Oct 05 '21 21:10 markl-vesper

Well, It looks like a good opportunity to learn about native code, I had a similar issue with other packages and I learned a lot creating this project, so please check the Java code, use Android Logcat with native logs and let me know if you have any questions 🙂

jdnichollsc avatar Oct 05 '21 21:10 jdnichollsc

@markl-vesper any fix facing same issue

gourav-singhal avatar Mar 08 '22 13:03 gourav-singhal