fix(ui): route external links out of the Android VK WebView
The Android VK client's WebView ignores target=_blank and navigates the Mini App's own window to the target, stranding the player outside the game with no way back (the dictionary lookup, About/Feedback links, the ad banner and the bot-link modal fallbacks). vk-bridge 3.x has no method to open an external URL, so external links are routed through VK's own leave-VK redirect (vk.com/away.php), which the client intercepts natively and hands to the system browser. onExternalLinkClick moves from lib/telegram to a new lib/links that composes the Telegram and VK routers; iOS and desktop VK open _blank correctly and are left alone.
This commit is contained in:
+3
-14
@@ -179,9 +179,10 @@ export function telegramOpenExternalLink(url: string): boolean {
|
||||
/**
|
||||
* isExternalHttpUrl reports whether href is an absolute http(s) URL on a different origin than the
|
||||
* app — so a same-origin or root-relative in-app (SPA) link is left to normal navigation, only a
|
||||
* genuinely external link is routed through Telegram's browser.
|
||||
* genuinely external link is routed through the host platform's browser (the Telegram router here
|
||||
* and the VK router in vk.ts share it).
|
||||
*/
|
||||
function isExternalHttpUrl(href: string): boolean {
|
||||
export function isExternalHttpUrl(href: string): boolean {
|
||||
try {
|
||||
const u = new URL(href, typeof location === 'undefined' ? undefined : location.href);
|
||||
if (u.protocol !== 'http:' && u.protocol !== 'https:') return false;
|
||||
@@ -206,18 +207,6 @@ export function routeExternalLinkInTelegram(anchor: { href: string; target: stri
|
||||
return telegramOpenExternalLink(anchor.href);
|
||||
}
|
||||
|
||||
/**
|
||||
* onExternalLinkClick is the anchor click handler that applies routeExternalLinkInTelegram. It
|
||||
* resolves the clicked anchor with closest(), so it works both attached directly on an <a> and
|
||||
* delegated on a container that renders links (e.g. {@html} markdown). Attach it as onclick on an
|
||||
* external link or its container; outside Telegram it is a no-op and the anchor's own
|
||||
* target=_blank handles the click.
|
||||
*/
|
||||
export function onExternalLinkClick(e: MouseEvent): void {
|
||||
const a = (e.target as HTMLElement | null)?.closest('a');
|
||||
if (a && routeExternalLinkInTelegram(a)) e.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* shareTelegramLink opens Telegram's native "share to a chat" picker for url with a
|
||||
* caption, through the Mini App SDK (https://t.me/share/url). Returns false outside
|
||||
|
||||
Reference in New Issue
Block a user