grabber
Installation
See sharp's instructions for installing libvips. Sharp is used to resize screenshots and turn them into JPEG, PNG or WebP images.
After that a simple npm install grabber
should do the trick.
ChromeDriver is straight-forward to install via npm install, but if you want to
use Firefox to take screenshots you'll have to be running Selenium server.
Try out some of these guides for getting Xvfb and Selenium running so that you can take "headless" screenshots in a Linux environment. You probably don't want to be screenshotting in OSX or Windows or a real (non-framebuffer) X server because the browser window is going to pop up.
- Running Headless Selenium with Chrome
- Headless Chrome/Firefox testing in NodeJS with Selenium and Xvfb
- Use Xvfb, Selenium and Chrome to drive a web browser in PHP
Limitations
Both Firefox and Chrome seem to have the limitation that you can't resize the browser window to be larger than the screen, so you're limited by your screen dimensions. In Linux you can probably get around this to some extent using Xvfb.
Chrome cannot take a screenshot of the full page and will only screenshot the visible portion. Firefox can screenshot the entire page, but this library doesn't allow for that just yet.
Usage
grabber = require 'grabber' chromeOptions = hostname: "127.0.0.1" port: 9515 pathname: "/wd/hub" args: "--url-base=/wd/hub" "--port=" + 9515 "--verbose" browser = grabberchromeinitchromeOptions return consoleerrorerr if err screenshotOptions = url: 'http://www.google.com/' width: 1024 height: 768 resize: 512 quality: 80 # see browser.waitForConditionInBrowser in wd condition: "document.querySelectorAll('.foo').length > 0" # see wd for documentation on browser : # Do something with browser like dismiss popups or scroll down to the # button of the page or whatever you want to do before you take a # screenshot. cb # remember to call cb() when you're done # save the file out: 'google.jpg' grabbercommandsscreenshot browserscreenshotOptions return consoleerrorerr if err # image now contains an instance of a sharp image object thing that you can # then do something with if you want. Probably not necesary if you passed # in an out parameter
Examples
Most of the action happens in the examples/ directory.
chrome_screenshot.coffee and firefox_screenshot.coffee are command-line utilities to take screenshots.
The parameters are url, width, height, resize, quality, crop. The CLI utilities also take an --out=filename.(png|jpeg|webp) parameter and support a -t parameter for testing with Thing's settings.