Skip to content

Repository files navigation

Telegram Disappearing Photos Extension

A Chrome extension that enables sending disappearing (self-destructing) photos on Telegram Web, a feature normally only available on mobile apps.

Caution

This is an educational project demonstrating Chrome extension development and reverse engineering techniques.

Important Notes:

  • This extension is not affiliated with, endorsed by, or officially supported by Telegram
  • This project modifies Telegram Web's behavior in ways not officially documented
  • For educational purposes only

Note

This project was developed as part of an assignment with the following constraints:

  1. Solution must be fully contained in a Chrome extension (no external servers)
  2. Cannot bundle Telegram web source files or external libraries (ie. gramjs, mtproto, mqtt, etc)
  3. Must work on web.telegram.org/a (version A), not version K or others
  4. Must send photos specifically (not videos, gifs, docs, or other file types)
  5. Must be able to send photos programmatically (not require manual UI interaction)

The exact assignment submission code can be found in the assignment branch. The main branch includes an additional UI component (Extension Popup) for ease of use, but it internally uses the same programmatic JavaScript API that fulfills the assignment requirements.

Table of Contents

Features

Core Functionality

  • Send Disappearing Photos: Send self-destructing photos that automatically delete after being viewed
  • Customizable TTL: Set time-to-live from 1 to 60 seconds
  • URL-based Sending: Send photos directly from any URL
  • Programmatic API: Access via JavaScript API for automation

Technical Features

  • Cache Patching: Automatically patches Telegram's service worker to enable disappearing photo support
  • Webpack Module Integration: Seamlessly integrates with Telegram's internal state management
  • Non-invasive: No bundled libraries or external dependencies
  • Clean Architecture: Modular design with separate concerns for patching, sending, and UI

Installation

  1. Clone or download this repository
  2. Open Chrome and navigate to chrome://extensions/
  3. Enable "Developer mode" in the top right
  4. Click "Load unpacked" and select the extension directory
  5. Navigate to web.telegram.org/a

Usage

Via Extension Popup

  1. Initialize the Extension

    • Click the extension icon in your browser toolbar
    • Click "Initialize Extension" button
    • Reload the Telegram Web page when prompted
    • The extension will patch the service worker cache to enable disappearing photos
  2. Send a Disappearing Photo

    • Open any chat on Telegram Web
    • Click the extension icon
    • Enter a photo URL (e.g., https://picsum.photos/800/600)
    • Select a TTL (Time To Live) using quick options or enter custom seconds (1-60)
    • Click "Send Disappearing Photo"
  3. Deinitialize (Optional)

    • Click "Deinitialize Extension" to remove the cache patch
    • Reload the page to restore original functionality

Via JavaScript API

Once initialized, you can programmatically send disappearing photos using the browser console:

// Send a disappearing photo with 10 second TTL
await sendDisappearingPhoto(blob, 10);

// Example: Fetch and send an image
const response = await fetch('https://picsum.photos/800/600');
const blob = await response.blob();
await sendDisappearingPhoto(blob, 30);

How It Works

Architecture Overview

The extension consists of several components working together:

  1. Content Script (content.js)

    • Injects scripts into the Telegram Web page context
    • Bridges communication between popup and page context
    • Manages initialization and deinitialization
  2. Telegram Integration (inject.js)

    • Accesses Telegram's webpack modules
    • Extracts internal actions and state management functions
    • Exposes sendDisappearingPhoto() API
  3. Cache Patcher (cache-patcher.js)

    • Patches the cached service worker code
    • Adds ttlSeconds parameter to InputMediaUploadedPhoto API calls
    • Persists patch across sessions using localStorage
  4. Send Helper (send-helper.js)

    • Handles photo sending requests from the popup
    • Converts URLs to blobs
    • Calls the sendDisappearingPhoto() function
  5. Popup UI (popup.html, popup.js)

    • User-friendly interface for initialization and sending
    • Status monitoring and feedback
    • Quick TTL selection options

Technical Implementation

The extension works by:

  1. Webpack Module Discovery: Searches through Telegram's webpack modules to find the state management module
  2. Action Extraction: Extracts getActions(), getGlobal(), and setGlobal() functions
  3. Cache Patching: Modifies the cached service worker to include ttlSeconds in photo uploads
  4. Message Sending: Uses Telegram's internal sendMessage action with custom attachment parameters

Key Innovation

The extension patches this code pattern in the service worker:

// Before (original)
new InputMediaUploadedPhoto({file:_, spoiler:l})

// After (patched)
new InputMediaUploadedPhoto({file:_, spoiler:l, ttlSeconds:f})

This enables the ttlSeconds parameter to be passed through to Telegram's API, enabling disappearing photos.

File Structure

telegram-web-disappearing-photos/
├── manifest.json           # Extension configuration
├── popup.html             # Extension popup UI
├── popup.js               # Popup logic and event handlers
├── content.js             # Content script (bridge)
├── inject.js              # Telegram integration (page context)
├── cache-patcher.js       # Service worker cache patcher
├── send-helper.js         # Photo sending helper
├── deinit-helper.js       # Deinitialization helper
├── background.js          # Background service worker
└── README.md              # This file

Development

Debugging

Enable console logging to see detailed information:

// All extension logs are prefixed with:
[Disappearing Photos]  // Main extension logs
[Cache Patch]          // Cache patching logs
[Send Helper]          // Photo sending logs

Reset Extension State

To reset the extension and re-patch:

// In browser console on Telegram Web
localStorage.removeItem('telegram_worker_patched');
// Then reload the page and reinitialize

Privacy & Security

  • No Data Collection: The extension does not collect or transmit any user data
  • Local Processing: All operations happen locally in your browser
  • No External Dependencies: No third-party libraries or external API calls
  • Open Source: All code is visible and auditable

License

This project is provided as-is for educational purposes only.

Tips

  • Check browser console for detailed logs if something goes wrong
  • Reinitialize after clearing browser cache

Troubleshooting

Extension not working after installation:

  • Make sure you're on web.telegram.org/a (not /k)
  • Click "Initialize Extension" and reload the page
  • Check browser console for error messages

"Please reload Telegram Web page" error:

  • Hard refresh the page (Ctrl+Shift+R or Cmd+Shift+R)
  • Reinitialize the extension

Photos not sending:

  • Ensure you have a chat open
  • Verify the extension is initialized (check status in popup)
  • Check that the image URL is accessible
  • Try a different image URL

Cache patch not persisting:

  • Don't clear browser cache while using the extension
  • Reinitialize if you clear cache or restart browser

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages