Skip to main content

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.

Warning

On Android, the sign-in link opens in your app instead of the browser if your app has a verified App Link that matches it. The link's path is /v1/session_transfers/redeem on your . The intent filter in the passkeys setupExpo Icon matches every path on that host, so it matches the link, and the user isn't signed in on the web.

To fix this, narrow the intent filter with pathPrefix or pathPattern to the paths that your app handles, or remove it if your app doesn't open links on that host. Keep your Android app registered on the Native applications page, which serves the assetlinks.json file.

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.

terminal
npx expo install expo-intent-launcher expo-application

Without 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 SessionTransferErrorExpo Icon 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.

components/open-on-web-button.tsx
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

What did you think of this content?

Last updated on