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:
- Solution must be fully contained in a Chrome extension (no external servers)
- Cannot bundle Telegram web source files or external libraries (ie. gramjs, mtproto, mqtt, etc)
- Must work on
web.telegram.org/a(version A), not version K or others - Must send photos specifically (not videos, gifs, docs, or other file types)
- 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.
- Features
- Installation
- Usage
- How It Works
- File Structure
- Development
- Privacy & Security
- License
- Tips
- Troubleshooting
- 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
- 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
- Clone or download this repository
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" in the top right
- Click "Load unpacked" and select the extension directory
- Navigate to web.telegram.org/a
-
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
-
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"
-
Deinitialize (Optional)
- Click "Deinitialize Extension" to remove the cache patch
- Reload the page to restore original functionality
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);The extension consists of several components working together:
-
Content Script (
content.js)- Injects scripts into the Telegram Web page context
- Bridges communication between popup and page context
- Manages initialization and deinitialization
-
Telegram Integration (
inject.js)- Accesses Telegram's webpack modules
- Extracts internal actions and state management functions
- Exposes
sendDisappearingPhoto()API
-
Cache Patcher (
cache-patcher.js)- Patches the cached service worker code
- Adds
ttlSecondsparameter toInputMediaUploadedPhotoAPI calls - Persists patch across sessions using localStorage
-
Send Helper (
send-helper.js)- Handles photo sending requests from the popup
- Converts URLs to blobs
- Calls the
sendDisappearingPhoto()function
-
Popup UI (
popup.html,popup.js)- User-friendly interface for initialization and sending
- Status monitoring and feedback
- Quick TTL selection options
The extension works by:
- Webpack Module Discovery: Searches through Telegram's webpack modules to find the state management module
- Action Extraction: Extracts
getActions(),getGlobal(), andsetGlobal()functions - Cache Patching: Modifies the cached service worker to include
ttlSecondsin photo uploads - Message Sending: Uses Telegram's internal
sendMessageaction with custom attachment parameters
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.
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
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 logsTo reset the extension and re-patch:
// In browser console on Telegram Web
localStorage.removeItem('telegram_worker_patched');
// Then reload the page and reinitialize- 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
This project is provided as-is for educational purposes only.
- Check browser console for detailed logs if something goes wrong
- Reinitialize after clearing browser cache
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