A photo from a slow host
+ +
+ The browser checks shouldn't wait for this photo.
+diff --git a/CHANGELOG.md b/CHANGELOG.md index fe8e2ea..2a2f7af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.3 (2026-11-12) + +- `--browser` no longer waits for photos from other sites: they get a blank stand-in, since contrast and phone width don't depend on them. A slow or unreachable image host used to hold each page for up to 30 seconds in each color scheme, so a site with many linked photos (TagKit's templates and nonprofit starter) ran for minutes. Images with a `width` and `height` keep their size. + ## 0.1.2 (2026-11-12) Knows TagAction's and TagBrush.css's next releases. diff --git a/README.md b/README.md index aaa8e56..1ff40f0 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ An agent that can't look at a screen can still run a command. TagCheck gives it Exit codes: 0 clean, 1 problems, 2 bad usage. -With `--browser`, pages that link TagBrush.css (any build, including the scoped and Shadow DOM ones) or TagAction from jsDelivr are served the copy installed in your project, if there is one, so the check works offline and tests your version. A stylesheet or script that still doesn't load is reported (`not-loaded`), since contrast and widths measured without it mean little, and the summary (or `"browser": true` in the JSON) says the browser checks ran. +With `--browser`, pages that link TagBrush.css (any build, including the scoped and Shadow DOM ones) or TagAction from jsDelivr are served the copy installed in your project, if there is one, so the check works offline and tests your version. A stylesheet or script that still doesn't load is reported (`not-loaded`), since contrast and widths measured without it mean little, and the summary (or `"browser": true` in the JSON) says the browser checks ran. Photos from other sites aren't downloaded: they get a blank stand-in of the same size, so a slow image host doesn't slow the checks. ## Rules diff --git a/package-lock.json b/package-lock.json index 81d23a5..1113f8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kovirlabs/tagcheck", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kovirlabs/tagcheck", - "version": "0.1.2", + "version": "0.1.3", "license": "Apache-2.0", "bin": { "tagcheck": "bin/tagcheck.mjs" diff --git a/package.json b/package.json index 54565d8..96b3572 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kovirlabs/tagcheck", - "version": "0.1.2", + "version": "0.1.3", "description": "Find semantic and accessibility mistakes in HTML from the command line, CI, or an AI agent: missing alt text and labels, fake buttons, skipped headings, broken id references, contrast in light and dark mode, and sideways scrolling on phones. Part of the Tag family with TagBrush.css and TagAction.", "keywords": [ "html", diff --git a/src/browser.mjs b/src/browser.mjs index 8c5ce2b..83e09aa 100644 --- a/src/browser.mjs +++ b/src/browser.mjs @@ -11,6 +11,7 @@ import { pathToFileURL } from 'node:url'; export const PHONE_WIDTH = 360; export const DESKTOP_WIDTH = 1280; +const BLANK_GIF = Buffer.from('R0lGODlhAQABAAAAACH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64'); async function loadPlaywright() { const require = createRequire(join(process.cwd(), 'package.json')); @@ -108,6 +109,10 @@ export async function checkInBrowser(files) { } for (const scheme of ['light', 'dark']) { const page = await browser.newPage({ viewport: { width: DESKTOP_WIDTH, height: 900 }, colorScheme: scheme, reducedMotion: 'reduce' }); + // Photos from other sites get a blank stand-in: neither check needs + // them, and a slow or unreachable image host would stall the page's + // load (and every page after it) for up to 30 seconds. + await page.route(/^https?:/, (route) => route.request().resourceType() === 'image' ? route.fulfill({ contentType: 'image/gif', body: BLANK_GIF }) : route.fallback()); for (const { pattern, path, contentType } of routes) await page.route(pattern, (route) => route.fulfill({ path, contentType })); // A stylesheet or script that doesn't load (offline, a typo in the URL) // would make every measurement below describe a different page. diff --git a/tests/check.spec.mjs b/tests/check.spec.mjs index 074d76d..ba51772 100644 --- a/tests/check.spec.mjs +++ b/tests/check.spec.mjs @@ -127,7 +127,7 @@ test.describe('command line', () => { test('--json prints a machine-readable report', () => { const report = JSON.parse(run('tests/fixtures', '--json').stdout); expect(report).toMatchObject({ tool: 'tagcheck', version: expect.any(String), errors: expect.any(Number), warnings: expect.any(Number) }); - expect(report.files.map((f) => f.file)).toEqual(['tests/fixtures/bad.html', 'tests/fixtures/good.html', 'tests/fixtures/low-contrast.html', 'tests/fixtures/not-loaded.html', 'tests/fixtures/redirect.html']); + expect(report.files.map((f) => f.file)).toEqual(['tests/fixtures/bad.html', 'tests/fixtures/good.html', 'tests/fixtures/low-contrast.html', 'tests/fixtures/not-loaded.html', 'tests/fixtures/redirect.html', 'tests/fixtures/remote-image.html']); }); test('--rules lists every rule', () => { @@ -184,6 +184,13 @@ test.describe('--browser', () => { expect(served('https://cdn.jsdelivr.net/npm/tagaction@0/tagaction.min.js')).toBe('tagaction.js'); }); + test('does not wait for photos from other sites', async () => { + const started = Date.now(); + const report = await checkFiles(['tests/fixtures/remote-image.html'], { browser: true }); + expect(report.files[0].problems).toEqual([]); + expect(Date.now() - started).toBeLessThan(10000); // a stalled image held each page for 30 seconds + }); + test('the report says whether the browser checks ran', async () => { expect((await checkFiles(['tests/fixtures/good.html'])).browser).toBe(false); }); diff --git a/tests/fixtures/remote-image.html b/tests/fixtures/remote-image.html new file mode 100644 index 0000000..076bd9a --- /dev/null +++ b/tests/fixtures/remote-image.html @@ -0,0 +1,17 @@ + + +
+ + +
+ The browser checks shouldn't wait for this photo.
+