connect.cookies
Host-gated cookie read/write for permitted sites, plus the change event.
Read and write cookies for sites you're granted access to. Cookies are
profile-scoped, and every call is host-gated: it needs the cookies capability
and a { host } grant matching the target url. A call for a URL your host grants
don't cover is denied β you never see cookies for sites you weren't granted.
- Capability:
cookies+ a{ host }grant covering the target URL - Namespace:
connect.cookies
{ "capabilities": ["cookies", { "host": "https://*.example.com/*" }] }public/docs-img/extensions/cookies-grant.pngWalkthrough
Read a site's session cookie.
- Declare
cookiesand a host pattern for the site:{ "capabilities": ["cookies", { "host": "https://app.example.com/*" }] } - Read for a URL your grant covers:
const [c] = await connect.cookies.getAll({ url: 'https://app.example.com/', name: 'session' }); - Write / delete with
set/removefor the same permitted URLs. - React to changes with
onChanged(you only hear about granted origins).
Methods
cookies.getAll(filter)
List cookies matching a filter, for a permitted site.
How to use it
- Scope with
urlordomain(must be covered by a host grant). - Narrow further with
name/path/secure/session.
Signature β connect.cookies.getAll({ url?, domain?, name?, path?, secure?, session? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | one of url/domain | Scope to this URL (host-gated). |
domain | string | one of url/domain | Scope to this domain (host-gated). |
name | string | no | Filter by cookie name. |
path | string | no | Filter by path. |
secure | boolean | no | Only secure / non-secure. |
session | boolean | no | Only session / persistent. |
Returns β Promise<Cookie[]>.
Errors β denied unless cookies and a host grant covering the scope are held.
const cookies = await connect.cookies.getAll({ url: 'https://app.example.com/' });cookies.get(details)
Read a specific cookie (or cookies) for a permitted site.
How to use it
- Pass the
url(host-gated) and optionally aname.
Signature β connect.cookies.get({ url, name? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | The site (host-gated). |
name | string | no | The cookie name. |
Returns β Promise<Cookie | Cookie[] | null>.
cookies.set(details)
Write a cookie.
How to use it
- Pass the
url(host-gated) plus the cookie fields you want. - Omit
expirationDatefor a session cookie.
Signature β connect.cookies.set({ url, name?, value?, domain?, path?, secure?, httpOnly?, expirationDate?, sameSite? })
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | yes | The site the cookie is for (host-gated). |
name / value | string | no | The pair to set. |
domain / path | string | no | Scope. |
secure / httpOnly | boolean | no | Flags. |
expirationDate | number | no | Unix seconds; omit for a session cookie. |
sameSite | 'no_restriction' | 'lax' | 'strict' | no | SameSite policy. |
Returns β Promise<Cookie>.
cookies.remove(details)
Delete a cookie.
How to use it
- Pass the
url(host-gated) and the cookiename.
Signature β connect.cookies.remove({ url, name }) Β· Returns Promise<void>.
Events
cookies.onChanged(cb)
Fires on any cookie change for origins you hold a host grant for β never other sites.
How to use it
- Subscribe; you only hear about origins your host grants cover.
- Read
removedto tell a set from a delete, and inspectcookie/cause.
Payload
| Field | Type | Description |
|---|---|---|
cookie | Cookie | The affected cookie. |
cause | string | Why it changed (e.g. explicit, expired, overwrite). |
removed | boolean | Whether the cookie was removed. |
const off = connect.cookies.onChanged(({ cookie, removed }) => {
if (!removed && cookie.name === 'session') refreshAuth();
});Notes
- Host-scoping is enforced on every call and on the change event β the capability
alone is never enough; the
{ host }grant defines which sites you can touch.
