1

I am trying to close the browser after a certain time, but it's not working on Android ( Works fine on ios). The code inside setTimeout is executing after I close the browser manually.

  const onclick = ()=>{
    openInAppBrowser('https://www.google.com/');
    setTimeout(()=>{
      close();
    }, 9000)
  }
export const openInAppBrowser = async (url:string) => {
  try {
    if (await InAppBrowser.isAvailable()) {
      const options: InAppBrowserOptions = {
        showTitle: false,
        toolbarColor: 'black',
        secondaryToolbarColor: 'black',
        enableUrlBarHiding: true,
        enableDefaultShare: true,
        forceCloseOnRedirection: false,
        enableBarCollapsing: true
      };

      const result = await InAppBrowser.open(url, options);
      return result;
    } else Linking.openURL(url);
  } catch (error) {
    console.log(error);
  }
};
export const close = async (): Promise<void> => {
    try {
        await InAppBrowser.close();
    } catch (error) {
        throw new Error(error as any);
    }
};
Lelouch
  • 53
  • 4

0 Answers0