puppeteer - Promise.resolve不是一个功能

时间:2017-11-09 23:49:49

标签: node.js puppeteer

这是我的代码:

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)

1 个答案:

答案 0 :(得分:0)

这是因为该页面可能会混乱/注入其自己的Promise对象。假设您是该页面的作者,您可以尝试仅在Promise对象不存在时进行polyfill。除此之外,这是puppeter的一个问题(见这里:https://github.com/GoogleChrome/puppeteer/issues/1343