Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
49568cd
feat(expo): add useNativeToWeb to open a signed-in system browser
wobsoriano Nov 14, 2026
96ce935
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 14, 2026
1c9d04e
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
0ea2927
feat(expo): replace useNativeToWeb with openInBrowser
wobsoriano Nov 16, 2026
11ad794
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
b175279
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
bb33179
docs(expo): add an openInBrowser changeset with an example
wobsoriano Nov 16, 2026
a9fdc72
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
7aa98b2
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
126aec7
docs(expo): tighten the openInBrowser changeset and import router in …
wobsoriano Nov 16, 2026
b15cecd
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
6160fb5
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
229506d
docs(expo): tighten the openInBrowser changeset
wobsoriano Nov 16, 2026
29d9257
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
b0b29a5
Merge branch 'rob/mobile-450-add-native-to-web-apis-to-expo' into rob…
wobsoriano Nov 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/expo-open-in-browser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@clerk/expo': minor
---

Introduce `openInBrowser()` for opening a page of your web app in the default browser with the native app's user already signed in.

```tsx
import { isSessionTransferError, openInBrowser } from '@clerk/expo/native-to-web';
import { router } from 'expo-router';

try {
// Opens Safari on iOS or the default browser on Android, signed in as the current user
await openInBrowser({ destination: 'https://app.example.com/settings' });
} catch (error) {
// The app has no signed-in user
if (isSessionTransferError(error) && error.code === 'signed_out') router.replace('/sign-in');
}
```

It resolves once the browser has the link, not once the web page has signed the user in. A double tap opens one tab, because a second call for the same destination joins the one in progress.

On Android it needs two more packages:

```sh
npx expo install expo-intent-launcher expo-application
```
5 changes: 5 additions & 0 deletions packages/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"expo-auth-session": "^7.0.11",
"expo-constants": "^18.0.13",
"expo-crypto": "^15.0.9",
"expo-intent-launcher": "^13.0.8",
"expo-local-authentication": "^17.0.8",
"expo-secure-store": "^15.0.8",
"expo-web-browser": "^15.0.11",
Expand All @@ -164,6 +165,7 @@
"expo-auth-session": ">=5",
"expo-constants": ">=12",
"expo-crypto": ">=12",
"expo-intent-launcher": ">=12",
"expo-local-authentication": ">=13.5.0",
"expo-secure-store": ">=12.4.0",
"expo-web-browser": ">=12.5.0",
Expand Down Expand Up @@ -200,6 +202,9 @@
"expo-crypto": {
"optional": true
},
"expo-intent-launcher": {
"optional": true
},
"expo-local-authentication": {
"optional": true
},
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/app-version/nativeAppIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function isExpoApplicationInstalled(): boolean {
return loadExpoApplication() !== null;
}

function loadExpoApplication(): ExpoApplication | null {
export function loadExpoApplication(): ExpoApplication | null {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require('expo-application') as ExpoApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import Module from 'node:module';

import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';

import { resolveBrowserLauncher } from '../launchBrowser.android';

const moduleWithLoad = Module as unknown as {
_load: (request: string, parent?: unknown, isMain?: boolean) => unknown;
};
const originalModuleLoad = moduleWithLoad._load;

const mocks = vi.hoisted(() => {
return {
appStateListeners: [] as Array<(state: string) => void>,
removeSubscription: vi.fn(),
startActivityAsync: vi.fn(),
applicationId: 'com.example.app' as string | null,
expoApplicationInstalled: true,
androidPackage: undefined as string | undefined,
};
});

vi.mock('react-native', () => {
return {
Platform: { OS: 'android' },
AppState: {
addEventListener: (_: string, listener: (state: string) => void) => {
mocks.appStateListeners.push(listener);
return { remove: mocks.removeSubscription };
},
},
};
});

const TRANSFER_URL = 'https://clerk.example.com/v1/session_transfers/redeem?token=one-time';

function pending() {
let resolve: (value: unknown) => void = () => {};
let reject: (reason: unknown) => void = () => {};
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
}

function changeAppState(state: string) {
mocks.appStateListeners.forEach(listener => listener(state));
}

async function outcome(promise: Promise<void>) {
const settled = await Promise.race([
promise.then(
() => 'resolved',
(error: unknown) => error,
),
new Promise(resolve => setTimeout(() => resolve('pending'), 0)),
]);
return settled;
}

describe('resolveBrowserLauncher on Android', () => {
beforeEach(() => {
mocks.appStateListeners = [];
mocks.removeSubscription.mockReset();
mocks.startActivityAsync.mockReset();
mocks.applicationId = 'com.example.app';
mocks.expoApplicationInstalled = true;
mocks.androidPackage = undefined;
vi.spyOn(moduleWithLoad, '_load').mockImplementation((request, parent, isMain) => {
if (request === 'expo-intent-launcher') {
return { startActivityAsync: mocks.startActivityAsync };
}
if (request === 'expo-application') {
if (!mocks.expoApplicationInstalled) {
throw new Error("Cannot find module 'expo-application'");
}
return { applicationId: mocks.applicationId };
}
if (request === 'expo-constants') {
return {
default: { executionEnvironment: 'standalone', expoConfig: { android: { package: mocks.androidPackage } } },
};
}
return originalModuleLoad.call(Module, request, parent, isMain);
});
});

afterEach(() => {
vi.restoreAllMocks();
});

test('sends REFERRER_NAME with the application id and leaves the browser choice to Android', async () => {
mocks.startActivityAsync.mockResolvedValue({ resultCode: 0 });

await resolveBrowserLauncher()(TRANSFER_URL);

expect(mocks.startActivityAsync).toHaveBeenCalledWith('android.intent.action.VIEW', {
data: TRANSFER_URL,
extra: { 'android.intent.extra.REFERRER_NAME': 'android-app://com.example.app' },
});
expect(mocks.startActivityAsync.mock.calls[0][1]).not.toHaveProperty('packageName');
});

test('falls back to the package name from the app config without expo-application', async () => {
mocks.expoApplicationInstalled = false;
mocks.androidPackage = 'com.example.config';
mocks.startActivityAsync.mockResolvedValue({ resultCode: 0 });

await resolveBrowserLauncher()(TRANSFER_URL);

expect(mocks.startActivityAsync).toHaveBeenCalledWith(
'android.intent.action.VIEW',
expect.objectContaining({ extra: { 'android.intent.extra.REFERRER_NAME': 'android-app://com.example.config' } }),
);
});

test('throws missing_dependency when no package name is available', () => {
mocks.expoApplicationInstalled = false;

expect(() => resolveBrowserLauncher()).toThrow(
expect.objectContaining({ code: 'missing_dependency', message: expect.stringContaining('expo-application') }),
);
});

test('resolves when the launch settles', async () => {
mocks.startActivityAsync.mockResolvedValue({ resultCode: 0 });

await expect(outcome(resolveBrowserLauncher()(TRANSFER_URL))).resolves.toBe('resolved');
expect(mocks.removeSubscription).toHaveBeenCalled();
});

test('resolves when the app leaves the foreground before the launch settles', async () => {
const launch = pending();
mocks.startActivityAsync.mockReturnValue(launch.promise);
const opening = resolveBrowserLauncher()(TRANSFER_URL);

changeAppState('active');
await expect(outcome(opening)).resolves.toBe('pending');
changeAppState('background');

await expect(outcome(opening)).resolves.toBe('resolved');
expect(mocks.removeSubscription).toHaveBeenCalled();
launch.reject(new Error('activity finished'));
await expect(outcome(opening)).resolves.toBe('resolved');
});

test('rejects with browser_unavailable when the launch fails first', async () => {
mocks.startActivityAsync.mockRejectedValue(new Error(`No Activity found to handle Intent { dat=${TRANSFER_URL} }`));

const result = await outcome(resolveBrowserLauncher()(TRANSFER_URL));

expect(result).toMatchObject({ name: 'SessionTransferError', code: 'browser_unavailable' });
expect(result).not.toHaveProperty('cause');
expect(String(result)).not.toContain('one-time');
expect(mocks.removeSubscription).toHaveBeenCalled();
});
});
Loading
Loading