0.1.4 • Published 7 years ago

chaldeas v0.1.4

Weekly downloads
18
License
APSL-2.0
Repository
github
Last release
7 years ago

Chaldeas

Chaldeas is a library that can automatically launch Chrome as Headless mode and Provide Devtools Protocol API at node.js

npm version Document Docker Automated buil Docker Build Statu

Dependency

  • Node 6.10.3 or later
  • GoogleChrome Version59 later or Canary
  • babel-runtime 6.23.0 or later
  • chrome-remote-interface 0.22.0 or later
  • lighthouse 1.6.5 or later
  • chrome-remote-interface-flowtype 0.1.2 or later

Architecture

  • AsyncAwait Support (babel-preset-es2017)
  • flowtype Support
  • eslint

API Document

Example

Print Page PDF

$ yarn add --dev chaldeas
import { writeFile } from 'fs';
import Chaldeas from 'chaldeas';

async function main() {
  const chaldeas = Chaldeas.new();

  try {
    const protocol = await chaldeas.fetchProtocol();

    const { Page, Network } = protocol;
    await Promise.all([
      Page.enable(),
      Network.enable(),
    ]);

    await Page.navigate({ url: 'https://github.com' });

    await Page.loadEventFired(async () => {
      const result = await Page.printToPDF();
      const fileName = (new Date()).getTime();
      const buffer = Buffer.from(result.data, 'base64');
      writeFile(`${fileName}.pdf`, buffer, (e) => {
        if (e) {
          throw e;
        }
      });

      await chaldeas.terminate();
    });
  } catch (error) {
    await chaldeas.terminate();
    console.error(error);
  }
}

main();

Development

  1. install npm modules
    • $ yarn
  2. Docker
  • $ yarn chrome:launch // alias of `yarn build; docker run -it -d --rm --name chaldeas --shm-size=1024m --cap-add=SYS_ADMIN -v `pwd`:/data teitei/chaldeas;`
    $ docker attach chaldeas
    
    root@ebcb835b0fcc:/data# ./node_modules/.bin/babel-node example/printPdf.js
    root@ebcb835b0fcc:/data# ls
    1497018362340.pdf  LICENSE    example  node_modules  src             yarn.lock
    Dockerfile         README.md  lib      package.json  yarn-error.log

Contributing

Bug reports and pull requests are welcome :) on GitHub at https://github.com/teitei-tk/Chaldeas.

Reference

LICENSE

Apache License 2.0

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.7

7 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