Skip to content

feat: support big file downloads (read from WA cache + streaming)#201697

Open
Adi1231234 wants to merge 2 commits intowwebjs:mainfrom
Adi1231234:feat/support-big-file-downloads
Open

feat: support big file downloads (read from WA cache + streaming)#201697
Adi1231234 wants to merge 2 commits intowwebjs:mainfrom
Adi1231234:feat/support-big-file-downloads

Conversation

@Adi1231234
Copy link
Copy Markdown
Contributor

@Adi1231234 Adi1231234 commented Apr 6, 2026

Description

downloadMedia re-downloads and decrypts media from WhatsApp's CDN on every call, even though the data is already sitting decrypted in the browser's memory. It also loads the entire file into a single base64 string, so a 25MB PDF becomes ~33MB in one allocation with no way to process it in chunks.

This PR fixes both problems:

Read from WhatsApp's own caches instead of re-downloading

When WhatsApp Web resolves a media message, it stores the result in InMemoryMediaBlobCache (250MB LRU pool, no per-file limit) and mediaObject.mediaBlob. This PR reads directly from those caches instead of going through downloadAndMaybeDecrypt and the CDN. For the mediaBlob path, OpaqueData.forceToBlob() returns the internal Blob directly without copying.

Add downloadMediaStream() for large files

Returns a Node.js Readable stream that reads the Blob in chunks via evaluateHandle + blob.slice(), so the full file never sits in Node.js memory at once. Chunk size defaults to 10MB and is configurable.

The cache-reading logic is extracted into a shared window.WWebJS.resolveMediaBlob(msgId) utility used by both methods.

Other changes: added *.d.ts to .eslintignore, added TypeScript interfaces for the new API, added !streamdownload example command, fixed downloadMedia return type to include | undefined.

Testing Summary

Test Details

Tested with images, videos, documents and audio messages across multiple accounts. Verified that cached media is read correctly and that streaming works for files up to 924MB. Confirmed forceToBlob() returns the internal Blob without copying via memory profiling.

Environment

  • Machine OS: Windows 11
  • Phone OS: Android 14
  • Library Version: 1.34.6
  • WhatsApp Web Version: 2.3000.1036713926
  • Browser Type and Version: Chromium 138.0.7204.251
  • Node Version: 22.20.0

Type of Change

  • Dependency change (package changes such as removals, upgrades, or additions)
  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-code change (documentation, README, etc.)

Checklist

  • My code follows the style guidelines of this project.
  • All new and existing tests pass (npm test).
  • Typings (e.g. index.d.ts) have been updated if necessary.
  • Usage examples (e.g. example.js) / documentation have been updated if applicable.

@github-actions github-actions bot added api changes API modifications typings Type definitions build Build system utility Utility code labels Apr 6, 2026
@Adi1231234 Adi1231234 force-pushed the feat/support-big-file-downloads branch from a456c06 to c22720f Compare April 6, 2026 13:53
@BenyFilho BenyFilho added the waiting for testers Needs testing label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications build Build system typings Type definitions utility Utility code waiting for testers Needs testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants