Skip to content

how can we close the inappbrowser when have detect redirect to another page? #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jianloong92 opened this issue Dec 1, 2023 · 8 comments

Comments

@jianloong92
Copy link

how can we close the inappbrowser when have detect redirect to another page?

@krini
Copy link

krini commented Jan 10, 2024

on iOS you can call the close() function. On Android you cannot close it as far as I know.

@arsencenko
Copy link

@krini but how to detect specific url that inappbrowser is currently in ?

@krini
Copy link

krini commented Mar 6, 2024

@krini but how to detect specific url that inappbrowser is currently in ?

You can not. If you close it, it is probably because you know the flow is done e.g. by polling a status endpoint.

@malikzype
Copy link

But that is very weired to hit a endpoint and keep checking if its successful or not. In case if the journey inapp browser is a bit long then it will be expensive operation to keep polling

@syedfaheem27
Copy link

@krini

Is there a way to close the in app browser on android automatically. I just want to close it programmatically. Here is a code snippet.

      const {theme} = useTheme();

    const inAppBrowserRef = useRef(InAppBrowser);

    console.log(inAppBrowserRef, '--------------------------');

    const terminalUrls = data.endURLs;
    const initialUrl = data.initialURL;

    const navigation = useNavigation();

    useEffect(() => {
        (async () => {
            try {
                if (await inAppBrowserRef.current.isAvailable()) {
                    await InAppBrowser.openAuth(initialUrl, terminalUrls[2]);
                }
            } catch (error) {
                console.error('Error in InAppBrowser:', error);
            }
        })();

        setTimeout(() => {
            if (Platform.OS === 'android') {
                inAppBrowserRef.current.close();
                inAppBrowserRef.current.closeAuth();
            } else {
                inAppBrowserRef.current.closeAuth();
            }
            navigateBack(navigation);
        }, 4000);
    }, []);

    

@krini
Copy link

krini commented Mar 21, 2025

@krini

Is there a way to close the in app browser on android automatically. I just want to close it programmatically. Here is a code snippet.

No, this line of code inAppBrowserRef.current.close();. will only work on ios.

On android the browser should be closed in the browser window and not from the app.

@syedfaheem27
Copy link

@krini So, there isn't a way to close the in-app browser programmatically rather than having to close it manually.

@krini
Copy link

krini commented Mar 21, 2025

@krini So, there isn't a way to close the in-app browser programmatically rather than having to close it manually.

If you are in control of the page in inappbrowser you can close it from there, not from the app code on Android.

Maybe you can solve it with a deeplink back to your app - however I didn't succeed in doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants