简体   繁体   中英

GCP App Engine whatsapp-web.js not generating QR code

I have a node.js app that uses whatsapp-web.js, I'm using Cloud Shell Editor to execute my app, when I see it in Web Preview everything it's okay, but when I execute: gcloud app deploy and I see my url, the QR code is not generated.

I executed: gcloud app logs tail -s default , and I found this error in console:

/workspace/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230
error: new Errors_js_1.ProtocolError(),
ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.

Node version: 18.12.1

This is my code


const express = require("express");
const bodyParser = require("body-parser");
const axios = require("axios");
var cors = require('cors')

const config = require("./config.json");
const { Client, LocalAuth } = require("whatsapp-web.js");

process.title = "whatsapp-node-api";
global.client = new Client({
  authStrategy: new LocalAuth({clientId: "my-client", dataPath: "/tmp"}),
  puppeteer: {
      headless: true,
      ignoreHTTPSErrors: true,
      args: ['--no-sandbox','--disable-setuid-sandbox']
    },
});

global.authed = false;

const app = express();

app.use(cors());

const port = process.env.PORT || config.port;

app.use(bodyParser.json({ limit: "50mb" }));

app.use(express.json());
app.use(bodyParser.urlencoded({ extended: true }));

client.on("qr", (qr) => {
  console.log("qr");
  process.last_qr = qr;
});

client.on("authenticated", () => {
  console.log("AUTH!");
  authed = true;
  process.last_qr = undefined;
});

client.on("ready", () => {
  console.log("Client is ready!");
});

client.on("disconnected", () => {
  console.log("disconnected");
});
client.initialize();

const chatRoute = require("./components/chatting");
const authRoute = require("./components/auth");

app.use(function (req, res, next) {
  console.log(req.method + " : " + req.path);
  next();
});
app.use("/chat", chatRoute);
app.use("/auth", authRoute);

app.listen(port, () => {
  console.log("Server Running Live on Port : " + port);
});

My app.yaml

runtime: nodejs18
env: standard
instance_class: F4_1G

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM