fix(connection): stop ERR_UNKNOWN_URL_SCHEME when opening app deep links on mobile

Telegram bug #654272: opening the connection app link (immediate-open / connect button)
showed a full-page net::ERR_UNKNOWN_URL_SCHEME on Android and silently failed on iOS, while
working on desktop.

Cause: a programmatic top-level navigation to a custom scheme (happ://, v2rayng://, …) via
window.location.href is rendered as a full-page error inside in-app WebViews (Telegram/Yandex)
on Android and does nothing on iOS — also wiping the fallback UI.

Add openAppScheme(): http(s) navigate normally; custom schemes launch via a hidden, contained
iframe so a failed launch never replaces the page — the app opens if installed, otherwise the
manual 'Open app' link stays usable (a user tap is the reliable trigger). Applied in
DeepLinkRedirect.tsx, Connection.tsx and the static public/miniapp/redirect.html (which now
also surfaces the manual button immediately instead of after 2s).
This commit is contained in:
c0mrade
2026-06-08 13:11:19 +03:00
parent d37872fd4f
commit 325e221e32
4 changed files with 70 additions and 11 deletions

View File

@@ -148,14 +148,27 @@
const manualBtn = document.getElementById('manualBtn');
manualBtn.href = url;
// Try to open the URL scheme directly
// This page is opened in external browser, so custom schemes work
window.location.href = url;
// Attempt to launch the app WITHOUT a top-level navigation. A direct
// `location.href = scheme` paints a full-page net::ERR_UNKNOWN_URL_SCHEME
// inside Android in-app browsers (Telegram/Yandex/…) and silently fails on
// iOS — hiding the manual button (Telegram bug #654272). A hidden iframe is
// contained: the app opens if installed, otherwise the failure stays inside
// the (invisible) frame and the button below stays usable.
try {
var frame = document.createElement('iframe');
frame.style.display = 'none';
frame.src = url;
document.body.appendChild(frame);
setTimeout(function() {
try { frame.parentNode.removeChild(frame); } catch (e) {}
}, 2000);
} catch (e) {
window.location.href = url;
}
// Show manual button after a delay in case redirect didn't work
setTimeout(function() {
document.getElementById('errorBlock').classList.add('show');
}, 2000);
// Programmatic opening is unreliable in in-app browsers, so surface the
// manual "Open app" button immediately — a user tap is the reliable trigger.
document.getElementById('errorBlock').classList.add('show');
})();
</script>
</body>