Whatsapp-web.js is running multiple Puppeteer processes with whatsapp-web.js results in extremely high CPU consumption. The issue is causing excessive resource utilization and negatively impacting the system's performance.
Expected behavior
Puppeteer processes should consume a reasonable amount of CPU resources, ensuring smooth and efficient execution of the application.
Shouldn't be only one processs?
Steps to Reproduce the Bug or Issue
Start the application with the provided code.
Observe the CPU usage while running multiple Puppeteer processes with whatsapp-web.js.
Relevant Code
I'm running singleton so there is only one instance
import { DataBase } from './database/Database';
import { PuppeteerManager } from './shared/PuppeteerManager';
import { WhatsappClient } from './shared/WhatsappClient';
import logger from './utils/logger';
export class Application {
private static instance: Application | null = null;
private dataBase = new DataBase();
private whatsappClient = new WhatsappClient();
private puppeteerManager = new PuppeteerManager();
private isInitialized = false;
private constructor() {
// Prevents multiple initializations
}
public static getInstance(): Application {
if (Application.instance === null) {
Application.instance = new Application();
Application.instance.init(); // Calls initialization only when the instance is created
}
return Application.instance;
}
private init() {
if (!this.isInitialized) {
this.dbConnect(); // Calls dbConnect only once
this.whatsappClient.initialize(); // Calls whatsappClient.init only once
this.puppeteerManager.initialize(); // Calls initialize of PuppeteerManager only once
this.isInitialized = true;
}
}
private dbConnect(): void {
this.dataBase.initConnect();
}
getPuppeteerManager(): PuppeteerManager {
return this.puppeteerManager;
}
Is there an existing issue for this?
Describe the bug
Whatsapp-web.js is running multiple Puppeteer processes with whatsapp-web.js results in extremely high CPU consumption. The issue is causing excessive resource utilization and negatively impacting the system's performance.
Expected behavior
Puppeteer processes should consume a reasonable amount of CPU resources, ensuring smooth and efficient execution of the application.
Shouldn't be only one processs?
Steps to Reproduce the Bug or Issue
Relevant Code
I'm running singleton so there is only one instance
import { DataBase } from './database/Database'; import { PuppeteerManager } from './shared/PuppeteerManager'; import { WhatsappClient } from './shared/WhatsappClient'; import logger from './utils/logger';
export class Application { private static instance: Application | null = null; private dataBase = new DataBase(); private whatsappClient = new WhatsappClient(); private puppeteerManager = new PuppeteerManager(); private isInitialized = false;
}
function uncaughtErrorHandler() { process.on('uncaughtException', (error: Error) => { logger.error(
Uncaught Exception: ${error.message}
); });}
uncaughtErrorHandler();
const appInstance = Application.getInstance();
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
No, I am not using Multi Device
Environment
Linux Ubuntu 22 node 19.3.0 whatsappweb 1.21.1
Additional context
No response