Cookies

Cookies

Multiple cookies

If you want to use different cookies to send request to avoid hitting cookies limit, you could use addCookies to add more than one cookies to the client.

const { Client } = require("genshin-kit.js");
// import { Client } from "genshin-kit.js"; (if you use typescript)
 
const client = new Client();
client.addCookies([{ ltoken: "LTOKEN", ltuid: "LTUID" }, {}, {}, {}]);

If you have more than one cookie, it will use the first , and then the second...

Custom Cookies Manager

const { Client, ClientCookieManager } = require("genshin-kit.js");
// import { Client , ClientCookieManager } from "genshin-kit.js"; (if you use typescript)
 
const manager = new ClientCookieManager();
manager.setCookie("LTUID", "LTOKEN");
 
const client = new Client({ cookieManager: manager });

You can use your own cookie manager to manage cookies.

// ...
manager.setCookie("", ""); // set cookie
manager.getAll(); // get all cookies
manager.delete(0); // delete cookie by index
manager.clear(); // clear all cookies
manager.get(); // get cookie to send request

Get Cookies from browser(Chrome)

Prepare:

  1. Install https://www.npmjs.com/package/chrome-cookies-secure (opens in a new tab)
npm i chrome-cookies-secure
  1. Open Chrome and login to the HoYoLab website
  2. Get the cookie in ClientCookieManager
// ...
manager.getBrowserCookie("Profile"); // you need to pass browser Profile
  1. Done ✨