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

Fix remote auth unzip on nodejs > 16 #3200

Closed bymarcelo closed 4 months ago

bymarcelo commented 4 months ago

PR Details

This PR fixes an error when restoring the session in the remote authentication method when using nodejs in version > 16

Description

Error details:

ProtocolError: Protocol error (Runtime.callFunctionOn): Execution context was destroyed.

Related Issue

3181 #2530 #2452 #1681 #2038

Motivation and Context

When using nodejs in versions higher than 16, in the remote authentication method the session is not restored.

How Has This Been Tested

Tested on node versions > 16 on Ubuntu and Windows

Types of changes

Checklist

alechkos commented 4 months ago

2412

Hagave commented 2 months ago

For me, worked this:

try npm i adm-zip

Find your remote Auth on the node modules folder

node_modules/whatsapp-web.js/src/authStrategies/RemoteAuth.js

(put out of try function (constructor) var AdmZip = require('adm-zip'); //

switch your unComprassSession default function for this one.

async unCompressSession(compressedSessionPath) {
    await new Promise((resolve, reject) => {
        const zip = new AdmZip(compressedSessionPath);
        zip.extractAllToAsync(this.userDataDir, true, false, (err) => {
            if (err) {
                reject(err);
            } else {
                resolve();
            }
        });
    });
    await fs.promises.unlink(compressedSessionPath);
}

Delete your old WhatsApp session. Create again and awaIt remote_session_saved save your session again. Try to connect one more time.

Linux (Debian) node v18 Whatsapp standard aws Store (s3) exodus