Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions scripts/preview-browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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};
Expand Down
61 changes: 42 additions & 19 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<ScanFailureFeedback | null>(null);
const [view, setView] = useState<'findings' | 'preview'>('findings');
const results = useRef<HTMLElement>(null);
// Focus only after React has committed the new report and its result element exists.
Expand All @@ -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;
Expand All @@ -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); }
}
Expand All @@ -130,14 +153,14 @@ export function App() {
<main id="main">
<section className="hero"><div className="hero-copy"><div className="eyebrow"><span className="tiny-sun" aria-hidden="true">✳</span> A MORE INCLUSIVE INTERNET STARTS HERE</div><h1>A clearer web.<br/><em>For everyone.</em></h1><p>See your website from a different perspective.<br className="desktop-break"/> Find accessibility barriers, understand their impact,<br className="desktop-break"/> and take the next step toward a more welcoming web.</p>
<WebsiteForm activity={busy ? lastAttempt?.mode === 'demo' ? 'Preparing an example report…' : 'Checking the page and preparing your report…' : !capabilitiesReady ? 'Checking scanner availability…' : cancelled ? 'Request cancelled. You can try again shortly.' : report ? 'Report ready.' : ''}
onCancel={cancel} cancelled={cancelled} canRetry={!busy && !!lastAttempt && (!!error || cancelled)}
onRetry={() => { 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'); }}/></div>
<div className="hero-visual" aria-label="Illustration: a fictional website seen through different visual filters"><div className="visual-top"><span><i/> A DIFFERENT PERSPECTIVE</span><span>↗</span></div><div className="hero-sample"><SampleSite/><div className="comparison-slice" aria-hidden="true"/></div><div className="visual-bottom"><span>Same website. Different experience.</span><span className="visual-toggle" aria-hidden="true">●</span></div><div className="floating-note"><span aria-hidden="true">◉</span> Design with more people in mind.</div></div></section>
<section className="principles" id="how-it-works" aria-label="How KindPath works"><article><span className="step">01 / DISCOVER</span><h2>Find the barriers.</h2><p>Explore clear findings with context about who they affect and why they matter.</p></article><article><span className="step">02 / SEE DIFFERENTLY</span><h2>Change your perspective.</h2><p>Compare the captured page with visual effects that illustrate potential challenges.</p></article><article><span className="step">03 / MAKE PROGRESS</span><h2>Know your next step.</h2><p>Turn findings into practical improvements, one thoughtful change at a time.</p></article></section>
{report && <section className="results" ref={results} tabIndex={-1} aria-labelledby="report-title"><div className="section-heading"><div><span className="eyebrow">YOUR EXPLORATION</span><h2 id="report-title">Small changes. Meaningful impact.</h2><p className="report-url">{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}</p>{report.mode === 'public' && report.requestedUrl && <p className="report-url">Requested URL: {report.requestedUrl}</p>}</div><span className="demo-badge">{report.mode === 'demo' ? 'Illustrative report' : report.mode === 'fixture' ? 'Real fixture scan' : 'Automated page scan'}</span></div><div className="notice">{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.'}</div>{pageNotice && <p className="notice" role="status">{pageNotice}</p>}<ScanCoverageNotice report={report}/><ReportExports key={`${report.mode}:${report.url}:${report.generatedAt}`} report={report}/><div className="view-switch" role="group" aria-label="Report view"><button aria-pressed={view === 'findings'} onClick={() => setView('findings')}>Accessibility findings <span>{report.findings.length}</span></button><button aria-pressed={view === 'preview'} onClick={() => setView('preview')}>Visual preview <span aria-hidden="true">◉</span></button></div>
<div hidden={view !== 'findings'}><FindingsReport key={`${report.mode}:${report.url}:${report.generatedAt}`} report={report}/></div><div hidden={view !== 'preview'}>{report.mode === 'public' && report.previewUnavailable ? <div className="notice">The website image could not be captured. Your accessibility report and JSON download are still available. Try another scan to request a new image.</div> : report.mode === 'public' && report.sitePreview ? <SiteVisualPreview key={report.scanId} snapshot={report.sitePreview}/> : <VisualPreview key={report.mode === 'fixture' ? report.scanner?.fixture : 'garden'} fixture={report.mode === 'fixture' && isFixture(report.scanner?.fixture) ? report.scanner.fixture : 'garden'}/>}</div></section>}
<div hidden={view !== 'findings'}><FindingsReport key={`${report.mode}:${report.url}:${report.generatedAt}`} report={report}/></div><div hidden={view !== 'preview'}>{report.mode === 'public' && report.previewUnavailable ? <div className="notice">The website image could not be captured. Your accessibility report and JSON download are still available.</div> : report.mode === 'public' && report.sitePreview ? <SiteVisualPreview key={report.scanId} snapshot={report.sitePreview}/> : <VisualPreview key={report.mode === 'fixture' ? report.scanner?.fixture : 'garden'} fixture={report.mode === 'fixture' && isFixture(report.scanner?.fixture) ? report.scanner.fixture : 'garden'}/>}</div></section>}
<section className="closing"><span aria-hidden="true">✳</span><p>Accessibility is a practice.<br/><strong>Every step makes a difference.</strong></p></section>
</main><footer><a className="brand" href="#">KindPath<span aria-hidden="true">↗</span></a><span>A more accessible web starts with a clearer perspective.</span><span>Built with intention.</span></footer>
</>;
Expand Down
8 changes: 6 additions & 2 deletions src/components/WebsiteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>(null);
useLayoutEffect(()=>{ if((cancelled || error) && canRetry)retryButton.current?.focus(); },[cancelled,error,canRetry]);
const errorMessage = useRef<HTMLParagraphElement>(null);
useLayoutEffect(() => {
if ((cancelled || error) && canRetry) retryButton.current?.focus();
else if (error) errorMessage.current?.focus();
}, [cancelled, error, canRetry]);
return <>
<form onSubmit={onSubmit} aria-busy={busy}>
<label htmlFor="website">Your website URL</label>
Expand All @@ -45,7 +49,7 @@ export function WebsiteForm({ url, activity, onCancel, onRetry, canRetry, cancel
<p className="form-note" role="status" aria-live="polite">{activity}</p>
{busy && <button type="button" className="secondary" onClick={onCancel}>Cancel request</button>}
{canRetry && <button ref={retryButton} type="button" className="secondary" onClick={onRetry}>Try again</button>}
{error && <p role="alert" id="url-error" className="error">{error}</p>}
{error && <p ref={errorMessage} tabIndex={-1} role="alert" id="url-error" className="error">{error}</p>}
</form>
<button className="text-button" disabled={busy} onClick={onExample}>
Just exploring? Try an example <span aria-hidden="true">↗</span>
Expand Down
Loading
Loading