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
14.53k stars 3.46k forks source link

const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1]; #2799

Closed keinou closed 4 months ago

keinou commented 4 months ago

Is there an existing issue for this?

Describe the bug

When client logged and bot was restarted, i receive this error:

/app/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34
        const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
                                                                    ^
TypeError: Cannot read properties of null (reading '1')
    at LocalWebCache.persist (/app/node_modules/whatsapp-web.js/src/webCache/LocalWebCache.js:34:69)
    at /app/node_modules/whatsapp-web.js/src/Client.js:771:36
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.11.1

Here is the client html. html.zip

Expected behavior

The initialize finish without errors.

Steps to Reproduce the Bug or Issue

I'm not sure what the mandatory steps are for this problem, as I only have one cell phone with this problem.

Relevant Code

In LocalWebCache.js

    async persist(indexHtml) {
        // extract version from index (e.g. manifest-2.2206.9.json -> 2.2206.9)
        const version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
        if(!version) return;

        const filePath = path.join(this.path, `${version}.html`);
        fs.mkdirSync(this.path, { recursive: true });
        fs.writeFileSync(filePath, indexHtml);
    }

A workaround provided by another user consists of manually placing the version in the code, like this:

    async persist(indexHtml) {
        // extract version from index (e.g. manifest-2.2206.9.json -> 2.2206.9)
        let version;
        if (indexHtml.match(/manifest-([\d\\.]+)\.json/) === null) {
            version = '2.2409.2';
        } else {
            version = indexHtml.match(/manifest-([\d\\.]+)\.json/)[1];
        }
        if (!version) return;

        const filePath = path.join(this.path, `${version}.html`);
        fs.mkdirSync(this.path, { recursive: true });
        fs.writeFileSync(filePath, indexHtml);
    }

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Additional context

No response

shifoc commented 4 months ago

2772 issue got closed when I reported it