Puppeteer script fails: TypeError in Promise.resolve

I’m having trouble with my Puppeteer script. It’s crashing after a click event with this error:

TypeError: Promise.resolve is not a function

The script navigates to a URL, waits for an iframe, clicks some elements, and tries to upload a file. It works fine until it tries to wait for a table after clicking an element.

Here’s a simplified version of what I’m trying to do:

async function scrapeWebsite(url, file) {
  try {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(url);

    const frame = page.frames()[0];
    await page.waitForSelector('iframe');
    const childFrame = frame.childFrames()[0];

    await childFrame.waitForSelector('.image-section');
    const imageSection = await childFrame.$('.image-section h2');
    await imageSection.click();

    const uploadButtons = await childFrame.$$('.upload-button');
    for (const button of uploadButtons) {
      await button.click();
      await childFrame.waitForSelector('.upload-modal');
      const fileInput = await childFrame.$('input[type=file]');
      await fileInput.uploadFile(file);
      await childFrame.waitForSelector('.upload-modal', { hidden: true });
    }
  } catch (error) {
    console.error('Scraping failed:', error);
  }
}

Any ideas why this might be failing? Is there a problem with how I’m using promises or async/await?

I’ve dealt with similar Puppeteer issues, and it seems like you might be facing a timing problem. Have you tried increasing the timeout for your waitForSelector calls? Sometimes the default timeout isn’t long enough, especially for dynamic content.

Also, consider using waitForNavigation after your clicks. This ensures the page has fully loaded before proceeding. Something like:

await Promise.all([
childFrame.click(‘.image-section h2’),
childFrame.waitForNavigation({ waitUntil: ‘networkidle0’ })
]);

This approach has saved me countless headaches with Puppeteer scripts.

Lastly, make sure you’re closing your browser instance at the end of your script. Unclosed instances can sometimes lead to unexpected behavior in subsequent runs.

yo, i had similar probs with puppeteer. try using page.evaluate() instead of direct DOM manipulation. it’s way more reliable. also, check ur node version - older ones can mess with promises. if all else fails, try playwright. it’s like puppeteer on steroids lol. good luck!

I’ve encountered similar issues with Puppeteer before, and it sounds like you might be running into a race condition. One thing that helped me was adding more explicit waits, especially after clicks.

Try adding a small delay after each click, like this:

await button.click();
await page.waitForTimeout(1000); // Add a 1-second delay

Also, make sure you’re using the latest version of Puppeteer. Older versions sometimes had quirks with promise handling.

Another trick that worked for me was wrapping problematic operations in a try/catch block and retrying a few times. Sometimes network hiccups or slow page loads can cause these errors.

Lastly, double-check that you’re not accidentally overwriting the global Promise object somewhere in your code. That could explain the ‘Promise.resolve is not a function’ error.

Hope this helps! Let me know if you need more details on any of these suggestions.