npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-measure-user-perf

v0.0.17

Published

Automate user interaction performance testing.

Downloads

5

Readme

chrome-measure-user-perf

Automate user interaction performance testing

Experimental status. Use at own risk!

This package utilizes Puppeteer and the Google Chrome Developer Tools Performance Timeline to record the duration of click events and the resulting browser render process on your webpage. You can set timing thresholds for each click event and this package will evaluate the success or failure of each interaction based on the timing threshold.

Motivation

A short presentation describing the motivation and process behind this package.

Use


npm install chrome-measure-user-perf

First add the data-click=[aUniqueIdentifier] to the HTML elements which initiate the user interactions you would like to measure.

<button data-click="1st">1st button interaction</button>
<button data-click="2nd">2nd button interaction</button>
<button data-click="3rd">3rd button interaction</button>

Then create your Node script.

import TraceRunner, { Config, ThrottleSetting } from 'chrome-measure-user-perf';

let config: Config = {
	host: 'http://localhost:8000',
	thresholds: { '1st': 500 ,'2nd': 400, '3rd': 1000 };,

  // The following name will be used to create a directory located inside
  // the current working directory on every invocation of TracerRunner.run
  // The directory is then deleted after every TraceRunner.run invocation.
	traceDirName: 'uniqueDirectoryName', // This will be created at ./uniqueDirectoryName/
	throttleSetting: ThrottleSetting.NO_THROTTLE,
	keepDir: false,
};

(async () => {
	const TR = new TraceRunner(config);
	await TR.run();
})();

Make sure the config.host matches the url your application is running on.

Execute your Node script invoking TraceRunner.run

Configuration

export interface Config {
	// Where your application is running.
	host: string;

	// Record of all the elements on the page with the "data-click" attribute
	// Key = Name of unique identifer given to the value of "data-click" for each element
	// Value = Test baseline (in milliseconds) which determines if that user interaction passes or fails
	thresholds: Record<string, number>;

	// Local Directory which will be temporarily created for every invocation of TraceRunner.run
	// MUST BE UNIQUE NAME FROM ANY OTHER DIRECTORY IN THE CURRENT WORKING DIRECTORY!
	// IT WILL BE DELETED AFTER EVERY RUN!
	traceDirName: string;

	// Enum for throttling the CPU of Chrome Dev Tools Performance Timeline
	// 0 = No Throttle, 4 = 4x Throttle
	throttleSetting?: ThrottleSetting;

	// Keep trace file directory between executions of TraceRunner.run. Helpful for debugging.
	keepDir?: boolean;

	// Time to wait for page load.
	// Can be increased if interactions are being executed by Puppeteer too soon before event listeners have been attached.
	// Or if the elements containing data-click attributes on the page have not rendered yet.
	pageLoadAwait?: number;
}

Defaults

const DEFAULT_CONFIG: Partial<Config> = { pageLoadAwait: 1000, throttleSetting: ThrottleSetting.NO_THROTTLE };

How it Works

  1. A new directory you name in the configuration object using traceDirName is created in the current working directory.
  2. Puppeteer opens a new instance of Chrome to collect all of the data-click attribute values on the page.
  3. For every data-click attribute values on the page a new Chrome instance is opened, Puppeteer clicks the element with the attribute, a performance timeline trace is recorded and placed in the local directory you name in the configuration object using traceDirName, and the Chrome instance is closed.
  4. Once the performance timeline traces have been recorded for every element containing the data-click attribute , the trace files are processed and results are printed to the console.
  5. The directory containing all of the trace files is removed using Trash.