Removing a cookie from the Chrome extension

I want to remove a cookie (by some criteria) from the Chrome extension. According to chrome.cookies.remove documentation , it expects an object with url fields (URL associated with the cookie) and name (Name of cookie to delete).

Now the cookie has the following fields: name, value, domain, hostOnly, path, secure, httpOnly, session, expirationDate, storeId , but not url . How to get the URL of a specific cookie so that it can be deleted?

For reference, one of my cookies is as follows:

 domain: ".google.com" expirationDate: 1364393586 hostOnly: false httpOnly: false name: "PREF" path: "/" secure: false session: false storeId: "0" value: "ID=8<snip>u" 
+6
javascript cookies google-chrome-extension
source share
2 answers

After some trial and error here, as I get the url, this works for everything (except maybe file:// )

 function extrapolateUrlFromCookie(cookie) { var prefix = cookie.secure ? "https://" : "http://"; if (cookie.domain.charAt(0) == ".") prefix += "www"; return prefix + cookie.domain + cookie.path; } 
+5
source share

I passed http://www.google.com as a url and it worked. Maybe he just wants to get the url matching the domain pattern.

 chrome.cookies.remove({url:"http://www.google.com", name: "PREF"}); 

(you also need to have a domain permission for google.com)

+1
source share

All Articles