The URL the cookie belongs to
The cookie name to read
A promise resolving to the cookie, or null
const cookie = await getCookie("https://shop.es-drei.de", "currency");
console.log(cookie?.value); // "2"
export async function getCookie(
url: string,
name: string,
): Promise<chrome.cookies.Cookie | null> {
if (!isCookiesApiAvailable()) {
logger.warn("chrome.cookies unavailable; cannot read cookie", { url, name });
return null;
}
try {
return await chrome.cookies.get({ url, name });
} catch (error: unknown) {
logger.warn("Failed to read cookie", { url, name, error });
return null;
}
}
Reads a single named cookie for the given URL. Returns
nullwhen the cookie is absent, the API is unavailable, or the read fails.