openInBrowser()
The openInBrowser() function opens a page of your web app in the device's default browser with the native app's user already signed in.
For setup steps, see Open your web app signed in from a native app.
Installation
On Android, this function requires expo-intent-launcher and expo-application. iOS doesn't need any extra packages.
npx expo install expo-intent-launcher expo-applicationWithout expo-intent-launcher, the function rejects with the missing_dependency error code on Android.
Then, import the function from the @clerk/expo/native-to-web subpath:
import { openInBrowser } from '@clerk/expo/native-to-web'Usage
openInBrowser() has the following function signature:
function openInBrowser(params: OpenInBrowserParams): Promise<void>Parameters
openInBrowser() accepts the following parameters (OpenInBrowserParams):
- Name
destination- Type
string- Description
The page to open, as an absolute URL. Outside development instances, it must use HTTPS. In production, it must share a root domain with one of your Clerk instance's domains.
Returns
openInBrowser() returns a Promise that resolves after it starts opening the sign-in link. It doesn't wait for the web page to sign the user in, and if the sign-in fails on the web, your app isn't notified. See how to handle a failed sign-in on the web.
The Promise rejects with a SessionTransferError when Clerk can't create the link, or when opening the link fails before the Promise resolves.
Overlapping calls for the same destination share one link, so a double tap opens one browser tab.
Example
The following example opens the settings page of a web app when the user selects Open on web. A signed-out user goes to the sign-in screen instead.
import { isSessionTransferError, openInBrowser } from '@clerk/expo/native-to-web'
import { router } from 'expo-router'
import { Alert, Button } from 'react-native'
export function OpenOnWebButton() {
const onPress = async () => {
try {
await openInBrowser({ destination: 'https://app.example.com/settings' })
} catch (error) {
if (isSessionTransferError(error) && error.code === 'signed_out') {
router.replace('/sign-in')
return
}
Alert.alert('Could not open the web app')
}
}
return <Button title="Open on web" onPress={onPress} />
}Feedback
Last updated on