Responsive Ad Area

Share This Post

test

Out of memory puppeteer or better-sqlite3

I have this script :

const puppeteer = require('puppeteer');
const db = require('better-sqlite3')('bdd.sqlite');
const stmt = db.prepare('INSERT INTO stats VALUES (?, ?, ?, ?, ?, ?)');
const fs = require('fs');
const debug = true;

var base_url = 'https://domain.tld/path'
var now = Date.now();

(async () => {
    const browser = await puppeteer.launch({
        headless: true,
    });

    async function caseOfTimeout(page, step, sel, ret) {
        const img = 'images/' + now + '.png';
        await page.screenshot({path: img, fullPage: true});
        var http_code = ' ';
        var content = await page.content();
        if (/Internals*Servers*Error/.test(content)) {
            http_code = " HTTP CODE 500";
        } else if (/Servives*Unavailable/.test(content)) {
            http_code = " Service Unavailable";
        }
        var err = 'ERROR on step "' + step + '", can't find selector [' + sel + ']' + http_code;
        console.log(err);
        const info = stmt.run(Date.now(), scraping_mode, img, (Date.now() - now), err, 'NOK');
        console.log(img);
        await browser.close();
        await db.close();
        process.exit(1);
    }

    const page = await browser.newPage();

    step = 'step 1: Open main url';
    sel = 'none';
    if (debug) process.stdout.write(step);
    await page.goto(base_url, { waitUntil: 'networkidle2', timeout: 8000 })
    .catch(() => caseOfTimeout(page, step, sel));
    if (debug) console.log(': OK');

    step = "step 2: Click on foobar";
    sel = 'a.link-caps';
    if (debug) process.stdout.write(step);
    await page.waitForSelector(sel, { timeout: 5000 })
    .catch(() => caseOfTimeout(page, step, sel));
    await page.click(sel);
    if (debug) console.log(': OK');

    step = "step 3: Add something";
    sel = 'input#edit-checkout';
    if (debug) process.stdout.write(step);
    await page.waitForSelector(sel, { timeout: 5000 })
    .catch(() => caseOfTimeout(page, step, sel));
    await page.click(sel);
    if (debug) console.log(': OK');

     await browser.close();

     console.log('TEST PASSED OK');
     const info = stmt.run(Date.now(), scraping_mode, 'none', (Date.now() - now), 'none', 'OK');

     await db.close();
     process.exit(0);

})();

But I don’t know why, I get Out of memory after a few hours even if I do

await db.close();

and

await browser.close();

What I’m doing wrong ???


Out of memory puppeteer or better-sqlite3
Out of memory puppeteer or better-sqlite3
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar