Длительная ошибка captureScreenshot (Page.captureScreenshot): цель закрыта - PullRequest
0 голосов
/ 14 апреля 2020

Есть ли способ продлить соединение? Я вижу эту ошибку как в Linux, так и в MacOS через ~ 10 минут.

{
  message: 'Protocol error (Page.captureScreenshot): Target closed.',
  stack: 'Error: Protocol error (Page.captureScreenshot): Target closed.\n' +
    '    at /ui/common/temp/node_modules/.pnpm/puppeteer/1.19.0/node_modules/puppeteer/lib/Connection.js:183:56\n' +
    '    at new Promise (<anonymous>)\n' +
    '    at CDPSession.send (/ui/common/temp/node_modules/.pnpm/puppeteer/1.19.0/node_modules/puppeteer/lib/Connection.js:182:12)\n' +
    '    at Page._screenshotTask (/ui/common/temp/node_modules/.pnpm/puppeteer/1.19.0/node_modules/puppeteer/lib/Page.js:915:39)\n' +
    '    at runMicrotasks (<anonymous>)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' +
    '  -- ASYNC --\n' +
    '    at Page.<anonymous> (/ui/common/temp/node_modules/.pnpm/puppeteer/1.19.0/node_modules/puppeteer/lib/helper.js:111:15)\n' +
    '    at /ui/src/middle-tier/pdf/puppeteer-render.js:368:37\n' +
    '    at Array.map (<anonymous>)\n' +
    '    at /ui/src/middle-tier/pdf/puppeteer-render.js:365:51\n' +
    '    at step (/ui/src/middle-tier/pdf/puppeteer-render.js:44:23)\n' +
    '    at Object.next (/ui/src/middle-tier/pdf/puppeteer-render.js:25:53)\n' +
    '    at fulfilled (/ui/src/middle-tier/pdf/puppeteer-render.js:16:58)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)'
}

Я получаю ее при настройке puppeteer-cluster@0.15.2

const cluster = await Cluster.launch({
    concurrency: Cluster.CONCURRENCY_BROWSER,
    maxConcurrency: 4,
    timeout: 660000,
    puppeteerOptions: {
        ignoreHTTPSErrors: true,
        dumpio: false,
    }
});

await cluster.task(async ({ page, data: req }) => generateExport(page, req));

cluster.queue(req);

Я также получаю ее при создании страницы с puppeteer@1.19.0.

const puppeteer = require('puppeteer');
const browser = await puppeteer.launch();
const page = await browser.newPage();
generateExport(page, req);

Ошибка возникает при съемке более 170 скриншотов:

/*
screenshotClips = [
    {
        x: boundingBox.x,
        y: clipY,
        width: boundingBox.width,
        height: clipHeight,
    },
    ...x170
];
*/

const screenshots = screenshotClips.map((clip, i) => {

    return page.screenshot({
        path: screenshotPaths[i],
        clip
    })
    .then(() => { ... })
    .catch(() => { ... })
    .finally(() => { ... });

return Promise
        .all(screenshots)
        .then(() => screenshotPaths);
...