How can I access the cookies?

I want to write my own add-on that accesses the cookies on the current web page. I’ve looked at the source code for live Http Headers, but I don’t understand where the code uses the variables “theDocument” and “gDocument” but I don’t see where the variables are defined. I’m a Java programmer, but not a JS programmers, so please forgive me if this is a rookie question.

Any help would be greatly appreciated as I’ve been spending an awful lot of time on this.

https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Cookies might give you a starting point.

Please follow the below ways for using Cookies. Ex.Visit OfflineBazaar for real example.
// sets the cookie cookie1
document.cookie =
‘cookie1=test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/’

// sets the cookie cookie2 (cookie1 is not overwritten)
document.cookie =
‘cookie2=test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/’

// remove cookie2
document.cookie = ‘cookie2=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/’

Ugh, no. See the MDN page I linked to.

document.cookie is a web API. It is the way that a script in a web page can access cookies. As such, you wouldn’t normally use it in an addon. It is also generally a pain to work with since it consists of one great big string containing all the cookies “associated with” a particular document.

There are special APIs to return any or all cookies that you might be interested in, and then to work with them. It is for you to decide if they are “on” the current web page. If you are specifically interested in cookies sent in http responses, you could intercept the respons and read the headers, but you wouldn’t normally need to do that.

Cookie management APIs here (and associated pages, see links at the end):
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsICookieManager2

WebExtensions API (coming soon to a Firefox near you):
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/cookies