Javascript 如何使用异步/等待方法将对象传递到phantom js页面?
下面是我使用“node--harmony async wait run”运行的脚本 我想将日志收集到“日志”数组中。但数组在等待函数中未定义Javascript 如何使用异步/等待方法将对象传递到phantom js页面?,javascript,node.js,asynchronous,phantomjs,Javascript,Node.js,Asynchronous,Phantomjs,下面是我使用“node--harmony async wait run”运行的脚本 我想将日志收集到“日志”数组中。但数组在等待函数中未定义 const phantomjs = async ({ development, script }) => { const instance = await phantom.create() const page = await instance.createPage() const logs = [] await page.prop
const phantomjs = async ({ development, script }) => {
const instance = await phantom.create()
const page = await instance.createPage()
const logs = []
await page.property('onConsoleMessage', function(msg, lineNum, sourceId) {
console.log('Console:', msg)
logs.push(msg) // => will be not executed. logs is undefined here
})
....some other actions
}
如何将消息传递到数组中?我认为这是因为
page.property
不返回承诺,这意味着没有意义使用wait page.property(xxx,function(){})
。所以,也许你可以先尝试包装一下你的页面。property