I want to remove a Cookie (according to some criteria) from within a Chrome Extension.
According to the documentation of chrome.cookies.remove
it expects an object with the fields url
(The URL associated with the cookie) and name
(The name of the cookie to remove).
Now a cookie has the following fields: name, value, domain, hostOnly, path, secure, httpOnly, session, expirationDate, storeId
but no url
. How do I get the URL of a specific cookie so I can remove it?
For reference one of my cookies looks like this:
domain: ".google.com"
expirationDate: 1364393586
hostOnly: false
httpOnly: false
name: "PREF"
path: "/"
secure: false
session: false
storeId: "0"
value: "ID=8<snip>u"
How could this API be abused? A malicious extension could steal cookies from sites the user visits. The API also exposes HttpOnly cookie data to the extension.
With the Cookies API your extensions have access to capabilities similar to those used by websites to store and read cookies. The API's features give extensions the ability to store information on a site-by-site basis.
When you delete cookies from your computer, you erase information saved in your browser, including your account passwords, website preferences, and settings. Deleting your cookies can be helpful if you share your computer or device with other people and don't want them to see your browsing history.
After some trial and error here's how I get the URL, this seems to work for everything (except perhaps file://
)
function extrapolateUrlFromCookie(cookie) {
var prefix = cookie.secure ? "https://" : "http://";
if (cookie.domain.charAt(0) == ".")
prefix += "www";
return prefix + cookie.domain + cookie.path;
}
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