@@ -5,9 +5,7 @@ import { Logger } from './logger';
55import uniqueFilename = require( 'unique-filename' ) ;
66
77export class Browser {
8-
9- constructor ( private log : Logger ) {
10- }
8+ constructor ( private log : Logger ) { }
119
1210 validateOptions ( options ) {
1311 options . width = parseInt ( options . width ) || 1000 ;
@@ -36,7 +34,7 @@ export class Browser {
3634
3735 if ( ( process as any ) . pkg ) {
3836 const parts = puppeteer . executablePath ( ) . split ( path . sep ) ;
39- while ( ! parts [ 0 ] . startsWith ( 'chrome-' ) ) {
37+ while ( ! parts [ 0 ] . startsWith ( 'chrome-' ) ) {
4038 parts . shift ( ) ;
4139 }
4240 const executablePath = [ path . dirname ( process . execPath ) , ...parts ] . join ( path . sep ) ;
@@ -47,10 +45,18 @@ export class Browser {
4745 args : [ '--no-sandbox' ] ,
4846 } ) ;
4947 } else {
50- browser = await puppeteer . launch ( {
51- env : env ,
52- args : [ '--no-sandbox' ] ,
53- } ) ;
48+ if ( env [ 'CHROME_BIN' ] ) {
49+ browser = await puppeteer . launch ( {
50+ executablePath : env [ 'CHROME_BIN' ] ,
51+ env : env ,
52+ args : [ '--no-sandbox' ] ,
53+ } ) ;
54+ } else {
55+ browser = await puppeteer . launch ( {
56+ env : env ,
57+ args : [ '--no-sandbox' ] ,
58+ } ) ;
59+ }
5460 }
5561 page = await browser . newPage ( ) ;
5662
@@ -61,29 +67,32 @@ export class Browser {
6167 } ) ;
6268
6369 await page . setCookie ( {
64- ' name' : 'renderKey' ,
65- ' value' : options . renderKey ,
66- ' domain' : options . domain ,
70+ name : 'renderKey' ,
71+ value : options . renderKey ,
72+ domain : options . domain ,
6773 } ) ;
6874
6975 await page . goto ( options . url ) ;
7076
7177 // wait for all panels to render
72- await page . waitForFunction ( ( ) => {
73- const panelCount = document . querySelectorAll ( '.panel' ) . length || document . querySelectorAll ( '.panel-container' ) . length ;
74- return ( < any > window ) . panelsRendered >= panelCount ;
75- } , {
76- timeout : options . timeout * 1000
77- } ) ;
78+ await page . waitForFunction (
79+ ( ) => {
80+ const panelCount =
81+ document . querySelectorAll ( '.panel' ) . length || document . querySelectorAll ( '.panel-container' ) . length ;
82+ return ( < any > window ) . panelsRendered >= panelCount ;
83+ } ,
84+ {
85+ timeout : options . timeout * 1000 ,
86+ }
87+ ) ;
7888
7989 if ( ! options . filePath ) {
8090 options . filePath = uniqueFilename ( os . tmpdir ( ) ) + '.png' ;
8191 }
8292
83- await page . screenshot ( { path : options . filePath } ) ;
93+ await page . screenshot ( { path : options . filePath } ) ;
8494
8595 return { filePath : options . filePath } ;
86-
8796 } finally {
8897 if ( page ) {
8998 await page . close ( ) ;
@@ -94,4 +103,3 @@ export class Browser {
94103 }
95104 }
96105}
97-
0 commit comments