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/payloads.ts
1import type { AdapterContext } from "../types";2import { filterXGraphQlEntries } from "./shared";34export function getRelevantXThreadEntries(context: AdapterContext) {5return filterXGraphQlEntries(context.network.getEntries()).filter(6(entry) =>7entry.method === "GET" &&8entry.finished &&9(10entry.url.includes("TweetDetail") ||11entry.url.includes("TweetResultByRestId") ||12entry.url.includes("TweetResultsByRestIds")13),14);15}1617export async function prefetchRelevantXThreadBodies(context: AdapterContext): Promise<void> {18const entries = getRelevantXThreadEntries(context).filter((entry) => entry.body === undefined && !entry.bodyError);19for (const entry of entries) {20await context.network.ensureBody(entry);21}22}2324export async function collectXJsonPayloads(context: AdapterContext): Promise<unknown[]> {25await prefetchRelevantXThreadBodies(context);26const entries = getRelevantXThreadEntries(context);2728const payloads: unknown[] = [];29for (const entry of entries) {30const payload = await context.network.getJsonBody(entry);31if (payload) {32payloads.push(payload);33}34}35return payloads;36}3738export async function waitForInitialXPayload(context: AdapterContext): Promise<void> {39try {40await context.network.waitForResponse(41(entry) =>42entry.url.includes("/graphql/") &&43(entry.url.includes("TweetDetail") || entry.url.includes("TweetResultByRestId")),44{ timeoutMs: Math.min(context.timeoutMs, 15_000) },45);46await prefetchRelevantXThreadBodies(context);47} catch {48context.log.debug("No tweet GraphQL response observed before timeout.");49}50}51