TypeError: Promise.resolve is not a function in Puppeteer automation

I’m working on a web scraping project using Puppeteer and encountering an unusual error. The script functions well until a certain point where I’m attempting to wait for an element to appear.

try {
    await browser.goto(targetUrl)
    let mainFrame = await browser.frames()[0];
    // waiting for nested frame to load
    await browser.waitFor("iframe")
    let nestedFrame = mainFrame.childFrames()[0]
    // waiting for content section to appear
    await nestedFrame.waitFor("div[data-section=content]", {timeout: 60000})
    // clicking the header to expand
    let header = await nestedFrame.$("div[data-section=content] h2")
    await header.click()
    let buttons = await nestedFrame.$$("div[data-section=content] form span button")
    for (let btn of buttons)
    {
        await btn.click()
        console.log('button clicked');
        await nestedFrame.waitFor("div.upload-container")
        console.log('container found');
        let fileInput = await nestedFrame.$("input[type=file]")
        await fileInput.uploadFile(filePath)
        console.log('file uploaded');
        await nestedFrame.waitFor("div.upload-container", { hidden: true })
        console.log('upload completed');
    }
} catch (error) {
    console.trace(error);
}

The script stops working immediately after logging ‘button clicked’, leading me to suspect the issue lies with nestedFrame.waitFor. The error message displayed is:

Trace: Error: Evaluation failed: TypeError: Promise.resolve is not a function
    at pollMutation (<anonymous>:18:22)
    at waitForPredicatePageFunction (<anonymous>:8:11)
    at <anonymous>:70:3
    at ExecutionContext.evaluateHandle

What might be causing this Promise.resolve error? I’m currently using the latest version of Puppeteer.

you’re using an outdated puppeteer version even though you said “latest”. that waitFor method got deprecated ages ago and breaks promises in modern browsers. switch to waitForSelector() - it’s way better with frame contexts. also check if your iframe’s loading the js environment properly. nested frames sometimes don’t get the right promise polyfills.

This happens because the iframe’s execution context gets messed up by whatever app is running inside it. When you click buttons that load dynamic content in nested frames, the page’s JavaScript can override browser APIs like Promise.resolve. I’ve hit this exact issue scraping SPAs that use their own promise libraries or polyfills. Wrap your waitFor calls in try-catch and fall back to polling with page.evaluate. What really saved me debugging time was getting a fresh frame reference after each button click - the execution context becomes unreliable after DOM changes, so grab a new handle to the nested frame before each waitFor.

This happens when the page context gets corrupted or JavaScript environments clash. I’ve seen it before with dynamic content that messes with the global scope. Usually the page overrides native Promise methods or pollutes the global namespace. Add a small delay before your waitFor call and use page.evaluate() to check if Promise.resolve exists in that context. Also, switch to waitForSelector() instead of the deprecated waitFor() - it’s way more stable with nested frames. What worked for me was reloading the nested frame reference after each major DOM change, since the frame context goes stale when dynamic content updates.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.