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

TargetCloseError: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed. #2838

Open
caetano157 opened this issue Feb 5, 2025 · 1 comment
Labels
bug Something isn't working needs triage Needs avaliation

Comments

@caetano157
Copy link

caetano157 commented Feb 5, 2025

Description

When i trying to get the QRCode, this issue happen's

Environment

  • Venom version(s): [email protected]
  • Browser: Chromium 117.0.5938.0
  • OS: "Rocky Linux 9.5 (Blue Onyx)
  • Node version: v18.20.4

Steps to Reproduce

just tried to start the app
another time, I managed to read the qrcode at the same time and the same error occurred.

 Page successfully accessed
Erro inicializando o client: Not Logged
TargetCloseError: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
    at CdpCDPSession.send (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CDPSession.js:64:35)
    at #evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:202:50)
    at ExecutionContext.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:117:36)
    at IsolatedWorld.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:124:30)
    at CdpFrame.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:353:43)
    at CdpFrame.<anonymous> (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/util/decorators.js:98:27)
    at CdpPage.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:841:43)
    at Whatsapp.initService (/home/codarhub/apps_nodejs/WappServer/node_modules/venom-bot/dist/api/whatsapp.js:59:58)
    at /home/codarhub/apps_nodejs/WappServer/node_modules/venom-bot/dist/api/whatsapp.js:47:24
TargetCloseError: Protocol error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
    at CdpCDPSession.send (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/CDPSession.js:64:35)
    at #evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:202:50)
    at ExecutionContext.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:117:36)
    at IsolatedWorld.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:124:30)
    at CdpFrame.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:353:43)
    at CdpFrame.<anonymous> (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/util/decorators.js:98:27)
    at CdpPage.evaluate (/home/codarhub/apps_nodejs/WappServer/node_modules/puppeteer/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:841:43)
    at Whatsapp.addChatWapi (/home/codarhub/apps_nodejs/WappServer/node_modules/venom-bot/dist/api/whatsapp.js:88:25)
    at /home/codarhub/apps_nodejs/WappServer/node_modules/venom-bot/dist/api/whatsapp.js:48:24
const app = express();
const path = require('path');
const router = express.Router();
const bodyParser = require('body-parser')
const venom = require('venom-bot');
let client; // Declare the client variable at the top level to have access in the entire application
const port = process.env.PORT || 21117; 
console.log("Rodando na porta:" + port)
venom
    .create({
        session: 'G4', //name of session
        browserArgs: ['--no-sandbox', '--disable-setuid-sandbox'],
        browserPathExecutable: '/home/codarhub/chromium/chrome-linux/chrome' // Caminho do Chromium portátil
    })
    .then((waClient) => {
        client = waClient; // Store the client instance in the variable
        start(client);
        console.log("Client iniciliazou com sucesso");
    })
    .catch((error) => {
        console.log("Erro inicializando o client:", error);
    });```

@caetano157 caetano157 added bug Something isn't working needs triage Needs avaliation labels Feb 5, 2025
@FernandoFiorini
Copy link

FernandoFiorini commented Feb 6, 2025

Works fine here this way:

const client = await venom.create(
...params...
  (base64Qrimg, asciiQR, attempts, urlCode) => {
//THIS IS JUST ONE WAY OF DOING, you can get the base64Qrimg, asciiQR, attempts...
                return res.status(200).json({
                    qrCodeContent: urlCode
                });

            }
 });

venom:^5.3.0

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

No branches or pull requests

2 participants