Extension Cookies API: Permissions, Partitioning, and SameSite
How Chrome extension Cookies API reads and sets site cookies, when permission is required, and how partition keys and SameSite behave.
This page summarizes Chrome extension documentation for the Cookies API (browser.cookies in Manifest V3, chrome.cookies in Manifest V2). The API lets an extension read and modify HTTP cookies on origins where the extension has host permissions. It is the supported way to work with full cookie metadata (including SameSite and partition keys), unlike document.cookie or the Cookie Store API.
Cookies API vs document.cookie: when to use which
Section titled “Cookies API vs document.cookie: when to use which”Use the Cookies API when the extension runs in a background or extension-origin context and needs detailed cookie data or cross-context control. The Web Store troubleshooting guide states when the cookies permission applies:
This exposes the chrome.cookies API and allows the extension to modify cookies on origins that it has host permissions to access.
When it is required
- Accessing
chrome.cookiesfrom the extension’s background context, or in another context that uses the extension origin (for example a popup). - Using
chrome.cookiesto interact with detailed cookie data, such as SameSite values.
When it is NOT required
- Using
document.cookieor the Cookie Store API.
For request/response rewriting, older declarative Web Request rules can add, edit, or remove cookies on the wire, but Chrome’s docs repeatedly prefer the Cookies API because it is less expensive computationally—for example on AddRequestCookie: “it is preferred to use the Cookies API because this is computationally less expensive.”
Host permissions and the cookies permission
Section titled “Host permissions and the cookies permission”Every Cookies API call that touches a site cookie is tied to a URL (or filter) on that origin. If the extension manifest does not grant host permissions for that URL, the call fails.
From CookieDetails:
The URL with which the cookie to access is associated. This argument may be a full URL, in which case any data following the URL path (e.g. the query string) is simply ignored. If host permissions for this URL are not specified in the manifest file, the API call will fail.
The same rule applies when setting a cookie: the url parameter is required and host permissions must cover it. Omitting domain when setting creates a host-only cookie; omitting expirationDate creates a session cookie.
Declare the cookies permission in the manifest when you use this API from extension contexts that need it, and pair it with explicit host permission patterns for every origin you read or write.
Partitioned cookies and partitionKey
Section titled “Partitioned cookies and partitionKey”Partitioned cookies are keyed to the origin of the top-level frame, so the same site embedded on different top-level sites can hold different cookie values.
Partitioned cookies allow a site to mark that certain cookies should be keyed against the origin of the top-level frame. This means that, for example, if site A is embedded using an iframe in site B and site C, the embedded versions of a partitioned cookie from A can have different values on B and C.
— Chrome, browser.cookies
How partitionKey works in Manifest V3
Section titled “How partitionKey works in Manifest V3”On the MV3 Cookies API, all methods operate on unpartitioned cookies by default. Pass partitionKey (CookiePartitionKey) on get, getAll, set, and remove to target cookies with the Partitioned attribute.
CookiePartitionKey field |
Role |
|---|---|
topLevelSite |
Top-level site where the partitioned cookie is available |
hasCrossSiteAncestor (Chrome 130+) |
Whether the cookie was set in a cross-site context; limits a top-level site embedded cross-site from reaching cookies set in a same-site context |
Chrome DevTools surfaces this as Partition Key: for cookies with independent partition state, the partition key is the site of the top-level URL the browser was visiting at the start of the request that set the cookie.
Manifest V2 limitation
Section titled “Manifest V2 limitation”The MV2 chrome.cookies reference documents different behavior:
chrome.cookies does not support partitioning, which means that all methods read and write cookies from all partitions. The cookies.set() method stores cookies in the default partition.
Extensions still on MV2 cannot isolate partition reads/writes the way MV3’s partitionKey does; plan migrations accordingly if you depend on CHIPS-style partitioned cookies.
Cookie fields developers ask about
Section titled “Cookie fields developers ask about”The Cookie type mirrors what DevTools shows. Common fields:
| Property | Meaning |
|---|---|
name, value |
Cookie pair |
domain, path |
Scope |
hostOnly |
Host must exactly match domain |
secure, httpOnly |
Transport and script access |
session, expirationDate |
Session vs persistent (epoch seconds) |
sameSite |
no_restriction, lax, strict, or unspecified |
partitionKey |
Partition target when present |
storeId |
Which cookie store (normal vs incognito) |
getAll accepts filters: domain, name, path, url, secure, session, storeId, and optionally partitionKey. Narrow filters reduce work and avoid touching unrelated cookies.
SameSiteStatus mapping
Section titled “SameSiteStatus mapping”A cookie’s ‘SameSite’ state … ‘no_restriction’ corresponds to a cookie set with ‘SameSite=None’, ‘lax’ to ‘SameSite=Lax’, and ‘strict’ to ‘SameSite=Strict’. ‘unspecified’ corresponds to a cookie set without the SameSite attribute.
— Chrome, browser.cookies
When setting cookies via the API, sameSite defaults to unspecified if omitted. Remember that SameSite=None on the web requires Secure; extension pages have additional limits (below).
Cookie stores and incognito
Section titled “Cookie stores and incognito”A CookieStore is a separate jar in the browser. Incognito windows use a different store than normal windows. Use getAllCookieStores() and pass storeId on get/set/remove when you must target a specific profile or incognito session.
Extension origins, Secure, and third-party behavior
Section titled “Extension origins, Secure, and third-party behavior”Rules from Storage and cookies explain cases that surprise authors who only know regular website cookies.
chrome-extension:// pages cannot set some attributes
Section titled “chrome-extension:// pages cannot set some attributes”The Secure cookie attribute is only supported for the https:// scheme. Consequently, chrome-extension:// pages are not able to set cookies with this attribute.
This also means that extension pages cannot use other cookie attributes where the Secure attribute is required:
SameSite=None
Partitioned
Cookies set on extension origins always use SameSite=Lax, so extension-set cookies on chrome-extension:// are not available in embedded frames; partitioning is not relevant there.
Third-party sites inside extension UI
Section titled “Third-party sites inside extension UI”When a third-party site is embedded in an extension page, it may use the extension origin as the partition key, so it will not see the same cookies as when navigated to directly (see the linked crbug.com/1463991 note in Storage and cookies).
For network requests from the extension to third-party origins, behavior mostly matches the open web, with two exceptions called out in the same document:
- Third-party cookies are not blocked in subframes when the tab’s top-level page is
chrome-extension://. - Requests from an extension to a third party are treated as same-site if the extension has host permissions for that party—so
SameSite=Strictcookies may be sent on those network requests (not viadocument.cookie, and not when third-party cookies are blocked globally).
Privacy Sandbox timelines can change third-party cookie settings; the Cookies API’s partitionKey is how you align extension logic with partitioned storage—see the API reference.
Common mistakes
Section titled “Common mistakes”- Calling
set/getwithout host permissions for theurlyou pass—silent failure or rejected promises. - Assuming MV2 reads one partition—MV2 merges partitions; only MV3’s
partitionKeyselects a partition. - Forgetting
partitionKeyon MV3 when debugging CHIPS cookies—you may read the unpartitioned view while the site set a partitioned cookie. - Trying to set
SameSite=NoneorPartitionedfrom an extension page onchrome-extension://—Secureis not supported there. - Using hundreds of CSS-based declarative rules when the real need is cookie inspection—unrelated to cookies, but if you combine declarativeContent with cookie tooling, note that large
cssselector lists “can slow down web sites.”
Sample code for the Cookies API lives under examples/api/cookies as noted in the API reference and MV2 reference.
How to check this on your site
Section titled “How to check this on your site”- Open the target page in Chrome, then Application → Storage → Cookies and confirm name,
SameSite,Secure, and Partition Key match what you expect, using View, add, edit, and delete cookies. - Install your unpacked extension, trigger a Cookies API
getAllorsetfor a testurl, and refresh the Application panel to see whether values and attributes update. - If you use partitioned cookies, filter DevTools with Only show cookies with an issue temporarily to catch invalid partition key values after edits.
- Compare MV3 behavior: repeat the same
urlwith and withoutpartitionKeyingetAlland verify you see the cookie jar your site actually uses. - You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.