这是我的代码:
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)
答案 0 :(得分:0)
这是因为该页面可能会混乱/注入其自己的Promise
对象。假设您是该页面的作者,您可以尝试仅在Promise
对象不存在时进行polyfill。除此之外,这是puppeter的一个问题(见这里:https://github.com/GoogleChrome/puppeteer/issues/1343)