Puppeteer

Learn how to configure Puppeteer on Discloud, including dependencies and RAM adjustments, to ensure proper operation in container environments.

📌 Requirements

To use Puppeteer on Discloud, a minimum of 512 MB RAM is recommended for basic tasks. However, depending on the complexity of your application, more RAM may be required.


📦 Adding Puppeteer

Puppeteer requires additional system dependencies. You must add puppeteer to the APT field in your discloud.config file.

discloud.config

APT=tools, puppeteer
# ...

⚙️ Configuring Puppeteer

Since Puppeteer runs in a containerized environment, you must add the --no-sandbox argument to ensure it works correctly.

const puppeteer = require("puppeteer");

(async () => {
    const browser = await puppeteer.launch({
        args: ["--no-sandbox"]
    });

    const page = await browser.newPage();
    await page.goto("https://example.com");

    console.log(await page.title());
    await browser.close();
})();

🚨 Why --no-sandbox?

Running Puppeteer inside a container requires disabling the sandbox to prevent security restrictions from blocking execution.


⚙️ Using Puppeteer with whatsapp-web.js

Since whatsapp-web.js also uses Puppeteer for QR code generation and background interactions, you must include --no-sandbox in its configuration.

const { Client } = require("whatsapp-web.js");

const client = new Client({
    puppeteer: {
        args: ["--no-sandbox"],
    }
});

client.initialize();

🚨 Troubleshooting QR Code Issues:

  • If the QR code does not appear in Discloud logs, increase the allocated RAM.

  • The more complex your interactions with WhatsApp, the more RAM Puppeteer will need to function properly.

Last updated