Debugging puppeteer in a docker container (locally and remotely) This should be helpful enough to debug when you're working in your local environment. In this case, my script opens my Github profile so you can see the URL in the list, click on the inspect button:Īnd you should be able to inspect the elements as if it were directly loaded in Google Chrome:Īnd all while being instantiated directly from a Puppeteer script! You can kill the script to stop the debugging whenever you need to. Once you start the puppeteer script ( node script.js) and wait for about 15 seconds, the remote target should appear as an item in the list. Navigate to chrome://inspect in your Google Chrome browser and go to the Devices tab. If you're working locally, running a Node.js script in your Windows, Mac or Linux environment, this script will work without any issue nor special configuration. You can use this script to test in case that you don't have already an environment with Puppeteer. if screenshots directory is not exist then create oneīrowser = await puppeteer.launch(options) Īwait tViewport() Ĭonsole.log(`\n? The screenshot has been succesfully generated.`) What matters in this script is the configuration, but I'll explain it in the next section: // script.js It will create a screenshot from a website, in this case my profile at GitHub and that's it, nothing fancy. This example script is going to simply start Puppeteer and will keep it open until the user stops the execution. To get started, you will need a functional puppeteer script that remains open so we can debug what's going on. In this article, I will explain you shortly how to connect to debug a Puppeteer script using Google Chrome's Remote Debugger. Debugging is easy using the Chrome Dev Tools as long as the headless mode is disabled, however when is enabled (in an environment where it needs to be disabled obligatorily like a server) it's not that easy to debug without the proper tools. A lot of projects decide to use Puppeteer for any of the mentioned tasks in their projects, however not everyone knows how to debug an instance of Chrome being manipulated by Puppeteer in headless mode. Puppeteer can be used nowadays for multiple things such as web scraping, automation and testing purposes.
0 Comments
Leave a Reply. |