chrome.cookies.getAll() and partitionKey

220 views
Skip to first unread message

Pavel Aronovich

unread,
Feb 7, 2024, 4:07:46 AM2/7/24
to Chromium Extensions
chrome.cookies.getAll({ url: url }) does not return cookies with partitionKey set, is that correct?

Pavel Aronovich

unread,
Feb 7, 2024, 4:15:59 AM2/7/24
to Chromium Extensions, Pavel Aronovich
And here's another question:

"Because chrome.cookies doesn't support partitioning, all of its methods read and write cookies from all partitions. The cookies.set() method stores cookies in the default partition."

"partitionKey - The partition key for reading or modifying cookies with the Partitioned attribute."

That is, partitionKey is in the documentation.

I don't understand this phrase then "chrome.cookies doesn't support partitioning" 

Please explain how to understand this?

Do I need get all cookies for url (included all partitionKey) and then save one, can I do this via 

chrome.cookies.getAll({ url: url }, ...) 

chrome.cookies.set({ ...,  partitionKey: cookie.partitionKey })

?


среда, 7 февраля 2024 г. в 12:07:46 UTC+3, Pavel Aronovich:

Oliver Dunk

unread,
Feb 7, 2024, 6:02:57 AM2/7/24
to Pavel Aronovich, Chromium Extensions
Hi Pavel,

chrome.cookies.getAll({ url: url }) does not return cookies with partitionKey set, is that correct?

Correct, without the partitionKey property set this should only include cookies in unpartitioned storage. This is the intended behavior.

I don't understand this phrase then "chrome.cookies doesn't support partitioning" 

Apologies, our documentation is out of date here. I have a draft of some updates but haven't yet been able to publish them.

In general, we are trying to follow the behavior in Firefox which is documented quite well on MDN. That might be helpful: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/getAll

As a final note, if you specify the `url` field, this currently causes Chrome to always filter out partitioned cookies, even if you set another property like `partitionKey`. We are working on a fix for this: https://chromium-review.googlesource.com/c/chromium/src/+/5269008. In the meantime, you might want to consider using domain instead.

Thanks for the understanding here, and let me know if you have any more questions. There's a lot changing around cookies at the moment and I don't think the extensions platform has quite caught up yet.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
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/2d56e8f0-6561-45d3-8298-8a8215167285n%40chromium.org.

Pavel Aronovich

unread,
Feb 7, 2024, 7:04:48 AM2/7/24
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Pavel Aronovich
"if included without topLevelSite, returns all cookies from partitioned and unpartitioned storage."

To get all the cookies, you need to do this?

chrome.cookies.getAll({ url: url,  partitionKey: {} })

среда, 7 февраля 2024 г. в 14:02:57 UTC+3, Oliver Dunk:

Oliver Dunk

unread,
Feb 7, 2024, 7:11:52 AM2/7/24
to Pavel Aronovich, Chromium Extensions
That's the intended behaviour. Due to the bug mentioned, though, including the `url` field sends us down a different code path and Chrome unintentionally excludes partitioned cookies.

`chrome.cookies.getAll({ domain: domain,  partitionKey: {} })` should correctly return all cookies as a workaround.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Pavel Aronovich

unread,
Feb 7, 2024, 7:15:43 AM2/7/24
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Pavel Aronovich
Understood, thanks.
I will be waiting for the error to be corrected.
In which version will this be fixed?
среда, 7 февраля 2024 г. в 15:11:52 UTC+3, Oliver Dunk:

Oliver Dunk

unread,
Feb 7, 2024, 7:17:49 AM2/7/24
to Pavel Aronovich, Chromium Extensions
Since the CL hasn't merged yet it isn't possible to say for sure. If it merges before February 19th, it will be in Chrome 123.
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Reply all
Reply to author
Forward
0 new messages