This package has been deprecated

Author message:

Please use lighthouse budgets instead

puppeteer-network-stats

0.3.0 • Public • Published

Puppeteer Network Stats

Build Status Coverage Status

Attach to a puppeteer page and collect network request stats.

Install

npm install puppeteer-network-stats

Usage

Example below:

  • captures data for all requests

  • request URLs based on the Network.requestWillBeSent event

  • response status based on the Network.responseReceived event

  • all event data is merged based on request ids

const PuppeteerNetworkStats = require('puppeteer-network-stats');
 
const config = {
  requestWillBeSent: ({request: {url}}) => ({url}),
  responseReceived: ({response: {status}}) => ({status})
};
 
const networkStats = new PuppeteerNetworkStats(config);
 
// const browser = await puppeteer.launch();
// const page = browser.newPage();
 
await networkStats.attach(page); // creates CDP session, registers listeners
 
// await page.goto(url);
 
networkStats.getRequests(); // gives you an map of all request data by id
 
networkStats.clearRequests(); // clears all captured requests
 
await networkStats.detach(page); // detaches CDP session

A similar configuration allows capturing data from any Network.* events.

As an example for debugging we can just log all event data easily:

const config = [
  'requestWillBeSent',
  'requestServedFromCache',
  'loadingFinished',
  'loadingFailed',
  'responseReceived'
].map(
  (event) => ({
    [event]: (params) => ({[event]: params})
  })
).reduce(
  (result, item) => ({...result, ...item}), {}
)

Readme

Keywords

none

Package Sidebar

Install

npm i puppeteer-network-stats

Weekly Downloads

0

Version

0.3.0

License

none

Unpacked Size

5.04 kB

Total Files

5

Last publish

Collaborators

  • csabapalfi