npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

miku-web-app

v6.7.0

Published

A npm module for Telegram Web App

Downloads

319

Readme

build npm cdnjs minified size license

miku-web-app

A npm module for Telegram Web App to prevent the pollution of the global scope.

Table of Contents

General Information

You can find docs on Telegram official website

This website features several demos of the WebApp, as well as update records and API documentation.

Setup

Using npm

$ npm i miku-web-app

Using CDN

If you prefer not to install the npm module, you can also use a CDN. Depending on your project's requirements, you can choose either the CJS (CommonJS) or MJS (ES Module) format:

CJS (CommonJS) Format

<script src="https://unpkg.com/miku-web-app@latest/dist/telegram.min.js"></script>

When using the CJS format, miku-web-app will be automatically added to the global scope.

MJS (ES Module) Format

<script type="module">
  import Telegram from 'https://unpkg.com/miku-web-app@latest/dist/telegram.min.mjs';
</script>

This method is suitable for projects using ES modules, allowing you to import the module directly in a <script type="module"> block without relying on window.

Usage

// destructured import
import { WebView, Utils, Game, WebApp } from 'miku-web-app'
// import all exported members
import * as Telegram from 'miku-web-app'
// import default export
import Telegram from 'miku-web-app'

For the WebApp to initialize correctly, it is important to import miku-web-app before vue-router. This is because vue-router's hash mode will change the location.hash value, which can cause the WebApp to fail to initialize. If you are not using hash mode, you do not need to worry about this import order.

// main.js
import 'miku-web-app' // add this line
import router from '@/router'
import App from './App.vue'

To ensure the WebApp is initialized correctly, include a call to ready() once the page has finished loading. For example, in a Vue project you can do this in the onMounted() hook, like this:

// App.vue
<script setup lang="ts">
import { onMounted } from 'vue'
import { WebApp } from 'miku-web-app'

onMounted(() => WebApp.ready())
</script>

There are some functions (e.g. WebApp.MainButton.onClick()) that may not be triggered on some platforms. In this case, you can try adding the following code to your application:

// For Windows Phone app
window.TelegramGameProxy_receiveEvent = Telegram.Game.Proxy_receiveEvent
// App backward compatibility
window.TelegramGameProxy = Telegram.Game.Proxy

If you want to use all of the objects in the global scope, you can add the following code:

window.Telegram = {
  Utils: Telegram.Utils,
  WebView: Telegram.WebView,
  WebApp: Telegram.WebApp
}
window.TelegramWebviewProxy = Telegram.WebView.Proxy

FAQ

1. Why does Telegram Desktop WebApp not work on some website (e.g. Vite)?

The browser used by Telegram WebView depends on your computer's OS:

  • Windows 8.1-10: EdgeHtml
  • Windows 11: EdgeChromium
  • macOS: Cocoa WebKit
  • Linux: WebKitGTK

By default, Telegram uses Edge Legacy in Windows 8.1-10. This older version of the browser is unable to support newer versions ECMAScript.

There are two ways to fix this problem:

If you choose to install Microsoft Edge WebView2, it is important to also let your users know to update their browsers. Telegram will attempt to use Chromium Edge on all Windows versions, and if it can't find a Chromium version, it will fall back to Edge Legacy.

If you don't have Microsoft Edge WebView2 installed, you may not be able to launch DevTools with right-click in Edge Legacy's WebView. As a consequence, debugging becomes extremely difficult.

This information via tdesktop/issues

2. Telegram.WebApp.sendData not working?

This method is only available for Web Apps launched via a Keyboard button (below the input box) not an inline keyboard button (under bot messages).

The solution can also be found on Stack Overflow.

Contact

Created by @miku3920. Feel free to contact me if you have any questions or run into any issues!