Access cookies from Google Chrome extension

Viewed 39654

Is there any way to access cookies from Chrome extension? this code

document.cookie.length

always returns - 0.

5 Answers

It's the first time I read something really wrong on this site. Getting actual document cookies from an extension is INDEED possible.

you just need these two things in your manifest:

"content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["cookie_handler.js"]
    }
  ],
  "permissions": [
    "tabs",
    "http://*/*",
    "https://*/*"
  ],

your cookie_handler.js will be executed in the same context of every loader page/frame/iframe. try to put there a single line:

alert(document.cookie);

and you will see :)

If you change manifest.json you have to delete the google chrome extension and add it again.

Try these steps:

  1. Click Extensions at the top of your Chrome browser -> Manage Extensions.
  2. Remove the Extension
  3. Click Load Unpacked -> Navigate to extension project folder.

The changes to manifest.json have been loaded.

Related