Sign inSign up

killia/screenshoter

By killia

•Updated over 3 years ago

This image allows to screenshot any webpage without popups

Image
0

170

killia/screenshoter repository overview

⁠screenshoter

Google Puppeteer⁠ as a Dockerized HTTP-service for making screenshots.

DockerHub

nodesource/node

⁠installation

docker pull killia/screenshoter

⁠build

docker build -t killia/screenshoter:1.4.0 .

⁠publish

docker push killia/screenshoter:1.4.0

⁠Features

This project was forked from mingalevme/screenshoter⁠. Additionally to the great features of this project, I added a Popup Blocker to discard undesired popups when you access any webpage.

⁠Usage

⁠Basic usage
docker run -d --restart always -p 8080:8080 --name screenshoter killia/screenshoter

... or while development:

via docker

docker build -t screenshoter-dev .
docker run --rm -p 8080:8080 --name screenshoter-dev screenshoter --metrics --metrics-collect-default

via nodejs

npm install
node app.js --host 127.0.0.1 --port 8080

Then navigate to url

curl "http://localhost:8080/take?url=https%3A%2F%2Fhub.docker.com%2Fr%2Fkillia%2Fscreenshoter%2F" > /tmp/screenshot.png

Or capture screenshot without popups

curl "http://localhost:8080/take?popup-block=true&delay=30000&url=https://www.bershka.com/it/" > /tmp/screenshot.png
⁠Puppeteer arguments
CLI argEnvVarDefaultComment
--puppeteer--proxy-serverPROXY_SERVERInitializes proxy-server argument for Puppeteer
⁠Logging
CLI argEnvVarDefaultComment
--logger-channelSCREENSHOTER_LOGGER_CHANNELconsoleConsole (StdOut/StdErr)
--logger-levelSCREENSHOTER_LOGGER_LEVELdebugGlobal default log level (debug, info, notice, warning, error, critical, alert, emergency)
--logger-console-levelSCREENSHOTER_LOGGER_CONSOLE_LEVELConsole logger level
⁠Cache
CLI argEnvVarDefaultComment
--cache-driverSCREENSHOTER_CACHE_DRIVERCache driver (available: null, s3, filesystem)
⁠S3
CLI argEnvVarDefaultComment
--cache-s3-endpoint-urlSCREENSHOTER_CACHE_S3_ENDPOINT_URLhttps://s3.amazonaws.com⁠s3 endpoint url
--cache-s3-regionSCREENSHOTER_CACHE_S3_REGIONus-east-1s3 region
--cache-s3-access-key-idSCREENSHOTER_CACHE_S3_ACCESS_KEY_IDS3 access key id
--cache-s3-secret-access-keySCREENSHOTER_CACHE_S3_SECRET_ACCESS_KEYS3 secret access key
--cache-s3-bucketSCREENSHOTER_CACHE_S3_BUCKETS3 bucket
--cache-s3-force-path-styleSCREENSHOTER_CACHE_S3_FORCE_PATH_STYLE0Use path-style
⁠FileSystem
CLI argEnvVarDefaultComment
--cache-file-system-base-dirSCREENSHOTER_CACHE_FILE_SYSTEM_BASE_DIR$TMP/screenshoterBase dir
--cache-file-system-modeSCREENSHOTER_CACHE_FILE_SYSTEM_MODE0o666File creation mode
⁠Prometheus metrics

To enable export Prometheus metrics (https://www.npmjs.com/package/express-prom-bundle⁠) add --metrics arg or set SCREENSHOTER_METRICS env var.

CLI argEnvVarDefaultComment
--metricsSCREENSHOTER_METRICSEnable metrics export
--metrics-collect-defaultSCREENSHOTER_METRICS_COLLECT_DEFAULTExport default Prometheus NodeJS metrics
--metrics-bucketsSCREENSHOTER_METRICS_BUCKETS0.1,0.5,1,3,5,10,20"http_request_duration_seconds" buckets

Example:

docker run -d --restart always -p 8080:8080 --name screenshoter killia/screenshoter --metrics --metrics-collect-default --metrics-buckets "1,3,5,10,20,30,60"

Metrics are available on /metrics-path.

You can restrict access to the service via link signing (https://www.npmjs.com/package/@killia/secure-link⁠). To enable the restriction run the service with secure-link-secret arg or SCREENSHOTER_SECURE_LINK_SECRET env var, that is you private key to sign/validate links.

CLI argEnvVarDefaultComment
--secure-link-secretSCREENSHOTER_SECURE_LINK_SECRETSecret key
--secure-link-hasherSCREENSHOTER_SECURE_LINK_HASHERmd5Hasher, md5/sha1
--secure-link-signature-argSCREENSHOTER_SECURE_SIGNATURE_ARGsignaturesignature query param name
--secure-link-expires-argSCREENSHOTER_SECURE_EXPIRES_ARGexpiresexpiration query param name

Example:

docker run -d --restart always -p 8080:8080 --name screenshoter -e "SCREENSHOTER_SECURE_LINK_SECRET=secret" killia/screenshoter --secure-link-hasher sha1 --secure-link-signature-arg _sig --secure-link-expires-arg _expires --secure-link-secret "secret"

NOTE the example uses both env var and arg for setting a secret, any one is enough.

⁠API Reference

GET /take
⁠Arguments
ArgTypeRequiredDescription
urlstringtrueAbsolute URL of the page to screenshot. Example: 'https://www.google.com⁠'
formatstringfalseImage file format. Supported types are png or jpeg. Defaults to png.
qualityintfalseThe quality of the image, between 1-100. Not applicable to png images.
fullintfalseWhen true, takes a screenshot of the full scrollable page. Defaults to false.
devicestringfalseOne of supported device, e.g. iPhone X, see https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts⁠ for a full list of devices
viewport-widthintfalseWidth in pixels of the viewport when taking the screenshot. Using lower values like 460 can help emulate what the page looks like on mobile devices. Defaults to 800.
viewport-heightintfalseHeight in pixels of the viewport when taking the screenshot. Defaults to 600.
is-mobilebool (int)falseWhether the meta viewport tag is taken into account. Defaults to false.
has-touchbool (int)falseSpecifies if viewport supports touch events. Defaults to false.
is-landscapebool (int)falseSpecifies if viewport is in landscape mode. Defaults to false.
device-scale-factorintfalseSets device scale factor (basically dpr) to emulate high-res/retina displays. Number from 1 to 4. Defaults to 1.
user-agentstringfalseSets user agent
cookiesjsonfalseList with cookies objects (https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagesetcookiecookies⁠), e.g. [{"name":"foo","value":"bar","domain":".example.com"}]
timeoutintfalseMaximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
fail-on-timeoutbool (int)falseIf set to false, we will take a screenshot when timeout is reached instead of failing the request. Defaults to false.
popup-blockerbool (int)falseIf set to true, we will disable any popup existing on the webpage. Defaults to false.
delayintfalseIf set, we'll wait for the specified number of seconds after the page load event before taking a screenshot.
wait-until-eventstringfalseControls when the screenshot is taken as the page loads. Supported events include: load - window load event fired (default); domcontentloaded - DOMContentLoaded event fired; networkidle0 - wait until there are zero network connections for at least 500ms; networkidle2 - wait until there are no more than 2 network connections for at least 500ms. domcontentloaded is the fastest but riskiest option–many images and other asynchronous resources may not have loaded yet. networkidle0 is the safest but slowest option. load is a nice middle ground.Defaults to load.
elementstringfalseQuery selector of element to screenshot.
transparencybool (int)falseHides default white webpage background for capturing screenshots with transparency, only works when format is png. Defaults to 0.
scroll-page-to-bottombool (int)false(thx https://github.com/Kiuber⁠) Scroll the page to the bottom (https://www.npmjs.com/package/puppeteer-autoscroll-down⁠).
scroll-page-to-bottom-sizeintfalse(scroll-page-to-bottom) Number of pixels to scroll on each step (default: 250).
scroll-page-to-bottom-delay-msintfalse(scroll-page-to-bottom) Delay in ms after each completed scroll step (default: 100).
scroll-page-to-bottom-steps-limitintfalse(scroll-page-to-bottom) Max number of steps to scroll.
widthintfalseIf resulted image's width is greater than provided value then image will be proportionally resized to provided width. This action runs before max-height checking. Defaults to 0 (do not resize).
max-heightintfalseIf resulted image's height is greater than provided value then image's height will be cropped to provided value. Defaults to 0 (do not crop).
ttlintfalseIf last cached screenshot was made less than provided seconds then the cached image will be returned otherwise image will be cached for future use.

Tag summary

Content type

Image

Digest

sha256:120a8f6d8…

Size

411 MB

Last updated

over 3 years ago

docker pull killia/screenshoter:1.4.2