diff --git a/public/inapp-browser.js b/public/inapp-browser.js new file mode 100644 index 0000000..7fc7c0b --- /dev/null +++ b/public/inapp-browser.js @@ -0,0 +1,74 @@ +// Detects "in-app browsers" — the webviews Telegram, Facebook, Instagram and +// friends open when you tap a link inside them. +// +// Why this exists: a member taps their sponsor's link in a Telegram chat, +// Telegram opens it in its own webview, and that webview can never hold a +// wallet. The page correctly reported "no wallet in this browser" and the +// member correctly replied that they were using Trust — both true, and +// completely at cross purposes. The instruction to "open your wallet's browser" +// is useless when the reason they are here is that they tapped a link. +// +// So: name the actual browser they are in, and give them the one thing that +// actually helps — the address on their clipboard. +(function () { + 'use strict'; + + function detect() { + var ua = navigator.userAgent || ''; + // Telegram exposes a proxy object in its webview on Android, and the Mini + // App bridge on both. Far more reliable than sniffing its UA, which is a + // plain Chrome string. + if (window.TelegramWebviewProxy || (window.Telegram && window.Telegram.WebApp && !window.ethereum)) return 'Telegram'; + if (/FBAN|FBAV|FB_IAB/i.test(ua)) return 'Facebook'; + if (/Instagram/i.test(ua)) return 'Instagram'; + if (/\bLine\//i.test(ua)) return 'LINE'; + if (/\bMessenger\b/i.test(ua)) return 'Messenger'; + if (/\bTwitter\b/i.test(ua)) return 'X'; + // Generic Android WebView: "; wv)" is the giveaway. Only treat it as an + // in-app browser when no wallet is present, since some wallet browsers are + // themselves WebViews and those are exactly the ones that DO work. + if (/; wv\)/i.test(ua) && !window.ethereum) return 'an in-app browser'; + return null; + } + + window.RMCInApp = { + name: detect, + // Returns HTML for the wallet-error slot, or '' when this is a normal + // browser and the existing "open your wallet's browser" advice is right. + notice: function (pathForWallet) { + var w = detect(); + if (!w) return ''; + var url = 'rmcircle.team' + (pathForWallet || location.pathname); + return 'You’re in ' + w + '’s built-in browser — it can’t hold a wallet, ' + + 'so no wallet app can connect here. That’s why this isn’t working, and it’s not anything you did wrong.' + + '