grabber

0.0.2 • Public • Published

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.

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 = grabber.chrome.init(chromeOptions(err, browser) ->
  return console.error(err) 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 
    cleanup: (browser, cb) ->
      # 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'
 
  grabber.commands.screenshot browserscreenshotOptions(err, image) ->
    return console.error(err) 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.

Readme

Keywords

none

Package Sidebar

Install

npm i grabber

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • lerouxb