@@ -118,16 +118,26 @@ class Chrome extends EventEmitter {
118118
119119 // initiate the connection process
120120 async _start ( ) {
121- const options = {
122- host : this . host ,
123- port : this . port ,
124- secure : this . secure ,
125- useHostName : this . useHostName ,
126- alterPath : this . alterPath ,
127- ...this . connectOptions ,
128- } ;
129121 try {
130- if ( ! this . process ) {
122+ if ( this . process )
123+ {
124+ const options = { local : this . local , cdp : this } ;
125+ // we first "connect" to stdio pipes, so that we can
126+ // first the protocol remotely via the pipe.
127+ await this . _connect ( ) ;
128+ const protocol = await this . _fetchProtocol ( options ) ;
129+ api . prepare ( this , protocol ) ;
130+ }
131+ else
132+ {
133+ const options = {
134+ host : this . host ,
135+ port : this . port ,
136+ secure : this . secure ,
137+ useHostName : this . useHostName ,
138+ alterPath : this . alterPath ,
139+ ...this . connectOptions ,
140+ } ;
131141 // fetch the WebSocket debugger URL
132142 const url = await this . _fetchDebuggerURL ( options ) ;
133143 // allow the user to alter the URL
@@ -137,12 +147,12 @@ class Chrome extends EventEmitter {
137147 // update the connection parameters using the debugging URL
138148 options . host = urlObject . hostname ;
139149 options . port = urlObject . port || options . port ;
150+ // fetch the protocol and prepare the API
151+ const protocol = await this . _fetchProtocol ( options ) ;
152+ api . prepare ( this , protocol ) ;
153+ // finally connect to the WebSocket
154+ await this . _connect ( ) ;
140155 }
141- // fetch the protocol and prepare the API
142- const protocol = await this . _fetchProtocol ( options ) ;
143- api . prepare ( this , protocol ) ;
144- // finally connect to the WebSocket or stdio
145- await this . _connect ( ) ;
146156 // since the handler is executed synchronously, the emit() must be
147157 // performed in the next tick so that uncaught errors in the client code
148158 // are not intercepted by the Promise mechanism and therefore reported
0 commit comments