0

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 alerts, 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.

tckmn
  • 57,719
  • 27
  • 114
  • 156
  • Hint: When your form gets submitted, the page is unloaded unless you `return true;` or call `event.preventDefault();`. – Rob W Aug 21 '13 at 19:41
  • @RobW Thanks, trying that now... EDIT: still doesn't work. :( – tckmn Aug 21 '13 at 19:44
  • @RobW I tried it and it still didn't work. I edited the line into my question though, to show that that is not the problem. – tckmn Aug 21 '13 at 19:47
  • @Doorkob Inspect the popup. You'll see an error about a mismatching API call. [`chrome.history.deleteUrl`](https://developer.chrome.com/extensions/history.html#method-deleteUrl) expects an object with key `url`, not a string. – Rob W Aug 21 '13 at 19:48
  • @RobW Ah, I was just hitting F12 and saw no errors. I will try the object now. – tckmn Aug 21 '13 at 19:57
  • http://developer.chrome.com/extensions/tut_debugging.html#inspect-popup – Rob W Aug 21 '13 at 19:57
  • @RobW Alright, thanks for that. That will help with debugging a lot. The object worked! If you post that as an answer I will accept it. – tckmn Aug 21 '13 at 19:58

1 Answers1

1

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 });
Rob W
  • 341,306
  • 83
  • 791
  • 678