Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Fetch any URL via Chrome CDP and convert the rendered page to clean markdown with YouTube transcript support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/lib/adapters/x/session.ts
1import type { AdapterContext } from "../types";23const X_SESSION_URLS = ["https://x.com/", "https://twitter.com/"] as const;4const REQUIRED_X_SESSION_COOKIES = ["auth_token", "ct0"] as const;56interface CookieLike {7name?: string;8value?: string | null;9}1011interface NetworkGetCookiesResult {12cookies?: CookieLike[];13}1415export function buildXSessionCookieMap(cookies: readonly CookieLike[]): Record<string, string> {16const cookieMap: Record<string, string> = {};17for (const cookie of cookies) {18const name = cookie.name?.trim();19const value = cookie.value?.trim();20if (!name || !value) {21continue;22}23cookieMap[name] = value;24}25return cookieMap;26}2728export function hasRequiredXSessionCookies(cookieMap: Record<string, string>): boolean {29return REQUIRED_X_SESSION_COOKIES.every((name) => Boolean(cookieMap[name]));30}3132export async function readXSessionCookieMap(33context: Pick<AdapterContext, "browser">,34): Promise<Record<string, string>> {35const { cookies } = await context.browser.targetSession.send<NetworkGetCookiesResult>(36"Network.getCookies",37{ urls: [...X_SESSION_URLS] },38);39return buildXSessionCookieMap(cookies ?? []);40}4142export async function isXSessionReady(43context: Pick<AdapterContext, "browser">,44): Promise<boolean> {45const cookieMap = await readXSessionCookieMap(context);46return hasRequiredXSessionCookies(cookieMap);47}48