Skip to content

fix: dual-compat for WA Web 2.3000.1043xxx ($1 vs _serialized, downloadMedia) - #201840

Open
erickmourasilva wants to merge 2 commits into
wwebjs:mainfrom
erickmourasilva:fix/wa-web-1043-serialized-compat-pr
Open

erickmourasilva wants to merge 2 commits into
wwebjs:mainfrom
erickmourasilva:fix/wa-web-1043-serialized-compat-pr

Conversation

@erickmourasilva

Copy link
Copy Markdown

Summary

  • Add widSerialized() / normalizeSerialized() so WID/MsgKey work with both _serialized (legacy) and $1 (WA Web 2.3000.1043xxx+).
  • Wire helpers into getMessageModel and getChatModel (fixes getChatById / typing crashes with r: r).
  • Dual-read LID/PN in getContactLidAndPhone and Message _patch from/to/author.
  • Use dual message id for downloadMedia / downloadMediaStream.
  • In resolveMediaBlob, fall back to DownloadManager.downloadAndMaybeDecrypt when the in-memory blob is missing or looks thumbnail-sized vs msg.size.

Compatibility

  • Old WA Web: unchanged path via _serialized.
  • New WA Web: falls back to $1 and mirrors onto _serialized for node-side consumers.

Test plan

  • Text receive + send on WA Web before 2.3000.1043xxx
  • Text receive + send on WA Web 2.3000.1043xxx+
  • msg.getChat() / typing indicator does not throw
  • Incoming image: downloadMedia() returns full media (bytes ≈ msg.size, not thumbnail)
  • getContactLidAndPhone still returns lid/pn strings

Closes #201831

Made with Cursor

Keep `_serialized` working for older WhatsApp Web clients and accept
`$1` on newer builds. Normalize models returned to Node, dual-read
LID/PN and message ids, and fall back to DownloadManager when the
in-memory media blob looks incomplete/thumbnail-sized.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added api changes API modifications utility Utility code labels Jul 15, 2026
@kulayRGB

Copy link
Copy Markdown

just heads up that _serialized to $1 rename is causing also msg.react() and msg.reply to fail silently. Adding react and reply fallback in Message.js fixes the issue. These fixes works for me

in async react(reaction)
-- from return this.client.sendReaction(this.id._serialized, reaction); --> to return this.client.sendReaction(this.id._serialized || this.id.$1, reaction);

in async reply()
-- from quotedMessageId: this.id._serialized, --> to quotedMessageId: this.id._serialized || this.id.$1

Lewson added a commit to Lewson/whatsapp-web.js that referenced this pull request Jul 18, 2026
…0.1043xxx)

Adapted from wwebjs upstream PR wwebjs#201840. Fixes media download failing
with opaque 'r: r' error after WhatsApp Web renamed id._serialized to
$1 and started returning thumbnails from mediaBlob.forceToBlob() in
version 2.3000.1043xxx (Jul-2026).

- Utils.js resolveMediaBlob: null-safe cache lookup + forceToBlob guard,
  plus fallback via WAWebDownloadManager.downloadAndMaybeDecrypt when
  the blob cache is empty or looks like a thumbnail.
- Message.js downloadMedia / downloadMediaStream: extract msgId with
  `this.id._serialized ?? this.id.$1` before passing to evaluate.
@github-actions

Copy link
Copy Markdown
Contributor

Marking this pull request as stale due to inactivity. Push changes or comment to keep it open. It will be closed in 7 days otherwise. Thank you for your contributions.

@github-actions github-actions Bot added the stale Inactive for a while label Aug 21, 2026
soltialabs pushed a commit to gperdomosoltia/mensajeria-masiva that referenced this pull request Sep 9, 2026
…ed vs $1)

The retry from the previous commit didn't help: logs showed every single
voice-note download failing all 3 attempts, while text messages in the same
window replied fine - not a transient navigation race.

Root cause: WhatsApp Web >= 2.3000.1043xxx exposes message ids as `$1`
instead of `_serialized` for @lid senders (WhatsApp's rollout of ids that
hide the real phone number - visible in our logs as "...@lid"). whatsapp-web.js's
Message.downloadMedia() still reads only `_serialized`, so it passes `undefined`
into the page, `Msg.get(undefined)` blows up inside WhatsApp Web's minified
bundle, and it surfaces here as the cryptic "r: r" error. Confirmed against
upstream issue wwebjs/whatsapp-web.js#201856 (open) - identical stack trace
reported by another user - with a fix in wwebjs/whatsapp-web.js#201840, which
is unmerged and not in any published npm release yet.

Added helper/downloadMediaCompat.js: a reimplementation of downloadMedia()
identical to upstream except it resolves the message id as
`this.id._serialized ?? this.id.$1`. Patching node_modules directly wasn't
viable - this Dockerfile runs `npm install` before `COPY . .`, so a
patch-package patch wouldn't exist yet when postinstall runs. Kept the
retryAsync wrapper around it as cheap defense-in-depth for an actual
navigation race, though it should no longer be needed for this specific bug.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Eonus added a commit to Eonus21/whatsapp-web.js that referenced this pull request Sep 24, 2026
fix(wa-2.3000): concurrent-inject guard + dual-compat serialized ids (wwebjs#201893 + wwebjs#201840)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api changes API modifications stale Inactive for a while utility Utility code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error con pupeter

3 participants