The CookieStore interface of the Cookie Store API provides methods for getting and setting cookies asynchronously from either a page or a service worker. Available only in secure contexts.

MDN Reference

interface CookieStore {
    onchange: ((this: CookieStore, ev: CookieChangeEvent) => any) | null;
    addEventListener<K extends "change">(
        type: K,
        listener: (this: CookieStore, ev: CookieStoreEventMap[K]) => any,
        options?: boolean | AddEventListenerOptions,
    ): void;
    addEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | AddEventListenerOptions,
    ): void;
    delete(name: string): Promise<void>;
    delete(options: CookieStoreDeleteOptions): Promise<void>;
    dispatchEvent(event: Event): boolean;
    get(name: string): Promise<CookieListItem | null>;
    get(options?: CookieStoreGetOptions): Promise<CookieListItem | null>;
    getAll(name: string): Promise<CookieList>;
    getAll(options?: CookieStoreGetOptions): Promise<CookieList>;
    removeEventListener<K extends "change">(
        type: K,
        listener: (this: CookieStore, ev: CookieStoreEventMap[K]) => any,
        options?: boolean | EventListenerOptions,
    ): void;
    removeEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | EventListenerOptions,
    ): void;
    set(name: string, value: string): Promise<void>;
    set(options: CookieInit): Promise<void>;
}
Hierarchy
  • EventTarget
    • CookieStore
Index

Properties

onchange: ((this: CookieStore, ev: CookieChangeEvent) => any) | null

Methods

  • The delete() method of the CookieStore interface deletes a cookie that matches the given name or options object.

    MDN Reference

    Parameters

    • name: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>

  • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • The getAll() method of the CookieStore interface returns a Promise that resolves as an array of cookies that match the name or options passed to it.

    MDN Reference

    Parameters

    • name: string

    Returns Promise<CookieList>

  • Parameters

    Returns Promise<CookieList>

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

    MDN Reference

    Type Parameters

    • K extends "change"

    Parameters

    Returns void

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

    MDN Reference

    Parameters

    Returns void

  • The set() method of the CookieStore interface sets a cookie with the given name and value or options object.

    MDN Reference

    Parameters

    • name: string
    • value: string

    Returns Promise<void>

  • Parameters

    Returns Promise<void>