File tree 4 files changed +544
-0
lines changed
4 files changed +544
-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
+ var puppeteer = require ( 'puppeteer' ) ;
2
+ var express = require ( 'express' ) ;
3
+ var path = require ( 'path' ) ;
4
+ var fs = require ( 'fs' ) ;
5
+ var app = express ( ) ;
6
+
7
+ // Image Diff: https://www.npmjs.com/package/blink-diff
8
+
9
+ app . use ( express . static ( 'static' ) ) ;
10
+ app . use ( 'screenshots' , express . static ( path . join ( __dirname , 'screenshots' ) ) ) ;
11
+
12
+ app . get ( '/screenshot' , function ( req , res ) {
13
+ var url = req . query . url ;
14
+ puppeteer . launch ( ) . then ( function ( browser ) {
15
+ browser . newPage ( ) . then ( function ( page ) {
16
+ page . goto ( url ) . then ( function ( loadedPage ) {
17
+ page . setViewport ( { height : 1500 , width :1920 } ) ;
18
+ var filename = 'screenshots/' + 'screenshot_' + Date . now ( ) + '.jpg' ;
19
+ var filepath = path . join ( __dirname , filename ) ;
20
+ page . screenshot ( { fullPage : true , path : filepath , quality :100 } ) . then ( function ( file ) {
21
+ res . sendFile ( filepath ) ;
22
+ browser . close ( ) ;
23
+ } ) ;
24
+ } ) ;
25
+ } ) ;
26
+ } ) ;
27
+ } ) ;
28
+
29
+ app . listen ( 3000 || process . env . PORT ) ;
30
+ console . log ( 'Running at localhost:' + 3000 ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " Tests" ,
3
+ "version" : " 1.0.0" ,
4
+ "main" : " index.js" ,
5
+ "license" : " MIT" ,
6
+ "dependencies" : {
7
+ "express" : " ^4.16.2" ,
8
+ "puppeteer" : " ^0.12.0"
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments