pixelpact
v0.1.6Extract a visual contract from a reference page and measure an implementation against it
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
extract_contract Extract a visual contract
Extracts a visual contract from a reference URL and saves it as JSON at outputPath. Call this once per reference design, before check_implementation or diff_pixels can be used, since both need a saved contract to compare against. Pass screenshotDir to also capture reference screenshots, which diff_pixels requires later. Returns a summary: the element count per viewport, any extraction warnings, and the path the contract was written to.
| Parameter | Type | Description |
|---|---|---|
outputPath * | string | Filesystem path to write the contract JSON to, for example ./contracts/home.json. |
url * | string | The reference URL to extract a visual contract from. |
freezeAnimations | boolean | Freeze CSS animations before measuring. Defaults to true. |
fullPage | boolean | Capture the full scrollable page instead of only the viewport. Defaults to true. |
headless | boolean | Run the browser headless. Defaults to true. |
masks | array | CSS selectors to exclude from the walk, for example ads or timestamps. |
maxElements | integer | Maximum elements to walk, 0 means unbounded. Defaults to 600. |
maxStates | integer | Maximum interactive elements to probe for hover and focus. Defaults to 120. |
screenshotDir | string | Directory to save reference screenshots to. Required later for diff_pixels to work. |
selector | string | CSS selector to scope the walk to. Defaults to the document body. |
timeout | integer | Navigation timeout in milliseconds. Defaults to 30000. |
viewports | array | Viewports to capture. Defaults to desktop 1440x900, tablet 768x1024, mobile 390x844. |
wait | integer | Extra settle time in milliseconds after navigation. Defaults to 2000. |
check_implementation Check an implementation against a contract
Measures an implementation URL against a previously saved visual contract: box position and size, computed styles, hover and focus states, and pseudo-elements. Call this after building or changing a UI to verify it matches the reference without a human looking at it. Needs contractPath from a prior extract_contract call. Returns a formatted deviation table (capped at 40 rows, with a note on how many were left out) plus the numeric totals, the pass rate, any missing selectors, and ok, which is true only when nothing deviated and nothing is missing.
| Parameter | Type | Description |
|---|---|---|
contractPath * | string | Path to a contract JSON file previously written by extract_contract. |
url * | string | The implementation URL to measure against the contract. |
headless | boolean | Run the browser headless. Defaults to true. |
maxStates | integer | Maximum interactive elements to probe. Defaults to 120. |
selector | string | CSS selector to scope the check to. Defaults to the contract root. |
timeout | integer | Navigation timeout in milliseconds. Defaults to 30000. |
tolerance | number | Allowed pixel tolerance for box and length values. Defaults to 1. |
viewport | string | Viewport name to check, for example desktop. Defaults to the first viewport in the contract. |
wait | integer | Extra settle time in milliseconds after navigation. Defaults to 2000. |
diff_pixels Pixel-diff an implementation against a contract screenshot
Renders the implementation URL and compares it pixel by pixel against the reference screenshot stored in the contract. Use this for a stricter visual check than check_implementation, after the structural check passes or when a subtle rendering difference is suspected. Requires the contract to have been extracted with screenshotDir set. Returns the percentage of differing pixels, the threshold it was compared against, ok, and the filesystem path of the generated diff image.
| Parameter | Type | Description |
|---|---|---|
contractPath * | string | Path to a contract JSON file previously written by extract_contract. |
url * | string | The implementation URL to capture and compare pixel by pixel. |
headless | boolean | Run the browser headless. Defaults to true. |
masks | array | CSS selectors to blank out before comparing, for example ads or timestamps. |
outDir | string | Directory to write the diff image to. Defaults to the OS temp directory. |
selector | string | CSS selector to scope the comparison to. Defaults to the contract root. |
threshold | number | Allowed percent of differing pixels before the comparison fails. Defaults to 0.5. |
timeout | integer | Navigation timeout in milliseconds. Defaults to 30000. |
viewport | string | Viewport name to compare. Defaults to the first viewport in the contract. |
wait | integer | Extra settle time in milliseconds after navigation. Defaults to 2000. |
read_contract_summary Read a saved contract summary
Reads a saved contract file and describes it without opening a browser or making any network request. Use this to inspect what a contract covers, for example before deciding whether diff_pixels is possible, since that needs screenshots to already exist. Returns the original source URL, when it was extracted, the viewports it covers, the element count per viewport, whether reference screenshots exist, and any warnings recorded at extraction time.
| Parameter | Type | Description |
|---|---|---|
contractPath * | string | Path to a contract JSON file previously written by extract_contract. |