Make browser._ensureChromeIsRunning idempotent
The _ensureChromeIsRunning should launch chrome only once and return the same promise for all its clients.
This commit is contained in:
parent
6c7ae41ae6
commit
c8664319ed
@ -63,6 +63,7 @@ class Browser {
|
||||
this._chromeArguments.push(...options.args);
|
||||
this._terminated = false;
|
||||
this._chromeProcess = null;
|
||||
this._launchPromise = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,8 +97,12 @@ class Browser {
|
||||
}
|
||||
|
||||
async _ensureChromeIsRunning() {
|
||||
if (this._chromeProcess)
|
||||
return;
|
||||
if (!this._launchPromise)
|
||||
this._launchPromise = this._launchChrome();
|
||||
return this._launchPromise;
|
||||
}
|
||||
|
||||
async _launchChrome() {
|
||||
this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {});
|
||||
let stderr = '';
|
||||
this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8'));
|
||||
|
Loading…
Reference in New Issue
Block a user