@types/xxxx package and had problems.Definitions by: in index.d.ts) so they can respond.When using the evaluate function, code is run in the browser's context and not node's. The below code compiles and throws ReferenceError: someText is not defined. If I do not add someText to the arguments of page.evaluate, the compiler should throw an error.
import puppeteer from "puppeteer";
async function main() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
let someText = "Some value";
await page.evaluate(() => {
console.log(someText);
});
}
main();
Versions:
That is not something the typings can fix, there is no mechanism that can prevent functions from capturing locals.
iirc they basically call toString() on the function to serialize it, there is nothing we can do.
Most helpful comment
That is not something the typings can fix, there is no mechanism that can prevent functions from capturing locals.
iirc they basically call
toString()on the function to serialize it, there is nothing we can do.