Code Monkey home page Code Monkey logo

layout-shift-gif's Introduction

Layout Shift GIF Generator - CLI

https://defaced.dev/tools/layout-shift-gif-generator/

Visualise the Core Web Vitals metric Cumulative Layout Shift (CLS) with a simple GIF.

Lighthouse is a great tool for identifying your overall Cumulative Layout Shift (CLS) score, but it's not so great for quickly visualising what's actually shifting on a page. The Layout Shift GIF Generator allows you to quickly identify which elements are moving around in the viewport.

Support this project
Help support the work that goes into creating and maintaining my projects and sponsor me via GitHub Sponsors.

Getting Started

Installation

The Layout Shift GIF Generator command line tool can be installed directly from NPM.

npm install -g layout-shift-gif

Usage

Once installed the tool can be used as per the following example.

layout-shift-gif --url https://blacklivesmatter.com/ --device mobile --output layout-shift.gif

This will generate an animated layout-shift.gif of https://blacklivesmatter.com/ showing the regions of Cumulative Layout Shift on the viewport of a simulated mobile device.

Options

Options:
      --help     Show help                                             [boolean]
      --version  Show version number                                   [boolean]
  -u, --url      Website URL                                 [string] [required]
  -d, --device   Device type                        [string] [default: "mobile"]
  -w, --width    Device viewport width                                  [number]
  -h, --height   Device viewport height                                 [number]
  -c, --cookies  Cookie filename                                        [string]
  -o, --output   Output filename          [string] [default: "layout-shift.gif"]
  -t, --type     CLS calculation method                [string] [default: "new"]

Examples

Basic Examples

Simulated Mobile Device

layout-shift-gif --url https://blacklivesmatter.com/ --device mobile

Simulated Desktop Device

layout-shift-gif --url https://blacklivesmatter.com/ --device desktop

Advanced Examples

Supplying Cookies

You can supply a cookie file in the Puppeteer JSON format allowing you to bypass cookie notices, or interstitals.

I recommend using the Export cookie JSON file for Puppeteer Chrome extension to export your cookies in the correct format.

layout-shift-gif --url https://blacklivesmatter.com/ --cookies cookies.json

Original CLS Calculation Method

In June 2021 Google changed how they calculate the CLS metric. Layout Shift GIF Generator defaults to the newest method, but if you require the old method it can still be access viable the --type option.

layout-shift-gif --url https://blacklivesmatter.com/ --type old

Device Simulation

The tool is able to check both a desktop and a mobile viewport.

  • The desktop viewport is a standard 1920x1080 resolution.

  • The mobile viewport is the Nexus 5X profile from Lighthouse.

Both the CPU and the network are throttled to simulate a good 3G network.

Hosted Version

If you don't wish to use the CLI version there is also a free hosted version running in a cloud function available on defaced.dev

Output

An outline of how to interpret the GIF output from this tool.

Page Screenshot

The screenshot of the page is taken after all the page elements have shifted and the CLS has been calculated.

Border Style

The border style of an outlined element represents the start and end positions of the elements shift.

  • A dashed border indicates the element's starting position.

  • A solid border indicates the element's end position.

Border Colour

The border colour of an outlined element represents the CLS score of that element against the overall page thresholds for CLS outlined by Google.

🟢 Good 0.1

🟠 Needs Improvement

🔴 Poor > 0.25

This means that if you see a shifting element with a red or orange outline then this element alone is contributing significantly to a negative CLS score for that page.

Corner Metric

The metric in the top left corner is the overall CLS score for that page and is the score you'll see in Lighthouse or Pagespeed Insights.

Corner Colour

The colour of the top left corner represents where the pages overall CLS score fits within the thresholds for CLS outlined by Google.

🟢 Good 0.1

🟠 Needs Improvement

🔴 Poor > 0.25

Sponsors

If you find this project useful please considering sponsoring me on GitHub Sponsors and help support the work that goes into creating and maintaining my projects.

Bonus

Sponsors are able to remove the project support message from all my CLI projects, as well as access other additional perks.

Author

Chris Johnson - defaced.dev - @defaced

layout-shift-gif's People

Contributors

adamread avatar workeffortwaste avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

layout-shift-gif's Issues

An option to bypass Error: net::ERR_CERT_AUTHORITY_INVALID

Hi =)
Is there a change you could add a way to use a localhost with https? Of course, the main problem about this is that I always have to add an exception when I navigate through a visual browser, pero using this project as a npm program through the terminal throws an error about my website's certificate.

Btw, excellent project!

TypeError: Cannot read properties of undefined (reading 'Nexus 5X')

Hi Thanks for adding apple silicon support, I tried it again and i get this issue:

╭─ericjohnson@ej-mba-m1 ~
╰─$ layout-shift-gif --url https://blacklivesmatter.com/ --device mobile --output layout-shift.gif                           1 ↵
file:///opt/homebrew/lib/node_modules/layout-shift-gif/layout-shift-gif.js:59
const phone = devices['Nexus 5X']
                     ^

TypeError: Cannot read properties of undefined (reading 'Nexus 5X')
    at file:///opt/homebrew/lib/node_modules/layout-shift-gif/layout-shift-gif.js:59:22
    at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Node.js v17.4.0

Steps to reproduce:

  1. Run npm install -g layout-shift-gif
  2. Run layout-shift-gif --url https://blacklivesmatter.com/ --device mobile --output layout-shift.gif
  3. The error above occurs.

Output the whole page

Is there a way I could output the whole page to the gif. I have pages that are very tall: multiple screens

Cookie prompts / pop-up windows

It'd be great if you try to close the cookie prompts / pop-up windows (or being able to specify which element to click). E.g.:

image

Use puppeteer-core to make CLI ux better

Love the idea of your package and CLI api ❤️.

I suggest to use puppeteer-core to prevent user from waiting of chrome downloading each time when package was used via npx. Waiting for 132.4 Mb each launch hurts UX a bit 😅.

We can use find_chrome.js script to get executablePath of local chrome instance or it'll download it's latest revision.

I can prepare PR, if you don't mind, do you?

Installs fine but cannot run (Macbook M1)

I figure this is related to having an M1, any ideas?

╭─ericjohnson@ej-mba-m1 ~
╰─$ npm install -g layout-shift-gif

added 126 packages, and audited 127 packages in 15s

11 packages are looking for funding
run npm fund for details

found 0 vulnerabilities
╭─ericjohnson@ej-mba-m1 ~
╰─$ layout-shift-gif --url https://blacklivesmatter.com/ --device mobile --output layout-shift.gif
TimeoutError: Timed out after 10000 ms while trying to connect to the browser! Only Chrome at revision r869685 is guaranteed to work.
at Timeout.onTimeout (/opt/homebrew/lib/node_modules/layout-shift-gif/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:205:20)

Add output to a text file with full css paths to affected divs.

For analyzing which divs specifically are affected it would be helpful if a full css selector to the div that has changed could be included in the output.

Something like body > div > div.foobar > div > span:nth-child(10)
It makes finding the affected elements much easier.

Include Readme and explanation of colors/border styles

While using the tool, I am presented with information about the CLS on the page via colored rectangles (I have seen green and orange) that animate by either popping into the gif or having their border-style change (from solid to dashed or vice versa).

What do the different colors and border styles indicate?

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.