chrome-headless-screenshot-api

Simple REST API to take screenshots of webpages using Chrome in headless mode.

Github星跟蹤圖

Chrome Headless Screenshot API

Simple REST API to take screenshots of webpages using Chrome in headless mode.

Demo: https://screenshot-demo.atslab.io/?url=https://github.com

This is a work in progress (see issues). Use in production isn't recommended at the moment (although we will be testing using it to power the ATS screenshot tool).

Note: The beta version of Chrome is being used for now, because opening new tabs through the remote debugging protocol doesn't work in the stable version of Chrome 59.

Running Locally

This project provides a simple Vagrantfile that will create a VM running Ubuntu and run a script that installs it's dependencies.

To get started running the API locally, first clone this repository:

git clone https://github.com/automatethatshit/chrome-headless-screenshot-api.git

Then, in the root of the repository, initialize the Vagrant VM by running:

vagrant up

Once the VM has booted and the provisioning script has run, ssh into the VM with:

vagrant ssh

And finally start the API by running:

node /chrome-headless-screenshot-api/src/runner.js

The Vagrantfile forwards port 3000 on the host machine to port 3000 on the guest. So the API should now be available to you at 127.0.0.1:3000.

API Usage

The API has only one route /, which accepts both GET and POST requests.

It accepts the following parameters as part of the query string for GET requests, or as URL encoded form parameters or a JSON object for POST requests:

url (string)

URL to take a screenshot of. This is the only required parameter.

full (boolean)

Whether or not to take a screenshot of the entire page or only the region visible without scrolling. Defaults value is true.

format (string)

Output file format. Accepted values are jpeg and png. Default value is jpeg.

delay (integer)

Number of seconds to pause before taking the screenshot. Default value is 2.

width (integer)

Browser width. Default value is 1440.

height (integer)

Browser width. Default value is 900.

ua (string)

User agent override. Default value is null.

Configuration

The configuration file is at src/config/config.yml.

It would be nice to be able to overwrite these values somewhere outside of version control, but for now all configuration comes from this file.

TODO: Document configuration parameters.

Credits

Thanks to David Schnurr for the Chrome headless screenshot capture code which is the basis of this project, and for the instructions for running Chrome headless on Ubuntu. David's code can be found at https://github.com/schnerd/chrome-headless-screenshots.

Thanks to Vladislav Bauer and the contributors to his project Manet (a screenshot REST API around SlimerJS and PhantomJS) which provided inspiration for this project and which its structure draws heavily from. We considered making this a fork of Manet, but ultimately decided not to for a number of reasons but mostly because we didn't plan on supporting all of it's options at the moment. We may consider submitting a pull request to Manet to support Chrome headless at some point in the future. (See: issue #82.)

Finally, this project wouldn't be possible without Andrea Cardaci and the contributors to chrome-remote-interface.

主要指標

概覽
名稱與所有者automatethatshit/chrome-headless-screenshot-api
主編程語言Java
編程語言Shell, JavaScript (語言數: 10)
平台
許可證Apache License 2.0
所有者活动
創建於2012-04-20 09:18:42
推送於2024-01-15 12:26:32
最后一次提交
發布數232
最新版本名稱v10.17.0 (發布於 )
第一版名稱BUG (發布於 2012-05-29 11:24:52)
用户参与
星數11.4k
關注者數350
派生數1.8k
提交數9k
已啟用問題?
問題數4574
打開的問題數359
拉請求數2708
打開的拉請求數37
關閉的拉請求數476
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?