Recently, I used Puppeteer for a new project.
I have a few questions about thea part of the API I don't understand. The documentation is very simple for these API introductions:
page.exposeFunction
page.evaluateOnNewDocument
Can I have a detailed demo to gain a better understanding?
Summary:
The Puppeteer function
page.exposeFunction()
essentially allows you to access Node.js functionality within the Page DOM Environment.On the other hand,
page.evaluateOnNewDocument()
evaluates a predefined function when a new document is created and before any of its scripts are executed.The Puppeteer Documentation for
page.exposeFunction()
states:Furthermore, the Puppeteer Documentation for
page.evaluateOnNewDocument
explains: