fix: use window.open(_blank) to trigger Amber's web/browser intent path
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 <assistant@shakespeare.diy>
This commit is contained in:
parent
f534c413fd
commit
00d9b69f81
1 changed files with 14 additions and 18 deletions
|
|
@ -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 <a> 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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue