forked from cyrus-and/chrome-remote-interface
/
index.js
31 lines (29 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var events = require('events');
var Chrome = require('./lib/chrome.js');
module.exports = function (options, callback) {
if (typeof options === 'function') {
callback = options;
options = undefined;
}
var notifier = new events.EventEmitter();
if (typeof callback === 'function') {
notifier.on('connect', callback);
}
// allow to register callbacks later
process.nextTick(function () {
// the default listener just disconnects from Chrome, this can be used
// to simply check the connection
if (notifier.listeners('connect').length === 0) {
notifier.on('connect', function (chrome) {
chrome.close();
});
}
// create the client passing the notifier
new Chrome(options, notifier);
});
return notifier;
};
module.exports.fetchProtocol = Chrome.fetchProtocol;
module.exports.listTabs = Chrome.listTabs;
module.exports.spawnTab = Chrome.spawnTab;
module.exports.closeTab = Chrome.closeTab;