From 00d9b69f819309a656962a81dc388b2c7d0a2cb2 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 18 Jun 2026 23:18:02 +0700 Subject: [PATCH] fix: use window.open(_blank) to trigger Amber's web/browser intent path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amber has two code paths: - Native path (no Browser.EXTRA_APPLICATION_ID): reads type from intent EXTRAS — impossible to set from a WebView URL navigation - Web/browser path (Browser.EXTRA_APPLICATION_ID set): reads type from URL query params — triggered when WebView opens URL as browser intent window.open(url, '_blank') causes Android WebView to fire a browser ACTION_VIEW intent which sets Browser.EXTRA_APPLICATION_ID, routing Amber to parse our nostrsigner: URL query params correctly. Previous attempts: - window.location.href: WebView intercepts as asset URL - window.open(_system): strips query params - anchor click: goes through native path (no extras = INVALID type) Co-authored-by: shakespeare.diy --- src/lib/amber.ts | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/lib/amber.ts b/src/lib/amber.ts index bdf1f0d..ce0311a 100644 --- a/src/lib/amber.ts +++ b/src/lib/amber.ts @@ -291,26 +291,22 @@ function buildCallbackUrl(): string { /** * Navigate to an Amber nostrsigner: URL. * - * 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). + * Amber has two code paths depending on how it receives the intent: + * + * 1. NATIVE path (no Browser.EXTRA_APPLICATION_ID): reads type from + * intent EXTRAS — not set when coming from a WebView URL navigation. + * + * 2. WEB/BROWSER path (Browser.EXTRA_APPLICATION_ID present): reads type + * from URL query params — set when a browser/WebView opens a URL. + * + * We need the WEB path. window.open('url', '_blank') causes the WebView + * to open the URL as a browser navigation, which sets + * Browser.EXTRA_APPLICATION_ID and routes Amber to parse our URL params. */ function openAmberUrl(url: string): void { - 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; - } + // _blank triggers the browser intent path in Android WebView, + // which sets Browser.EXTRA_APPLICATION_ID so Amber reads URL query params. + window.open(url, '_blank'); } /**