Here is the script I run using 'node --harmony-async-await run'
I want to collect logs into 'logs' array. But the array is undefined inside await function.
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
}
How to pass msg into array?
I think it is because page.property does not return a promise, it means that there is no meaning use await page.propperty(xxx, function () {}). so maybe you can try to wrap your page.propperty first