shitty document.cookie impl

This commit is contained in:
Toshit Chawda 2024-08-09 22:02:14 -07:00
parent 4829cd4a23
commit 956c0aa02a
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -1,28 +1,22 @@
import { parse } from "set-cookie-parser"; import { parse } from "set-cookie-parser";
import { ScramjetClient } from "../client"; import { ScramjetClient } from "../client";
import IDBMapSync from "@webreflection/idb-map/sync";
export default function (client: ScramjetClient, self: typeof window) { export default function (client: ScramjetClient, self: typeof window) {
let cookieStore = new IDBMapSync(client.url.host, {
durability: "relaxed",
prefix: "Cookies",
});
client.Trap("Document.prototype.cookie", { client.Trap("Document.prototype.cookie", {
get(ctx) { get(ctx) {
const cookiestring = ctx.get(); let cookies = cookieStore.entries();
// dbg.log("original cookiestring", cookiestring); if (client.url.protocol !== "https:") {
// cookies = cookies.filter(([_k, v]) => !v.args.includes(["Secure"]));
// if (!cookiestring) return ""; }
// cookies = cookies.filter(([_k, v]) => !v.args.includes(["HttpOnly"]));
// cookies = Array.from(cookies.map(([k, v]) => `${k}=${v.value}`));
// let string = ""; return cookies.join("; ");
//
// for (const cookiestr of cookiestring.split(";")) {
// const cookie = parse(cookiestr.trim())[0];
// if (cookie.name.startsWith(client.url.hostname + "@")) {
// let name = cookie.name.substring(client.url.hostname.length + 1);
// string += `${name}=${cookie.value}; `;
// }
// }
//
// return string.trimEnd();
return "sp_t=00246e00653d39d1341bbe9d10f138c4; OptanonConsent=isGpcEnabled=0&datestamp=Sat+Jul+20+2024+16%3A11%3A26+GMT-0400+(Eastern+Daylight+Time)&version=202405.2.0&browserGpcFlag=0&isIABGlobal=false&hosts=&landingPath=https%3A%2F%2Fopen.spotify.com%2F&groups=BG169%3A1%2Ct00%3A1%2Ci00%3A1%2CBG170%3A1%2Cs00%3A1%2Cf00%3A1%2Cm00%3A1%2Cf11%3A1";
}, },
set(ctx, value: string) { set(ctx, value: string) {
// dbg.debug("setting cookie", value); // dbg.debug("setting cookie", value);
@ -43,7 +37,4 @@ export default function (client: ScramjetClient, self: typeof window) {
// @ts-ignore // @ts-ignore
delete self.cookieStore; delete self.cookieStore;
// sp_t=00e49dc8-59d0-4b5f-9beb-ec7b67368498; path=/; expires=Invalid Date
// OTZ=7653361_72_76_104100_72_446760;path=/;expires=Mon, 19 Aug 2024 20:01:06 GMT;secure
} }