I am building and extension with Firefox’s Addon SDK (v1.9).
My application is supposed to remove cookies as they are added (or changed) based on a database of matching URIs.
I accomplish this task by adding an observer to ‘cookie-changed’ and implementing nsICookie to identify matching cookies and nsICookieManager to remove the cookie if a match is found.
Problem
I need know what website (URL) each cookie was added / changed from.
Unfortunately, by the time the cookie manager sends the
cookie-changednotification that information is already lost – the cookie manager only knows which host the cookie is added for (and it might not be the host of the page setting the cookie ifdomainparameter was used). It might even be that there was no URL in the first place, e.g. if the cookie is set by an extension.What you could do is register an observer for the
http-on-examine-responsenotification. You can look at theSet-Cookieheader of the channel as well as the channel URL so whencookie-changednotification is sent later you will know which website is responsible. Something like this:Note: This code hasn’t been tested.
Documentation: observer notifications, nsIHttpChannel