0

I've got a Chrome Extension I am writing to emulate certain gui calls and automate them, everything is working as intended except that I cannot see any contents inside chrome.cookies. I can get limited cookie data from document.cookie but I need the chrome.cookies extension options to emulate the session. Basically by default https://www.owasp.org/index.php/HttpOnly restricts that access (which is normally fine)

this is what I am trying to get at https://developer.chrome.com/extensions/cookies

In order to access chrome.cookies I have altered my manifest.json:

{
  "manifest_version": 2,

  "name": "Call Builder",
  "description": "This extension auto creates Dialog nodes",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "myPopup.html"
  },
  "permissions": ["cookies", "tabs",  "*://*.mydomain.com/*"],
  "content_scripts": [
    {
      "matches": ["*://*.mydomain.com/*"],
      "js": ["router.js"]
    }
  ]
}

note the line "permissions": ["cookies", "tabs", "*://*.mydomain.com/*"], I know I've done the right thing with "cookies" in "permissions" but when I try to access chrome.cookies (or any of it's methods) it is empty (undefined) what is the reason?

EDIT

PLEASE READ MY COMMENT BELOW :-) this issue is a scoping issue and it's not documented nor covered - TLDR; while chrome.tabs is available in both js spaces chrome.cookies isn't and this isn't mentioned in the answer nor the chrome documentation

Mr Heelis
  • 2,370
  • 4
  • 24
  • 34
  • 1
    See the content scripts documentation: only several chrome API are exposed. Do it in the popup or use an event/background page script. – wOxxOm Feb 09 '17 at 13:06
  • so it's popup only? – Mr Heelis Feb 09 '17 at 13:07
  • Pardon me, what do you mean by that? – wOxxOm Feb 09 '17 at 18:14
  • the answer in the `"suggested answer"` isn't actually answering the question. It is a scoping issue, and it's not documented and it's misleading in the the extreme. Basically the answer is that the ` "chrome.cookies"` object is available via `"myPopup.html"` via it's associated JavaScripts, it's *NOT* available in "content_scripts": like router.js in my example.. the reason this is misleading is that the websocket piping object `chrome.tabs` *is* available in both scopes – Mr Heelis Feb 10 '17 at 10:52

0 Answers0