chrome-remote-interface
Advanced tools
Comparing version 0.12.2 to 0.12.3
@@ -46,4 +46,4 @@ #!/usr/bin/env node | ||
} | ||
}).on('error', function () { | ||
console.error('Cannot connect to Chrome'); | ||
}).on('error', function (err) { | ||
console.error('Cannot connect to Chrome:', err); | ||
}); |
@@ -54,6 +54,18 @@ var defaults = require('./defaults.js'); | ||
Chrome.prototype.close = function () { | ||
Chrome.prototype.close = function (callback) { | ||
var self = this; | ||
self.ws.removeAllListeners(); | ||
self.ws.close(); | ||
function closeWebSocket(callback) { | ||
self.ws.close(); | ||
self.ws.once('close', function () { | ||
self.ws.removeAllListeners(); | ||
callback(); | ||
}); | ||
} | ||
if (callback) { | ||
closeWebSocket(callback); | ||
} else { | ||
return new Promise(function (fulfill, reject) { | ||
closeWebSocket(fulfill); | ||
}); | ||
} | ||
}; | ||
@@ -60,0 +72,0 @@ |
@@ -12,3 +12,3 @@ { | ||
"homepage": "https://github.com/cyrus-and/chrome-remote-interface", | ||
"version": "0.12.2", | ||
"version": "0.12.3", | ||
"repository": { | ||
@@ -15,0 +15,0 @@ "type": "git", |
@@ -49,4 +49,4 @@ chrome-remote-interface | ||
} | ||
}).on('error', function () { | ||
console.error('Cannot connect to Chrome'); | ||
}).on('error', function (err) { | ||
console.error('Cannot connect to Chrome:', err); | ||
}); | ||
@@ -486,6 +486,10 @@ ``` | ||
#### chrome.close() | ||
#### chrome.close([callback]) | ||
Close the connection to Chrome. | ||
`callback` is executed when the WebSocket is successfully closed. | ||
When `callback` is omitted a `Promise` object is returned. | ||
Contributors | ||
@@ -492,0 +496,0 @@ ------------ |
@@ -5,15 +5,34 @@ var Chrome = require('../'); | ||
describe('closing a connection', function () { | ||
it('should allow a subsequent new connection', function (done) { | ||
Chrome(function (chrome) { | ||
chrome.close(); | ||
describe('with callback', function () { | ||
it('should allow a subsequent new connection', function (done) { | ||
Chrome(function (chrome) { | ||
chrome.close(); | ||
done(); | ||
chrome.close(function () { | ||
Chrome(function (chrome) { | ||
chrome.close(done); | ||
}).on('error', function () { | ||
assert(false); | ||
}); | ||
}); | ||
}).on('error', function () { | ||
assert(false); | ||
}); | ||
}).on('error', function () { | ||
assert(false); | ||
}); | ||
}); | ||
describe('without callback', function () { | ||
it('should allow a subsequent new connection', function (done) { | ||
Chrome(function (chrome) { | ||
chrome.close().then(function () { | ||
Chrome(function (chrome) { | ||
chrome.close(done); | ||
}).on('error', function () { | ||
assert(false); | ||
}); | ||
}).catch(function () { | ||
assert(false); | ||
}); | ||
}).on('error', function () { | ||
assert(false); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -9,4 +9,3 @@ var Chrome = require('../'); | ||
Chrome(function (chrome) { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).on('error', function () { | ||
@@ -20,4 +19,3 @@ assert(false); | ||
Chrome({'host': 'localhost', 'port': 9222}, function (chrome) { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).on('error', function () { | ||
@@ -60,5 +58,4 @@ assert(false); | ||
}).on('error', function (err) { | ||
chrome.close(); | ||
assert(err instanceof Error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -75,4 +72,3 @@ }).on('error', function () { | ||
Chrome().then(function (chrome) { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).catch(function () { | ||
@@ -86,4 +82,3 @@ assert(false); | ||
Chrome({'host': 'localhost', 'port': 9222}).then(function (chrome) { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).catch(function () { | ||
@@ -126,5 +121,4 @@ assert(false); | ||
}).catch(function (err) { | ||
chrome.close(); | ||
assert(err instanceof Error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -131,0 +125,0 @@ }).on('error', function () { |
@@ -9,5 +9,4 @@ var Chrome = require('../'); | ||
chrome.once('event', function (message) { | ||
chrome.close(); | ||
assert(message.method); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -22,5 +21,4 @@ chrome.send('Network.enable'); | ||
chrome.once('Network.requestWillBeSent', function (message) { | ||
chrome.close(); | ||
assert(!message.method); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -34,5 +32,4 @@ chrome.send('Network.enable'); | ||
chrome.Network.requestWillBeSent(function (message) { | ||
chrome.close(); | ||
assert(!message.method); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -39,0 +36,0 @@ chrome.send('Network.enable'); |
@@ -9,4 +9,3 @@ var Chrome = require('../'); | ||
chrome.once('Network.requestWillBeSent', function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -22,5 +21,4 @@ chrome.send('Network.enable'); | ||
chrome.send('Page.enable', function (error, response) { | ||
chrome.close(); | ||
assert(!error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -34,5 +32,4 @@ }); | ||
chrome.send('Network.setCacheDisabled', {'cacheDisabled': true}, function (error, response) { | ||
chrome.close(); | ||
assert(!error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -46,4 +43,3 @@ }); | ||
chrome.once('Network.requestWillBeSent', function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -59,5 +55,4 @@ chrome.Network.enable(); | ||
chrome.Page.enable(function (error, response) { | ||
chrome.close(); | ||
assert(!error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -71,5 +66,4 @@ }); | ||
chrome.Network.setCacheDisabled({'cacheDisabled': true}, function (error, response) { | ||
chrome.close(); | ||
assert(!error); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -83,4 +77,3 @@ }); | ||
chrome.send('Network.enable').then(function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).catch(function () { | ||
@@ -96,4 +89,3 @@ assert(false); | ||
}).catch(function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -107,4 +99,3 @@ }); | ||
chrome.Network.enable().then(function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}).catch(function () { | ||
@@ -120,4 +111,3 @@ assert(false); | ||
}).catch(function () { | ||
chrome.close(); | ||
done(); | ||
chrome.close(done); | ||
}); | ||
@@ -124,0 +114,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
363736
6288
516