import { Cookie, CookieJar } from 'tough-cookie'; export const cookieJar = new CookieJar(); export function writeCookies(cookieJar, cookies) { cookies.forEach((chromeCookie) => { const toughCookie = Cookie.fromJSON({ key: chromeCookie.name, value: chromeCookie.value, domain: chromeCookie.domain, path: chromeCookie.path, secure: chromeCookie.secure, httpOnly: chromeCookie.httpOnly, sameSite: chromeCookie.sameSite, expires: chromeCookie.expirationDate ? new Date(chromeCookie.expirationDate * 1000) : 'Infinity', }); cookieJar.setCookie(toughCookie, `http${chromeCookie.secure ? 's' : ''}://${chromeCookie.domain}${chromeCookie.path}`, () => { console.log('Cookie added to tough-cookie jar!'); }); }); }