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

network-har

v0.5.5

Published

CLI utility to retrieve network activity in HAR (HTTP Archive) format

Downloads

18

Readme

network-har

Build Status Docker Pulls

What is network-har?

CLI utility that uses Nightmare.js and the nightmare har plugin to capture network activity in HAR (HTTP Archive) format. It also provides a docker image which retrieves the HAR by running nightmarejs headlessly.

Use cases

  • integration testing (are specific requests being made? how often?)
  • performance testing (HAR contains detailed timing information of the network requests)
  • getting page weight, number of js / css / ajax / font / ... requests

Getting started

Only 1 command is required to be executed to retrive the network information. Can be used as a:

  1. nodejs binary: network-har [options]
  2. docker image (runs in a headless electron environment): docker run --rm alexbardas/network-har [options]

1. From nodejs

Install

npm install -g network-har

Usage

network-har [options]

2. From docker

Install

docker pull alexbardas/network-har

Usage

docker run --rm alexbardas/network-har [options]

Gain access inside the container:

docker run -it --entrypoint=/bin/bash --rm alexbardas/network-har
root@containerid:/src# ./network-har.sh [options]
Usefulness

The network-har.sh (docker's image entrypoint) can be used to headlessly retrieve the network information in a CI step which is based on the alexbardas/network-har docker image.

Jq command line JSON preprocessor is already installed on the provided docker image, so the json HAR output can be very easily parsed inside the container.

API

The following commands can be interchangeable, but they depend on the executing environment:

  • network-har [options] (if nodejs is available and the network-har npm package is installed and if the environment already has an X server -> many ifs)
  • docker run --rm alexbardas/network-har [options] (if docker is installed)
  • ./network-har.sh [options] (inside a docker container created from the provided image. Useful in a CI step)

Options

--help

Prints detailed help information.

docker run --rm alexbardas/network-har --help
--debug (optional, no extra arguments)

Opens a minimal window manager (jwm) and a vnc server (x11vnc) in the docker container to allow remote debugging. Connect with a vnc viewer to localhost:5900 using the password secret. Free VNC viewers:

  • for macOS: Screen Sharing (comes with every macOS version)
  • for windows: TightVNC
--url string (required)

The website for which the har information is needed.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com
--header string:string (optional, default: none)

Additional headers to be added to the http request. Can be used multiple times.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --header "Cache-Control:no-cache" \
  --header "Accept-Language:en-us"
--retries number (optional, default: 2)

Number of maximum retries for getting the network HAR in case the the command fails with a network error. Useful because electron can have intermittent network failures.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --retries 3
--useragent string (optional, default: none)

Overrides default electron useragent with a new value.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --useragent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2860.0 Safari/537.36"
--viewport number,number (optional, default: 375,667)

Overrides default electron viewport with new values.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --viewport 1366,768
--wait number (optional, default: 5000)

Waits for the specified number of ms after the request is made until retrieving the network information.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --wait 10000
--wait string (optional, default: none)

Waits for a specific element defined by a string selector to be available in the DOM.

docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --wait "#hnmain"

Examples

Retrieve the network HAR for hackernews for:

  • 1024x768 viewport
  • network-har useragent
  • Cache-Control: no-cache and Accept-Language: en-US headers
  • 10s wait time for network resources
  • 3 maximum retries
  • '#hnmain' waits for the element having this selector to be in the DOM
docker run --rm alexbardas/network-har \
  --url https://news.ycombinator.com \
  --useragent "network-har" \
  --viewport 1024,768 \
  --header "Cache-Control:no-cache" \
  --header "Accept-Language:en-US" \
  --retries 3 \
  --wait "#hnmain"

Debugging

Nodejs binary:

  • It's most likely in this case that a X Window System is already present. Because it needs to open devtools in order to record the network activity and devtools works only when the electron browser is displayed, the debugging should be done directly in this environment.

Docker image:

  • There is an extra option which allows remote debugging: --debug. An extra window manager and vnc server are started in order to enable debugging from the user's host machine inside the docker container.

Contributing

  1. Network-har is an open source project and welcome contributions.

  2. See CONTRIBUTING.md to get your local environment set up.