Clean up Browser annotations. (#138)

This commit is contained in:
Alexei Filippov 2017-07-25 20:39:50 -07:00 committed by Andrey Lushnikov
parent aa28eb80f0
commit 83f4e43564

View File

@ -58,11 +58,11 @@ class Browser {
`--user-data-dir=${this._userDataDir}`,
]);
if (typeof options.headless !== 'boolean' || options.headless) {
this._chromeArguments.push(...[
this._chromeArguments.push(
`--headless`,
`--disable-gpu`,
`--hide-scrollbars`,
]);
`--hide-scrollbars`
);
}
if (typeof options.executablePath === 'string') {
this._chromeExecutable = options.executablePath;
@ -96,7 +96,7 @@ class Browser {
}
/**
* @return {string}
* @return {!Promise<string>}
*/
async version() {
await this._ensureChromeIsRunning();
@ -104,12 +104,18 @@ class Browser {
return version.Browser;
}
/**
* @return {!Promise}
*/
async _ensureChromeIsRunning() {
if (!this._launchPromise)
this._launchPromise = this._launchChrome();
return this._launchPromise;
}
/**
* @return {!Promise}
*/
async _launchChrome() {
this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {});
let stderr = '';
@ -146,24 +152,27 @@ class Browser {
module.exports = Browser;
helper.tracePublicAPI(Browser);
/**
* @param {!ChildProcess} chromeProcess
* @return {!Promise<number>}
*/
function waitForRemoteDebuggingPort(chromeProcess) {
return new Promise(fulfill => {
const rl = readline.createInterface({ input: chromeProcess.stderr });
let fulfill;
let promise = new Promise(x => fulfill = x);
rl.on('line', onLine);
rl.once('close', () => fulfill(-1));
return promise;
/**
* @param {string} line
*/
function onLine(line) {
const match = line.match(/^DevTools listening on .*:([\d]+)$/);
const match = line.match(/^DevTools listening on .*:(\d+)$/);
if (!match)
return;
rl.removeListener('line', onLine);
fulfill(Number.parseInt(match[1], 10));
}
});
}
class TaskQueue {
@ -172,11 +181,11 @@ class TaskQueue {
}
/**
* @param {function():!Promise} task
* @param {function()} task
* @return {!Promise}
*/
postTask(task) {
let result = this._chain.then(task);
const result = this._chain.then(task);
this._chain = result.catch(() => {});
return result;
}