Difference between cookies returned by chrome.cookies.getAll() and those displayed in Chrome Developer Tools.

277 views
Skip to first unread message

Tamar Y

unread,
May 7, 2023, 8:32:29 AM5/7/23
to Chromium Extensions
Hello,

I am working on a Chrome extension that needs to access all cookies for some applications domain.
I am using the chrome.cookies.getAll API to retrieve the cookies, but I noticed that the result is different from what I see in the Developer Tools.

For example, when I try to get all cookies for Twitter using the following code:

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

            // Extract the cookie names
            const cookieNames = filteredCookies.map((cookie) => cookie.name);
            // Save the cookie names to storage
            const storageKey = `${domain}:cookies`;
            const storageValue = cookieNames;
            const items = {};
            items[storageKey] = storageValue;
            chrome.storage.local.set(items, function () {
                console.log("Cookies saved for domain " + domain);
                resolve(filteredCookies);

            });
        });

I get a list of cookies that does not include some cookies that I can see in the "Application" tab of the Developer Tools.


The results I get from get all cookies:
[
"ab.storage.deviceId.a9882122-ac6c-486a-bc3b-fab39ef624c5",
"g_state",
"at_check",
"mbox",
"_ga",
"_ga_BYKEBDM7DS",
"_ga",
"_gid",
"guest_id",
"att",
"guest_id_marketing",
"guest_id_ads",
"gt",
"personalization_id",
"ct0",
"_twitter_sess"
]

But in the "application" tab in the dev tools I can see different data (screenshot attached)
(e.g the "auth_token" is missing from the getAll cookies method, but exists in the dev tools)


Could you please explain why this happens and how can I get all cookies for a domain, including the ones that are not returned by chrome.cookies.getAll?

Thank you for your help.
cookies-devtools.png

wOxxOm

unread,
May 7, 2023, 10:14:27 AM5/7/23
to Chromium Extensions, Tamar Y
Sounds like a bug. I don't see it here though (all twitter cookies are returned).

Tamar Y

unread,
May 8, 2023, 6:41:54 AM5/8/23
to Chromium Extensions, wOxxOm, Tamar Y
Thank you for taking the time to respond to my message.

I discovered that this issue occurs in incognito mode.
Is there a difference between incognito and regular modes that could explain this behavior?

Thanks.

ב-יום ראשון, 7 במאי 2023 בשעה 17:14:27 UTC+3, wOxxOm כתב/ה:

wOxxOm

unread,
May 8, 2023, 7:03:29 AM5/8/23
to Chromium Extensions, Tamar Y, wOxxOm
The incognito mode is a separate user profile that exists temporarily while the incognito window is open, so it has its own cookies, which you can get by specifying storeId:'1' in getAll parameters.

wOxxOm

unread,
May 8, 2023, 7:05:08 AM5/8/23
to Chromium Extensions, wOxxOm, Tamar Y
...and you'll have to enable "Allow in Incognito" in the details of your extension in chrome://extensions page.

Tamar Y

unread,
May 8, 2023, 8:25:51 AM5/8/23
to Chromium Extensions, wOxxOm, Tamar Y
Thanks! 
Adding the storeId:1 to the getAll parameters solved the issue. 

ב-יום שני, 8 במאי 2023 בשעה 14:05:08 UTC+3, wOxxOm כתב/ה:
Reply all
Reply to author
Forward
0 new messages