Commit 0557ac9 1 parent 43d5d16 commit 0557ac9 Copy full SHA for 0557ac9
File tree 7 files changed +464
-0
lines changed
7 files changed +464
-0
lines changed Original file line number Diff line number Diff line change
1
+ /node_modules
Original file line number Diff line number Diff line change
1
+ /node_modules
Original file line number Diff line number Diff line change
1
+ FROM node:12-buster-slim
2
+
3
+ RUN apt-get update \
4
+ && apt-get install -y wget gnupg \
5
+ && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
6
+ && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
7
+ && apt-get update \
8
+ && apt-get install -y google-chrome-stable fonts-freefont-ttf libxss1 fonts-noto-color-emoji \
9
+ --no-install-recommends \
10
+ && rm -rf /var/lib/apt/lists/*
11
+
12
+ ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
13
+ ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/google-chrome-stable
14
+
15
+ ADD package.json yarn.lock /app/
16
+
17
+ RUN cd /app && yarn install \
18
+ # Add user so we don't need --no-sandbox.
19
+ # same layer as npm install to keep re-chowned files from using up several hundred MBs more space
20
+ && groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
21
+ && mkdir -p /home/pptruser/Downloads \
22
+ && chown -R pptruser:pptruser /home/pptruser \
23
+ && chown -R pptruser:pptruser /app/node_modules
24
+
25
+ ADD . /app/
26
+
27
+ # Run everything after as non-privileged user.
28
+ USER pptruser
29
+
30
+ CMD ["node" , "/app/screenshot.js" ]
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " screenshotter" ,
3
+ "version" : " 1.0.0" ,
4
+ "private" : true ,
5
+ "dependencies" : {
6
+ "pngjs" : " ^6.0.0" ,
7
+ "puppeteer" : " ^5.5.0"
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ const puppeteer = require ( "puppeteer" ) ;
2
+ const fs = require ( "fs" ) ;
3
+ const PNG = require ( "pngjs" ) . PNG ;
4
+
5
+ function sleep ( ms ) {
6
+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
7
+ }
8
+
9
+ const URL = process . env . URL || "CHANGEME" ;
10
+
11
+ ( async ( ) => {
12
+ const browser = await puppeteer . launch ( {
13
+ args : [ "--no-sandbox" , "--disable-setuid-sandbox" ] ,
14
+ } ) ;
15
+
16
+ const page = await browser . newPage ( ) ;
17
+
18
+ /* Kindle 4 NT resolution */
19
+ await page . setViewport ( { width : 600 , height : 800 } ) ;
20
+
21
+ /* Might want to use networkidle0 here, depending on the type of page */
22
+ /* See https://github.com/puppeteer/puppeteer/blob/main/docs/api.md */
23
+ await page . goto ( URL , { waitUntil : "networkidle2" } ) ;
24
+
25
+ /* This is a bit silly. ¯\_(ツ)_/¯
26
+ Networkidle2 doesn't always seem to wait long enough. */
27
+ await sleep ( 3000 ) ;
28
+
29
+ await page . screenshot ( { path : "dash.png" } ) ;
30
+
31
+ await fs . createReadStream ( "dash.png" )
32
+ . pipe ( new PNG ( { colorType : 0 } ) )
33
+ . on ( "parsed" , function ( ) {
34
+ this . pack ( ) . pipe ( fs . createWriteStream ( "dash.png" ) ) ;
35
+ } ) ;
36
+
37
+ browser . close ( ) ;
38
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments