ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function getCookie

    • Reads a single named cookie for the given URL. Returns null when the cookie is absent, the API is unavailable, or the read fails.

      Parameters

      • url: string

        The URL the cookie belongs to

      • name: string

        The cookie name to read

      Returns Promise<null | Cookie>

      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;
      }
      }