Skip to content

fix(Utils): resolve getChats() CDP 'r: r' on WhatsApp Web 2.3000.x ($1 rename + fault-isolated getChatModel) - #201910

Open
cripperzprodigy wants to merge 1 commit into
wwebjs:mainfrom
cripperzprodigy:fix/getchats-r-r-2.3000x
Open

cripperzprodigy wants to merge 1 commit into
wwebjs:mainfrom
cripperzprodigy:fix/getchats-r-r-2.3000x

Conversation

@cripperzprodigy

Copy link
Copy Markdown

Problem Description

On WhatsApp Web 2.3000.x (e.g. 2.3000.1046738589), calling client.getChats() consistently throws a minified CDP evaluation error:

Evaluation failed: r: r
    at Client.getChats (Client.js:1669:23)

Root Causes

  1. Property Rename (_serialized → $1): WhatsApp Web's minified bundler renamed internal WID and key object serialization properties from _serialized to $1. In src/util/Injected/Utils.js, calls like .createWid(chat.id._serialized) pass undefined, throwing minified r: r exceptions inside #evaluate.
  2. Promise.all Fail-Fast Trap: window.WWebJS.getChats and window.WWebJS.getChannels map all chats through getChatModel() inside an unprotected Promise.all. If an account is in multiple groups/channels and ANY single chat throws (e.g. stale group metadata, kicked from group, LID migration glitch in toPn, or revoked newsletter), the entire getChats() batch rejects.

Proposed Changes

  1. _serialized || $1 Fallbacks:
    Added fallback lookups across all 9 direct crash sites in Injected/Utils.js (e.g., chat.id._serialized || chat.id.$1).

  2. __ensureSerializedIds Model Normalizer:
    Hooked a normalizer into getMessageModel, getChatModel, and getContactModel ensuring that models returned across the CDP boundary into Node.js always guarantee id._serialized.

  3. __getChatModelSafe Fault-Tolerant Resolver:

    • Routes getChats() and getChannels() through __getChatModelSafe: if metadata enrichment fails for an individual group or channel, it falls back to basic chat serialization (chat.serialize()) instead of rejecting the whole batch.
    • Wrapped groupMetadata.update() and newsletterMetadata.update() in try/catch error boundaries.
    • Filtered unresolvable entries with results.filter(Boolean).

Verification

  • Validated with automated unit tests including vm-sandbox simulation of throwing group metadata and unmigrated LID participants.
  • Verified in live production on an active account with 2,560 contacts and multiple groups on WhatsApp Web 2.3000.1046738589 — getChats() successfully recovers offline message history without errors.

- WhatsApp Web 2.3000.x renamed internal ID property `_serialized` to `$1`
- Add `_serialized || $1` fallback chains across 9 crash sites in Injected/Utils.js
- Add `__ensureSerializedIds` normalizer to ensure models returned across CDP guarantee `_serialized`
- Add `__getChatModelSafe` fault-isolated chat resolution so one malformed/stale chat or revoked newsletter cannot fail the entire `getChats()`/`getChannels()` Promise.all batch
- Wrap `groupMetadata.update()` and `newsletterMetadata.update()` in try/catch error boundaries
@github-actions github-actions Bot added api changes API modifications utility Utility code labels Sep 3, 2026
@Furqanameen

Copy link
Copy Markdown

Is there anybody who has done it to get older messages smooth as it has been doing on the web?
I am stuck to get this feature to make it same way and then do my customization.

@emrecirik

Copy link
Copy Markdown

Confirmed on WhatsApp Web 2.3000.1047868043 (whatsapp-web.js 1.34.7, puppeteer 24.38.0, Chrome, Node 22).

For the record, the underlying page-side error behind the minified r: r is:

DataError: Failed to execute 'get' on 'IDBObjectStore': No key or key range specified.

i.e. an undefined key (the missing _serialized) reaching IndexedDB. chat.fetchMessages() fails identically (#201884 looks like the same root cause). Restoring _serialized makes getChats() return all 344 chats and fetchMessages() work again.

One robustness note on the $1 fallback: that name is a minified, build-specific symbol and will change on the next rename. Resolving it by value rather than by name has survived every build I've tested:

for (const value of Object.values(key)) {
    if (typeof value === 'string' && /^(true|false)_/.test(value)) return value;
}

(as a last resort after _serialized and before the user@server reconstruction).

raqueri1970-sketch pushed a commit to raqueri1970-sketch/sistema-de-auditoria that referenced this pull request Oct 15, 2026
… "r: r"

- Rebuild trouxe o Chromium 154 do Debian e converteu o perfil do WhatsApp; fixado o Chrome 146.0.7680.31
  (o que rodava até 15/10 e o mesmo do D90).
- WhatsApp Web 2.3000.x renomeou _serialized para $1: toda mensagem falhava com "r: r". Aplicada a correção
  da PR wwebjs/whatsapp-web.js#201910 sobre a 1.34.7 (agora fixa no package.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017yLm1GdRee1EUUWwHLXtUM

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 utility Utility code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants