Provide Google Chrome Devtools API Interface
2.0K
Chaldeas is a library that can automatically launch Chrome as Headless mode and Provide Devtools Protocol API at node.js
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();
$ yarn
$ 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
Bug reports and pull requests are welcome :) on GitHub at https://github.com/teitei-tk/Chaldeas.
Apache License 2.0
Content type
Image
Digest
Size
407.9 MB
Last updated
almost 9 years ago
docker pull teitei/chaldeas