
TypeScript & WebOctober 19, 2018• 2 min read
WebScreen: Declarative Headless Chrome Screenshot & DOM Capture Automation
Whether you are generating visual regression snapshots across environments, archiving marketing pages, or extracting specific UI widgets for documentation, manually taking and cropping browser screenshots quickly becomes tedious.
To automate this workflow, I built WebScreen (daniazar/webscreen)—a declarative, JSON-driven screenshot engine written in TypeScript on top of Headless Chrome and the Puppeteer API.
Declarative Capture via url.json#
Instead of writing custom imperative Puppeteer scripts every time you need to capture a new site or component, WebScreen reads a declarative url.json manifest where each entry specifies:
- Full-Page or Viewport Capture (
fullPage,capturePage, customviewport.widthviewport.height). - Targeted DOM Element Crops (
elements): An array of CSS selectors (.classor#id) that WebScreen locates in the live DOM, computes bounding boxes for, and exports as isolated image files. - Output Format (
extension): Supports losslesspngor compressedjpegoutput.
json[ { "url": "https://github.com/", "name": "github", "fullPage": true, "capturePage": true, "elements": [ ".home-hero-signup" ], "extension": "jpeg" }, { "url": "https://google.com/", "viewport": { "width": 300, "height": 400 }, "capturePage": true, "elements": [ ".content", "#hplogo" ] } ]
How the Capture Pipeline Works#
Interactive Architecture Diagram
Rendering architecture diagram...
For each target in url.json:
- Viewport Configuration: If a custom
viewportis defined (e.g.,300x400to simulate a mobile device), WebScreen resizes the headless browser tab before navigation so responsive media queries trigger accurately. - Page-Level Capture: When
capturePage: trueis enabled, it captures either the visible viewport or the stitchedfullPagescroll height. - Sub-Element Isolation: It iterates through the
elementsarray, queries each CSS selector viapage.$(selector), and renders an exact bounding-box screenshot of that DOM node (github_0.jpeg,google_1.png, etc.).
The repository and documentation are available on GitHub at github.com/daniazar/webscreen.
Share or cite this engineering article
Related Articles & Companion Deep-Dives
October 14, 2026 • 4 min read
Read articleSurfZar: Real-Time 3D Algebraic Surface Visualizer & Hybrid GPU Solver in WebGL2
October 12, 2026 • 5 min read
Read articleSurfZar Deep-Dive: Differential Geometry Probing (Gaussian & Mean Curvature), Implicit CSG & Watertight 3D Printing
October 10, 2026 • 5 min read
Read article