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
514 stars 117 forks source link

[Bug]: `useCloudStorage` seems to be not working in Web clients #273

Closed thecoorum closed 4 months ago

thecoorum commented 4 months ago

Telegram Application

Telegram Web A, Telegram Web K

Describe the Bug

Using await cloudStorage.get(...) will do nothing and not throw any error in try catch block despite that cloudStorage.supports("get") returns true

To Reproduce

Steps to reproduce the behavior:

  1. Implement method using cloud storage
  2. Open component/page using this method and try to fetch cloud storage data
  3. See no data in variable which awaits the result and no error in catch block

Expected Behavior

Data is fetched successfully

heyqbnk commented 4 months ago

I have tried to reproduce it using the reactjs-template but was still unable to do it. Do you have and reproducible example? Also check if you are using the latest @tma.js versions

thecoorum commented 4 months ago

Hey @heyqbnk! Sorry, was not touching the laptop during the weekend. Will try to reproduce with starters today

thecoorum commented 4 months ago

Okay, I was able to reproduce the issue here https://github.com/thecoorum/tma-cloud-storage-web-issue. And here is the Mini App to test it out https://t.me/tma_cloud_storage_web_issue_bot/app

heyqbnk commented 4 months ago

For some reason, this project works fine for me. Could you try using different devices or maybe even networks? I tried to reproduce the problem using both your application and repository, launching it on myself. None of it showed the problem.

image

thecoorum commented 4 months ago
Ah, okay. Seems like I was testing it against outdated web client. Are there any difference between webk.telegram.org and web.telegram.org? I thought both are using K web client by default, but seems they are different. Here are the app window from both of them. You could also notice that the main button is not initializing in the webk.telegram.org. I think then the issue is resolved by itself. Anyway, thanks for looking into this one so quickly web.telegram.org webk.telegram.org
image image
heyqbnk commented 4 months ago

I assume, this is the problem on the webk.telegram.org side. To be honest, it is the first time I hear about this version of Telegram. As far as I know, Web K version is placed on the web.telegram.org/k URL. I am not sure, but @tma.js will probably not work outside of web.telegram.org by default due to security reasons. It just restricts the list of parent iframe URLs which are capable of processing Telegram Mini Apps methods.

You can learn more about this mechanism in the docs: https://docs.telegram-mini-apps.com/packages/tma-js-sdk/methods-and-events#target-origin

To try to solve the issue, just try calling something like:

import { setTargetOrigin } from '@tma.js/sdk';

setTargetOrigin('https://webk.telegram.org');

I am not sure this will help, but we could give it a try