P
P
penguin_astronaut2020-12-07 08:39:09
JavaScript
penguin_astronaut, 2020-12-07 08:39:09

Why do PLaywright/Puppeteer hang during execution?

There is a parser script that runs in the cron. Everything seems to be working fine, but sometimes something happens and the script hangs, you can see from the running processes that chrome has started and, apparently, something is happening already during execution. Is there any way to 100% complete the script? Code example:

const { chromium } = require('playwright');

(async () => {
  let browser;
  let context;
  let page;
  try {
    browser = await chromium.launch({
      proxy: {
        //proxy init
      }
    });
    context = await browser.newContext();
    page = await context.newPage();

    page.on('response', async (response) => {
      if (response.url() === variants[type]) {
        const res = {};
        res.result = await response.text();
        res.status = 'success';
        console.log(JSON.stringify(res))
      }
    });

    await page.setDefaultTimeout(60000)
    await page.goto('site address');
    await page.type('some data'); 
    await page.click('element');
    await page.waitForResponse(variants[type]);
  } catch (e) {
    console.log(JSON.stringify({status: 'error', error: e.message}));
  } finally {
    await page.screenshot({ path: `test.png` });
    await context.clearCookies()
    await browser.close();
  }
})();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question