tests: sibling demo claim browser tests wait for their navigations
Page.navigate and Page.reload answer before their navigation commits (measured on Chromium 151), so demo_claim_browser.mjs and demo_claim_resume_browser.mjs polled Runtime.evaluate across commits: the token shell's location.replace, form posts after the page's 650 ms hold, the step-up redirect chain and its auto-submit, both reloads, and every scene change, often on a condition the outgoing page already met. Both scripts now record main-frame Page.frameNavigated events and wait, sending nothing, until exactly the expected documents have committed (the helper from 365a79ca, plus a navigate() wrapper, also passed to demo_claim_motion.mjs). Two submissions whose listeners already called preventDefault had the page post anyway after its hold; their prototype.submit is now stubbed, as the UX scenes already do. Added: exact commit sequences, and the CSP-blocked post commits nothing. No assertion removed, no sleeps or retries added.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+323
−28
docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-browser-siblings.md+219 −0internal/console/testdata/demo_claim_browser.mjs+47 −5internal/console/testdata/demo_claim_motion.mjs+5 −4internal/console/testdata/demo_claim_resume_browser.mjs+52 −19
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-browser-siblings.md b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-browser-siblings.md| new file mode 100644 |
| index 000000000..0c8c24556 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/REVIEW-BRIEF-flake-demo-browser-siblings.md |
| @@ -0,0 +1,219 @@ |
| +# Review brief: navigation waits in the sibling demo claim browser scripts, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `flake-demo-browser-siblings`. |
| +Under review: the diff `origin/main..flake-demo-browser-siblings` (base |
| +365a79ca). Code changes, all test-only: |
| + |
| +- `internal/console/testdata/demo_claim_browser.mjs` |
| +- `internal/console/testdata/demo_claim_resume_browser.mjs` |
| +- `internal/console/testdata/demo_claim_motion.mjs` (helper used only by |
| + `demo_claim_browser.mjs`; it now takes a `navigate` function) |
| + |
| +This brief is the other file. No product code changed. |
| +Authorities: `internal/console/static/demo_claim.js` (what the page does |
| +on its own), the Go tests that drive the scripts |
| +(`demo_claim_page_test.go` `TestDemoClaimBrowserHeadless`, |
| +`demo_spent_token_test.go` `TestDemoSpentTokenBrowserHeadless`, |
| +`demo_claim_ux_test.go` `TestDemoClaimUXHeadless*`, |
| +`demo_claim_resume_browser_test.go` `TestDemoClaimSelectStepUpHeadless`), |
| +and the merged fix for the third sibling, 365a79ca |
| +(`demo_claim_kept_browser.mjs`, reviewed in |
| +`FINDINGS-flake-demo-claim-browser.md`). This change is that review's P3. |
| + |
| +You are an independent reviewer. Read this brief, then the code it |
| +names, and check every claim against that code. |
| + |
| +## The race |
| + |
| +The scripts drive Chromium over CDP. After starting a navigation they |
| +went straight into `until()`, which polls `Runtime.evaluate` every |
| +100 ms. Two things go wrong: |
| + |
| +1. A command that reaches the outgoing document while the next one |
| + commits can fail with CDP -32000 "Inspected target navigated or |
| + closed". That is the error main CI hit in the kept script on |
| + 2026-11-19. |
| +2. A condition the outgoing document already meets passes on the wrong |
| + page, and the assertions after it run against that page. |
| + |
| +Measured locally with temporary logging (since removed; Chromium |
| +151.0.7922.173, node v24.19.0): **`Page.navigate` and `Page.reload` both |
| +answer before their navigation commits**, by 4 to 52 ms. So every |
| +`Page.navigate` followed by `until()` polled across a commit, not only the |
| +ones the P3 named. |
| + |
| +Where the outgoing page already met the condition (the wrong-page case): |
| + |
| +- `demo_claim_browser.mjs` UX scenes: every scene after the first |
| + navigates from the previous scene's `/demo/claim` (another server) to |
| + this one's. `until('readyState === "complete" && #claim')` is true on |
| + the previous page, so `dataset.state === scene.State` could be read |
| + from the previous scene. |
| +- Both `Page.reload` calls (fast scene and `liveMotion`): the settled |
| + "claimed" condition is true before the reload. |
| +- `demo_claim_resume_browser.mjs`: most navigations go from one |
| + `/demo/claim` with radios to another with the same radio condition |
| + (e.g. old line 164 to `?csp=before`). |
| + |
| +## The navigation sequences |
| + |
| +`Frame.url` in `Page.frameNavigated` has no fragment. `history.replaceState` |
| +(the page's first line, which also turns `?replay=1` into `/demo/claim`) |
| +does not commit a document. Server redirects do not commit. Form posts in |
| +`#claim` are cancelled by the page and re-sent with |
| +`HTMLFormElement.prototype.submit` after a paint and a 650 ms hold |
| +(`demo_claim.js` lines 43-59). |
| + |
| +### demo_claim_browser.mjs, token flow (`TestDemoClaimBrowserHeadless`, `TestDemoSpentTokenBrowserHeadless`) |
| + |
| +1. `Page.navigate` to `/demo/claim#<token>`: commit `/demo/claim` (the |
| + shell). The shell POSTs the token with `fetch`, waits for its hold, |
| + then: |
| + - accepted: `location.replace("/demo/claim")`: second commit |
| + `/demo/claim`. Expect `[page, page]`. |
| + - refused (spent token, `expectedError`): error shown, no navigation. |
| + Expect `[page]`. |
| +2. Email typed, Enter: page holds, posts `/demo/claim/prove`, 303, commit |
| + `/demo/claim` (code form). Expect `[page]`. |
| +3. "Use a different address", Enter: same, commit `/demo/claim`. Expect |
| + `[page]`. |
| +4. Code typed, Enter: the test's own submit listener records the |
| + submission. Before this change the page still posted the code 650 ms |
| + later (the listener's `preventDefault` does not stop |
| + `prototype.submit`), racing the script's last six reads. Now the same |
| + evaluate stubs `HTMLFormElement.prototype.submit`, as the UX scenes |
| + already do (line 238), so nothing navigates. Nothing on the Go side |
| + reads that post: `TestDemoClaimBrowserHeadless` checks the intent |
| + exchange count, leaks, the sent mail and that no operation exists. |
| + |
| +### demo_claim_browser.mjs, UX scenes (`TestDemoClaimUXHeadless*`) |
| + |
| +- Each scene: `Page.navigate` to `<origin>/demo/claim[#refused-token]`: |
| + one commit `<origin>/demo/claim`. The fragment scenes (expired, kept, |
| + taken-down, invalid) are refused tokens, so the shell stays. |
| +- email/code/one/many: `prototype.submit` is already stubbed (line 238); |
| + no navigation. |
| +- fast: `Page.reload`: commit `<origin>/demo/claim`. |
| +- `liveMotion`: `Page.navigate` to `?replay=1`: commit `/demo/claim?replay=1`; |
| + then `Page.reload`: commit `/demo/claim` (replaceState changed the URL). |
| +- motion (`demo_claim_motion.mjs`): `Page.navigate` to `about:blank` |
| + (commit `about:blank`), then to the scene URL (commit it). Both now go |
| + through `navigate`. |
| + |
| +### demo_claim_resume_browser.mjs (`TestDemoClaimSelectStepUpHeadless`) |
| + |
| +- 18 `Page.navigate` calls, none with a fragment, none to a page that |
| + navigates itself (the `testProgress` pages poll `/demo/claim/status` |
| + with `fetch`). Each commits exactly its URL. All now go through |
| + `navigate(url)`. |
| +- `?csp=before`, choose and `requestSubmit`: after the hold the page |
| + posts `/demo/claim/select`, the server answers with a redirect to the |
| + fake Keymail on another port, and the edited CSP `form-action` blocks |
| + that redirect. Measured: no document commits. The script waits for the |
| + CSP log entry (no CDP commands), then reads `location.origin`. New |
| + assertion: no commit since the post started, so that read is on the |
| + `?csp=before` page. |
| +- Line 221 (was 194), submit with the test's `preventDefault`, then |
| + check the button stays disabled: same as token step 4. The page would |
| + have posted `/demo/claim/select` 650 ms later. If the script had been |
| + slow, that post would have run the whole Keymail round trip and |
| + chosen the account before the real choice below. Now stubbed; |
| + `Page.navigate` on the next line gives a fresh document. |
| +- Lines 227-234 (was 198-201), the real choice. Two clicks on the |
| + button; the second is swallowed by the page's `submitted` guard. Then: |
| + hold, POST `/demo/claim/select`, 303 to Keymail `/oauth/authorize`, |
| + 303 to `/auth/stepup/callback`, 303 to `/demo/claim`: **commit 1**, |
| + the resumed first paint (progress view with |
| + `form[data-auto-submit]`). Its script calls `requestSubmit`: hold, |
| + POST `/demo/claim/select`, 303 to `/demo/claim`: **commit 2**, the |
| + progress view that polls. Expect |
| + `[target/demo/claim, target/demo/claim]`. Measured: two commits, |
| + roughly 0.7 s apart, matching the two holds. |
| + |
| +## The fix |
| + |
| +Same helper as the kept script (365a79ca), copied into each script |
| +because each has its own CDP plumbing (`call`, `evaluate`, `until` are |
| +already per-script copies): |
| + |
| +- `commits`: every main-frame `Page.frameNavigated` URL for our session. |
| +- `committed(since, urls)`: waits, sending no CDP commands, until |
| + `urls.length` commits have arrived after `since` (150 × 100 ms, as |
| + `until()`), then `deepEqual`s them against `urls`. |
| +- New `navigate(url, urls = [url])`: records `since`, sends |
| + `Page.navigate`, then `committed`. The reloads and the actions that |
| + navigate (Enter, button clicks) use `since` and `committed` inline. |
| + |
| +The existing `until()` calls stay, for DOM readiness after the commit. |
| +No assertion was removed or loosened. Added: each step's exact commit |
| +sequence, and "the CSP-blocked post committed nothing". There are no |
| +new sleeps and no retries. |
| + |
| +## Tests run (docs-t1, shared and busy) |
| + |
| +Commands and results: |
| + |
| +``` |
| +go test ./internal/console -run 'TestDemoClaimBrowserHeadless$|TestDemoSpentTokenBrowserHeadless$|TestDemoClaimUXHeadless|TestDemoClaimSelectStepUpHeadless$' -count=1 -v -timeout 25m |
| +go test ./internal/console -run 'TestDemoClaimBrowserHeadless$|TestDemoSpentTokenBrowserHeadless$|TestDemoClaimUXHeadless$|TestDemoClaimUXHeadlessFast390$|TestDemoClaimUXHeadlessMotion1280Dark$|TestDemoClaimSelectStepUpHeadless$' -count=5 -v -timeout 30m |
| +``` |
| + |
| +- First command: 10/10 `--- PASS` (all four Motion variants, both Fast, |
| + the quick UX scenes, token, spent token, step-up), `ok ... 211.770s`. |
| +- Second: 5/5 `--- PASS` for each of the six tests (30 runs), |
| + `ok ... 882.054s`. |
| + |
| +Like the kept script, the -32000 never reproduced locally; this |
| +Chromium answered commands across these navigations. The fix is for the |
| +invariant, not a local repro. |
| + |
| +## What to check |
| + |
| +1. After every navigation the scripts start or expect, is there any CDP |
| + command between the start and the last expected commit? Check |
| + especially the token flow, the UX scene loop, both reloads, |
| + `checkClaimMotion`, and the resume chain at lines 227-234. |
| +2. Is any navigation left that still goes straight to `until()` or |
| + `evaluate()`? Search for `Page.navigate`, `Page.reload`, `key('Enter'`, |
| + `requestSubmit`, `.click()` on submit buttons, and `location.`. |
| +3. Are the expected sequences right? In particular: two commits for the |
| + resume chain (no intermediate document from the Keymail and callback |
| + redirects), one commit for the refused-token scenes, `about:blank` |
| + for the motion helper, `/demo/claim` (not `?replay=1`) after the |
| + `liveMotion` reload. |
| +4. Stubbing `HTMLFormElement.prototype.submit` in token step 4 and resume |
| + line 221: does it weaken anything either test proved? Both tests' |
| + listeners already called `preventDefault`, so the post was never what |
| + they meant to send. Does the Go side depend on that post anywhere? |
| +5. The new `commits.slice(blocked)` assertion after the CSP block: could |
| + Chromium commit an error page for a `form-action` redirect block, now |
| + or later, and make this a new flake? |
| +6. The strict `deepEqual` turns any unexpected commit (bfcache restore, |
| + a late event from an earlier step) into a failure. Is a strict |
| + sequence right for these flows? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the problem, the evidence |
| +(file:line, verified), the failure scenario and a concrete fix. End with |
| +exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run the full test suites. If you run anything, run only |
| +`go test ./internal/console -run 'TestDemoClaimBrowserHeadless$|TestDemoClaimSelectStepUpHeadless$' -v`. |
diff --git a/internal/console/testdata/demo_claim_browser.mjs b/internal/console/testdata/demo_claim_browser.mjs| index aa7aeba68..3596317e0 100644 |
| --- a/internal/console/testdata/demo_claim_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_browser.mjs |
| @@ -22,12 +22,15 @@ const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu', |
| '--user-data-dir=' + profile], {stdio: ['ignore', 'ignore', 'ignore', 'pipe', 'pipe']}); |
| let sequence = 0, buffered = '', session; |
| const pending = new Map(); |
| +// Every document the tab's main frame commits, in order (fragment excluded). |
| +const commits = []; |
| chrome.stdio[4].on('data', bytes => { |
| buffered += bytes.toString(); |
| let end; |
| while ((end = buffered.indexOf('\0')) !== -1) { |
| const message = JSON.parse(buffered.slice(0, end)); |
| buffered = buffered.slice(end + 1); |
| + if (message.method === 'Page.frameNavigated' && message.sessionId === session && !message.params.frame.parentId) commits.push(message.params.frame.url); |
| const resolve = pending.get(message.id); |
| if (resolve) { pending.delete(message.id); resolve(message); } |
| } |
| @@ -52,6 +55,24 @@ async function until(expression) { |
| } |
| throw Error('browser_condition_timeout: ' + await evaluate('JSON.stringify({text:document.body.innerText,email:document.getElementById("email")?.value,focus:document.activeElement.tagName,valid:document.querySelector("form")?.checkValidity()})')); |
| } |
| +// Page.navigate and Page.reload both answer before their navigation |
| +// commits (Chromium 151, measured 2026-11-19), the token shell replaces |
| +// itself with /demo/claim once its exchange lands, and a submitted form |
| +// posts after the page's 650 ms hold. A command that reaches the outgoing |
| +// document as the next one commits fails with -32000 "Inspected target |
| +// navigated or closed", and a condition polled too soon can pass on the |
| +// outgoing page. So a step that navigates waits, sending nothing, until |
| +// the main frame has committed exactly the documents it expects, and only |
| +// then polls the page. |
| +async function committed(since, urls) { |
| + for (let i = 0; i < 150 && commits.length - since < urls.length; i++) await new Promise(resolve => setTimeout(resolve, 100)); |
| + assert.deepEqual(commits.slice(since), urls); |
| +} |
| +async function navigate(url, urls = [url]) { |
| + const since = commits.length; |
| + await call('Page.navigate', {url}); |
| + await committed(since, urls); |
| +} |
| async function key(key, code, number) { |
| await call('Input.dispatchKeyEvent', {type:key === 'Enter' ? 'keyDown' : 'rawKeyDown', key, code, windowsVirtualKeyCode:number, ...(key === 'Enter' ? {text:'\r', unmodifiedText:'\r'} : {})}); |
| await call('Input.dispatchKeyEvent', {type:'keyUp', key, code, windowsVirtualKeyCode:number}); |
| @@ -65,7 +86,10 @@ try { |
| if (target.startsWith('[')) { |
| await runUX(JSON.parse(target)); |
| } else { |
| - await call('Page.navigate', {url:target}); |
| + // The fragment is the token: a refused one stays on the shell, an accepted |
| + // one replaces the shell with /demo/claim. |
| + const page = target.split('#')[0]; |
| + await navigate(target, expectedError ? [page] : [page, page]); |
| if (expectedError) { |
| await until('location.hash === "" && document.getElementById("claim-error")?.hidden === false'); |
| assert.equal(await evaluate('document.getElementById("claim-error").textContent'), expectedError); |
| @@ -89,7 +113,11 @@ try { |
| await call('Input.insertText', {text:'shop@example.com'}); |
| await key('Tab','Tab',9); |
| assert.equal(await evaluate('document.activeElement.tagName'), 'BUTTON'); |
| + // Each address posts to /demo/claim/prove, which sends the browser back |
| + // to /demo/claim. |
| + let since = commits.length; |
| await key('Enter','Enter',13); |
| + await committed(since, [page]); |
| await until('!!document.getElementById("code")'); |
| assert.equal(await evaluate('document.querySelector("label[for=code]") !== null'), true); |
| await captureClaim(call, evaluate, screenshots, 'code', [390, 1280]); |
| @@ -98,7 +126,9 @@ try { |
| await evaluate('document.querySelector(".claim-email-change summary").click(); document.getElementById("email").focus()'); |
| await call('Input.insertText', {text:'another@example.com'}); |
| await key('Tab','Tab',9); |
| + since = commits.length; |
| await key('Enter','Enter',13); |
| + await committed(since, [page]); |
| await until('!!document.getElementById("code") && !document.querySelector(".claim-email-change").open'); |
| assert.deepEqual(await evaluate('window.claimCSPViolations'), []); |
| await evaluate('document.getElementById("code").focus()'); |
| @@ -106,7 +136,12 @@ try { |
| assert.equal(await evaluate('document.getElementById("code").form.checkValidity()'), true); |
| await key('Tab','Tab',9); |
| assert.equal(await evaluate('document.activeElement.textContent'), 'Confirm'); |
| - await evaluate(`document.getElementById('code').form.addEventListener('submit', event => { |
| + // The page cancels the submit event and posts the form itself after its |
| + // 650 ms hold, through HTMLFormElement.prototype.submit, so the listener's |
| + // preventDefault alone does not stop that post. Stub it: the reads below |
| + // must not race a navigation to the code's result. |
| + await evaluate(`HTMLFormElement.prototype.submit = function() {}; |
| + document.getElementById('code').form.addEventListener('submit', event => { |
| event.preventDefault(); |
| const form = event.target; |
| window.claimCodeSubmission = { |
| @@ -145,11 +180,13 @@ async function runUX(scenes) { |
| if (scene.Session) cookies.push({name:'carlos_console_session',value:scene.Session,url:origin,path:'/',httpOnly:true}); |
| await call('Network.setCookies',{cookies}); |
| if (scene.Name === 'missing') await call('Network.setBlockedURLs',{urls:['*demo_claim.js*']}); |
| - await call('Page.navigate',{url:scene.URL}); |
| + // Each scene is a fresh /demo/claim (on its own server); a scene's |
| + // fragment is a refused token, so the shell stays put. |
| + await navigate(scene.URL,[origin+'/demo/claim']); |
| await until('document.readyState === "complete" && !!document.getElementById("claim")'); |
| assert.equal(await evaluate('document.getElementById("claim").dataset.state'),scene.State,scene.Name); |
| if (scene.Name === 'motion') { |
| - await checkClaimMotion(call, evaluate, until, screenshots, scene.URL, scene); |
| + await checkClaimMotion(call, evaluate, until, navigate, screenshots, scene.URL, scene); |
| process.stdout.write('live progress: centred rings/dots/ticks, spin, flowing path, calm breathe, zero CSP violations; '+(scene.Widths ?? [390,1280]).join('/')+' '+(scene.Themes ?? ['light','dark']).join('/')+' passed\n'); |
| continue; |
| } |
| @@ -181,7 +218,9 @@ async function runUX(scenes) { |
| } |
| assert.equal(await evaluate('window.claimBlankFrames'),0,'blank progress frame'); |
| await captureClaim(call,evaluate,screenshots,'live-done',[390,1280]); |
| + const since = commits.length; |
| await call('Page.reload'); |
| + await committed(since,[origin+'/demo/claim']); |
| await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),false); |
| assert.equal(await evaluate('document.querySelector(".claim-command")?.open ?? false'),false); |
| @@ -218,7 +257,7 @@ async function liveMotion(scene) { |
| for (const width of scene.Widths ?? [390,1280]) for (const theme of scene.Themes ?? ['light','dark']) for (const motion of ['no-preference','reduce']) { |
| await call('Emulation.setDeviceMetricsOverride',{width,height:900,deviceScaleFactor:1,mobile:false}); |
| await call('Emulation.setEmulatedMedia',{features:[{name:'prefers-color-scheme',value:theme},{name:'prefers-reduced-motion',value:motion}]}); |
| - await call('Page.navigate',{url:scene.URL+'?replay=1'}); |
| + await navigate(scene.URL+'?replay=1'); |
| await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claiming"'); |
| await until('document.getElementById("claim")?.dataset.state === "claimed"'); |
| assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),true); |
| @@ -237,7 +276,10 @@ async function liveMotion(scene) { |
| await writeFile(screenshots+'/reveal-'+motion+'-'+theme+'-'+width+'.png',Buffer.from(shot.data,'base64')); |
| } |
| assert.deepEqual(await evaluate('window.claimCSPViolations'),[]); |
| + // The page replaced ?replay=1 with /demo/claim, so that is what reloads. |
| + const since = commits.length; |
| await call('Page.reload'); |
| + await committed(since,[new URL(scene.URL).origin+'/demo/claim']); |
| await until('document.readyState === "complete" && document.getElementById("claim")?.dataset.state === "claimed"'); |
| assert.equal(await evaluate('document.getElementById("claim").classList.contains("is-celebrating")'),false); |
| assert.equal(await evaluate('document.getAnimations().length'),0); |
diff --git a/internal/console/testdata/demo_claim_motion.mjs b/internal/console/testdata/demo_claim_motion.mjs| index a38924cfd..651f4f4ea 100644 |
| --- a/internal/console/testdata/demo_claim_motion.mjs |
| +++ b/internal/console/testdata/demo_claim_motion.mjs |
| @@ -46,8 +46,9 @@ const motionState = `(() => { |
| })()`; |
| // only.Widths and only.Themes narrow the run to some of the variants, so the |
| -// Go side can split them across tests; absent, every variant runs. |
| -export async function checkClaimMotion(call, evaluate, until, screenshots, url, only = {}) { |
| +// Go side can split them across tests; absent, every variant runs. navigate |
| +// loads a page and returns once that document has committed. |
| +export async function checkClaimMotion(call, evaluate, until, navigate, screenshots, url, only = {}) { |
| // Change the fixture's operation, then let the real status endpoint and page |
| // script advance the UI. Never manufacture the state attributes in the test. |
| const phase = async value => { |
| @@ -55,13 +56,13 @@ export async function checkClaimMotion(call, evaluate, until, screenshots, url, |
| assert.equal(response.status, 204); |
| }; |
| for (const width of only.Widths ?? [390,1280]) for (const theme of only.Themes ?? ['light','dark']) for (const motion of ['no-preference','reduce']) { |
| - await call('Page.navigate', {url:'about:blank'}); |
| + await navigate('about:blank'); |
| await phase('future-phase'); |
| await call('Emulation.setDeviceMetricsOverride', {width,height:900,deviceScaleFactor:1,mobile:false}); |
| await call('Emulation.setEmulatedMedia', {features:[ |
| {name:'prefers-color-scheme',value:theme}, {name:'prefers-reduced-motion',value:motion} |
| ]}); |
| - await call('Page.navigate', {url}); |
| + await navigate(url); |
| await until('document.readyState === "complete" && document.getElementById("claim-progress")?.dataset.stage === "0"'); |
| assert.equal(await evaluate('document.querySelectorAll(".claim-steps [aria-current]").length'), 0); |
| let baseline; |
diff --git a/internal/console/testdata/demo_claim_resume_browser.mjs b/internal/console/testdata/demo_claim_resume_browser.mjs| index 5b54820ea..9031fbce2 100644 |
| --- a/internal/console/testdata/demo_claim_resume_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_resume_browser.mjs |
| @@ -12,6 +12,8 @@ let sequence = 0, buffered = '', session; |
| const pending = new Map(); |
| let security = [], statusRequests = 0; |
| const submissions = []; |
| +// Every document the tab's main frame commits, in order (fragment excluded). |
| +const commits = []; |
| chrome.stdio[4].on('data', bytes => { |
| buffered += bytes.toString(); |
| @@ -19,6 +21,7 @@ chrome.stdio[4].on('data', bytes => { |
| while ((end = buffered.indexOf('\0')) !== -1) { |
| const message = JSON.parse(buffered.slice(0, end)); |
| buffered = buffered.slice(end + 1); |
| + if (message.method === 'Page.frameNavigated' && message.sessionId === session && !message.params.frame.parentId) commits.push(message.params.frame.url); |
| if (message.method === 'Network.requestWillBeSent' && new URL(message.params.request.url).pathname === '/demo/claim/status') statusRequests++; |
| if (message.method === 'Log.entryAdded' && message.params.entry.source === 'security') security.push(message.params.entry.text); |
| if (message.method === 'Runtime.bindingCalled' && message.params.name === 'claimSubmitted') submissions.push(JSON.parse(message.params.payload)); |
| @@ -46,6 +49,23 @@ async function until(expression) { |
| } |
| throw Error('browser_condition_timeout: ' + await evaluate('JSON.stringify({text:document.body.innerText,email:document.getElementById("email")?.value,focus:document.activeElement.tagName,valid:document.querySelector("form")?.checkValidity()})')); |
| } |
| +// Page.navigate answers before its navigation commits (Chromium 151, |
| +// measured 2026-11-19), most steps here move between /demo/claim pages that |
| +// meet the same condition, and a submitted choice posts after the page's |
| +// 650 ms hold. A command that reaches the outgoing document as the next one |
| +// commits fails with -32000 "Inspected target navigated or closed", and a |
| +// condition polled too soon can pass on the outgoing page. So a step that |
| +// navigates waits, sending nothing, until the main frame has committed |
| +// exactly the documents it expects, and only then polls the page. |
| +async function committed(since, urls) { |
| + for (let i = 0; i < 150 && commits.length - since < urls.length; i++) await new Promise(resolve => setTimeout(resolve, 100)); |
| + assert.deepEqual(commits.slice(since), urls); |
| +} |
| +async function navigate(url, urls = [url]) { |
| + const since = commits.length; |
| + await call('Page.navigate', {url}); |
| + await committed(since, urls); |
| +} |
| async function key(key, code, number) { |
| await call('Input.dispatchKeyEvent', {type:key === 'Enter' ? 'keyDown' : 'rawKeyDown', key, code, windowsVirtualKeyCode:number, ...(key === 'Enter' ? {text:'\r', unmodifiedText:'\r'} : {})}); |
| await call('Input.dispatchKeyEvent', {type:'keyUp', key, code, windowsVirtualKeyCode:number}); |
| @@ -89,14 +109,14 @@ try { |
| {name:'carlos_console_session',value:single.session,url:single.target,path:'/',httpOnly:true,sameSite:'Lax'}, |
| {name:'carlos_demo_claim_flow',value:single.cookie,url:single.target,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| ]}); |
| - await call('Page.navigate',{url:single.target+'/demo/claim'}); |
| + await navigate(single.target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("#claim input[type=hidden][name=accountId]")'); |
| assert.equal(await evaluate('document.querySelectorAll("#claim input[type=radio]").length'),0); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'),'Keep in shop'); |
| assert.equal(await evaluate('document.querySelector(".claim-single").innerText.includes("Has room")'),true); |
| assert.equal(await evaluate('document.querySelector(".claim-single").innerText.includes("apps and instances")'),false); |
| await capture('one'); |
| - await call('Page.navigate',{url:single.target+'/demo/claim?long=1'}); |
| + await navigate(single.target+'/demo/claim?long=1'); |
| await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 2'); |
| assert.equal(await evaluate('document.querySelector(".claim-card .claim-row-name").textContent.length > 100'), true); |
| assert.equal(await evaluate('document.querySelector(".claim-address .claim-old").textContent.length > 100'), true); |
| @@ -106,7 +126,7 @@ try { |
| {name:'carlos_console_session',value:single.capacitySession,url:single.capacityTarget,path:'/',httpOnly:true,sameSite:'Lax'}, |
| {name:'carlos_demo_claim_flow',value:single.capacityCookie,url:single.capacityTarget,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| ]}); |
| - await call('Page.navigate',{url:single.capacityTarget+'/demo/claim'}); |
| + await navigate(single.capacityTarget+'/demo/claim'); |
| await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 2'); |
| const capacityCards = await evaluate('Array.from(document.querySelectorAll(".claim-card"), card => ({text:card.innerText,disabled:card.querySelector("input").disabled}))'); |
| assert(capacityCards.every(card=>card.disabled)); |
| @@ -119,7 +139,7 @@ try { |
| {name:'carlos_console_session',value:single.pickerSession,url:single.pickerTarget,path:'/',httpOnly:true,sameSite:'Lax'}, |
| {name:'carlos_demo_claim_flow',value:single.pickerCookie,url:single.pickerTarget,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| ]}); |
| - await call('Page.navigate',{url:single.pickerTarget+'/demo/claim'}); |
| + await navigate(single.pickerTarget+'/demo/claim'); |
| await until('document.readyState === "complete" && document.querySelectorAll(".claim-card").length === 30'); |
| assert.equal(await evaluate('document.body.innerText.includes("2305843009213693951") || !!document.querySelector("meter")'), false, 'sentinel or meter shown'); |
| assert.equal(await evaluate('document.querySelector(".claim-search").hidden'), false, 'script did not reveal the search box'); |
| @@ -155,22 +175,25 @@ try { |
| {name:'carlos_demo_claim_flow',value:flowCookie,url:target,path:'/demo/claim',httpOnly:true,secure:true,sameSite:'Lax'} |
| ]}); |
| await call('Network.setBlockedURLs', {urls:['*demo_claim.js*']}); |
| - await call('Page.navigate', {url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("input[type=radio][name=accountId]")'); |
| assert.equal(await evaluate('document.querySelector("button[type=submit]").disabled'),false,'script failure disabled the manual fallback'); |
| assert.equal(await evaluate('document.querySelector("form").getBoundingClientRect().height > 0'),true,'script failure hid the form'); |
| assert.equal(await evaluate('document.querySelector("#claim form").checkValidity()'),false,'native required radio missing'); |
| await call('Network.setBlockedURLs', {urls:[]}); |
| - await call('Page.navigate', {url:target+'/demo/claim?csp=before'}); |
| + await navigate(target+'/demo/claim?csp=before'); |
| await until('document.readyState === "complete" && !!document.querySelector("input[type=radio][name=accountId]")'); |
| + const blocked = commits.length; |
| await evaluate(`document.querySelector('input[value='+${JSON.stringify(account)}+']').click(); document.querySelector('form[action="/demo/claim/select"]').requestSubmit()`); |
| for (let i=0; i<50 && !security.some(s=>s.includes('form-action')); i++) await new Promise(r=>setTimeout(r,100)); |
| assert(security.some(s=>s.includes('form-action')), 'Chromium did not reproduce redirect CSP block: '+JSON.stringify(security)); |
| + // The blocked post commits nothing: this is still the ?csp=before page. |
| + assert.deepEqual(commits.slice(blocked), [], 'the blocked post committed a document'); |
| assert.equal(await evaluate('location.origin'), target); |
| process.stdout.write('before: Chromium blocked the cross-port Keymail redirect\n'); |
| security = []; |
| submissions.length = 0; |
| - await call('Page.navigate', {url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("input[type=radio][name=accountId]")'); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").disabled'),true); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").textContent'),'Choose an account'); |
| @@ -191,13 +214,23 @@ try { |
| assert.equal(await evaluate('document.querySelector(".claim-card:last-of-type input").disabled'),true,'the view-only account must sort last'); |
| assert.equal(await evaluate('!!document.querySelector(".claim-search")'),false,'three accounts need no search box'); |
| await capture('many'); |
| - await evaluate(`const form = document.querySelector('form[action="/demo/claim/select"]'); form.addEventListener('submit', event => event.preventDefault(), {once:true}); form.requestSubmit(); document.querySelector('#claim input[type=radio]:not(:disabled)').click()`); |
| + // The page cancels the submit event and posts the form itself after its |
| + // 650 ms hold, through HTMLFormElement.prototype.submit, so the listener's |
| + // preventDefault alone does not stop that post. Stub it: this submission |
| + // must not choose the account, nor race the check and navigation below. |
| + await evaluate(`HTMLFormElement.prototype.submit = function() {}; const form = document.querySelector('form[action="/demo/claim/select"]'); form.addEventListener('submit', event => event.preventDefault(), {once:true}); form.requestSubmit(); document.querySelector('#claim input[type=radio]:not(:disabled)').click()`); |
| assert.equal(await evaluate('document.querySelector("#claim button[type=submit]").disabled'),true,'radio change re-enabled submitted button'); |
| - await call('Page.navigate', {url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("input[type=radio][name=accountId]")'); |
| await evaluate(`document.querySelector('input[value='+${JSON.stringify(account)}+']').click()`); |
| submissions.length = 0; |
| + // The choice posts after the page's hold, and fresh auth sends it through |
| + // Keymail and the step-up callback, all redirects, back to /demo/claim: |
| + // the resumed first paint, which posts the same account itself after the |
| + // hold and lands on /demo/claim again, the progress view. |
| + const chosen = commits.length; |
| await evaluate(`const button = document.querySelector('form[action="/demo/claim/select"] button'); button.click(); button.click()`); |
| + await committed(chosen, [target+'/demo/claim', target+'/demo/claim']); |
| await until(`!!document.querySelector("p[role=status]") && !document.querySelector('form[action="/demo/claim/select"]')`); |
| assert.equal(await evaluate('location.pathname'),'/demo/claim'); |
| assert.equal(await evaluate('location.hash'),''); |
| @@ -239,13 +272,13 @@ try { |
| await call('Page.removeScriptToEvaluateOnNewDocument', {identifier:clipboardStub.identifier}); |
| const noClipboard = await call('Page.addScriptToEvaluateOnNewDocument', {source: |
| "Object.defineProperty(navigator, 'clipboard', {value:undefined})"}); |
| - await call('Page.navigate', {url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("[data-copy-target=claim-cli-command]")'); |
| assert.equal(await evaluate('document.querySelector("[data-copy-target=claim-cli-command]").getBoundingClientRect().height'), 0); |
| assert.equal(await evaluate('document.getElementById("claim-cli-command").textContent'), "carlos auth login --console '"+target+"'"); |
| await call('Page.removeScriptToEvaluateOnNewDocument', {identifier:noClipboard.identifier}); |
| await call('Network.setBlockedURLs', {urls:['*demo_claim.js*']}); |
| - await call('Page.navigate', {url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.querySelector("[data-copy-target=claim-cli-command]")'); |
| assert.equal(await evaluate('document.querySelector("[data-copy-target=claim-cli-command]").getBoundingClientRect().height'), 0); |
| assert.equal(await evaluate('document.getElementById("claim-cli-command").textContent'), "carlos auth login --console '"+target+"'"); |
| @@ -255,7 +288,7 @@ try { |
| const requestsAtDone=statusRequests; |
| await new Promise(r=>setTimeout(r,3500)); |
| assert.equal(statusRequests,requestsAtDone,'done kept polling'); |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=fail'}); |
| + await navigate(target+'/demo/claim?testProgress=fail'); |
| await until('!!document.getElementById("claim-progress")'); |
| const beforeFailure=statusRequests; |
| await until('document.getElementById("claim-reload")?.hidden === false'); |
| @@ -266,11 +299,11 @@ try { |
| await new Promise(r=>setTimeout(r,3500)); |
| assert.equal(statusRequests-beforeFailure,3,'failure fallback kept polling'); |
| await call('Network.setBlockedURLs',{urls:['*demo_claim.js*']}); |
| - await call('Page.navigate',{url:target+'/demo/claim'}); |
| + await navigate(target+'/demo/claim'); |
| await until('document.readyState === "complete" && !!document.getElementById("claim-reload")'); |
| assert.equal(await evaluate('document.getElementById("claim-reload").getBoundingClientRect().height > 0'),true,'no-script reload link hidden'); |
| await call('Network.setBlockedURLs',{urls:[]}); |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=abort'}); |
| + await navigate(target+'/demo/claim?testProgress=abort'); |
| await until('!!document.getElementById("claim-progress")'); |
| const beforeAbort=statusRequests; |
| await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.aborted'); |
| @@ -279,7 +312,7 @@ try { |
| await new Promise(r=>setTimeout(r,3500)); |
| assert.equal(statusRequests-beforeAbort,1,'aborted kept polling'); |
| assert.equal(security.length,0,JSON.stringify(security)); |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=stopping'}); |
| + await navigate(target+'/demo/claim?testProgress=stopping'); |
| await until('document.querySelector("li[aria-current=step]")?.dataset.step === "2"'); |
| await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.stopping'); |
| assert.equal(await evaluate('document.querySelectorAll("[aria-current=step]").length'),0); |
| @@ -287,7 +320,7 @@ try { |
| assert.equal(await evaluate('!!document.querySelector(".claim-steps .is-failed")'),true); |
| await capture('stopping-live'); |
| await until('document.getElementById("claim-status")?.textContent === document.getElementById("claim-progress")?.dataset.aborted'); |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=unknown'}); |
| + await navigate(target+'/demo/claim?testProgress=unknown'); |
| await until('!!document.getElementById("claim-progress") && document.querySelectorAll("[aria-current=step]").length === 0'); |
| const unknownPolls = statusRequests; |
| await new Promise(r=>setTimeout(r,6500)); |
| @@ -297,7 +330,7 @@ try { |
| process.stdout.write('fallback: stopped after three failures, retained no-script reload, stopped on abort; no CSP violations\n'); |
| // A long "Starting your app": the bar sits inside the step's band and |
| // never goes back, and the step's detail rotates through reassurance. |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=starting'}); |
| + await navigate(target+'/demo/claim?testProgress=starting'); |
| await until('document.querySelector("li[aria-current=step]")?.dataset.step === "2"'); |
| const original = await evaluate('document.querySelector("li[aria-current=step] .claim-step-detail").textContent'); |
| const bar = 'Number(document.querySelector(".claim-bar").getAttribute("aria-valuenow"))'; |
| @@ -310,7 +343,7 @@ try { |
| assert.equal(await evaluate('document.getElementById("claim-stuck").hidden'),true,'stuck before the deadline'); |
| await capture('starting-hint'); |
| // Past the server's deadline plus grace, still reporting progress: stuck. |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=stuck'}); |
| + await navigate(target+'/demo/claim?testProgress=stuck'); |
| await until('!!document.getElementById("claim-progress")'); |
| assert.equal(await evaluate('document.getElementById("claim-stuck").hidden'),true,'stuck before polling'); |
| await until('document.getElementById("claim-stuck")?.hidden === false'); |
| @@ -325,7 +358,7 @@ try { |
| // Past the irreversible commit the rollback deadline does not apply: an |
| // overdue committed claim says it is the person's and still finishing, |
| // never that it will be undone. |
| - await call('Page.navigate',{url:target+'/demo/claim?testProgress=committed'}); |
| + await navigate(target+'/demo/claim?testProgress=committed'); |
| await until('!!document.getElementById("claim-progress")?.dataset.committedFor'); |
| const committedPolls = statusRequests; |
| await until('document.getElementById("claim-finishing")?.hidden === false'); |