I am making a Chrome extension to remove certain URLs from my history, using Chrome's history API. Here is the code so far:
document.addEventListener('DOMContentLoaded', function() {
var form = document.getElementById('form'),
query = document.getElementById('query')
form.onsubmit = function(e) {
e.preventDefault()
// alert(chrome.history) // [object Object]
// alert(chrome.history.deleteUrl) // function () { [native code] }
// alert(query.value) // whatever I typed
chrome.history.deleteUrl(query.value)
}
query.focus()
})
(form
is the form in my popup, and query
is the text box in which you can type.)
As you can see from the three alert
s, the variables are fine. However, the code isn't actually removing the URL from the history. When I check (in chrome://history/
), the URLs are still there.
Here is my manifest.json
, if that matters:
{
"manifest_version": 2,
"name": "UnVizit",
"description": "Mark a link as \"not visited\" easily",
"version": "0.1.0",
"permissions": [
"history"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
I am using version 28.0.1500.95 (Official Build 213514) m
of Chrome.
You should not pass a string to the chrome.history.deleteUrl
method, but an object with key url. If you inspect your popup, you would see the following error:
Error: Invocation of form history.deleteUrl(string) doesn't match definition history.deleteUrl(object details, optional function callback)
In summary, change
chrome.history.deleteUrl(query.value)
to
chrome.history.deleteUrl({ url: query.value });