File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,28 @@ const serverOptions = {root: path};
1414
1515const server = httpServer . createServer ( serverOptions ) ;
1616
17+ // see https://github.com/puppeteer/puppeteer/issues/3397#issuecomment-434970058
18+ async function logMsg ( msg ) {
19+ // serialize my args the way I want
20+ const args = await Promise . all ( msg . args ( ) . map ( arg => arg . executionContext ( ) . evaluate ( arg => {
21+ // I'm in a page context now. If my arg is an error - get me its message.
22+ if ( arg instanceof Error )
23+ return arg . message ;
24+ // return arg right away. since we use `executionContext.evaluate`, it'll return JSON value of
25+ // the argument if possible, or `undefined` if it fails to stringify it.
26+ return arg ;
27+ } , arg ) ) ) ;
28+ console . log ( ...args ) ;
29+ }
30+
1731server . listen ( port , host , function ( ) {
18- console . log ( `Server running at http://${ host } :${ port } /` ) ;
32+ console . log ( `[puppeteer] Server running at http://${ host } :${ port } /` ) ;
1933
2034 ( async ( ) => {
2135 const browser = await puppeteer . launch ( ) ;
2236 const page = await browser . newPage ( ) ;
23- page . on ( 'console' , msg => console . log ( msg . text ( ) ) ) ;
24- console . log ( "navigating to: " , url ) ;
37+ page . on ( 'console' , logMsg ) ;
38+ console . log ( "[puppeteer] Navigating to: " , url ) ;
2539 await page . goto ( url ) ;
2640
2741 const failures = await page . evaluate ( ( ) => {
You can’t perform that action at this time.
0 commit comments