// 02 FIELD TOOLS
html-canonicalizer
Rebuilds a block of HTML with the fewest elements and the least CSS that draw the same picture, and proves it. The tool is called canon. Give it a page and an element, and it hands back that element with every wrapper that contributed nothing taken out and every remaining element carrying only the declarations it needs, with no stylesheet and no classes to chase. A card buried in eight nested wrappers goes from 29 elements to 11, and the Hacker News front page from 807 to 411, both pixel-identical.
How it knows
Chrome is the layout engine and the judge. canon reads the computed style, box and line of text of everything in the element, asks a clean tab what each kind of element looks like with no styles at all, and writes out a faithful copy. Then it tries removals in batches and keeps a change only if the browser can't tell the difference. The finished result is checked three ways: every box and line of text lands where it did to 1/32 of a pixel, every computed style matches, and a screenshot matches the original pixel for pixel. When something can't be reproduced, it says how many pixels differ and exits with status 2; it never rounds a difference down to "identical".
The same engine also runs as WebAssembly inside a live page, handed an element, and works under a strict Content-Security-Policy. There it checks by layout and computed style, without screenshots.
Stated honestly
- The result is a still picture. Links become plain text, hover states and scripts are gone, and tags other than images, SVG, tables and form controls become
<div>or<span>, so semantics and accessibility are lost. - It needs Chrome or Chromium on the machine, and about 2,000 elements take 10 to 40 seconds.