proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.33k stars 228 forks source link

Getting warning as "Another InAppBrowser is already being presented" #131

Closed nihp closed 4 years ago

nihp commented 4 years ago

I am getting warning as "Another InAppBrowser is already being presented" after the click on the link second time without closing the previously opened window and failed to open the link.

Steps to reproduce:

  1. Clock on the link which needs to be open
  2. It will open the url
  3. Then I swipe from left to right
  4. It goes to the previous screen
  5. Then I tried to open another link
  6. It failed to open and shows the above warning in my simulator

Note: If I click done in 3rd step means it works well. But here I need will swipe to go back. In this cases how can I make it to work.

I am using react-native version ==> 0.61.5

jdnichollsc commented 4 years ago

Can you share your code please?

yilinjuang commented 4 years ago

I think I have it fixed. Please check the pr

On Sat, Jan 4, 2020, 02:38 Juan David Nicholls Cardona < notifications@github.com> wrote:

Can you share your code please?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/proyecto26/react-native-inappbrowser/issues/131?email_source=notifications&email_token=ABPDZCGHZVSUEZST6YW4YCDQ36AZRA5CNFSM4J7IHZN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIBZGKY#issuecomment-570659627, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPDZCFXJQ3PK6WXLFMDNLTQ36AZRANCNFSM4J7IHZNQ .

jdnichollsc commented 4 years ago

Ohh thanks, let me check and publish a new version this weekend 👍

jdnichollsc commented 4 years ago

Done! thanks for your help! ❤️

klaaz0r commented 4 years ago

I am getting this on the latest version with just using the example code.

mstfymrtc commented 4 years ago

Also I'm getting same error on iPhone 11. But works on iPhone 8. Both are iOS 13.1.

joshbuchea commented 4 years ago

I was also getting the Another InAppBrowser is already being presented error message with the latest version (downloaded 3.3.4 today) when using the example code in an app with React Native 0.60.5. Tested on the iOS Simulator with iPhone X on iOS 13.3.

Was able to resolve by:

💥hopefully that helps a few folks, as I wasted ~45 minutes on this issue

jdnichollsc commented 4 years ago

mmm very odd, reopening to have this issue in mind, any pull request is welcome! 👍

prayuditb commented 4 years ago

I also facing this issue. but unfortunately, the solution from @joshbuchea didn't work for me. I'm using version v3.3.4

claudiozam commented 4 years ago

The solution from @joshbuchea didn't work for me :( I'm using version v3.3.4

jdnichollsc commented 4 years ago

@prayuditb @claudiozam in what platform? In Android, check if this configuration works for you https://github.com/proyecto26/react-native-inappbrowser/blob/master/example/android/app/src/main/AndroidManifest.xml#L13

jdnichollsc commented 4 years ago

One little question, are you using closeAuth before?

claudiozam commented 4 years ago

@jdnichollsc in IOS. We are not using closeAuth.

jdnichollsc commented 4 years ago

Check the new version 3.4.0 and let me know, or if you can check the follow validation and send a pull request, always is welcome! https://github.com/proyecto26/react-native-inappbrowser/blob/master/index.js#L161

jdnichollsc commented 4 years ago

I think we can remove that validation and clear any listener if the openAuth function is called again, what do you think guys?

jdnichollsc commented 4 years ago

After checking in a personal app, this error is happening here https://github.com/proyecto26/react-native-inappbrowser/blob/master/ios/RNInAppBrowser.m#L274 So it looks like safariViewControllerDidFinish is not working as expected, and I don't understand why

jdnichollsc commented 4 years ago

Hello folks! @nihp @frankyjuang @klaaz0r @mstfymrtc @joshbuchea @prayuditb @claudiozam can you help me debugging InAppBrowser from your apps and let me know if this method is not being called (it's used to clear the promises when the browser is closed)

debug-xcode

I can't reproduce this issue from demo project Thanks in advance! 👍

lucasrodes commented 4 years ago

any updates? getting this problem on iOS 13.4, running the emulator. I think I managed to make it work by removing the line modalTransitionStyle: 'partialCurl' from the demo example.

import { Linking } from 'react-native'
import InAppBrowser from 'react-native-inappbrowser-reborn'

...
  async openLink() {
    try {
      const url = 'https://www.google.com'
      if (await InAppBrowser.isAvailable()) {
        const result = await InAppBrowser.open(url, {
          // iOS Properties
          dismissButtonStyle: 'cancel',
          preferredBarTintColor: '#453AA4',
          preferredControlTintColor: 'white',
          readerMode: false,
          animated: true,
          modalPresentationStyle: 'overFullScreen',
          // modalTransitionStyle: 'partialCurl',
          modalEnabled: true,
          enableBarCollapsing: false,
          // Android Properties
          showTitle: true,
          toolbarColor: '#6200EE',
          secondaryToolbarColor: 'black',
          enableUrlBarHiding: true,
          enableDefaultShare: true,
          forceCloseOnRedirection: false,
          // Specify full animation resource identifier(package:anim/name)
          // or only resource name(in case of animation bundled with app).
          animations: {
            startEnter: 'slide_in_right',
            startExit: 'slide_out_left',
            endEnter: 'slide_in_left',
            endExit: 'slide_out_right'
          },
          headers: {
            'my-custom-header': 'my custom header value'
          }
        })
        Alert.alert(JSON.stringify(result))
      }
      else Linking.openURL(url)
    } catch (error) {
      Alert.alert(error.message)
    }
  }
...

Don't know if this makes any sense, started with react this year.

jdnichollsc commented 4 years ago

@lucasrodes in your case it's ok because you don't need partialCurl transition :)

claudiozam commented 4 years ago

@jdnichollsc We were able to reproduce the error (Tested on a real device - IPhone X and IPhone 8: IOS 13.5.1)

1- Launch the InAppBrowser by clicking a button. 2- The InAppBrowser pops up. 3- Close the InAppBrowser (by pressing the "Close" button in the top left corner) right after (before the website is rendered). 4- Try to open the InAppBrowser again using the button from step 1. 5- The InAppBrowser pops up for a "milisecond" and gets closed right after automatically without human intervention.

jdnichollsc commented 4 years ago

@claudiozam Can you provide a sample app that exhibits this issue? It would be a lot simpler to debug if we had a sample, thanks!

claudiozam commented 4 years ago

@jdnichollsc the method (void) flowDidFinish is not being called. We think this issue is related with http redirects (301 / 302) and some sync problem.

Saludos y gracias!!!

jdnichollsc commented 4 years ago

Do you know if safariViewControllerDidFinish is not being called too?

claudiozam commented 4 years ago

@jdnichollsc yes the method safariViewControllerDidFinish is not being called too

claudiozam commented 4 years ago

Also i was able to reproduce the issue in the example app. But it was difficult to test it (No warning all the time...).

I used different URLs. https://bit.ly/2AS3txf https://httpstat.us/301?sleep=1000 https://httpstat.us/302?sleep=1000 https://httpstat.us/301?sleep=5000

jdnichollsc commented 4 years ago

Thanks, let me check! 👍

claudiozam commented 4 years ago

The methods flowDidFinish and safariViewControllerDidFinish are not being called if you are using a modal + InAppBrowser in IOS. You must close the modal and wait a couple of seconds. But I don't know why i was hable to reproduce the message "Another InAppBrowser is already being presented" in the example App. RN Fast Refresh issue?

jdnichollsc commented 4 years ago

Are you updating the code while the browser is opened?

claudiozam commented 4 years ago

No, only before the browser is open and after the user close it

jacquesdev commented 4 years ago

My temporary fix for this issue, is do a try/catch, and then in the catch manually close the browser instance and then re-open it.

await InAppBrowser.close()
InAppBrowser.open(url, config)

A bit of a hack, but the users get a good experience

nhanha commented 4 years ago

@jacquesdev 👍 Your are number 1.

jasperkuperus commented 4 years ago

Are you updating the code while the browser is opened?

This was indeed my issue: Open the InAppBrowser, then modify your code, resulting in a refresh. Close the InAppBrowser, reopen and you get this error. So that's related to reloading the app while the InAppBrowser is open.

My solution to this is try to not refresh your app while having the InAppBrowser opened. Once this did happen and you get this error: Kill the app and re-open it. It's not pretty, but it works for me.

jasperkuperus commented 4 years ago

I ran into a new scenario, where opening an in app browser twice, the second time it crashes. Nothing really helped me. The await InAppBrowser.close() didn't help, and also the await InAppBrowser.isAvailable() didn't help me (always results in true, even when it crashes). The first in app browser is certainly closed before opening the second.

I ended up doing a very ugly hack, something along these lines:

async function open() {
  try {
    await InAppBrowser.open('...', {});
  } catch (error) {
    await new Promise((resolve) => setTimeout(resolve, 500));
    await InAppBrowser.open('...', {});
  }
}

@jdnichollsc @frankyjuang Can we have another look at this issue? These hacks really shouldn't be necessary...

yilinjuang commented 4 years ago

@jdnichollsc @frankyjuang Can we have another look at this issue? These hacks really shouldn't be necessary...

I'm not using this anymore. Sorry cant help

jdnichollsc commented 4 years ago

Let me check if I can deploy a new version this weekend, sorry for the delay

janpe commented 4 years ago

I seem to be getting this error when in a case like this: I have a modal (react-native-modal) where I have a button. When I press the button I close the modal and open the browser, but the closing animation of the modal seems to break the browser. The browser slides up to open but when the modal close animation happens the browser closes too. If I wait for the modal to close before opening the browser everything seems to work all normal.

indapublic commented 4 years ago

Works for me after removing modalTransitionStyle: 'partialCurl', you should restart your app (not fast refresh) after this change

jdnichollsc commented 4 years ago

Please debug the last changes from develop branch, there's a pending PR of the new version 3.5.0 https://github.com/proyecto26/react-native-inappbrowser/pull/195

yuya-iwabuchi commented 4 years ago

I am experiencing the exact same issue as @janpe reported above with the latest version, 3.5.1.

jdnichollsc commented 4 years ago

Feel free to attach a repository in order to reproduce this issue and I'll be happy to re-open this issue and take a look 👍

ghost commented 3 years ago

Hello,

I'm facing the same issue using with aws-amplify.

I'm using the following versions: "react-native": "0.64.1" "react-native-inappbrowser-reborn": "^3.6.3"

import Amplify from 'aws-amplify'
import { Linking } from 'react-native';
import InAppBrowser from 'react-native-inappbrowser-reborn';

Amplify.configure({
      Auth: {
            userPoolId: 'COGNITO_USER_POOL_ID',
            userPoolWebClientId: 'COGNITO_USER_POOL_WEBCLIENT_ID',
            region: 'eu-central-1',
            oauth: {
                  domain: 'auth.myApp',
                  scope: ['email', 'profile', 'openid',],
                  redirectSignIn: 'myApp://',
                  redirectSignOut: 'myApp://',
                  responseType: 'code',
                  async urlOpener(url: string, redirectUrl: string) {
                              const response = await InAppBrowser.openAuth(url, redirectUrl, {
                                    showTitle: false,
                                    enableUrlBarHiding: true,
                                    enableDefaultShare: false,
                                    ephemeralWebSession: false,
                              });
                              if (response.type === 'success') await Linking.openURL(response.url);
                  }
            }
      },
})
nathanwkwong commented 2 years ago

My case trigger the warning:

  1. open in app browser with InAppBrowser.open(url)
  2. minimise the app, and open a deep link than will trigger another call of InAppBrowser.open(url)

My workaround so far that I can getting ride of the warning and open the browser successfully:

  1. try to close and open the browser with InAppBrowser.close() and InAppBrowser.open(promotionUrl)
  2. and a retry callback on the .catch() of InAppBrowser.open(promotionUrl)
let retryCounter = 0;

const openBrowser = () => {
    InAppBrowser.close();
    InAppBrowser.open(promotionUrl)
        .then(() => {
            // success handling...
        })
        .catch(() => {
            if (retryCounter < 2) {
                setTimeout(() => {
                    retryCounter++;
                    openBrowser();
                }, 1000);
            } else {
               // failed handling...
            }
        });
};

openBrowser();
abdalla-finder commented 1 month ago

any update?