How can I dynamically inject functions to evaluate using Puppeteer?
问题 I am using Puppeteer for headless Chrome. I wish to evaluate a function inside the page that uses parts of other functions, defined dynamically elsewhere. The code below is a minimal example / proof. In reality functionToInject() and otherFunctionToInject() are more complex and require the pages DOM. const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(someURL); var functionToInject = function(){ return 1+1; } var otherFunctionToInject = function