Add dev/: training and export scripts, GPAI rule tests, browser tests, workspace map
28e3615 verified Download dev/browser-tests/mobile.mjs from Devseis/Caveat: direct link, hf CLI and curl.
- Browser
- Download file 3.44 kB
-
https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/mobile.mjs
- Command line
-
hf download hf://spaces/Devseis/Caveat/dev/browser-tests/mobile.mjs
-
curl -L -o mobile.mjs https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/mobile.mjs
3.44 kB
| import puppeteer from "puppeteer-core"; | |
| import fs from "fs"; | |
| const LOG = "/Users/umer/Documents/hf/tools/browser-tests/out/mobile.log"; | |
| fs.writeFileSync(LOG, ""); | |
| const log = (m) => fs.appendFileSync(LOG, m + "\n"); | |
| const S = "/Users/umer/Documents/hf/tools/browser-tests/out"; | |
| const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true, | |
| userDataDir: S + "/prof4", args: ["--disable-gpu"], protocolTimeout: 60000 }); | |
| const page = await browser.newPage(); await page.setCacheEnabled(false); | |
| const errors = []; | |
| page.on("pageerror", (e) => errors.push(e.message)); | |
| await page.setRequestInterception(true); | |
| const STUB = "export const env = {}; export async function pipeline(){ return async () => [{ label: 'high_risk', score: 0.9 }]; }"; | |
| page.on("request", (r) => { | |
| const u = r.url(); | |
| if (u.includes("cdn.jsdelivr.net/npm/@huggingface/transformers")) return r.respond({ status: 200, contentType: "application/javascript", headers: { "Access-Control-Allow-Origin": "*" }, body: STUB }); | |
| if (/\.onnx|clarity\.ms|workers\.dev/.test(u)) return r.abort(); | |
| r.continue(); | |
| }); | |
| for (const [w, h] of [[390, 844], [360, 740]]) { | |
| await page.emulate({ viewport: { width: w, height: h, deviceScaleFactor: 2, isMobile: true, hasTouch: true }, | |
| userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1" }); | |
| for (const [name, hash] of [["check", ""], ["results", "#results"], ["story", "#story"], ["learn2", "#learn-2"], ["learn7", "#learn-7"], ["learn12", "#learn-12"]]) { | |
| await page.goto("http://localhost:8766/" + hash, { waitUntil: "domcontentloaded" }); | |
| await new Promise((r) => setTimeout(r, 1200)); | |
| const m = await page.evaluate(() => { | |
| const vw = document.documentElement.clientWidth; | |
| const wide = [...document.querySelectorAll("body *")].filter((el) => { | |
| const r = el.getBoundingClientRect(); if (!r.width || getComputedStyle(el).display === "none") return false; | |
| let p = el.parentElement; while (p) { const o = getComputedStyle(p).overflowX; if (o === "auto" || o === "scroll" || o === "hidden") return false; p = p.parentElement; } | |
| return r.right > vw + 1 || r.left < -1; | |
| }).slice(0, 5).map((el) => el.tagName.toLowerCase() + (el.id ? "#" + el.id : "") + (el.className ? "." + String(el.className).split(" ")[0] : "") + " right=" + Math.round(el.getBoundingClientRect().right)); | |
| const tabs = document.querySelector(".tabs"); | |
| return { vw, scrollW: document.documentElement.scrollWidth, wide: wide.filter(x=>!x.includes('sr-only')), tabsScroll: tabs.scrollWidth > tabs.clientWidth, content: document.querySelectorAll('.chapter').length + ' chapters, lesson=' + (document.querySelector('#lesson h2')?.textContent||'-') + ', visibleTab=' + (document.querySelector('.tab-btn[aria-selected=true]')?.textContent||'') }; | |
| }); | |
| log(`${w}px ${name}: viewport ${m.vw}, page width ${m.scrollW} ${m.scrollW > m.vw ? "❌ HORIZONTAL SCROLL" : "✅ no horizontal scroll"}${m.tabsScroll ? " (tab bar scrolls sideways)" : ""}${m.wide.length ? " | overflowing: " + m.wide.join(", ") : ""} [${m.content}]`); | |
| if (w === 390) await page.screenshot({ path: `${S}/m_${name}.png`, fullPage: true }); | |
| } | |
| } | |
| log("page errors:", errors.length ? [...new Set(errors)].join(" | ") : "none"); | |
| await browser.close(); | |