Search code examples
google-chrome-devtoolspuppeteer

How to stop all JS scripts in Puppeteer


I would like to be able to stop any scripts from being able to run in puppeteer after the page has loaded. The reason for this is to stop carousel images and lazy loading images and essentially get the page to behave as statically as possible to enable screenshots where the images aren't changing etc.

By doing page.evaluate('debugger;') it is possible to pause the whole script, but this does not let you continue with taking screen shots as the a evaluate function does not exit until you exit the debugger (If the gui is enabled)


Solution

  • After phoning a friend the following seems to work:

    await page.evaluate('document.body.innerHTML = document.body.innerHTML')