So I am using chrome.cookies.getAll({}, function(c){console.log(c);})
to get all the cookies stored on the system. However, if I need to process the resulting cookie to either delete or whatever, I need a URL associated with each cookie. The URL strangely is not in the cookie structure: http://developer.chrome.com/extensions/cookies.html#type-Cookie
Anyone know how to get the URL associated with a cookie?
You can build the URL from the information you've got from getAll()
:
var cookie; // one single cookie from the array
var url = '';
// get prefix, like https://www.
url += cookie.secure ? 'https://' : 'http://';
url += cookie.domain.charAt(0) == '.' ? 'www' : '';
// append domain and path
url += cookie.domain;
url += cookie.path;
console.log(url); // something like "https://www.stackoverflow.com/"
The domain property gives you the domain associated with the cookie. And path gives you the path inside that domain. From the Cookie API Test Extension:
function removeCookie(cookie) {
var url = "http" + (cookie.secure ? "s" : "") + "://" + cookie.domain +
cookie.path;
chrome.cookies.remove({"url": url, "name": cookie.name});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With