@mirawision/chrome-api
Version:
A comprehensive TypeScript library for Chrome Extension API, providing type-safe wrappers and utilities for bookmarks, commands, context menus, cookies, downloads, storage, notifications, runtime, scripting, and side panel functionalities.
71 lines (70 loc) • 2.77 kB
TypeScript
/// <reference types="chrome" />
interface CookieDetails {
url: string;
name: string;
value?: string;
domain?: string;
path?: string;
secure?: boolean;
httpOnly?: boolean;
sameSite?: chrome.cookies.SameSiteStatus;
expirationDate?: number;
storeId?: string;
}
interface CookieQuery {
url?: string;
name?: string;
domain?: string;
path?: string;
secure?: boolean;
session?: boolean;
storeId?: string;
}
/**
* A class that provides a type-safe wrapper around Chrome's cookies API.
* This class allows you to get, set, remove, and monitor cookies across different domains
* and cookie stores in the browser.
*/
declare class Cookies {
/**
* Retrieves information about a single cookie.
* @param details - The details (name, url, storeId) of the cookie to retrieve
* @returns A promise that resolves to the cookie if found, null otherwise
* @throws {Error} If there's an error retrieving the cookie
*/
static get(details: CookieDetails): Promise<chrome.cookies.Cookie | null>;
/**
* Retrieves all cookies that match the given query.
* @param details - The query parameters to filter cookies
* @returns A promise that resolves to an array of matching cookies
* @throws {Error} If there's an error retrieving the cookies
*/
static getAll(details: CookieQuery): Promise<chrome.cookies.Cookie[]>;
/**
* Sets a cookie with the given details.
* @param details - The details of the cookie to set
* @returns A promise that resolves to the created/updated cookie, or null if setting failed
* @throws {Error} If there's an error setting the cookie
*/
static set(details: CookieDetails): Promise<chrome.cookies.Cookie | null>;
/**
* Removes a cookie matching the given details.
* @param details - The details of the cookie to remove
* @returns A promise that resolves to the details of the removed cookie
* @throws {Error} If there's an error removing the cookie
*/
static remove(details: CookieDetails): Promise<CookieDetails>;
/**
* Lists all cookie stores in the browser.
* @returns A promise that resolves to an array of cookie stores
* @throws {Error} If there's an error retrieving the cookie stores
*/
static getAllCookieStores(): Promise<chrome.cookies.CookieStore[]>;
/**
* Adds a listener for cookie change events.
* @param callback - Function called when a cookie is created, removed or changed
* @returns A function that removes the listener when called
*/
static addChangedListener(callback: (changeInfo: chrome.cookies.CookieChangeInfo) => void): () => void;
}
export { Cookies, CookieDetails, CookieQuery };