0

I am developing an add-on for Mozilla. I use this function when I visit a site to list all the cookies contained there. At first, the code was working properly. When I visited a site, I was getting a list with the cookies contained in there, then in a second site I was getting the cookies contained ONLY in the second site. Now, without changing anything, when I visit a second site, I get some cookies from the previous site. I need to hit the new site 2 times in a row to get only its cookies. Are there any recent changes in the way that cookieManager works or any other ideas what is wrong with the code?

//Mozilla 39.0
var{ToggleButton}=require("sdk/ui/button/toggle");
var prefService=require("sdk/preferences/service");
var imagePermission="permissions.default.image";
var windows = require("sdk/windows").browserWindows;
var Request = require("sdk/request").Request;
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
require("sdk/tabs").on("load",logURL);
function logURL(tab) {
    console.log(tab.url);
    func();
    func(); //i use this to check if the removeAll() works.
};
function func() {
    var {Cc, Ci} = require("chrome");
    var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
    var iter = cookieManager.enumerator;
    var cookie_count = 0;
    var hosts = [];
    var names = [];
    console.log(hosts.length);
    while (iter.hasMoreElements()) {
        cookie_count++;
        var cookie = iter.getNext();
        if (cookie instanceof Ci.nsICookie) {
            hosts.push(cookie.host);
            names.push(cookie.name);
        }
    }
    //if a call this function twice without changing the page the cookie list seems empty
    cookieManager.removeAll();
    console.log(cookie_count);
    console.log(hosts);
    console.log(names);
};

The sites I visit are first youtube.com, which gives 6 cookies, then I hit intel.com, which gives 29 cookies, but there are leftovers from youtube.com. If I hit intel.com again, I get 26 cookies with no trace of leftovers from previous site (youtube.com). The number of the cookies you will get may vary a bit.

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • Please provide complete code so we can duplicate the problem. In other words, this appears to execute once, and only once. How is it executed when you "hit the new site"? please also describe the *exact* sites you are visiting and the order in which you do so. – Makyen Oct 29 '16 at 18:38
  • I 've updated my post as asked. Thank you for your time and sorry for little info at first, it is my first post! – user3004946 Oct 30 '16 at 15:01

0 Answers0