【问题标题】:puppeteer - Promise.resolve is not a functionpuppeteer - Promise.resolve 不是函数
【发布时间】:2017-11-12 08:00:00
【问题描述】:

这是我的代码:

try {
    await page.goto(url)
    var frame = await page.frames()[0];
    // iframe isn't present from the beginning (for whatever reason)
    await page.waitFor("iframe")
    var child = frame.childFrames()[0]
    // wait for the image cut block to be visible
    await child.waitFor("section[data-type=imagecut]", {timeout: 60000})
    // open the image cut
    let section = await child.$("section[data-type=imagecut] h1")
    await section.click()
    let elements = await child.$$("section[data-type=imagecut] fieldset div a")
    for (let element of elements)
    {
        await element.click()
        console.log('click');
        await child.waitFor("table.boxy-wrapper")
        console.log('wait for table');
        let file_upload = await child.$("input[name=file_upload]")
        await file_upload.uploadFile(file)
        console.log('uploaded');
        await child.waitFor("table.boxy-wrapper", { hidden: true })
        console.log('waited');
    }
} catch (e) {
    console.trace(e);
}

在记录“点击”消息后失败,所以我猜是await child.waitFor

这是完整的错误信息:

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 (/Users/a.lau/Projects/chrome-headless/node_modules/puppeteer/lib/ExecutionContext.js:54:15)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Object.module.exports.test (/Users/a.lau/Projects/chrome-headless/test.js:306:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

【问题讨论】:

    标签: node.js puppeteer


    【解决方案1】:

    这是因为页面可能会弄乱/注入自己的Promise 对象。假设您是该页面的作者,您可能会尝试仅在 Promise 对象不存在时才使用 polyfill。除此之外,这是 puppeter 中的一个问题(请参阅此处:https://github.com/GoogleChrome/puppeteer/issues/1343

    【讨论】:

    • 我会检查一下,我不是网页的创建者,但它由我的公司管理。
    猜你喜欢
    • 2017-06-03
    • 2018-07-21
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 2018-12-02
    • 2021-12-04
    • 2017-12-25
    • 2021-11-30
    相关资源
    最近更新 更多