@@ -50,6 +50,7 @@ class Page extends EventEmitter {
5050 client . send ( 'Runtime.enable' , { } ) ,
5151 client . send ( 'Security.enable' , { } ) ,
5252 client . send ( 'Performance.enable' , { } ) ,
53+ client . send ( 'Log.enable' , { } ) ,
5354 ] ) ;
5455 if ( ignoreHTTPSErrors )
5556 await client . send ( 'Security.setOverrideCertificateErrors' , { override : true } ) ;
@@ -103,7 +104,7 @@ class Page extends EventEmitter {
103104 client . on ( 'Security.certificateError' , event => this . _onCertificateError ( event ) ) ;
104105 client . on ( 'Inspector.targetCrashed' , event => this . _onTargetCrashed ( ) ) ;
105106 client . on ( 'Performance.metrics' , event => this . _emitMetrics ( event ) ) ;
106-
107+ client . on ( 'Log.entryAdded' , event => this . _onLogEntryAdded ( event ) ) ;
107108 this . _target . _isClosedPromise . then ( ( ) => this . emit ( Page . Events . Close ) ) ;
108109 }
109110
@@ -125,6 +126,14 @@ class Page extends EventEmitter {
125126 this . emit ( 'error' , new Error ( 'Page crashed!' ) ) ;
126127 }
127128
129+ _onLogEntryAdded ( event ) {
130+ const { level, text, args} = event . entry ;
131+ if ( args )
132+ args . map ( arg => helper . releaseObject ( this . _client , arg ) ) ;
133+
134+ this . emit ( Page . Events . Console , new ConsoleMessage ( level , text ) ) ;
135+ }
136+
128137 /**
129138 * @return {!Puppeteer.Frame }
130139 */
@@ -1048,7 +1057,7 @@ class ConsoleMessage {
10481057 * @param {string } text
10491058 * @param {!Array<*> } args
10501059 */
1051- constructor ( type , text , args ) {
1060+ constructor ( type , text , args = [ ] ) {
10521061 this . _type = type ;
10531062 this . _text = text ;
10541063 this . _args = args ;
0 commit comments