Skip to content
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

Is it possible to trigger a callback when the browser closes? #415

Closed
aryella-lacerda opened this issue May 13, 2023 · 5 comments
Closed

Comments

@aryella-lacerda
Copy link

Hello! Thanks for maintaining this project, it's been very helpful to our team. But we're stuck on a minor issue: is it possible to trigger a callback when the user closes out of the browser? 🤔

@oddlyspaced
Copy link

You can handle the BrowserResult promise for the cancel event, for deeplinking and successful callbacks i have a separate deeplink handler in my code that dismisses it.
This is how I have been handling the success and failure situations in my code. Both approaches lead to closing of the browser

@niteshagrawal
Copy link

You can handle the BrowserResult promise for the cancel event, for deeplinking and successful callbacks i have a separate deeplink handler in my code that dismisses it. This is how I have been handling the success and failure situations in my code. Both approaches lead to closing of the browser

can you attach an example that how you are doing it? any help will be appreciated.

@aryella-lacerda
Copy link
Author

  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(url, {...});

      // when the users presses the cancel/close button 
      if (result.type === 'cancel') {
        onCancel(); 
      }

      // when you call the close() method
      if (result.type === 'dismiss') {
        onDismiss(); 
      }
    } else {
      Linking.openURL(url);
    }
  } catch (error) {
    console.log(error.message);
  }

@niteshagrawal
Copy link

  try {
    if (await InAppBrowser.isAvailable()) {
      const result = await InAppBrowser.open(url, {...});

      // when the users presses the cancel/close button 
      if (result.type === 'cancel') {
        onCancel(); 
      }

      // when you call the close() method
      if (result.type === 'dismiss') {
        onDismiss(); 
      }
    } else {
      Linking.openURL(url);
    }
  } catch (error) {
    console.log(error.message);
  }

thanks for the response aryella. i am trying to integrate keycloak login with react native app using inapp-browser. issue is that after opening browser, i can't get any response. only response i get is "type:cancel" when i close the browser. how to close the browser after successful login in inapp-browser.
thanks in advance.

@jdnichollsc
Copy link
Member

how to close the browser after successful login in inapp-browser.

you need to redirect users to the app using deep linking

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

4 participants