Puppeteer/ chromium help

Any puppeteer node for node-red has issues (at least that is what I found), especially when there are updates to chromium or the puppeteer package. Instead I have switched to the npm package and use a function node to go through the actions.

In the setup tab use (make sure to install chromium via the commandline):

and for the code itself, example:

function delay(time) {
    return new Promise(function (resolve) {
        setTimeout(resolve, time)
    });
}

const browser = await puppeteer.launch({
    headless: true,
    executablePath: '/usr/bin/chromium',
    args: [
        '--incognito',
    ]
});
const user = 'someuser'
const pass = 'somepasswprd'

node.status({ fill: "yellow", shape: "ring", text: "starting browser" });
const page = await browser.newPage();

await page.goto('https://example.com/', {
    waitUntil: 'networkidle2', networkIdleTimeout: 15000
})
node.status({ fill: "blue", shape: "ring", text: "login" });


await page.waitForSelector('#user');
await page.locator('#user').fill(user);
await page.locator('#password').fill(pass);
await page.locator('.btn-primary').click();

await page.waitForNavigation({ waitUntil: "networkidle2" });
await delay(2000);
...
2 Likes