Skip to content

Message.downloadMedia() throws opaque r: r for all incoming media #201833

Description

@LC-Duarte

Issue Priority

High (immediate attention needed)

Issue Description

Message.downloadMedia() throws an opaque r: r error for every incoming media message. This reproduces with directly sent and forwarded images and PDF documents.

The client remains connected and receives text messages normally. The failure is isolated to media download. Without a try/catch around msg.downloadMedia(), the rejected promise reaches triggerUncaughtException and terminates the Node.js process. Catching it prevents the crash but leaves the message without media data.

Observed stack:

node:internal/process/promises:391
    triggerUncaughtException(err, true /* fromPromise */);
    ^

r: r
    at #evaluate (.../puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)
    at async ExecutionContext.evaluate (.../ExecutionContext.js:277:16)
    at async IsolatedWorld.evaluate (.../IsolatedWorld.js:100:16)
    at async CdpFrame.evaluate (.../api/Frame.js:362:20)
    at async CdpPage.evaluate (.../api/Page.js:830:20)
    at async Message.downloadMedia (.../whatsapp-web.js/src/structures/Message.js:518:24)

This started suddenly after working earlier on the same day, with no application or dependency update. The same application code and lockfile had previously downloaded forwarded media successfully.

I also tested a strict archived WhatsApp Web snapshot to rule out a local-cache fallback:

  • Live version observed: 2.3000.1043163628
  • Strict remote snapshot: 2.3000.1043159177-alpha
  • webVersionCache: remote with strict: true

The client connected successfully with the archived snapshot, but downloadMedia() failed in the same way. Recreating the Docker containers, deleting the LocalAuth session, scanning a new QR code, and testing direct/forwarded image/PDF messages did not change the result.

Steps To Reproduce

  1. Initialize a client using LocalAuth and Chromium.
  2. Wait for the ready event.
  3. Send an image or PDF to the connected account, either directly or by forwarding it.
  4. In the message handler, check msg.hasMedia and call await msg.downloadMedia().
  5. Observe Puppeteer's ExecutionContext.evaluate reject with the opaque error r: r.
  6. If the call is not caught, Node.js terminates through triggerUncaughtException.

Code Sample

const { Client, LocalAuth } = require('whatsapp-web.js');

const client = new Client({
    authStrategy: new LocalAuth({ dataPath: './session' }),
    puppeteer: {
        headless: true,
        executablePath: '/usr/bin/chromium-browser',
        args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
    },
});

client.on('message', async (msg) => {
    if (!msg.hasMedia) return;

    const media = await msg.downloadMedia();
    console.log(media?.mimetype, media?.data?.length);
});

client.initialize();

Environment

  • WhatsApp Account Type: unavailable at report time
  • Authentication Strategy: LocalAuth
  • whatsapp-web.js Version: 1.34.7
  • WhatsApp Web Version: 2.3000.1043163628; also reproduced with strict archived 2.3000.1043159177-alpha
  • Browser Type: Chromium
  • Browser Version: 149.0.7827.53
  • Computer OS Version: Alpine Linux 3.23.4, Docker Linux ARM64
  • Phone OS Version: unavailable at report time
  • Node.js Version: 20.20.2

Checklist

  • I use the latest released version of whatsapp-web.js.
  • I searched open issues for downloadMedia, downloadAndMaybeDecrypt, media download, and the opaque r error and found no clear duplicate.
  • I verified the failure originates inside Message.downloadMedia() / Puppeteer page evaluation, not in downstream application handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions