From d298c8dfc6000884bb47a9a49bbf55c9376531c6 Mon Sep 17 00:00:00 2001 From: implexrr <84114379+implexrr@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:55:47 -0500 Subject: [PATCH 1/3] fix: guide recovery after website scan failures --- scripts/preview-browser.mjs | 35 ++++++++++++++---- src/App.tsx | 57 ++++++++++++++++++++--------- src/components/WebsiteForm.tsx | 8 +++- src/components/scanFeedback.test.ts | 28 +++++++++++--- src/components/scanFeedback.ts | 55 +++++++++++++++++++++------- 5 files changed, 138 insertions(+), 45 deletions(-) diff --git a/scripts/preview-browser.mjs b/scripts/preview-browser.mjs index 0782402..1e08702 100644 --- a/scripts/preview-browser.mjs +++ b/scripts/preview-browser.mjs @@ -636,18 +636,39 @@ try { await page.getByRole('alert').filter({ hasText: 'report did not match' }).waitFor(); assert.equal(await page.locator('.results').count(), 0); } - for (const [status, code] of [[429, 'SCANNER_BUSY'], [503, 'SCAN_FAILED']]) { - publicStatus = status; publicResponse = { error: 'Controlled unavailable scan', code }; + const scanRetry = page.getByRole('button', { name: 'Try again', exact: true }); + const submittedEntry = ' example.com/start '; + await websiteEntry.fill(submittedEntry); + for (const [diagnostic, explanation] of [ + [{ stage: 'page-loading', code: 'HTTP_STATUS', httpStatus: 403 }, 'Access to the page was refused (HTTP 403)'], + [{ stage: 'page-loading', code: 'REDIRECT_HOST_CHANGED' }, 'hostname'], + [undefined, 'The scan could not finish'], + ]) { + publicStatus = 503; + publicResponse = { code: 'SCAN_FAILED', error: 'PRIVATE_SENTINEL', diagnostic }; await publicButton.click(); - await page.getByRole('alert').filter({ hasText: status === 429 ? 'Another scan is still finishing' : 'The scan could not finish' }).waitFor(); + const failure = page.getByRole('alert').filter({ hasText: explanation }); + await failure.waitFor(); + assert.equal(await failure.evaluate(node => node === document.activeElement), true); + assert.equal(await websiteEntry.inputValue(), submittedEntry); + assert.equal(await scanRetry.count(), 0); assert.equal(await page.locator('.results').count(), 0); + assert.equal(await page.getByText('PRIVATE_SENTINEL').count(), 0); } - publicStatus = 503; publicResponse = {code:'SCAN_FAILED',error:'PRIVATE_SENTINEL',diagnostic:{stage:'page-loading',code:'HTTP_STATUS',httpStatus:403}}; + await websiteEntry.fill('example.com/edited'); + assert.equal(await page.getByRole('alert').count(), 0); + await websiteEntry.fill(submittedEntry); + publicStatus = 429; publicResponse = { code: 'SCANNER_BUSY' }; await publicButton.click(); - await page.getByRole('alert').filter({hasText:'Access to the page was refused (HTTP 403)'}).waitFor(); - assert.equal(await page.locator('.results').count(),0); - assert.equal(await page.getByText('PRIVATE_SENTINEL').count(),0); + await page.getByRole('alert').filter({ hasText: 'Another scan is still finishing' }).waitFor(); + assert.equal(await scanRetry.evaluate(node => node === document.activeElement), true); + assert.equal(await websiteEntry.inputValue(), submittedEntry); + const retryRequest = page.waitForRequest(request => request.url().endsWith('/api/scan-public')); publicStatus = 200; publicResponse = publicReport; + await scanRetry.click(); + assert.deepEqual((await retryRequest).postDataJSON(), { url: publicReport.requestedUrl }); + await page.locator('.results').waitFor(); + assert.equal(await scanRetry.count(), 0); delayPublic = true; const publicStarted = new Promise(resolve => { notifyPublic = resolve; }); await publicButton.click(); diff --git a/src/App.tsx b/src/App.tsx index ae9ee8c..33cd856 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,7 +7,8 @@ import type { FixtureId } from '../shared/fixtures'; import { scanPageNoticeText } from '../shared/scanPageNotice'; import type { Report } from '../shared/types'; import { normalizeWebsiteEntry } from './components/websiteEntry'; -import { scanErrorMessage } from './components/scanFeedback'; +import { scanFailureFeedback } from './components/scanFeedback'; +import type { ScanFailureFeedback } from './components/scanFeedback'; import { WebsiteForm } from './components/WebsiteForm'; import { ReportExports } from './components/ReportExports'; import { ScanCoverageNotice } from './components/ScanCoverageNotice'; @@ -44,7 +45,7 @@ export function App() { const [busy, setBusy] = useState(false); const [lastAttempt,setLastAttempt] = useState<{value:string;mode:AnalysisMode}|null>(null); const [cancelled,setCancelled] = useState(false); - const [error, setError] = useState(''); + const [failure, setFailure] = useState(null); const [view, setView] = useState<'findings' | 'preview'>('findings'); const results = useRef(null); // Focus only after React has committed the new report and its result element exists. @@ -59,41 +60,53 @@ export function App() { function cancel() { if (!analysisRequest.current) return; const pending = analysisRequest.current; analysisRequest.current = null; pending.abort(); - setBusy(false); setReport(null); setError(''); setCancelled(true); + setBusy(false); setReport(null); setFailure(null); setCancelled(true); } function changeUrl(value: string) { - setUrl(value); setReport(null); setError(''); setCancelled(false); setLastAttempt(null); setView('findings'); + setUrl(value); setReport(null); setFailure(null); setCancelled(false); setLastAttempt(null); setView('findings'); } function changeFixture(fixture: FixtureId) { if (!isFixture(fixture) || fixture === selectedFixture) return; analysisRequest.current?.abort(); analysisRequest.current = null; - setSelectedFixture(fixture); setReport(null); setError(''); setBusy(false); setView('findings'); + setSelectedFixture(fixture); setReport(null); setFailure(null); setBusy(false); setView('findings'); setLastAttempt(null); setCancelled(false); } async function analyze(value: string, mode: AnalysisMode = 'public') { if (analysisRequest.current || (mode==='public'&&!capabilitiesReady)) return; const abort = new AbortController(); analysisRequest.current = abort; - setBusy(true); setError(''); setReport(null); setView('findings'); setCancelled(false); + setBusy(true); setFailure(null); setReport(null); setView('findings'); setCancelled(false); setLastAttempt({value,mode}); const fixture = mode === 'fixture'; + let requestStarted = false; try { if (!fixture) { value = normalizeWebsiteEntry(value); if (mode === 'public') value = websiteUrl(value).href; - setUrl(value); + if (mode === 'demo') setUrl(value); setLastAttempt({value,mode}); } if(mode==='public'&&!publicEnabled)throw new Error('Website scanning is unavailable. Start the local API or use the explicitly labelled example.'); + requestStarted = true; const response = await fetch(mode === 'fixture' ? '/api/scan-fixture' : mode === 'public' ? '/api/scan-public' : '/api/analyze', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(fixture ? { fixture: value } : { url: value }), signal: AbortSignal.any([abort.signal, AbortSignal.timeout(mode === 'demo' ? 10000 : 90000)]), }); let data; try { data = await response.json(); } - catch { throw new Error('The response could not be read. No report was created. Try again.'); } - if (!response.ok) throw new Error(scanErrorMessage(data,response.status)); + catch (cause) { + if (cause instanceof Error && cause.name === 'TimeoutError') throw cause; + if (abort.signal.aborted || analysisRequest.current !== abort) return; + const { retryable } = scanFailureFeedback(undefined, response.status); + setFailure({ message: 'The response could not be read. No report was created.', retryable }); + return; + } + if (abort.signal.aborted || analysisRequest.current !== abort) return; + if (!response.ok) { + setFailure(scanFailureFeedback(data, response.status)); + return; + } if (!data || typeof data !== 'object' || Array.isArray(data) || data.mode !== mode) { - throw new Error('The report did not match the requested scan. Try again.'); + throw new Error('The report did not match the requested scan.'); } if (mode === 'public') { let matches = false; @@ -103,18 +116,28 @@ export function App() { matches = data.requestedUrl === requested.href && data.url === scanned.href && !navigationRejection(requested.href, scanned.href); } catch { /* Reject missing or malformed report URLs without displaying their contents. */ } - if (!matches) throw new Error('The report did not match the requested website. Try again.'); + if (!matches) throw new Error('The report did not match the requested website.'); if (!hasMatchingCaptureResult(data,publicCaptureEnabled)) { - throw new Error('The website snapshot did not match this scan. Try again.'); + throw new Error('The website snapshot did not match this scan.'); } } if (fixture && (data.mode !== 'fixture' || data.scanner?.fixture !== value || data.url !== `fixture:${value}`)) { - throw new Error('The report did not match the requested built-in page. Try scanning again.'); + throw new Error('The report did not match the requested built-in page.'); } - if (abort.signal.aborted || analysisRequest.current !== abort) return; + if (mode === 'public') setUrl(value); setReport(data); setView('findings'); } catch (cause) { - if (!abort.signal.aborted && analysisRequest.current === abort) setError(cause instanceof Error && cause.name !== 'TimeoutError' ? cause.message : 'The request timed out. Try again.'); + if (abort.signal.aborted || analysisRequest.current !== abort) return; + if (requestStarted && cause instanceof Error && cause.name === 'TimeoutError') { + setFailure({ message: 'The request timed out. Try again shortly.', retryable: true }); + } else if (requestStarted && cause instanceof TypeError) { + setFailure({ message: 'KindPath could not reach the scanner. Check your connection and try again.', retryable: true }); + } else { + setFailure({ + message: cause instanceof Error ? cause.message : 'The scan could not finish. No report was created.', + retryable: requestStarted && mode !== 'public', + }); + } } finally { if (analysisRequest.current === abort) { analysisRequest.current = null; setBusy(false); } } @@ -130,8 +153,8 @@ export function App() {
A MORE INCLUSIVE INTERNET STARTS HERE

A clearer web.
For everyone.

See your website from a different perspective.
Find accessibility barriers, understand their impact,
and take the next step toward a more welcoming web.

{ if (lastAttempt) void analyze(lastAttempt.value,lastAttempt.mode); }} capabilitiesLoading={!capabilitiesReady} publicScanningEnabled={publicEnabled} url={url} busy={busy} error={error} onUrlChange={changeUrl} onSubmit={submit} + onCancel={cancel} cancelled={cancelled} canRetry={!busy && !!lastAttempt && (failure?.retryable === true || cancelled)} + onRetry={() => { if (lastAttempt) void analyze(lastAttempt.value,lastAttempt.mode); }} capabilitiesLoading={!capabilitiesReady} publicScanningEnabled={publicEnabled} url={url} busy={busy} error={failure?.message ?? ''} onUrlChange={changeUrl} onSubmit={submit} onExample={() => { setUrl('https://example.com'); void analyze('https://example.com', 'demo'); }} fixture={selectedFixture} onFixtureChange={changeFixture} onFixtureScan={() => { void analyze(selectedFixture, 'fixture'); }}/>
A DIFFERENT PERSPECTIVE↗
Same website. Different experience.
Design with more people in mind.
diff --git a/src/components/WebsiteForm.tsx b/src/components/WebsiteForm.tsx index 81c3844..4df733c 100644 --- a/src/components/WebsiteForm.tsx +++ b/src/components/WebsiteForm.tsx @@ -24,7 +24,11 @@ interface WebsiteFormProps { export function WebsiteForm({ url, activity, onCancel, onRetry, canRetry, cancelled, busy, error, onUrlChange, onSubmit, onExample, onFixtureScan, fixture, onFixtureChange, publicScanningEnabled, capabilitiesLoading }: WebsiteFormProps) { const retryButton=useRef(null); - useLayoutEffect(()=>{ if((cancelled || error) && canRetry)retryButton.current?.focus(); },[cancelled,error,canRetry]); + const errorMessage = useRef(null); + useLayoutEffect(() => { + if ((cancelled || error) && canRetry) retryButton.current?.focus(); + else if (error) errorMessage.current?.focus(); + }, [cancelled, error, canRetry]); return <>
@@ -45,7 +49,7 @@ export function WebsiteForm({ url, activity, onCancel, onRetry, canRetry, cancel

{activity}

{busy && } {canRetry && } - {error && } + {error && }
- } + }

Accessibility is a practice.
Every step makes a difference.

KindPathA more accessible web starts with a clearer perspective.Built with intention.
; From 8728ba053aefc5efe69d69e8b55c156d8331342e Mon Sep 17 00:00:00 2001 From: implexrr <84114379+implexrr@users.noreply.github.com> Date: Wed, 11 Nov 2026 18:05:19 -0500 Subject: [PATCH 3/3] fix: sanitize scan request errors and detect deadlines --- src/App.tsx | 16 ++++++++-------- src/components/scanFeedback.test.ts | 4 +++- src/components/scanFeedback.ts | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 5184bea..ffeaa3f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -77,7 +77,7 @@ export function App() { setBusy(true); setFailure(null); setReport(null); setView('findings'); setCancelled(false); setLastAttempt({value,mode}); const fixture = mode === 'fixture'; - let requestStarted = false; + let timeout: AbortSignal | undefined; try { if (!fixture) { value = normalizeWebsiteEntry(value); @@ -86,18 +86,18 @@ export function App() { setLastAttempt({value,mode}); } if(mode==='public'&&!publicEnabled)throw new Error('Website scanning is unavailable. Start the local API or use the explicitly labelled example.'); - requestStarted = true; + timeout = AbortSignal.timeout(mode === 'demo' ? 10000 : 90000); const response = await fetch(mode === 'fixture' ? '/api/scan-fixture' : mode === 'public' ? '/api/scan-public' : '/api/analyze', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(fixture ? { fixture: value } : { url: value }), - signal: AbortSignal.any([abort.signal, AbortSignal.timeout(mode === 'demo' ? 10000 : 90000)]), + signal: AbortSignal.any([abort.signal, timeout]), }); let data; try { data = await response.json(); } catch (cause) { - if (cause instanceof Error && cause.name === 'TimeoutError') throw cause; + if (timeout.aborted) throw cause; if (abort.signal.aborted || analysisRequest.current !== abort) return; const { retryable } = scanFailureFeedback(undefined, response.status); - setFailure({ message: 'The response could not be read. No report was created.', retryable }); + setFailure({ message: 'The response could not be read. No report was received.', retryable }); return; } if (abort.signal.aborted || analysisRequest.current !== abort) return; @@ -128,14 +128,14 @@ export function App() { setReport(data); setView('findings'); } catch (cause) { if (abort.signal.aborted || analysisRequest.current !== abort) return; - if (requestStarted && cause instanceof Error && cause.name === 'TimeoutError') { + if (timeout?.aborted) { setFailure({ message: 'The request timed out. Try again shortly.', retryable: true }); - } else if (requestStarted && cause instanceof TypeError) { + } else if (timeout && cause instanceof TypeError) { setFailure({ message: 'KindPath could not reach the scanner. Check your connection and try again.', retryable: true }); } else { setFailure({ message: cause instanceof Error ? cause.message : 'The scan could not finish. No report was created.', - retryable: requestStarted && mode !== 'public', + retryable: timeout !== undefined && mode !== 'public', }); } } finally { diff --git a/src/components/scanFeedback.test.ts b/src/components/scanFeedback.test.ts index ae4453b..e9bbc86 100644 --- a/src/components/scanFeedback.test.ts +++ b/src/components/scanFeedback.test.ts @@ -7,7 +7,9 @@ test('scan failures give bounded guidance without exposing internal diagnostics' assert.match(scanErrorMessage({code:'SCANNER_BUSY',error:'private diagnostic'},429),/finishing/); assert.match(scanErrorMessage({code:'SCANNER_CLEANUP_FAILED'},503),/safely/); assert.match(scanErrorMessage({code:'PUBLIC_SCANNING_DISABLED'},503),/built-in page/); - assert.equal(scanErrorMessage({error:'Use a public HTTP/HTTPS URL.'},400),'Use a public HTTP/HTTPS URL.'); + assert.deepEqual(scanFailureFeedback({error:'PRIVATE_SENTINEL'},400), { + message: 'The scan request was rejected. Check the address or built-in page selection.', retryable: false, + }); for(const value of [{code:'constructor',error:'private diagnostic'}, {code:'__proto__'}, {error:'private diagnostic'}, null]) { assert.equal(scanErrorMessage(value,503),'The request could not finish. No report was created.'); } diff --git a/src/components/scanFeedback.ts b/src/components/scanFeedback.ts index ea2cb0d..e2bf405 100644 --- a/src/components/scanFeedback.ts +++ b/src/components/scanFeedback.ts @@ -12,7 +12,7 @@ const failures = new Map([ ['SCAN_RATE_LIMITED', { message: 'Too many requests. Wait up to a minute and try again.', retryable: true }], ['SCANNER_BUSY', { message: 'Another scan is still finishing. Try again shortly.', retryable: true }], ['SCANNER_CLEANUP_FAILED', { message: 'The previous scan could not finish safely. Scanning is unavailable until cleanup is verified.', retryable: false }], - ['SCANNER_UNAVAILABLE', { message: 'The scanner is unavailable. Check that the local scanner is running.', retryable: false }], + ['SCANNER_UNAVAILABLE', { message: 'The scanner is currently unavailable.', retryable: false }], ['PUBLIC_SCANNING_DISABLED', { message: 'Website scanning is not available yet. Scan a built-in page or explore an example.', retryable: false }], ['SCAN_FAILED', { message: 'The scan could not finish. No report was created.', retryable: false }], ]); @@ -44,8 +44,8 @@ export function scanFailureFeedback(value: unknown, status: number): ScanFailure } const known = typeof data.code === 'string' ? failures.get(data.code) : undefined; if (known) return known; - if (status === 400 && typeof data.error === 'string' && data.error.length <= 500) { - return { message: data.error, retryable: false }; + if (status === 400) { + return { message: 'The scan request was rejected. Check the address or built-in page selection.', retryable: false }; } return { message: 'The request could not finish. No report was created.', retryable: temporaryHttpStatuses.has(status) }; }