Code Monkey home page Code Monkey logo

ecoindex_puppeteer's Introduction

Ecoindex puppeteer

Provides puppeteer tools that retrieve ecoindex parameters from a puppeteer page, according to ecoindex definition.

This module provides tools that you can use to get EcoIndex parameters with puppeteer.
This module does not get the EcoIndex value. You have to combine it with https://www.npmjs.com/package/ecoindex in order to current final EcoIndex score.

Install

Install this module as you normally do :
npm install ecoindex_puppeteer

How to use ?

Get page metrics.

Introduction

According to the EcoIndex definition (https://www.ecoindex.fr/comment-ca-marche/), the metrics used for EcoIndex computing are kept after this scenario :

  • clear browser cache
  • visit a URL
  • scroll to the bottom of the page
  • wait for 3 seconds.

The module will provide tools that will automate this scenario and the recovery of the 3 needed metrics:

  • the number of DOM elements
  • the number of requests
  • the total requests size (in Bytes)

The module does not initiate a Puppeteer browser session. It is regardless of the puppeteer configuration.

Get metrics

You can get a URL metrics using the method getPageMetrics(page, url).

import {getPageMetrics} from '../src/EcoIndexPage';

const metrics = await getPageMetrics(page, 'https://www.ecoindex.fr');

You can also define an object to get scenario events :

import {EcoIndexPage} from '../src/EcoIndexPage';

const ecoIndexPage = new EcoIndexPage();

ecoIndexPage.on(null, (eventName, eventData) => {
    console.log(`eventName`);
});

const metrics = await ecoIndexPage.getMetrics(page, 'https://www.ecoindex.fr');

Turn page metrics into EcoIndex score

You can use the ecoindex module in order to get ecoindex values from metrics object :

import {getPageMetrics} from '../src/EcoIndexPage';

const metrics = await getPageMetrics(page, 'https://www.ecoindex.fr');

const ecoIndexValue = ecoindex.computeEcoIndex(
    metrics.getDOMElementsCount(), 
    metrics.getRequestsCount(), 
    metrics.getSize()
);

ecoindex_puppeteer's People

Contributors

tsecher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.