0

I have the following code but occasionally it hangs on page.click(clickSelector) and I have to restart the process. I'm trying to make sure it can run in the background without interference.

let clickAndWaitForTarget = async (clickSelector, page, browser) => {
  try {
    await page.waitForSelector(clickSelector, { timeout: 60000 });
  } catch (error) {
    console.log('SELECTOR ' + clickSelector + ' NOT FOUND IN 60 SECONDS');
    return null;
  }
  const pageTarget = page.target();
  console.log("SELECTOR FOUND! LET'S ROLL...");
  await page.click(clickSelector); // HANGING HERE
  console.log('CLICKED IT');
  try {
    const newTarget = await browser.waitForTarget(
      target => target.opener() === pageTarget,
      { timeout: 45000 }
    );
    const newPage = await newTarget.page();
    return newPage;
  } catch {
    return null;
  }
};

Any ideas? I'm using Puppeteer version 2.0.0

1 Answers1

0

you can try this.

await Promise.all([
  page.waitForNavigation(waitOptions),
  page.click(selector, clickOptions),
]);

I think it helps.