fix: add Object.hasOwn polyfill for old iOS/Android WebViews

@telegram-apps/sdk v3 depends on valibot which uses Object.hasOwn.
On Safari < 15.4 and old Android WebViews this method is missing,
causing LaunchParamsRetrieveError and broken initData auth.

Ref: https://github.com/Telegram-Mini-Apps/tma.js/issues/683
This commit is contained in:
c0mrade
2026-04-13 14:42:26 +03:00
parent 362a69812f
commit 7b0e6d8bc8

View File

@@ -27,6 +27,16 @@ import { getCachedFullscreenEnabled, isTelegramMobile } from './hooks/useTelegra
import './i18n';
import './styles/globals.css';
// Polyfill Object.hasOwn for older iOS/Android WebViews (Safari < 15.4, old Chrome).
// @telegram-apps/sdk v3 depends on valibot which uses Object.hasOwn internally.
// Without this, init() throws LaunchParamsRetrieveError on affected devices.
// See: https://github.com/Telegram-Mini-Apps/tma.js/issues/683
if (typeof (Object as { hasOwn?: unknown }).hasOwn !== 'function') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Object as any).hasOwn = (obj: object, prop: PropertyKey): boolean =>
Object.prototype.hasOwnProperty.call(obj, prop);
}
// Only initialize Telegram SDK when running inside Telegram
const isTelegramEnv =
!!(window as unknown as Record<string, unknown>).TelegramWebviewProxy ||