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

@@ -33,6 +33,9 @@ class Browser extends EventEmitter {
this._closeCallback = closeCallback || new Function();
/** @type {Map<string, Target>} */
this._targets = new Map();
this._connection.setClosedCallback(() => {
this.emit(Browser.Events.Disconnected);
});
this._connection.on('Target.targetCreated', this._targetCreated.bind(this));
this._connection.on('Target.targetDestroyed', this._targetDestroyed.bind(this));
this._connection.on('Target.targetInfoChanged', this._targetInfoChanged.bind(this));
@@ -136,7 +139,8 @@ class Browser extends EventEmitter {
Browser.Events = {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged'
TargetChanged: 'targetchanged',
Disconnected: 'disconnected'
};
helper.tracePublicAPI(Browser);