Implement browser.stdout and browser.stderr streams
This patch adds browser.stdout and browser.stderr streams. These streams allow to get the browser instance output, e.g. ```js browser.stderr.pipe(process.stdout); ```
This commit is contained in:
parent
aa5419a577
commit
34f043d821
@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let {Duplex} = require('stream');
|
||||||
let http = require('http');
|
let http = require('http');
|
||||||
let path = require('path');
|
let path = require('path');
|
||||||
let removeRecursive = require('rimraf').sync;
|
let removeRecursive = require('rimraf').sync;
|
||||||
@ -64,6 +65,9 @@ class Browser {
|
|||||||
this._terminated = false;
|
this._terminated = false;
|
||||||
this._chromeProcess = null;
|
this._chromeProcess = null;
|
||||||
this._launchPromise = null;
|
this._launchPromise = null;
|
||||||
|
|
||||||
|
this.stderr = new ProxyStream();
|
||||||
|
this.stdout = new ProxyStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,6 +116,8 @@ class Browser {
|
|||||||
this._terminated = true;
|
this._terminated = true;
|
||||||
removeRecursive(this._userDataDir);
|
removeRecursive(this._userDataDir);
|
||||||
});
|
});
|
||||||
|
this._chromeProcess.stderr.pipe(this.stderr);
|
||||||
|
this._chromeProcess.stdout.pipe(this.stdout);
|
||||||
|
|
||||||
await waitForChromeResponsive(this._remoteDebuggingPort, () => !this._terminated);
|
await waitForChromeResponsive(this._remoteDebuggingPort, () => !this._terminated);
|
||||||
if (this._terminated)
|
if (this._terminated)
|
||||||
@ -153,3 +159,17 @@ function waitForChromeResponsive(remoteDebuggingPort, shouldWaitCallback) {
|
|||||||
req.end();
|
req.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ProxyStream extends Duplex {
|
||||||
|
_read() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {?} chunk
|
||||||
|
* @param {string} encoding
|
||||||
|
* @param {function()} callback
|
||||||
|
*/
|
||||||
|
_write(chunk, encoding, callback) {
|
||||||
|
this.push(chunk, encoding);
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user