A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

9 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 toolbar: Back and Forward are greyed out when there's nowhere to go cc08c7a 1 week, 2 days ago History
states.mjs · 3.5 KB · 62 lines
1// Per-tab loading states: driven by real signals, never invented.
2import { sleep, traceStates } from "./lib.mjs";
3
4export default async function (ctx) {
5 const { call: T, check, base } = ctx;
6 await T("page.goto", { url: base + "/free" });
7
8 let s = await traceStates(ctx, base + "/slow?ms=1500", 5200);
9 console.log(" /slow :", s.join(" → "));
10 check(s.includes("waiting") && s.includes("receiving") && s[s.length - 1] === "idle", "a slow page: waiting → receiving → idle");
11
12 s = await traceStates(ctx, base + "/hang", 8500);
13 console.log(" /hang :", s.join(" → "));
14 check(s.includes("waiting") && s.includes("slow"), "a request that never answers becomes 'slow' after 6 s");
15 await T("page.goto", { url: base + "/free" });
16 await sleep(400);
17 check(((await T("tabs.list")).find((x) => x.active).state ?? "idle") === "idle", "navigating away clears the slow state");
18
19 s = await traceStates(ctx, base + "/fail", 2500);
20 console.log(" /fail :", s.join(" → "));
21 check(s.includes("failed") && !s.includes("slow"), "a dropped connection → failed (no stale 'slow' from the previous hung page)");
22 await T("page.goto", { url: base + "/free" });
23
24 s = await traceStates(ctx, base + "/redir/slow", 5200);
25 console.log(" /redir/slow :", s.join(" → "));
26 check(s.join(">").includes("waiting>redirecting"), "a slow redirect: waiting → redirecting → (next hop)");
27 check(s[s.length - 1] === "idle" && s.includes("receiving"), "…then receiving, then idle");
28 s = await traceStates(ctx, base + "/redir/chain", 1500);
29 check(s.every((x) => x === "idle"), "an instant redirect never flashes a throbber", s.join("→"));
30
31 await T("x402.approval", { mode: "auto", maxUsd: 1 });
32 s = await traceStates(ctx, base + "/premium", 4500);
33 console.log(" /premium ($.50):", s.join(" → "));
34 check(s.includes("pay-settled"), "an x402 payment shows pay-settled, then idle");
35 await T("x402.approval", { mode: "ask", maxUsd: 0 });
36
37 // The animation really runs, and the tab's <svg> node survives refreshes (no restart flicker).
38 const c = await ctx.chrome();
39 T("page.goto", { url: base + "/hang", wait: false }).catch(() => {});
40 await sleep(900);
41 const clock = () => c.ev(`(() => { const s = document.querySelector('#status.show .ic svg'); return s ? { t: s.getCurrentTime(), paused: s.animationsPaused() } : null })()`);
42 const a = await clock();
43 await sleep(600);
44 const b = await clock();
45 const reduced = await c.ev(`matchMedia("(prefers-reduced-motion: reduce)").matches`);
46 if (reduced) check(!!(a && b && b.paused), "Reduce Motion is on: the status icon is paused (a still frame), as the default Follow System intends");
47 else check(!!(a && b && b.t > a.t + 0.4 && !b.paused), "the status icon's animation clock advances", `t ${a?.t.toFixed(2)} → ${b?.t.toFixed(2)}`);
48 await c.ev(`window.__n = document.querySelector('#tabs .tab.on .th svg'); 1`);
49 await sleep(1200);
50 check(await c.ev(`window.__n === document.querySelector('#tabs .tab.on .th svg')`), "the tab icon node persists across refreshes (its animation isn't restarted)");
51 await c.ev(`setMotionMode("never")`);
52 await sleep(300);
53 const n1 = await clock();
54 await sleep(500);
55 const n2 = await clock();
56 check(!!(n1 && n2 && n2.paused && Math.abs(n2.t - n1.t) < 0.05), "mode Never freezes the animation");
57 await c.ev(`setMotionMode("always")`);
58 await sleep(300);
59 check((await clock())?.paused === false, "mode Always animates regardless of the system setting");
60 await c.ev(`setMotionMode("system")`);
61 await T("page.goto", { url: base + "/free" });
62}