UPDATE I am running in docker and using puppeteer version 1.11.0, since this is the latest version that is supported by alpine linux. I am also running with --no-sandbox
Just for the sake of code organization, I'd like to do this in puppeteer...
async function crawler(url, evaluater) {
const browser = await puppeteer.launch(...)
const page = await browser.newPage()
await page.goto(url)
const result = await page.evaluate(evaluater)
return result
}
crawler('https://website.com', () => {
return document.querySelectorAll(...)
})
But I get the following error....
Error: Evaluation failed: TypeError: Cannot read property
'querySelectorAll' of undefined
I assume the evaluator function is actually passed to eval
so I would expect the below to work in that case
const result = await page.evaluate(evaluater.toString())
This doesn't work either though. There is no error message, but undefined
is returned. If I move the function inline, the data is returned.
Is there any way that I can provide a callback to page.evaluate
that is not defined inline but passed in as a variable?