From 55f73ac11196798c30151cff952b61fcd9742793 Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Wed, 16 Mar 2022 15:35:37 +0100 Subject: [PATCH] check port availability before starting Chromedriver fixes #74 --- src/launcher.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/launcher.js b/src/launcher.js index ece2fd9..be474c8 100644 --- a/src/launcher.js +++ b/src/launcher.js @@ -65,15 +65,10 @@ export default class ChromeDriverLauncher { log.warn('Falling back to use global chromedriver bin') command = process && process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver' } - this.process = spawn(command, this.args) - - if (typeof this.outputDir === 'string') { - this._redirectLogStream() - } else { - this.process.stdout.pipe(split2()).on('data', log.info) - this.process.stderr.pipe(split2()).on('data', log.warn) - } + /** + * wait for port to be available before starting Chromedriver + */ try { await tcpPortUsed.waitUntilFree(this.options.port, POLL_INTERVAL, POLL_TIMEOUT) } catch (err) { @@ -83,6 +78,15 @@ export default class ChromeDriverLauncher { ) } + this.process = spawn(command, this.args) + + if (typeof this.outputDir === 'string') { + this._redirectLogStream() + } else { + this.process.stdout.pipe(split2()).on('data', log.info) + this.process.stderr.pipe(split2()).on('data', log.warn) + } + try { await tcpPortUsed.waitUntilUsed(this.options.port, POLL_INTERVAL, POLL_TIMEOUT) } catch (err) {