Why I'm not getting all cookies through these ways?

Viewed 115

Well, I need get all cookies from the current website in my chrome extension. I tried two ways:

using document.cookie:

   var getCookies = function(){
        var pairs = document.cookie.split(";");
    
        var adapted_cookies = [];
        var cookies = {};
        for (var i=0; i<pairs.length; i++){
          var pair = pairs[i].split("=");
          cookies[(pair[0]+'').trim()] = unescape(pair.slice(1).join('='));
        }
        
        Object.entries(cookies).forEach(([key, value]) => {
          let form_cookie = {
            name:key,
            value: value
          }
    
          adapted_cookies.push(form_cookie);
      });

and using chrome.cookies.getAll in my background.js:

chrome.cookies.getAll({}, (cookies) => {
    console.log(cookies)
})

here is my manifest:

{
    "manifest_version": 2,
    "name": "Auto Follow",
    "version": "1.0",
    "icons": {
        "720": "follow_icon.png" 
    },
    "description": "xxx",
    "background": {
        "scripts": ["background.js"]
     },
    "permissions": [
        "cookies",
        "https://www.instagram.com/"
      ],
    "content_scripts": [
        {
            "matches": ["https://www.instagram.com/"],
            "js": ["jquery.js","content.js"]
        }
    ]
}

Result: both alternatives bring cookies, but not all for some reason. The document.cookie bring me a lot of them, but not all, and the chrome.cookies.getAll() bring me only one. Someone know something that can help me?

0 Answers
Related