import { chromium } from "playwright"; import { writeFileSync, appendFileSync } from "fs"; const LOG_FILE = "flightics_requests.log"; writeFileSync(LOG_FILE, `=== Flightics Network Log - ${new Date().toISOString()} ===\n\n`); function log(text) { console.log(text); appendFileSync(LOG_FILE, text + "\n"); } const browser = await chromium.launch({ headless: false }); const context = await browser.newContext(); const page = await context.newPage(); const requests = []; // Interceptar todas las peticiones de red page.on("request", (req) => { const url = req.url(); const method = req.method(); const resourceType = req.resourceType(); // Filtrar solo XHR/fetch (las llamadas a APIs) if (resourceType === "xhr" || resourceType === "fetch") { const entry = { method, url, headers: req.headers(), postData: req.postData() || null, }; requests.push(entry); log(`\n>>> ${method} ${url}`); log(` HEADERS: ${JSON.stringify(req.headers())}`); if (entry.postData) { log(` BODY: ${entry.postData}`); } } }); page.on("response", async (res) => { const req = res.request(); if (req.resourceType() === "xhr" || req.resourceType() === "fetch") { const status = res.status(); const url = res.url(); log(`<<< ${status} ${url}`); try { const contentType = res.headers()["content-type"] || ""; if (contentType.includes("json")) { const body = await res.json(); log(` RESPONSE: ${JSON.stringify(body, null, 2)}`); } } catch { // ignore } } }); log("Abriendo Flightics... Navega y busca vuelos manualmente."); log("Presiona Ctrl+C cuando termines.\n"); log(`Log guardado en: ${LOG_FILE}\n`); await page.goto("https://www.flightics.com/"); // Esperar a que el usuario interactue y cierre await new Promise(() => {});