domstat - A Puppeteer based CLI tool to check web performance
Tags: webdev, javascript, webperf, npm
Published: 2022-08-02 14:30:00

domstat is a [Puppeteer](https://github.com/puppeteer/puppeteer) based CLI tool that runs locally and checks for webpage performance statistics. 

Domstat consolidates select Chrome dev tools statistics at one place and gives a bird's eye overview on how a webpage performed at runtime. 
 
![](https://i.ibb.co/NsFkC54/Screenshot-2022-06-26-at-00-07-39.png)

[Source code](https://github.com/meetdave3/domstat)

To run this, you should have node & npm installed on your machine. You can do so by [downloading node.js](https://nodejs.org/en/download/)

Using npm

```bash
npm i -g domstat 
domstat --url=example.com
```

Alternatively, using npx

```bash
npx domstat --url=example.com
```

# Plot

domstat parses the browser-level API numbers like DOM user timings & code coverage. Similar to httpstat for cURL related information.

domstat also takes inspiration from [this web.dev article](https://web.dev/critical-rendering-path-measure-crp/#navigation-timing) which gives an in-detail explanation about measuring critical rendering path using the Navigation Timing API.

# How does domstat help?

Let's take a look at a scenario where we want to check and compare the dom timings & coverage for different websites.

Below are the domstats for optimised "movies" web application in different frameworks. You can find the repositories on [https://github.com/orgs/tastejs/repositories](https://github.com/orgs/tastejs/repositories)

Angular: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqe2ig5xh3wyk0v79052.png)

Next.js: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gw4g89iqtztp06c415e.png)

Nuxt:
 ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61roalqok4hrrv6wf01f.png)

All of the above movies web application score a 90+ on Lighthouse / Pagespeed audit, domstat on the other hand leverages the browser's API and helps further by giving insights about the loading behaviour. 
   
These statistics are available on the Chrome's devtools but they aren't consolidated at one place. Example: The CSS & JS coverage statistics are present in the [Sources tab](https://developer.chrome.com/docs/devtools/coverage/), to get the DOM timings, you need to run the Performance audit from the [Performance tab](https://developer.chrome.com/docs/devtools/evaluate-performance/) and so on. 

Domstat consolidates all these numbers at one place and gives a bird's eye overview on how the webpage performed. 

By default the tests don't have cpu or network throttling yet but I wish to add more such flags soon.

# Building the CLI

The CLI is built using React. Yes, React! Seems that React can do a lot of things. From Desktop apps with Electron to a fullstack app with Next.js.

I used [create-ink-app](https://github.com/vadimdemedes/create-ink-app) to build the CLI tool. The create-ink-app spins up a basic project structure for Ink apps and lets you avoid the boilerplate and get to building beautiful CLIs in no time.

Checkout [ink](https://www.npmjs.com/package/ink) to know more about writing CLI tools with React :) 

# Closing notes

I've been using the Chrome DevTools to check site's performance, running tests to check and compare runtime performance of different pages. 

This CLI tool is a step closer to knowing the APIs well, the tools gives quick insights and saves the hassle of clicking around the already overwhelming browser's dev tools.

There's a good potential for improving the tool further & if you're familiar with the Node.js ecosystem and React, you're most welcome to contribute to make this better. 

The goal isn't to make another lighthouse like tool, but only to consolidate the important scattered statistics from the browser's API at one place, using one command.