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:
parent
fdebfc0d37
commit
f534c413fd
1 changed files with 18 additions and 5 deletions
|
|
@ -291,13 +291,26 @@ function buildCallbackUrl(): string {
|
||||||
/**
|
/**
|
||||||
* Navigate to an Amber nostrsigner: URL.
|
* Navigate to an Amber nostrsigner: URL.
|
||||||
*
|
*
|
||||||
* Use window.location.href for all platforms — Android handles the
|
* In Capacitor WebView, custom URI schemes must be opened via a
|
||||||
* nostrsigner: custom scheme via intent-filter regardless of whether
|
* temporary <a> element click — this triggers Android's intent system
|
||||||
* we're in a WebView or browser. window.open(_system) was stripping
|
* correctly without the WebView trying to load it as an asset URL
|
||||||
* query parameters causing Amber to receive a malformed request.
|
* (window.location.href) or stripping query params (window.open _system).
|
||||||
*/
|
*/
|
||||||
function openAmberUrl(url: string): void {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue