I am creating my first Chrome extension, the extension will allow user to enter a search term and that search term will searched through the browser history and the results will be shown, after which the user can delete the results by clicking on a delete button. Here is my code -
window.onload = function() {
function getHistory() {
var div = document.getElementById('all');
var search = document.getElementById("search").value;
if (search === '') {
div.innerHTML = '';
div.innerHTML = div.innerHTML + 'Nothing To Search.';
}
else {
var microseconds = 1000 * 60 * 60 * 24 * 365 * 45;
var start = (new Date).getTime() - microseconds;
chrome.history.search({text: search, startTime: start, maxResults: 200}, function(data) {
if(Object.keys(data).length === 0) {
div.innerHTML = '';
div.innerHTML = div.innerHTML + 'Nothing Found.';
}
else {
div.innerHTML = '';
data.forEach(function(page) {
div.innerHTML = div.innerHTML + '<p>'+page.title+'</p> <a href='+page.url+' target="_blank"><p>'+page.url+'</p></a> <br>';
});
document.getElementById('delete').onclick = deleteHistory;
}
});
}
}
function deleteHistory() {
var search = document.getElementById("search").value;
var microseconds = 1000 * 60 * 60 * 24 * 365 * 45;
var start = (new Date).getTime() - microseconds;
chrome.history.search({text: search, startTime: start, maxResults: 200}, function(data) {
var div = document.getElementById('all');
data.forEach(function(page) {
chrome.history.deleteUrl({url: page.url}, function() {
div.innerHTML = '';
div.innerHTML = div.innerHTML + 'All Clear!';
});
});
});
}
document.getElementById('get').onclick = getHistory;
}
So far everything is working, except when i delete history, it is deleted but it still shows in browser history. Please tell me what am i doing wrong? Also is there anything else that i could have improved in the code? Thank you.
So this is a bug with chromium and it is already reported here - https://code.google.com/p/chromium/issues/detail?id=395955 . The bug is still not fixed, so unfortunately nothing can be done about this issue right now.