LoginSignup
2

More than 5 years have passed since last update.

nightmareでScreenshotを撮る

Last updated at Posted at 2017-06-22

nightmareってなんぞ?

nightmareはelectronを使用して作られているブラウザで、headlessで動かすことができます。また、コールバック地獄なしに操作ができます。
以前は、Phantom.jsのwrapperだったみたいです。

環境

node.js v8.1.2

Screenshotを撮る

使い方はすごく簡単なので、実際ソース見てください。

'use strict';

const Nightmare = require('nightmare');

const nightmare = new Nightmare();
// showにtrueをセットすると可視化されます。
// const nightmare = new Nightmare({show:true});


main();

async function main() {
    await screenshot('https://www.google.co.jp');
}

async function screenshot(url) {
    await nightmare
        .goto(url)
        .viewport(1024, 768)
        .screenshot('screenshot.png')
        .end();
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2