Skip to content

Commit

Permalink
clarify chrome remote interface var in CLI driver
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Aug 1, 2016
1 parent 69622b8 commit b6592d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 18 additions & 9 deletions lighthouse-core/gather/drivers/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ const port = process.env.PORT || 9222;
const log = require('../../lib/log.js');

class CriDriver extends Driver {
constructor() {
super();

/**
* Chrome remote interface instance.
*/
this._cri = null;
}

/**
* @return {!Promise<null>}
* @return {!Promise<undefined>}
*/
connect() {
return new Promise((resolve, reject) => {
if (this._chrome) {
if (this._cri) {
return resolve();
}

Expand All @@ -43,7 +51,8 @@ class CriDriver extends Driver {

chromeRemoteInterface({port: port, chooseTab: tab}, chrome => {
this._tab = tab;
this._chrome = chrome;
this._cri = chrome;
// The CRI instance is also an EventEmitter, so use directly for event dispatch.
this._eventEmitter = chrome;
this.enableRuntimeEvents().then(_ => {
resolve();
Expand All @@ -57,7 +66,7 @@ class CriDriver extends Driver {
disconnect() {
return new Promise((resolve, reject) => {
if (!this._tab) {
this._chrome.close();
this._cri.close();
return resolve();
}

Expand All @@ -74,11 +83,11 @@ class CriDriver extends Driver {
/* eslint-enable new-cap */
})
.then(() => {
if (this._chrome) {
this._chrome.close();
if (this._cri) {
this._cri.close();
}
this._tab = null;
this._chrome = null;
this._cri = null;
this._eventEmitter = null;
this.url = null;
});
Expand All @@ -91,14 +100,14 @@ class CriDriver extends Driver {
* @return {!Promise}
*/
sendCommand(command, params) {
if (this._chrome === null) {
if (this._cri === null) {
throw new Error('connect() must be called before attempting to send a command.');
}

return new Promise((resolve, reject) => {
this.formattedLog('method => browser', {method: command, params: params});

this._chrome.send(command, params, (err, result) => {
this._cri.send(command, params, (err, result) => {
if (err) {
this.formattedLog('method <= browser ERR', {method: command, params: result}, 'error');
return reject(result);
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/gather/drivers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Driver {
constructor() {
this._url = null;
this.PAUSE_AFTER_LOAD = 500;
this._chrome = null;
this._traceEvents = [];
this._traceCategories = Driver.traceCategories;
this._eventEmitter = null;
Expand Down

0 comments on commit b6592d4

Please sign in to comment.