From f534c413fdabb1428840968d09e44d97b0e8e942 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 18 Jun 2026 23:10:13 +0700 Subject: [PATCH] fix: use anchor click to open nostrsigner: URLs in Capacitor WebView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit window.location.href causes WebView to try loading nostrsigner: as an asset URL. window.open(_system) strips query params. The only reliable method in Capacitor WebView is creating a temporary element and clicking it — this correctly triggers Android's intent system with the full URL intact. Co-authored-by: shakespeare.diy --- src/lib/amber.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) 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; + } } /**