The documentation says:
The method adds a function called name on the page's window object. When called, the function executes puppeteerFunction in node.js and returns a Promise which resolves to the return value of puppeteerFunction.
the key part is "on the page's window object". You're trying to find the function in window.document
object.
This code should fix your problem:
await page.evaluate(() => {
window.getInfo();
});
Also be aware that any such function returns a Promise, so you might want to do:
await page.evaluate(async () => {
await window.getInfo();
});
if your function should e.g. return something you want to later use inside page.evaluate()
callback function.
See the documentation for Puppeteer API.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…