feat(browser): add browser.disconnected event (#960)

This patch adds a 'disconnected' event for the browser. The event is issued
when the "browser" loses connection to the chrome process.

References #952
This commit is contained in:
Adi Prasetyo
2017-11-04 08:46:17 +07:00
committed by Andrey Lushnikov
parent 88ba52a363
commit 03fefb53f8
4 changed files with 47 additions and 1 deletions

View File

@@ -75,6 +75,13 @@ class Connection extends EventEmitter {
});
}
/**
* @param {function()} callback
*/
setClosedCallback(callback) {
this._closeCallback = callback;
}
/**
* @param {string} message
*/
@@ -108,6 +115,10 @@ class Connection extends EventEmitter {
}
_onClose() {
if (this._closeCallback) {
this._closeCallback();
this._closeCallback = null;
}
this._ws.removeAllListeners();
for (const callback of this._callbacks.values())
callback.reject(new Error(`Protocol error (${callback.method}): Target closed.`));