diff --git a/scripts/preview-browser.mjs b/scripts/preview-browser.mjs index 0782402..7a34891 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(); @@ -793,9 +814,10 @@ try { assert.ok(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth)); await page.setViewportSize({width:1280,height:900});await assertDownload(publicResponse); publicResponse={...publicReport,scanId:data.imagePreview.scanId,previewUnavailable:true}; - await publicButton.click();await page.locator('.results').waitFor();await assertDownload(publicResponse); + await publicButton.click();await page.locator('.results').waitFor(); await page.getByRole('button',{name:/Visual preview/}).click(); - await page.getByText('The website image could not be captured. Your accessibility report and JSON download are still available. Try another scan to request a new image.',{exact:true}).waitFor(); + await page.getByText('The website image could not be captured. Your accessibility report and JSON download are still available.',{exact:true}).waitFor(); + await assertDownload(publicResponse); assert.equal(await page.locator('iframe').count(),0); for(const scanId of [undefined,'old']){ publicResponse={...publicReport,scanId,previewUnavailable:true}; diff --git a/src/App.tsx b/src/App.tsx index ae9ee8c..ffeaa3f 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 timeout: AbortSignal | undefined; 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.'); + 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 { 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 (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 received.', 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 (timeout?.aborted) { + setFailure({ message: 'The request timed out. Try again shortly.', retryable: true }); + } 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: timeout !== undefined && mode !== 'public', + }); + } } finally { if (analysisRequest.current === abort) { analysisRequest.current = null; setBusy(false); } } @@ -130,14 +153,14 @@ 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.
01 / DISCOVER

Find the barriers.

Explore clear findings with context about who they affect and why they matter.

02 / SEE DIFFERENTLY

Change your perspective.

Compare the captured page with visual effects that illustrate potential challenges.

03 / MAKE PROGRESS

Know your next step.

Turn findings into practical improvements, one thoughtful change at a time.

{report &&
YOUR EXPLORATION

Small changes. Meaningful impact.

{report.mode === 'fixture' ? 'Scanned fixture' : report.mode === 'public' ? 'Scanned page' : 'Submitted URL'}: {report.mode === 'fixture' && isFixture(report.scanner?.fixture) ? fixtureTitle(report.scanner.fixture) : report.url}

{report.mode === 'public' && report.requestedUrl &&

Requested URL: {report.requestedUrl}

}
{report.mode === 'demo' ? 'Illustrative report' : report.mode === 'fixture' ? 'Real fixture scan' : 'Automated page scan'}
{report.mode === 'fixture' ? 'These are real automated results for the selected built-in page. The visual preview uses that same page. No public website was fetched.' : report.mode === 'demo' ? `This is demo data, not an assessment of ${new URL(report.url).hostname}.` : 'Automated results for the final scanned page only. Manual review is still required.'}{report.mode === 'demo' && !report.sitePreview && ' The visual preview uses a separate built-in fixture, not the submitted URL.'}
{pageNotice &&

{pageNotice}

}
-
} + }

Accessibility is a practice.
Every step makes a difference.

KindPathA more accessible web starts with a clearer perspective.Built with intention.
; 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 && }