Add dev/: training and export scripts, GPAI rule tests, browser tests, workspace map
28e3615 verified Download dev/browser-tests/consent.mjs from Devseis/Caveat: direct link, hf CLI and curl.
- Browser
- Download file 4.2 kB
-
https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/consent.mjs
- Command line
-
hf download hf://spaces/Devseis/Caveat/dev/browser-tests/consent.mjs
-
curl -L -o consent.mjs https://huggingface.co/spaces/Devseis/Caveat/resolve/main/dev/browser-tests/consent.mjs
4.2 kB
| import puppeteer from "puppeteer-core"; | |
| const S = "/Users/umer/Documents/hf/tools/browser-tests/out"; | |
| const b = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: true, userDataDir: S + "/prof_consent", protocolTimeout: 90000 }); | |
| const p = await b.newPage(); await p.setCacheEnabled(false); | |
| const errs = []; p.on("pageerror", (e) => errs.push(e.message)); | |
| let log = []; | |
| await p.setRequestInterception(true); | |
| p.on("request", (r) => { | |
| const u = r.url(); | |
| if (/clarity\.ms|google|gstatic/.test(u)) log.push(u.replace(/\?.*/, "")); | |
| if (/clarity\.ms/.test(u)) return r.abort(); // detect, but don't send real analytics | |
| if (u.includes("cdn.jsdelivr.net/npm/@huggingface/transformers")) return r.respond({ status: 200, contentType: "application/javascript", headers: { "Access-Control-Allow-Origin": "*" }, body: "export const env={}; export async function pipeline(){ return async()=>[{label:'high_risk',score:.9}]; }" }); | |
| if (/\.onnx|workers\.dev/.test(u)) return r.abort(); | |
| r.continue(); | |
| }); | |
| const visit = async (path = "/") => { log = []; await p.goto("http://localhost:8766" + path, { waitUntil: "networkidle2" }); await new Promise((r) => setTimeout(r, 600)); }; | |
| const bannerShown = () => p.evaluate(() => !document.getElementById("consent").hidden); | |
| const tpRequests = () => log.length ? log.join(", ") : "none"; | |
| await p.setViewport({ width: 390, height: 844, deviceScaleFactor: 2, isMobile: true, hasTouch: true }); | |
| await visit(); | |
| const font = await p.evaluate(async () => { await document.fonts.ready; return [...document.fonts].filter((f) => f.status === "loaded").map((f) => f.family).join(",") || "none"; }); | |
| console.log(`1 first visit: banner=${await bannerShown()} | third-party requests: ${tpRequests()} | self-hosted font loaded: ${font}`); | |
| await p.screenshot({ path: S + "/consent_banner.png" }); | |
| await p.click("#consentDecline"); await new Promise((r) => setTimeout(r, 300)); | |
| console.log(`2 after Decline: banner=${await bannerShown()} | clarity requested: ${log.some((u) => u.includes("clarity"))}`); | |
| await visit(); console.log(`3 revisit after Decline: banner=${await bannerShown()} | third-party requests: ${tpRequests()}`); | |
| await p.click("#consentSettings"); await p.click("#consentAccept"); await new Promise((r) => setTimeout(r, 500)); | |
| console.log(`4 Accept via footer settings: clarity requested: ${log.some((u) => u.includes("clarity.ms/tag/yqfpt9xwwk"))}`); | |
| await visit(); console.log(`5 revisit after Accept: banner=${await bannerShown()} | clarity requested: ${log.some((u) => u.includes("clarity"))}`); | |
| await p.evaluate(() => { document.cookie = "_clck=test; path=/; max-age=3600"; document.cookie = "_clsk=test; path=/; max-age=3600"; }); | |
| log = []; await p.click("#consentSettings"); await p.click("#consentDecline"); await p.waitForNavigation({ waitUntil: "networkidle2" }).catch(() => {}); await new Promise((r) => setTimeout(r, 500)); | |
| const ck = await p.evaluate(() => document.cookie); | |
| console.log(`6 withdraw (Decline after Accept): page reloaded, clarity requested after reload: ${log.some((u) => u.includes("clarity"))} | clarity cookies left: ${/_cl(ck|sk)=/.test(ck)}`); | |
| await p.evaluate(() => localStorage.removeItem("caveat-consent")); await p.evaluate(() => { document.cookie = "_clck=legacy; path=/; max-age=3600"; }); | |
| await visit(); const legacy = await p.evaluate(() => /_clck=/.test(document.cookie)); | |
| console.log(`7 legacy Clarity cookie from old page, no choice yet: removed=${!legacy} | banner=${await bannerShown()}`); | |
| await visit("/privacy.html"); | |
| const st0 = await p.$eval("#state", (e) => e.textContent); await p.click("#allow"); const st1 = await p.$eval("#state", (e) => e.textContent); await p.click("#deny"); const st2 = await p.$eval("#state", (e) => e.textContent); | |
| console.log(`8 privacy page: third-party requests: ${tpRequests()} | state: "${st0}" → "${st1}" → "${st2}"`); | |
| const w = await p.evaluate(() => document.documentElement.scrollWidth); | |
| console.log(` privacy page width at 390px: ${w}`); await p.screenshot({ path: S + "/privacy_top.png" }); | |
| console.log("page errors:", errs.length ? errs.join(" | ") : "none"); await b.close(); | |