diff --git a/example/double-smarf.js b/example/double-smarf.js new file mode 100644 index 0000000..0f5e0a9 --- /dev/null +++ b/example/double-smarf.js @@ -0,0 +1,14 @@ +var chrome = require('../index'); + +chrome.getCookies('http://smarf.toomanycooks.kitchen', function (err, cookies) { + chrome.getCookies('http://smarf.toomanycooks.kitchen', function (err, cookies) { + + if (err) { + console.error(err); + return; + } + + console.log(cookies); + + }); +}); diff --git a/index.js b/index.js index 80abc85..f54db21 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,8 @@ var sqlite3 = require('sqlite3'), crypto = require('crypto'), Cookie = tough.Cookie, path, - ITERATIONS; + ITERATIONS, + dbClosed = false; if (process.platform === 'darwin') { @@ -223,6 +224,11 @@ var getCookies = function (uri, format, callback) { return callback(new Error('Could not parse URI, format should be http://www.example.com/path/')); } + if (dbClosed) { + db = new sqlite3.Database(path); + dbClosed = false; + } + getDerivedKey(function (err, derivedKey) { if (err) { @@ -312,14 +318,17 @@ var getCookies = function (uri, format, callback) { } - return callback(null, output); + db.close(function(err) { + if (!err) { + dbClosed = true; + } + return callback(null, output); + }); }); }); - db.close(); - }); };