fix: use anchor click to open nostrsigner: URLs in Capacitor WebView

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 <a> element and
clicking it — this correctly triggers Android's intent system with the
full URL intact.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
shakespeare.diy 2026-06-18 23:10:13 +07:00
parent fdebfc0d37
commit f534c413fd

View file

@ -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 <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).
*/
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;
}
}
/**