When I call a function normally, it works, but when I call it in page.evaluate()
, the function is not defined. Here's a demo:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
page.on('console', msg => console.log(msg.text())) // so console.log() works in page.evaluate()
const test = () => console.log('works')
await test() // it runs
await page.evaluate(() => test()) // ReferenceError: test is not defined
})()