LoginSignup
7
8

More than 5 years have passed since last update.

pixivの技術ブログで紹介されてたHeadless Chromeのコードをchromyで3分の1にしてみた

Last updated at Posted at 2017-08-10

下記の記事で紹介されていたコードをchromyで書き直してみた。

Headless Chromeでデザイン変更履歴を追える魚拓を作ってみた

元コードが空行とコメント抜いて66行くらいで、chromyで書いたコードが21行。

const Chromy = require('chromy')
const util = require('util')
const fs = require('fs')

const writeFile = util.promisify(fs.writeFile)

async function main () {
  const chromy = new Chromy({waitFunctionPollingInterval: 200})
  await chromy.chain()
    .goto('https://www.pixiv.net/')
    .wait(_ => {
      const result = (window.scrollY + window.innerHeight >= window.document.body.scrollHeight)
      window.scrollTo(0, window.scrollY + window.innerHeight)
      return result
    })
    .screenshotDocument()
    .result((image) => {
      return writeFile('capture.png', image)
    })
    .end()
    .then(_ => chromy.close())
}

main()
7
8
0

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
7
8