pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.53k stars 3.7k forks source link

TypeError: Cannot read properties of undefined (reading 'pupPage') #3241

Closed leonardosantosdev closed 1 month ago

leonardosantosdev commented 3 months ago

Is there an existing issue for this?

Describe the bug

Every time i call a Message method using chat.lastMessage, this error occurs: TypeError: Cannot read properties of undefined (reading 'pupPage')

I tried Message.downloadMedia() and Message.getInfo(). both returned the same error.

async getInfo() {
        // whenever the function needs to access this.client.pupPage
        const info = await this.client.pupPage.evaluate(async (msgId) => { 
            const msg = window.Store.Msg.get(msgId);
            if (!msg || !msg.id.fromMe) return null;

            return new Promise((resolve) => {
                setTimeout(async () => {
                    resolve(await window.Store.getMsgInfo(msg.id));
                }, (Date.now() - msg.t * 1000 < 1250) && Math.floor(Math.random() * (1200 - 1100 + 1)) + 1100 || 0);
            });
        }, this.id._serialized);

        return info;
    }

But if i call any Message method after a chat.fetchMessages(), i have zero problems.

Is there something am i missing?

Expected behavior

A regular and correct return of media contend and/or message info

Steps to Reproduce the Bug or Issue

const client = new Client({
  authStrategy: new LocalAuth(),
});

client.on("qr", (qr) => {
  qrcode.generate(qr, { small: true });
});

const chats = await client.getChats();

const messageInfo = await chats[0].lastMessage.getInfo();

Relevant Code

No response

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Windows 10 whatsapp-web.js v1.25.0

Additional context

No response