@@ -78,19 +78,26 @@ class Chrome extends EventEmitter {
7878 callback = params ;
7979 params = undefined ;
8080 }
81+
82+ return this . sendRaw ( {
83+ method,
84+ params : params || { }
85+ } , callback ) ;
86+ }
87+
88+ sendRaw ( message , callback ) {
8189 // return a promise when a callback is not provided
8290 if ( typeof callback === 'function' ) {
83- this . _enqueueCommand ( method , params , callback ) ;
91+ this . _enqueueCommand ( message , callback ) ;
8492 return undefined ;
8593 } else {
8694 return new Promise ( ( fulfill , reject ) => {
87- this . _enqueueCommand ( method , params , ( error , response ) => {
95+ this . _enqueueCommand ( message , ( error , response ) => {
8896 if ( error ) {
89- const request = { method, params} ;
9097 reject (
9198 error instanceof Error
9299 ? error // low-level WebSocket error
93- : new ProtocolError ( request , response )
100+ : new ProtocolError ( message , response )
94101 ) ;
95102 } else {
96103 fulfill ( response ) ;
@@ -272,20 +279,17 @@ class Chrome extends EventEmitter {
272279 }
273280
274281 // send a command to the remote endpoint and register a callback for the reply
275- _enqueueCommand ( method , params , callback ) {
282+ _enqueueCommand ( message , callback ) {
276283 const id = this . _nextCommandId ++ ;
277- const message = {
278- id, method,
279- params : params || { }
280- } ;
284+ message = { id, ...message } ;
281285 this . _ws . send ( JSON . stringify ( message ) , ( err ) => {
282286 if ( err ) {
283287 // handle low-level WebSocket errors
284288 if ( typeof callback === 'function' ) {
285289 callback ( err ) ;
286290 }
287291 } else {
288- this . _callbacks [ id ] = callback ;
292+ this . _callbacks [ message . id ] = callback ;
289293 }
290294 } ) ;
291295 }
0 commit comments