Telegram-Mini-Apps / telegram-apps

Made from scratch TypeScript packages, examples and documentation you will surely need to start developing on Telegram Mini Apps.
https://docs.telegram-mini-apps.com/
MIT License
693 stars 192 forks source link

[Bug]: open https link in mini app with inner safari browser #496

Closed jianbinking closed 3 weeks ago

jianbinking commented 1 month ago

Telegram Application

Telegram for iOS

Describe the Bug

as a telegram mini app developer, I'm going to open a https link e.g. https://www.google.com/ but I will get jump into safari app and open this link, NOT open it in the telegram's inner safari browser I have tried these functions blow, none of them works, can anyone who have the same issue and found any solutions?

const url = "https://www.google.com"

// 1. tried with telegram sdk
import {initUtils} from "@telegram-apps/sdk-react";
const utils = initUtils()
utils.openLink(url, {
            tryInstantView: true,
            tryBrowser: true
        })

// 2. tried with telegram post event
        const data = JSON.stringify({
            url,
            try_instant_view: true
        });
        window.TelegramWebviewProxy.postEvent('web_app_open_link', data);

// 3. tried with js methods
window.open(url, "_blank")

if use "_self" or "_parent", the website will open in the mini app's current page, which is not I want

To Reproduce

Steps to reproduce the behavior:

  1. open any https links in mini app

Expected Behavior

open the page in the inner safari browser instead of safari app

heyqbnk commented 1 month ago

tryBrowser is undocumented by Telegram, so we can't rely on this parameter. You also should specify not true, but the browser identifier.

Try using tryBrowser: 'safari'. Until then, I don't know any other possible way of avoid opening the link outside the Telegram application. I don't think there is any

jianbinking commented 1 month ago

thanks @heyqbnk for your reply ~ I'm using the react version SDK "@telegram-apps/sdk-react": "^1.1.3", as you says, I tried to set the tryBrowser to safari, it no works

then I tried install the js version SDK and tried like this:

import { openLink } from '@telegram-apps/sdk';

openLink('https://telegram.org', {
  tryBrowser: 'chrome',
  tryInstantView: true,
});

but 1. try tryBrowser has no param 'safari', even I set the tryBrowser to 'safari' it still open the link in the safari app, NOT the inner safari browser

I found that the ton wallet tg mini app can open the explorer url in the inner safari browser, after check the their html code, they are using:

<a target="_blank" href="https://tonviewer.com/transaction/0b416d1c4dbb9c045063bc661c141faef9c1d26040c7a093737c0152b428c301" rel="noreferrer noopener">在区块链浏览器中查看</a>

however, as I tried to add this to my demo mini app, the page still open in the safari app, not inner safari quite amazing

heyqbnk commented 1 month ago

Wait. Do you want to open the link in the internal Telegram browser or in the external one?

jianbinking commented 1 month ago

I want to open the link in the internal Telegram browser coz the link is a website dapp, can connect with other mini tg wallet apps

import {initUtils} from "@telegram-apps/sdk-react";
const utils = initUtils()
utils.openLink(url, {
    tryInstantView: true,
    tryBrowser: true
})

above code works well on android side, but on iOS side it can not open the link in the internal Telegram browser

heyqbnk commented 1 month ago

I am not sure I can really help with this question. The problem is probably on the Telegram for iOS side. They should probably improve the openLink method to choose how to open the link exactly

heyqbnk commented 3 weeks ago

Closing due to we have nothing to do here. Just waiting for this feature to be implemented by the Telegram devs