chrome.cookies.getAll function does'nt return all the cookies i could see in developer tools.

1,447 views
Skip to first unread message

Ashok Kumar

unread,
Aug 9, 2019, 2:33:36 AM8/9/19
to Chromium Extensions
0

I am creating an extension which gets cookie from my domain and process it. But the problem here is that chrome.cookies.getAll(domain:"mydomain") doesnt return the all the cookies. for example i am getting cookies of firebase.google.com but its retuning only one cookie but when i go to firebase.google.com i could many cookie items

Manifest permission i used

"permissions": [ "tabs", "activeTab", "cookies", "https://*/*", "contextMenus", "storage", "webNavigation" ],

backgroundjs:

chrome.cookies.getAll({domain:"firebase.google.com"},function(cookie){ console.log(cookie); });

What i could see in console contains only one cookie value. But when i go to url firebase.google.com i could see more number of cookies in developer tools.

Screenshot 2019-08-08 at 11.16.13 PM.png

Screenshot 2019-08-08 at 11.16.39 PM.png

How could i get all the cookies in getAll function?


Eric Lawrence

unread,
Aug 9, 2019, 8:40:08 AM8/9/19
to Chromium Extensions
At what point in time is your background page calling the .getall function? If you use url as your filter instead of domain, do you get different cookies?

Simeon Vincent

unread,
Aug 9, 2019, 8:17:56 PM8/9/19
to Chromium Extensions
I think the problem is that when you're inspecting cookies on firebase.google.com, you're seeing a lot of cookies that aren't actually associated with the domain you provided. Unfortunately the screenshot you provided is missing the relevant data. Note that the domain column in the below screenshot lists a number of cookies associated with domains other than the URL you currently have selected in the left side nav bar.

all-cookies.png


And note that when I filter cookies to the domain I care about I significantly reduce the number of cookies I see.

filtered-cookies.png


If you'd like to more exhaustively examine your cookies, you could do something like this…

const matchDomain = '.firebase.google.com';

chrome
.cookies.getAll({}, cookies => {
 
const filteredCookies = cookies.filter(cookie =>
    cookie
.domain.endsWith(matchDomain)
 
)
  console
.log(filteredCookies)
})

Here we're requesting literally every cookie we can and manually filtering to the specific domain we want. Also note that your permissions are currently only for https sites – off-hand I can't remember if cookie access is limited by your host permissions' protocols.

Simeon - @dotproto
Extensions Developer Advocate

PhistucK

unread,
Aug 10, 2019, 8:15:39 AM8/10/19
to Simeon Vincent, Chromium Extensions
Your (Simeon) screenshot actually seems to show a Developer Tools bug.
I would expect (right hand entry) .youtube.com cookies not to show up in the (left hand picked) firebase.google.com domain cookies, but only in the (left hand picked) youtube.com domain cookies.
Otherwise, why are there (left hand) domains at all there if they show unrelated cookies?
I do not think they are supposed to show cookies-per-frame.

(Note that the domain column is relevant even if this seemingly buggy behavior is fixed, because foo.baz.com can see .baz.com cookies)

PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/3a9adf50-c913-4163-ba79-2243d7862f47%40chromium.org.

Simeon Vincent

unread,
Aug 11, 2019, 12:42:45 AM8/11/19
to Chromium Extensions, sim...@chromium.org
TBH I find the way cookies are currently displayed to be a rather confusing. Since it's the weekend and I can't just ask someone what's up, I pulled up the devtools source and started poking around. It looks like the list of domains on the left is actually a list of frames. So in in my screenshot, the reason we see 3 domains is because we have the main document, another document fetched by the service worker, and an iframe loaded for the youtube iframe API.

It looks like Chrome, Safari, and Firefox all have basically the same approach to displaying cookies. I vaguely recall previous incarnations of devtools having a dedicated Cookies tab that was a bit more straight forward, but I can find any screenshots.

Simeon - @dotproto
Extensions Developer Advocate

P.S. I'm 100% procrastinating from working on a talk I'm going to be giving at JS Conf US on Monday. I guess I have to get back to it now…


On Saturday, August 10, 2019 at 5:15:39 AM UTC-7, PhistucK wrote:
Your (Simeon) screenshot actually seems to show a Developer Tools bug.
I would expect (right hand entry) .youtube.com cookies not to show up in the (left hand picked) firebase.google.com domain cookies, but only in the (left hand picked) youtube.com domain cookies.
Otherwise, why are there (left hand) domains at all there if they show unrelated cookies?
I do not think they are supposed to show cookies-per-frame.

(Note that the domain column is relevant even if this seemingly buggy behavior is fixed, because foo.baz.com can see .baz.com cookies)

PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

PhistucK

unread,
Aug 11, 2019, 1:37:35 AM8/11/19
to Simeon Vincent, Chromium Extensions
They are not even frames. If you have three iFrames with the same origin (different paths, though), the origin will only be shown once in the left hand tree.
So that is an aggregation of the origins used by all of the frames on the document. :(

Shows one origin.

It is a mess and can be outright misleading/not very debuggable if you have path-locked cookies...

PhistucK


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/610d60ba-2c01-47f5-8035-59fdba6bae2f%40chromium.org.
Reply all
Reply to author
Forward
0 new messages