0.2.2 • Published 5 years ago

webpage-capture v0.2.2

Weekly downloads
50
License
MIT
Repository
github
Last release
5 years ago

webpage-capture

NPM version Build Status Dependency Status Coverage percentage

A super simple way to capture webpages screenshots using phantomjs.

NPM

Installation

If you want to use it inside your scripts, save and install it in your project dependencies.

npm install --save webpage-capture
yarn add webpage-capture

Once it has done you can require webpage-capture in your script and start using it.

Global module

You can also use it as a cli-tool installing it as a global module:

npm install -g webpage-capture
yarn global add webpage-capture

Than you can start playing around with the options using the built-in help typing: -h, --help


Usage

The most basic use is with a single input and default settings:

const webCapture = require('webpage-capture');
webCapture('https://github.com/b4dnewz', {}, (err, res) => {
  // handle err
  console.log('Output saved to:', res);
});

You can also capture multiple source urls:

const webCapture = require('webpage-capture');
webCapture([
  'https://github.com/b4dnewz',
  'https://github.com/b4dnewz/webpage-capture'
], {}, (err, res) => {
  // handle err
  console.log('Output saved to:', res);
});

Or render HTML text and capture it:

const webCapture = require('webpage-capture');
webCapture('<h1>this is c00l</h1>', {}, (err, res) => {
  // handle err
  console.log('Output saved to:', res);
});

It can also render the same source in multiple viewports resolutions:

const webCapture = require('webpage-capture');
webCapture('https://github.com/b4dnewz', {
  viewport: ['desktop', 'laptop-mdpi', 'nexus-7']
}, (err, res) => {
  // handle err
  console.log('Output saved to:', res);
});

It can accept many options to customize the capturing behavior:

const webCapture = require('webpage-capture');
const options = {
  debug: false,
  outputDir: './output',
  outputType: 'file',
  whiteBackground: true,
  renderOptions: {
    format: 'png',
    quality: 80
  },
  crop: false,
  clipRect: {
    top: 0,
    left: 0
  },
  viewport: 'desktop',
  userAgent: 'random'
};

webCapture('https://github.com/b4dnewz', options, (err, res) => {
  // handle err
  console.log('Output saved to:', res);
});

Options

outputDir

Type: String Default value: ./output

Where to save the files in case of 'file' outputType.

outputType

Type: String Default value: file

The capture output type that can be: file, base64 or html.

renderOptions

Type: Object Default value: { format: 'png', quality: 80 }

The options to pass to phantomjs page renderer.

crop

Type: Object Default value: false

If true the screenshot will be cropped as viewportSize.

userAgent

Type: string Default value: random

Let select the user agent to use, by default is a random browser user agent.

debug

Type: Boolean Default value: false

If enabled show extra execution logs useful when debugging.

whiteBackground

Type: Boolean Default value: true

Force the pages to have a white background color.

viewportSize

Type: Object Default value: { width: 1280, height: 800 }

The default page viewportSize for phantomjs.


License

MIT © Filippo Conti

Contributing

  1. Create an issue and describe your idea
  2. Fork the project (https://github.com/b4dnewz/webpage-capture/fork)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Write some tests and run it (npm run test')
  6. Publish the branch (git push origin my-new-feature)
  7. Create a new Pull Request
0.2.5

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.2.0-beta.3

5 years ago

0.2.0-beta.2

5 years ago

0.2.0-beta.1

5 years ago

0.2.0-beta.0

5 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago