import { normalizeHostBridgeExternalUrl } from '../../../packages/shared/src/contracts/hostBridge'; export function shouldOpenInMobileShellWebView( rawUrl: string, allowedOrigin: string, ) { if (rawUrl === 'about:blank') { return true; } if ( !rawUrl.startsWith('/') && !rawUrl.startsWith('#') && !/^[a-z][a-z0-9+.-]*:/i.test(rawUrl) ) { return false; } try { const url = new URL(rawUrl, allowedOrigin); if (url.protocol !== 'http:' && url.protocol !== 'https:') { return false; } return url.origin === allowedOrigin; } catch { return false; } } export function resolveMobileShellExternalUrl(rawUrl: string) { return normalizeHostBridgeExternalUrl(rawUrl); } export function shouldAcceptMobileShellHostBridgeMessage( rawUrl: string, allowedOrigin: string, ) { return rawUrl !== 'about:blank' && shouldOpenInMobileShellWebView(rawUrl, allowedOrigin); } export function resolveMobileShellWebViewUrl( rawUrl: string, allowedOrigin: string, ) { if ( rawUrl === 'about:blank' || !shouldOpenInMobileShellWebView(rawUrl, allowedOrigin) ) { return null; } try { return new URL(rawUrl, allowedOrigin).toString(); } catch { return null; } }