You have probably missunderstood the meaning (and inner workings) of an asynchronous call.
I would propose the following approach:
Provide a list of URLs and a callback to be executed with a list of unvisited URLs as argument (after the history check has been completed for all URLs).
For each URL in the original list:
a. Check if it has been visited (and add it to the list of unvisited URLs if so).
b. Increment a checkedURLs
counter.
c. Check if all URLs have been (asynchronously) checked, i.e. checkedURLs
equals the length of the original URL list.
When you detect that all URLs have been checked (see 2.c.), execute the specified callback (see 1.), passing the list of unvisited URLs as argument.
Some sample code for a demo extension:
manifest.json:
{
"manifest_version": 2,
"name": "Demo",
"version": "0.0",
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"browser_action": { "default_title": "Demo Extension" },
"permissions": ["history"]
}
background.js:
/* List of URLs to check against */
var urlList = [
"http://stackoverflow.com/",
"http://qwertyuiop.asd/fghjkl",
"https://www.google.com/",
"https://www.qwertyuiop.asd/fghjkl"
];
/* Callback to be executed after all URLs have been checked */
var onCheckCompleted = function(unvisitedURLs) {
console.log("The following URLs have not been visited yet:");
unvisitedURLs.forEach(function(url) {
console.log(" " + url);
});
alert("History check complete !\n"
+ "Check console log for details.");
}
/* Check all URLs in <urls> and call <callback> when done */
var findUnvisited = function(urls, callback) {
var unvisitedURLs = [];
var checkedURLs = 0;
/* Check each URL... */
urls.forEach(function(url) {
chrome.history.getVisits({ "url": url }, function(visitItems) {
/* If it has not been visited, add it to <unvisitedURLs> */
if (!visitItems || (visitItems.length == 0)) {
unvisitedURLs.push(url);
}
/* Increment the counter of checked URLs */
checkedURLs++;
/* If this was the last URL to be checked,
execute <callback>, passing <unvisitedURLs> */
if (checkedURLs == urls.length) {
callback(unvisitedURLs);
}
});
});
}
/* Bind <findUnvisited> to the browser-action */
chrome.browserAction.onClicked.addListener(function() {
findUnvisited(urlList, onCheckCompleted);
});