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

Browser window get dismissed without redirection URL in Android 9 devices

Open abhay-sqh opened this issue 3 years ago • 10 comments

We are using InAppBrowser.openAuth(baseUrl, redirectionUrl, browserConfig) function of library to Open inApp browser and implement Oauth implementation in our App which is working fine in many devices of Android and almost all devices on iOS but in case of Android9 devices this function is giving {message: "chrome tabs activity destroyed" 
type: "dismiss"} and browser window get closed and User is not able to proceed (due to unavailability of redirectionUrl) further.

Produced in below platform:

  • Android 9(Samsung A8+)
  • Android 9(Samsung Galaxy S10)
  • Android 9(Redmi 8A )

Using following configurations:

  • react-native-cli: 2.0.1
  • react-native: 0.62.2
  • Plugin Version: "react-native-inappbrowser-reborn": "3.6.3"

Steps to Reproduce the Issue:

Simply use InAppBrowser.openAuth(baseUrl, redirectionUrl, browserConfig) function in Android 9 on above mentioned devices with all the required configs provided in documentation and its giving below response in success:

{message: "chrome tabs activity destroyed" 
type: "dismiss"}

As we debug a lot in our code and library's code as well, So we find that below function openAuthSessionPolyfillAsync inside library utils file giving the above mentioned error object which is coming when one Promise get resolved mentioned in Promise.race(). We also tested this scenario in devices in which Authentication flow is working fine and find that in that case event listener _redirectHandler added in Promise waitForRedirectAsync firing an event with redirection URL and success Object first before resolving the second Promise But in our case in which we are getting issue in Android 9, Second Promise openBrowserAsync is resolved before getting any event from event listener.

export async function openAuthSessionPolyfillAsync(
 startUrl: string,
 returnUrl: string,
 options?: InAppBrowserOptions
): Promise<AuthSessionResult> {
 invariant(
   !_redirectHandler,
   'InAppBrowser.openAuth is in a bad state. _redirectHandler is defined when it should not be.'
 );
 let response = null;
 try {
   response = await Promise.race([
     waitForRedirectAsync(returnUrl),
     openBrowserAsync(startUrl, options).then(function (result) {
       return checkResultAndReturnUrl(returnUrl, result);
     }),
   ]);
 } finally {
   closeAuthSessionPolyfillAsync();
   RNInAppBrowser.close();
 }
 return response;
}

Event Listener added in below function:

function waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
  return new Promise(function (resolve) {
    _redirectHandler = (event: RedirectEvent) => {
      if (event.url && event.url.startsWith(returnUrl)) {
        resolve({ url: event.url, type: 'success' });
      }
    };
    Linking.addEventListener('url', _redirectHandler);
  });
}

Please Suggest.

abhay-sqh avatar Oct 07 '21 05:10 abhay-sqh

I am facing the same issue.

@abhay-sqh did you manage to resolve this issue or work around it?

timkuilman avatar Dec 08 '21 15:12 timkuilman

Hey folks, hope you're doing well

What's your configuration from Android manifest file?

jdnichollsc avatar Dec 19 '21 17:12 jdnichollsc

Hey @abhay-sqh ...did you find the root cause of this? I'm facing a similar issue on some devices running on Android 8/9

jartmez avatar Apr 21 '22 14:04 jartmez

Any news on this matter? I am also seeing that issue

luneo7 avatar May 18 '22 15:05 luneo7

I found the solution for me!

I'm using the lib react-native-splash-screen and I changed some things on Android Manifest

So I just rollback the intent-filter position on the Android Manifest and it worked again.

From:

<activity
      android:name=".SplashActivity"
      android:label="@string/app_name"
      android:theme="@style/SplashTheme"
    >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="rkz98" android:scheme="rkz98" />
        <data android:host="rkz98.page.link" android:scheme="http" />
        <data android:host="rkz98.page.link" android:scheme="https" />
      </intent-filter>
    </activity>
    <activity
      android:exported="true"
      android:name=".MainActivity"
      android:launchMode="singleTask"
      android:label="@string/app_name"
      android:screenOrientation="portrait"
      android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    />

To:

<activity
      android:name=".SplashActivity"
      android:label="@string/app_name"
      android:theme="@style/SplashTheme"
    >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity
      android:exported="true"
      android:name=".MainActivity"
      android:launchMode="singleTask"
      android:label="@string/app_name"
      android:screenOrientation="portrait"
      android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
    >
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="rkz98" android:scheme="rkz98" />
        <data android:host="rkz98.page.link" android:scheme="http" />
        <data android:host="rkz98.page.link" android:scheme="https" />
      </intent-filter>
    </activity>

rkz98 avatar May 31 '22 21:05 rkz98

For me the solution was to add the redirectUri in the openAuth()-Call.

I changed my call from openAuth("authenticationLink?...&redirect_uri={LINK_TO_BACKEND_API}); to: openAuth("authenticationLink?...&redirect_uri={LINK_TO_BACKEND_API}, "myapp://deeplinkpath");

seco35 avatar Oct 16 '22 23:10 seco35

Also I got some situations, and we already had react-native-splash as dependency.

And here we already calls openAuth with deep link argument

I'm trying to figure out why this happens 🥹🥹.

@seco35 @rkz98 @luneo7 @jartmez @timkuilman @jdnichollsc @abhay-sqh

Are you also using react-native-splash ?

jacksonsmith avatar Jun 28 '23 23:06 jacksonsmith

I've seen this happen a handful of times in Sentry logs. The one instance where I was able to narrow down the cause was a Chromebook with Chrome v109

image

Switching the default browser over to Brave resolved it for the user.

jamesholcomb avatar Aug 17 '23 18:08 jamesholcomb

Any updates on this issue? I'm facing this same problem.

ruanblimaig avatar Apr 02 '24 11:04 ruanblimaig