Skip to content

Expo listen for browser dismiss

In my expo react native app, the user is directed to a URL in a WebBrowser. I would like to be able to listen for when the user closes/ dismisses the WebBrowser and then execute a function. Is this possible?

Answer

I solved this by using an authentication session (openAuthSessionAsync) instead of a standard web browser (openBrowserAsync). With an auth session a promise is returned and every second the system checks whether the window has been closed by the user. If it has been then that promise will resolve with { type: 'cancel' }.