Anki can not save long-time cookie on Mac PC client

I attempted to save my persistent data by using cookies and set the expiration time of the cookies to a few days, but when I restart my anki, the cookies will be deleted. This issue occurred on the Mac anki client, but was not found on the ankidroid.

This is my environmental information:
Anki 2.1.54 (b6a7760c) Python 3.9.7 Qt 6.3.1 PyQt 6.3.1
Platform: Mac 10.15.7
Flags: frz=True ao=True sv=2

This is the code I used to set cookies

export interface CookieOptions {
  expires?: Date;
  path?: string;
  domain?: string;
  secure?: boolean;
  sameSite?: 'strict' | 'lax' | 'none';
}

const setCookie = function(name: string, value: string, options?: CookieOptions) {
  let cookieStr = `${encodeURIComponent(name)}=${encodeURIComponent(value)};`;

  if (options) {
    if (options.expires) {
      cookieStr += `expires=${options.expires.toUTCString()};`;
    }
    if (options.path) {
      cookieStr += `path=${options.path};`;
    }
    if (options.domain) {
      cookieStr += `domain=${options.domain};`;
    }
    if (options.secure) {
      cookieStr += `secure;`;
    }
    if (options.sameSite) {
      cookieStr += `sameSite=${options.sameSite};`;
    }
  }

  document.cookie = cookieStr;
};

const getCookie = function(name: string): string | null {
  const cookieArr = document.cookie.split('; ');
  for (let i = 0; i < cookieArr.length; i++) {
    const [cookieName, cookieValue] = cookieArr[i].split('=');
    if (decodeURIComponent(cookieName) === name) {
      return decodeURIComponent(cookieValue);
    }
  }
  return null;
};

const removeCookie = function(name: string) {
  setCookie(name, '', { expires: new Date(0) });
};

// @ts-ignore
export { setCookie, getCookie, removeCookie };```

I found that the port numbers of the addresses are different (one address accessed each time Anki starts), so the cookies are stored in different places. Is there any solution to this problem?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.