diff --git a/src/lib/amber.ts b/src/lib/amber.ts index 2691c96..bdf1f0d 100644 --- a/src/lib/amber.ts +++ b/src/lib/amber.ts @@ -291,13 +291,26 @@ function buildCallbackUrl(): string { /** * Navigate to an Amber nostrsigner: URL. * - * Use window.location.href for all platforms — Android handles the - * nostrsigner: custom scheme via intent-filter regardless of whether - * we're in a WebView or browser. window.open(_system) was stripping - * query parameters causing Amber to receive a malformed request. + * In Capacitor WebView, custom URI schemes must be opened via a + * temporary element click — this triggers Android's intent system + * correctly without the WebView trying to load it as an asset URL + * (window.location.href) or stripping query params (window.open _system). */ function openAmberUrl(url: string): void { - window.location.href = url; + const isCapacitor = !!(window as unknown as { Capacitor?: { isNativePlatform?: () => boolean } }).Capacitor?.isNativePlatform?.(); + if (isCapacitor) { + // Create a temporary anchor and click it — this is the only reliable + // way to fire an Android intent from a Capacitor WebView without + // the WebView intercepting the navigation or stripping query params. + const a = document.createElement('a'); + a.href = url; + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); + setTimeout(() => document.body.removeChild(a), 100); + } else { + window.location.href = url; + } } /**