Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteAuth Puppeteer ProtocolError #3427

Open
2 tasks done
Khalidmamdou7 opened this issue Jan 1, 2025 · 6 comments
Open
2 tasks done

RemoteAuth Puppeteer ProtocolError #3427

Khalidmamdou7 opened this issue Jan 1, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@Khalidmamdou7
Copy link

Khalidmamdou7 commented Jan 1, 2025

Is there an existing issue for this?

  • I have searched the existing issues.

Is this a problem caused by your code, or is it specifically because of the library?

  • I have double-checked my code carefully.

Describe the bug.

Whenever I run my script after using RemoteAuth configured with mongo, after 5~10 seconds (possibly fetching data from mongo) a ProtocolError occurs and the process is closed.

here is the full error message:

node index.js
<projectfullpath>/bot/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329
                error: new Errors_js_1.ProtocolError(),
                       ^

ProtocolError: Protocol error (Runtime.callFunctionOn): Execution context was destroyed.
    at /home/khaled/data/projects/js-projects/cli-projects/opportunities-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24
    at new Promise (<anonymous>)
    at CDPSessionImpl.send (/home/khaled/data/projects/js-projects/cli-projects/opportunities-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16)
    at ExecutionContext._ExecutionContext_evaluate (/home/khaled/data/projects/js-projects/cli-projects/opportunities-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:211:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (/home/khaled/data/projects/js-projects/cli-projects/opportunities-bot/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:107:16) {
  originalMessage: 'Execution context was destroyed.'
}

Node.js v20.11.1

Note that at the first time running the script (a fresh session before authentication), it authenticates successfully and works perfectly and a remote_session_saved event occurs, and 2 collections are stored in mongodb. However, after running again and utilizing the data stored in mongo, it throws the mentioned error. LocalAuth works perfectly.

here are the versions am using:

    "mongoose": "^8.9.3",
    "whatsapp-web.js": "^1.26.0",
    "wwebjs-mongo": "^1.1.0"

here is the code snippet:

const { Client, Location, Poll, List, Buttons, LocalAuth, RemoteAuth } = require('whatsapp-web.js');
const crypto = require('crypto');
const qrcode = require('qrcode-terminal');

// Require database
const { MongoStore } = require('wwebjs-mongo');
const mongoose = require('mongoose');


MONGODB_URI = process.env.MONGODB_URI ? process.env.MONGODB_URI: "secret connection string removed";
let client;

async function initializeClient() {
    try {
        await mongoose.connect(MONGODB_URI);
        const store = new MongoStore({ mongoose: mongoose });
        client = new Client({
            authStrategy: new RemoteAuth({
                store: store,
                backupSyncIntervalMs: 1000 * 60 * 60 * 1
            })
        });

        client.initialize();

        client.on('remote_session_saved', () => {
            console.log('Remote session saved');
        });
        
        client.on('loading_screen', (percent, message) => {
            console.log('LOADING SCREEN', percent, message);
        });

        // Pairing code only needs to be requested once
        let pairingCodeRequested = false;
        client.on('qr', async (qr) => {
            // NOTE: This event will not be fired if a session is specified.
            console.log('QR RECEIVED', qr);
            qrcode.generate(qr, {small: true});

            // paiuting code example
            const pairingCodeEnabled = false;
            if (pairingCodeEnabled && !pairingCodeRequested) {
                const pairingCode = await client.requestPairingCode('96170100100'); // enter the target phone number
                console.log('Pairing code enabled, code: '+ pairingCode);
                pairingCodeRequested = true;
            }
        });

        client.on('authenticated', () => {
            console.log('AUTHENTICATED');
        });

        client.on('auth_failure', msg => {
            // Fired if session restore was unsuccessful
            console.error('AUTHENTICATION FAILURE', msg);
        });

        client.on('ready', async () => {
            console.log('READY');
            const debugWWebVersion = await client.getWWebVersion();
            console.log(`WWebVersion = ${debugWWebVersion}`);

            client.pupPage.on('pageerror', function(err) {
                console.log('Page error: ' + err.toString());
            });
            client.pupPage.on('error', function(err) {
                console.log('Page error: ' + err.toString());
            });

            
        });
        
        
    } catch (error) {
        console.error('Error connecting to MongoDB or initializing client:', error);
    }
}

initializeClient();

Expected Behavior

As a user I expected to authenticate successfully and start working, but I am seeing the error I mentioned before ProtocolError

Steps to Reproduce the Bug or Issue

Use RemoteAuth configured with mongodb. Run your program the first time and authenticate and wait for the remote session to be saved using the remote-session-saved event handler. close the program and reruns it again without deleting the session info from the mongodb. It will try to load then the error will be thrown.

WhatsApp Account Type

Standard

Browser Type

Chromium

Operation System Type

Ubuntu

Phone OS Type

Android

WhatsApp-Web.js Version

1.2.6

WhatsApp Web Version

2.3000.1019099659

Node.js Version

v20.11.1

Authentication Strategy

RemoteAuth

Additional Context

No response

@Khalidmamdou7 Khalidmamdou7 added the bug Something isn't working label Jan 1, 2025
@Khalidmamdou7
Copy link
Author

Same error occured with RemoteAuth with aws-s3

@Tina4545
Copy link

Tina4545 commented Jan 2, 2025

same error, pliz help

@DarckBlezzer
Copy link

I am using new LocalAuth but I get the same error from time to time

@satishcoder20
Copy link

satishcoder20 commented Jan 4, 2025

Facing same issue, we are stuck

@Hasnen-mr @Khalidmamdou7 please help here as you are expert in this library

@lionezajoao
Copy link

Any fixes? Same error here using RemoteAuth with aws-s3

@Nathannmi
Copy link

Also experiencing this issue for about 2 weeks and unable to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants