Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: TypeError: undefined is not an object (evaluating 'window.TelegramGameProxy.receiveEvent') #664

Open
destyk opened this issue Feb 15, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@destyk
Copy link

destyk commented Feb 15, 2025

Telegram Application

Telegram for iOS

Describe the Bug

A TypeError occurs when load page on iOS devices using Mobile Safari UI/WKWebView via InlineKeyboard. The error message indicates that undefined is not an object (evaluating 'window.TelegramGameProxy.receiveEvent').
TypeError undefined is not an object (evaluating 'window.TelegramGameProxy.receiveEvent')

Solutions from #418 and #342 are not available in version 3, as method subscribe is no longer available.

Environment

  • Browser: Mobile Safari UI/WKWebView
  • Device: iPhone
  • OS: iOS 18.2.1

telegram-apps version
"@telegram-apps/sdk-react": "^3.0.7",

To Reproduce

Steps to reproduce the behavior:

  • Open Mobile Safari on an iPhone with iOS 18.2.1.
  • Observe the error message in the console.

Expected Behavior

The page should load without errors and the window.TelegramGameProxy.receiveEvent should be defined.

@destyk destyk added the bug Something isn't working label Feb 15, 2025
@destyk
Copy link
Author

destyk commented Feb 15, 2025

Possible solution:

import { on } from "@telegram-apps/sdk-react"

on('*', () => console.log('All events initialized'), true)

But I do not know how correct it is and whether it will work correctly.

UPD: This solution does not work.

@heyqbnk
Copy link
Member

heyqbnk commented Feb 19, 2025

Unfortunately, the problem solution is out of bounds of the current library. It seems, that the problem is the Telegram client for iOS focuses on the Telegram SDK, not the current package, and expects this field (window.TelegramGameProxy.receiveEvent) to defined initially.

To solve the problem, it is required to do the following:

  1. Create an issue in this client to prevent such kind of behavior. They should check if window.TelegramGameProxy.receiveEvent is even defined, before calling it.
  2. Define a <script/> tag in the <head/> with the following content:
window.TelegramGameProxy = { receiveEvent: function() {} };

Note that this script must be specified before the main bundle, where the SDK's init function is called. Otherwise, you may break Mini Apps event's handling.

Your solution does not work as long as your bundle is loaded asynchronously and the code inside your bundle will most likely be called after the code, inserted by the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants