ScreenshotGrabberPlus (name can be changed)
Capture screenshots and console messages for multiple urls. You can also compare 2 sets of data to find any changes.
Table of contents
- What does it do
- How to use
- Comparing 2 reports
- Tips on generating list of URLS
What does it do
You give a .txt file with a list of urls to the program and for each url it will:
- Open the url in a headless chrome browser instance and wait for it load.
- Capture a screenshot into a .png file.
- Capture the contents of the browser console into a .txt file.
The results can be found inside the reports folder.
It is able to achieve fast speeds by loading the urls into multiple tabs inside multiple browsers at the same time. (This can be hardware intensive but you can specify limits for the number of tabs and browsers to best fit your computer's capabilities).
It is also capable of authenticating before visiting the urls so that you can capture pages that are not open to the public. See authentication below for more information on that.
- Node.js v8.3 or higher
- ImageMagick (only required for the compare functionality)
How to use
- Clone this repo
- Go into its directory using your favorite terminal program
$ cd path/to/repo
- Install npm packages
$ npm install
- Create a .txt file with the urls you want to process (one per line).
https://google.com https://bing.com https://yahoo.com
- Run the program
$ node index.js --urls=urls.txt
||The directory name to save the screenshots in.||Current date time|
||Path to file with the list of urls||
||Path to the authentication file. See more info about authentication below||Not set|
||The maximum number of tabs allowed to open at the same time per browser.||
||The maximum number of browsers instances allowed to open at the same time.||
||Specify a custom viewport width in pixels.||800|
||Specify a custom viewport height in pixels.||600|
||If set to true, the browser will not open in headless mode||Not set|
||Skip the capture of console messages found in page.||Not set|
||Skip the capture of console errors found in page.||Not set|
||Do not include the host part of the url in the directory name. This is useful for comparing the same pages but on different enviroments such as Devl, Staging, Prod.||Not set|
||Display additional program infomation.||Not set|
||Display the help screen.||Not set|
This tool is able to authenticate via a simple username/password form page or by cookies.
For it to work, duplicate either the auth-by-login-sample.json or auth-by-cookie-sample.json file, replace the dummy information with your information and point to it when starting the program by using the auth parameter:
node index.js --auth authentication.json
The browser will try to authenticate first and when it succeeds, it will start processing the list of urls.
There are 2 methods of authentication available: login and cookie.
Auth by login
This method attempts to authenticate by automating the process of entering the username and password into a login form.
Sample file: auth-by-login-sample.json
||The url for the authentication form||https://example.com|
||The selector to target the username field||input[name=user]|
||The selector to target the password field||input[name=password]|
||The selector to target the submit button||input[type=submit]|
||The selector to target an element that if found it confirms the authentication was successful||body.authenticated|
||The authentication username||username|
||The authentication password (Note: you may omit this property and you will be prompted for it at runtime )||password|
Auth by cookie
This method sets the authentication cookies that you specify in the
Sample file: auth-by-cookie-sample.json
||An array of cookie objects. See page.setCookie over at the puppeteer docs for more info about the cookie object||
Comparing 2 reports
You can compare two reports to find any changes to pages that may have occured after some action such as updating your CMS, updating a NPM package or even an event like the Y2k.
Use the compare.sh script to visualy compare the screenshots and diff the console messages/errors.
$ bash compare.sh <path/to/report1> <path/to/report2>
$ brew install imagemagick
Compare a set of urls over a period of time
# Process the urls $ node index.js --directory 1999 # Wait a year... # Process the same urls again $ node index.js --directory 2000 # Now compare the screenshots from last year versus the ones from this year $ bash compare.sh ./report/1999 ./report/2000
Compare a set of urls before and after making changes to the website's code.
# Process the urls as they are now $ node index.js --directory Before # Make changes to your website's code... # Process the same urls again after the changes $ node index.js --directory After # Now compare the screenshots from Before the changes versus After the changes $ bash compare.sh ./report/Before ./report/After
Compare sets from 2 different environments such as Prod vs Staging.
To make that possible use the
# Process the pages at the Production server e.g.: https://example.com/blablabla $ node index.js --do-not-include-host --urls prod-urls.txt --directory Prod # Process the same pages again but at the Staging server e.g.: https://staging.example.com/blablabla $ node index.js --do-not-include-host --urls staging-urls.txt --directory Staging # Now compare the screenshots from the Staging server versus the Prod server $ bash compare.sh ./report/Prod ./report/Staging
Tips on generating list of URLS
It is easy to generate a list of URLs for a WordPress site through wp-cli.
# List post types registered on a site wp --url=www.example.com/ post-type list # List permalinks for the found post types. wp --url=www.example.com/ post list --fields=url --post_type=post,page --post_status=publish --format=csv | tail -n +2
To get a list of popular sites or URLs, check the Google Analytics account under Reports > Behavior > Content Drilldown and use Export into CSV. Then copy the list of urls from the .csv file into a .txt file (one url per line).
Fix npm vulnerabilities
The compare script now creates an html page for you to visualize the differences more easily
Added option to drop the host part of the url in reports to make it easier to compare urls from 2 different environments (e.g.: Staging vs Prod)
Improved error handling
Added option to enter authentication password via a secure prompt
Added option to authenticate by cookie
Added script to compare 2 sets of data.