Instructions to use botezx/flagtldr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Grok
How to use botezx/flagtldr with Grok:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download scripts/e2e/screens.mjs from botezx/flagtldr: direct link, hf CLI and curl.
- Browser
- Download file 12.4 kB
-
https://huggingface.co/botezx/flagtldr/resolve/main/scripts/e2e/screens.mjs
- Command line
-
hf download hf://botezx/flagtldr/scripts/e2e/screens.mjs
-
curl -L -o screens.mjs https://huggingface.co/botezx/flagtldr/resolve/main/scripts/e2e/screens.mjs
12.4 kB
| // Loads the unpacked extension in Chrome for Testing, configures it through the real | |
| // options page, opens a mock x.com thread and saves screenshots to docs/screenshots/. | |
| // Prereqs: scripts/e2e/mock-x-server.py on :8443; classifier service on :8765 (any backend). | |
| import puppeteer from "puppeteer-core"; | |
| import path from "node:path"; | |
| import { fileURLToPath } from "node:url"; | |
| import { setTimeout as sleep } from "node:timers/promises"; | |
| const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); | |
| const EXT = path.join(ROOT, "extension"); | |
| const OUT = path.join(ROOT, "docs", "screenshots"); | |
| const CHROME = process.env.CHROME || process.argv[2]; | |
| const BACKEND = process.env.XA_BACKEND || "service"; | |
| const browser = await puppeteer.launch({ | |
| executablePath: CHROME, | |
| headless: true, | |
| args: [ | |
| `--disable-extensions-except=${EXT}`, `--load-extension=${EXT}`, | |
| "--host-resolver-rules=MAP x.com 127.0.0.1:8443", "--ignore-certificate-errors", | |
| "--no-sandbox", "--window-size=1280,900", "--lang=pl", | |
| ], | |
| defaultViewport: { width: 1280, height: 900 }, | |
| }); | |
| try { | |
| const sw = await browser.waitForTarget((t) => t.type() === "service_worker" && t.url().endsWith("service-worker.js"), { timeout: 15000 }); | |
| const extId = new URL(sw.url()).host; | |
| console.log("extension loaded:", extId); | |
| // 1. options page | |
| const opt = await browser.newPage(); | |
| opt.on("dialog", (d) => d.accept()); | |
| await opt.goto(`chrome-extension://${extId}/src/options/options.html`); | |
| await opt.waitForFunction(() => document.getElementById("systemPrompt").value.length > 0); | |
| await opt.click("#loadExample"); | |
| await opt.waitForFunction(() => document.getElementById("ls.labels").value.length > 0); | |
| await opt.$eval("#classifyEnabled", (e) => { e.checked = true; }); | |
| await opt.select("#classifierBackend", BACKEND); | |
| await opt.click("#save"); | |
| await opt.waitForFunction(() => /Zapisano/.test(document.getElementById("status").textContent)); | |
| await opt.screenshot({ path: path.join(OUT, "options.png"), fullPage: true }); | |
| console.log("options.png"); | |
| // 2. mock x.com thread with marks | |
| const x = await browser.newPage(); | |
| x.on("console", (m) => { if (/flagtldr|x-addons/.test(m.text())) console.log("page:", m.text()); }); | |
| await x.goto("https://x.com/teza_autor/status/100", { waitUntil: "networkidle0" }); | |
| await x.waitForSelector(".xa-badge", { timeout: 60000 }); | |
| await sleep(500); | |
| await x.screenshot({ path: path.join(OUT, "thread-marks.png") }); | |
| console.log("thread-marks.png"); | |
| const grokTargets = []; | |
| browser.on("targetcreated", (t) => { if (/\/i\/grok/.test(t.url())) grokTargets.push(t.url()); }); | |
| const resultText = () => x.evaluate(() => { | |
| const h = document.querySelector(".xa-result-host"); | |
| return h ? h.shadowRoot.querySelector(".card").innerText : ""; | |
| }); | |
| const clickSummary = async () => { | |
| await x.evaluate(() => document.querySelectorAll(".xa-result-host").forEach((n) => (n.__xaClose ? n.__xaClose() : n.remove()))); | |
| await x.click('article[data-testid="tweet"] .xa-summary-btn'); | |
| }; | |
| const setOpts = async (o) => { | |
| await opt.bringToFront(); | |
| await opt.reload(); | |
| await opt.waitForFunction(() => document.getElementById("systemPrompt").value.length > 0); | |
| for (const [k, v] of Object.entries(o)) await opt.select("#" + k, v); | |
| await opt.click("#save"); | |
| await opt.waitForFunction(() => /Zapisano/.test(document.getElementById("status").textContent)); | |
| await x.bringToFront(); | |
| await sleep(300); | |
| }; | |
| // v0.4.1 panel checks: fixed top-level host above X's virtualized, image-heavy timeline, opaque themed | |
| // background, scrolling body, no Grok UI chrome (thinking line, suggestion chips, action buttons), @mentions as links. | |
| const panelCheck = () => x.evaluate(() => { | |
| const h = document.querySelector(".xa-result-host"), root = h.shadowRoot, card = root.querySelector(".card"), body = root.querySelector(".body"); | |
| const r = card.getBoundingClientRect(), pts = [[0.5, 0.5], [0.2, 0.15], [0.8, 0.85], [0.5, 0.05]]; | |
| const hits = pts.map(([fx, fy]) => document.elementFromPoint(r.left + r.width * fx, r.top + r.height * fy) === h); | |
| const ban = document.querySelector(".banner span")?.getBoundingClientRect(); | |
| const head = root.querySelector(".top").getBoundingClientRect(); | |
| return { pos: getComputedStyle(h).position, parent: h.parentElement === document.documentElement, mode: h.dataset.mode, hits, | |
| bg: getComputedStyle(card).backgroundColor, bodyBg: getComputedStyle(body).backgroundColor, text: card.innerText, | |
| mentions: [...root.querySelectorAll("a.mention")].map((a) => a.getAttribute("href")), | |
| links: [...root.querySelectorAll(".body a")].map((a) => [a.getAttribute("href"), a.getAttribute("rel")]), | |
| scrolls: body.scrollHeight > body.clientHeight + 10 && /auto|scroll/.test(getComputedStyle(body).overflowY), | |
| fits: r.bottom <= innerHeight + 1 && r.top >= -1, | |
| bannerOverlap: !!ban && !(ban.right < head.left || ban.left > head.right || ban.bottom < head.top || ban.top > head.bottom) }; | |
| }); | |
| const assertPanel = (c, theme) => { | |
| const bad = []; | |
| if (c.pos !== "fixed" || !c.parent) bad.push("not a fixed top-level host"); | |
| if (!c.hits.every(Boolean)) bad.push("page content paints over the panel " + JSON.stringify(c.hits)); | |
| if (/rgba\(.*, 0(\.\d+)?\)$/.test(c.bg) || c.bg === "transparent") bad.push("transparent background " + c.bg); | |
| if ({ dark: "rgb(0, 0, 0)", dim: "rgb(21, 32, 43)", light: "rgb(255, 255, 255)" }[theme] !== c.bg) bad.push(`theme ${theme} bg ${c.bg}`); | |
| for (const s of ["Thought for", "Myślał", "Daj linki do źródeł", "Jakie są konkretne efekty reformy?", "Porównaj z innymi krajami", "Wygeneruj ponownie", "Udostępnij"]) | |
| if (c.text.includes(s)) bad.push("Grok UI chrome leaked: " + s); | |
| if (!c.mentions.includes("https://x.com/ekonomistka")) bad.push("no @mention link " + JSON.stringify(c.mentions)); | |
| if (c.mentions.some((m) => /example\.com/.test(m))) bad.push("email treated as mention"); | |
| if (!c.links.every(([h, rel]) => /^https?:\/\//.test(h) && /noopener/.test(rel || ""))) bad.push("unsafe link " + JSON.stringify(c.links)); | |
| if (!c.scrolls) bad.push("long answer does not scroll inside the panel"); | |
| if (!c.fits) bad.push("panel exceeds viewport"); | |
| if (c.bannerOverlap) bad.push("X banner overlaps panel header"); | |
| if (bad.length) throw new Error("panel check failed (" + theme + "): " + bad.join("; ")); | |
| console.log(`panel ok (${theme}, ${c.mode}): fixed, on top, bg ${c.bg}, scrolls, mentions ${c.mentions.length}, links ${c.links.length}, no Grok chrome`); | |
| }; | |
| // 3. one-click Grok (default: hidden same-origin iframe) – overlay while Grok streams, then result panel. | |
| // X-like layout: virtualized image-heavy timeline + "Pokaż 31 wpisów" banner, dark theme. | |
| await x.goto("https://x.com/teza_autor/status/100?virtual=1&theme=dark", { waitUntil: "networkidle0" }); | |
| await x.waitForSelector(".xa-badge", { timeout: 60000 }); | |
| await clickSummary(); // focal post at the top (a sticky header would intercept a scrolled-into-view click) | |
| await x.evaluate(() => window.scrollTo(0, 420)); | |
| await x.waitForFunction(() => { | |
| const h = document.getElementById("xa-overlay-host"); | |
| return h && h.shadowRoot.querySelector('li[data-k="streaming"].on'); | |
| }, { timeout: 30000 }).catch(async (e) => { | |
| await x.screenshot({ path: "/tmp/xa-step3-fail.png" }); | |
| console.log("step3 state:", await x.evaluate(() => JSON.stringify({ ov: document.getElementById("xa-overlay-host")?.shadowRoot?.textContent?.slice(0, 400), | |
| res: !!document.querySelector(".xa-result-host"), btns: document.querySelectorAll(".xa-summary-btn").length, toast: document.querySelector("[id*=toast]")?.textContent }))); | |
| throw e; | |
| }); | |
| await sleep(700); | |
| await x.screenshot({ path: path.join(OUT, "summary-overlay.png") }); | |
| console.log("summary-overlay.png"); | |
| await x.waitForSelector(".xa-result-host", { timeout: 60000 }); | |
| await sleep(900); | |
| const t1 = await resultText(); | |
| if (!/Kontrargumenty/.test(t1) || !/Otwórz w Groku/.test(t1)) throw new Error("unexpected result panel: " + t1); | |
| assertPanel(await panelCheck(), "dark"); | |
| await x.screenshot({ path: path.join(OUT, "summary-result.png") }); | |
| // scroll the page under the panel: the panel stays put and X's cells never cover it | |
| await x.evaluate(() => window.scrollBy(0, 900)); await sleep(400); | |
| assertPanel(await panelCheck(), "dark"); | |
| await x.evaluate(() => { const b = document.querySelector(".xa-result-host").shadowRoot.querySelector(".body"); b.scrollTop = b.scrollHeight; }); await sleep(200); | |
| await x.screenshot({ path: path.join(OUT, "summary-result-dark-timeline.png") }); | |
| console.log("summary-result.png, summary-result-dark-timeline.png"); | |
| // narrow window -> bottom sheet | |
| await x.setViewport({ width: 760, height: 900 }); await sleep(500); | |
| { const c = await panelCheck(); if (c.mode !== "sheet") throw new Error("expected sheet mode at 760px, got " + c.mode); assertPanel(c, "dark"); } | |
| await x.screenshot({ path: path.join(OUT, "summary-result-sheet.png") }); | |
| await x.setViewport({ width: 1280, height: 900 }); await sleep(300); | |
| const frames = await x.evaluate(() => document.querySelectorAll("#xa-grok-frame").length); | |
| console.log(`summary-result.png (iframe mode; grok tabs opened: ${grokTargets.length}; leftover frames: ${frames})`); | |
| if (grokTargets.length) throw new Error("iframe mode should not open tabs"); | |
| // light theme (as in botex-human's report) | |
| await x.goto("https://x.com/teza_autor/status/100?virtual=1&theme=light", { waitUntil: "networkidle0" }); | |
| await x.waitForSelector(".xa-badge", { timeout: 60000 }); | |
| await clickSummary(); | |
| await x.waitForFunction(() => /Kontrargumenty/.test(document.querySelector(".xa-result-host")?.shadowRoot.querySelector(".card").innerText || ""), { timeout: 60000 }); | |
| await sleep(600); | |
| assertPanel(await panelCheck(), "light"); | |
| await x.screenshot({ path: path.join(OUT, "summary-result-light.png") }); | |
| console.log("summary-result-light.png"); | |
| await x.goto("https://x.com/teza_autor/status/100", { waitUntil: "networkidle0" }); | |
| await x.waitForSelector(".xa-badge", { timeout: 60000 }); | |
| // 4. background-tab context | |
| await setOpts({ grokContext: "tab" }); | |
| await clickSummary(); | |
| await x.waitForSelector(".xa-result-host", { timeout: 60000 }); | |
| const t2 = await resultText(); | |
| const open = (await browser.pages()).map((p) => p.url()).filter((u) => /\/i\/grok/.test(u)); | |
| console.log(`tab mode ok=${/Kontrargumenty/.test(t2)}; grok tabs created=${grokTargets.length}, still open=${open.length}`); | |
| if (!/Kontrargumenty/.test(t2) || grokTargets.length !== 1 || open.length) throw new Error("tab mode failed"); | |
| // 5. failure -> fallback panel (Grok page without composer) | |
| await setOpts({ grokContext: "iframe" }); | |
| await x.evaluate(() => fetch("/__mock/grok-mode?broken")); | |
| await clickSummary(); | |
| await x.waitForFunction(() => { | |
| const h = document.querySelector(".xa-result-host"); | |
| return h && /Kopiuj prompt/.test(h.shadowRoot.querySelector(".card").innerText); | |
| }, { timeout: 90000 }); | |
| await sleep(300); | |
| await x.screenshot({ path: path.join(OUT, "summary-fallback.png") }); | |
| console.log("summary-fallback.png:", (await resultText()).split("\n").find((l) => /Powód/.test(l))); | |
| await x.evaluate(() => fetch("/__mock/grok-mode?ok")); | |
| // 6. legacy manual handoff (clipboard + open Grok) | |
| await setOpts({ provider: "grok-handoff" }); | |
| await x.evaluate(() => document.querySelectorAll(".xa-result-host").forEach((n) => (n.__xaClose ? n.__xaClose() : n.remove()))); | |
| await x.click('article[data-testid="tweet"] .xa-summary-btn'); | |
| await x.waitForFunction(() => { | |
| const h = document.getElementById("xa-panel-host"); | |
| return h && /schowka|Błąd/.test(h.shadowRoot.querySelector(".b").textContent); | |
| }, { timeout: 20000 }).catch(async (e) => { await x.screenshot({ path: "/tmp/xa-step6-fail.png" }); | |
| console.log("step6:", await x.evaluate(() => JSON.stringify({ url: location.href, p: document.getElementById("xa-panel-host")?.shadowRoot?.textContent, r: document.querySelectorAll(".xa-result-host").length }))); throw e; }); | |
| await x.bringToFront(); | |
| await x.screenshot({ path: path.join(OUT, "summary-handoff.png") }); | |
| console.log("summary-handoff.png"); | |
| await setOpts({ provider: "grok-auto" }); | |
| } finally { | |
| await browser.close(); | |
| } | |