@@ -80,19 +80,26 @@ class Chrome extends EventEmitter {
8080 callback = params ;
8181 params = undefined ;
8282 }
83+
84+ return this . sendRaw ( {
85+ method,
86+ params : params || { }
87+ } , callback ) ;
88+ }
89+
90+ sendRaw ( message , callback ) {
8391 // return a promise when a callback is not provided
8492 if ( typeof callback === 'function' ) {
85- this . _enqueueCommand ( method , params , callback ) ;
93+ this . _enqueueCommand ( message , callback ) ;
8694 return undefined ;
8795 } else {
8896 return new Promise ( ( fulfill , reject ) => {
89- this . _enqueueCommand ( method , params , ( error , response ) => {
97+ this . _enqueueCommand ( message , ( error , response ) => {
9098 if ( error ) {
91- const request = { method, params} ;
9299 reject (
93100 error instanceof Error
94101 ? error // low-level WebSocket error
95- : new ProtocolError ( request , response )
102+ : new ProtocolError ( message , response )
96103 ) ;
97104 } else {
98105 fulfill ( response ) ;
@@ -289,20 +296,17 @@ class Chrome extends EventEmitter {
289296 }
290297
291298 // send a command to the remote endpoint and register a callback for the reply
292- _enqueueCommand ( method , params , callback ) {
299+ _enqueueCommand ( message , callback ) {
293300 const id = this . _nextCommandId ++ ;
294- const message = {
295- id, method,
296- params : params || { }
297- } ;
301+ message = { id, ...message } ;
298302 this . _send ( JSON . stringify ( message ) , ( err ) => {
299303 if ( err ) {
300304 // handle low-level WebSocket errors
301305 if ( typeof callback === 'function' ) {
302306 callback ( err ) ;
303307 }
304308 } else {
305- this . _callbacks [ id ] = callback ;
309+ this . _callbacks [ message . id ] = callback ;
306310 }
307311 } ) ;
308312 }
0 commit comments