• Stars
    star
    1,346
  • Rank 34,902 (Top 0.7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

API and CLI tool to fetch and query Chome DevTools heap snapshots.

Puppeteer Heap Snapshot

Capture heap snapshots and query the snapshot for objects matching a set of properties. Read more about it in this blog post.

Install

Install via npm/yarn.

$ npm install puppeteer-heap-snapshot

API

captureHeapSnapshot(target: Puppeteer.Target): HeapSnapshot

Capture a heap snapshot from a Puppeteer page target (obtained via await page.target()). Warning: this data structure can grow very large (1mb - 250mb or more) so be sure you have enough memory available.

Example:

const browser = await Puppeteer.launch();
const page = await browser.newPage();

await page.goTo("https://google.com")

const heapSnapshot = await captureHeapSnapshot(await page.target());

findObjectsWithProperties(heapSnapshot: HeapSnapshot, properties: string[], options?: { ignoreProperties?: string[] }): BuiltHeapValue[]

Find objects in the heap snapshot that include a set of properties. This operation is computationally expensive traversing the large heap snapshot graph and may be slow. To improve performance, you can specify a list of properties in ignoreProperties to skip traversing and serialization. These properties will not be present on the result.

const objects = findObjectsWithProperties(heapSnapshot, ["foo", "bar"]);

// objects = [{
//   "foo": true,
//   "bar": false,
//   "baz": "lorem ipsum"
// }]

Warning: this code is not optimized and may be slow if many objects match your query and/or the matching objects are large.

findObjectWithProperties(heapSnapshot: HeapSnapshot, properties: string[], options?: { ignoreProperties?: string[] }): BuiltHeapValue[]

Identical to findObjectsWithProperties except it throws an error if no object found or more than one object found.

CLI

This package comes with a small CLI that allows you to fetch heap snapshots for URLs and run queries on them.

$ npx puppeteer-heap-snapshot --help
Usage: puppeteer-heap-snapshot [options] [command]

Options:
  --debug               Enable debug mode (non-headless Chrome, debug logging)
  --no-headless         Do not run Chrome in headless mode
  -w, --wait <timeout>  Add a wait time before taking a heap snapshot (default: "10000")
  -h, --help            display help for command

Commands:
  fetch [options]       fetch a heap snapshot for a URL and write to a file
  query [options]       fetch/read a heap snapshot and output the matching objects in JSON
  help [command]        display help for command

For example, fetch from a URL and output matching objects:

$ npx puppeteer-heap-snapshot query -u https://www.instagram.com/p/CVEJmFTgdRw/ -p video_view_count,video_play_count,shortcode,video_url --no-headless | jq .
>> Opening Puppeteer page at: https://www.instagram.com/p/CVEJmFTgdRw/
>> Taking heap snapshot..
[
  {
    "__typename": "GraphVideo",
    "id": "2685313477274358896",
    "shortcode": "CVEJmFTgdRw",
    "dimensions": {
      "height": 1138,
      "width": 640
    },
    "has_audio": true,
    "video_url": "https://scontent-dub4-1.cdninstagram.com/v/t50.2886-16/245967496_255835479890012_5087347215509320349_n.mp4?efg=eyJ2ZW5jb2RlX3RhZyI6InZ0c192b2RfdXJsZ2VuLjY0MC5jbGlwcy5iYXNlbGluZSIsInFlX2dyb3VwcyI6IltcImlnX3dlYl9kZWxpdmVyeV92dHNfb3RmXCJdIn0&_nc_ht=scontent-dub4-1.cdninstagram.com&_nc_cat=108&_nc_ohc=rWf9nUMf15MAX-SnjOC&edm=AABBvjUBAAAA&vs=1007318140116355_4062183883&_nc_vs=HBksFQAYJEdJZ3FxUTVjV09aV3J1Z0FBSjF5Z2ExVzQ1bEdicV9FQUFBRhUAAsgBABUAGCRHSnZtbmc0SUxSVkZlNDBLQU54WGpxeTVyR2M4YnFfRUFBQUYVAgLIAQAoABgAGwAVAAAm6q%2FRme3ItUAVAigCQzMsF0A35mZmZmZmGBJkYXNoX2Jhc2VsaW5lXzFfdjERAHX%2BBwA%3D&ccb=7-4&oe=626815EC&oh=00_AT_n_BkYsvtICC3t_C2HlRaILWv4xsqZAjcZKcRoR36fng&_nc_sid=83d603",
    "video_view_count": 1728940,
    "video_play_count": 3612084,
    "is_video": true,
    "tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjp0cnVlLCJ1dWlkIjoiYjNmNGRlYjAxMzk1NGZhM2FmNmQ1OWY1YTUwYzEzZmEyNjg1MzEzNDc3Mjc0MzU4ODk2In0sInNpZ25hdHVyZSI6IiJ9",
    "upcoming_event": null,
    "edge_media_to_tagged_user": {
      "edges": []
    },
    "edge_media_to_caption": {
      "edges": [
        {
          "node": {
            "created_at": "1634334356",
            "text": "You can feel the pain through that facial expression! 梁\n @jago.artist\nRome, Italy"
          }
        }
      ]
    },
    "can_see_insights_as_brand": false,
    "caption_is_edited": false,
    "has_ranked_comments": false,
    "like_and_view_counts_disabled": false,
    "comments_disabled": false,
    "commenting_disabled_for_viewer": false,
    "taken_at_timestamp": 1634334355,
    "edge_media_preview_like": {
      "count": 166233,
      "edges": []
    },
    "edge_media_to_sponsor_user": {
      "edges": []
    },
    "is_affiliate": false,
    "is_paid_partnership": false,
    "location": null,
    "nft_asset_info": null,
    "viewer_has_liked": false,
    "viewer_has_saved": false,
    "viewer_has_saved_to_collection": false,
    "viewer_in_photo_of_you": false,
    "viewer_can_reshare": true,
    "owner": {
      "id": "303273692",
      "is_verified": false,
      "profile_pic_url": "https://scontent-dub4-1.cdninstagram.com/v/t51.2885-19/277325903_668349461072817_8676852949764101515_n.jpg?stp=dst-jpg_s150x150&_nc_ht=scontent-dub4-1.cdninstagram.com&_nc_cat=1&_nc_ohc=kh9ga1KrRAMAX9grvVd&edm=AABBvjUBAAAA&ccb=7-4&oh=00_AT_cEiCoW8MI44lLvf9UAyzlx0oFE2nOBKb1fz5egVb36g&oe=626CCED0&_nc_sid=83d603",
      "username": "earthpix",
      "blocked_by_viewer": false,
      "restricted_by_viewer": null,
      "followed_by_viewer": false,
      "full_name": "  EarthPix  ",
      "has_blocked_viewer": false,
      "is_embeds_disabled": false,
      "is_private": false,
      "is_unpublished": false,
      "requested_by_viewer": false,
      "pass_tiering_recommendation": true,
      "edge_owner_to_timeline_media": {
        "count": 8690
      },
      "edge_followed_by": {
        "count": 23020451
      }
    },
    "is_ad": false,
    "coauthor_producers": [],
    "pinned_for_users": [],
    "encoding_status": null,
    "is_published": true,
    "product_type": "clips",
    "title": "",
    "video_duration": 23.9,
    "thumbnail_src": "https://scontent-dub4-1.cdninstagram.com/v/t51.2885-15/245961614_4361781063908112_409992614002041515_n.jpg?stp=c0.249.640.640a_dst-jpg_e35&_nc_ht=scontent-dub4-1.cdninstagram.com&_nc_cat=100&_nc_ohc=n88eii2iM2gAX_UthWA&edm=AABBvjUBAAAA&ccb=7-4&oh=00_AT84-O-4_gUIoKKa2IfsGy4eiw3jCbO09oi4rLA5P_1Nvw&oe=6267DE3F&_nc_sid=83d603",
    // ... <snip>
  }
]

More Repositories

1

console.image

The one thing Chrome Dev Tools didn't need.
JavaScript
1,772
star
2

voyeur.js

Voyeur is a tiny (1.2kb) Javascript library that lets you traverse and manipulate the DOM the way it should have been.
JavaScript
731
star
3

Taskfile

Repository for the Taskfile template.
Shell
336
star
4

aristochart

Sophisticated and simplified Javascript 2D line charts.
JavaScript
246
star
5

console.snapshot

An actual useful fork of the console.image. Snapshot the canvas and output it to the console.
JavaScript
164
star
6

node-sfx

Add some sound effects to your node programs.
JavaScript
70
star
7

polytunes

Liberate your music library.
JavaScript
38
star
8

tinyrequire

To the point dependency management.
JavaScript
33
star
9

SKImport

Design and import your SKPhysicsBodys with a fancy editor and loader class.
JavaScript
19
star
10

benchmartian

Run Javascript benchmarks from the CLI.
JavaScript
15
star
11

SKMech

SKMech is a set of handy utilities for SpriteKit.
Objective-C
13
star
12

jQPad

jQPad's official repository
JavaScript
12
star
13

movie-plots

Literal movie plots.
JavaScript
7
star
14

gulp-js1k

Gulp plugin for js1k.
JavaScript
7
star
15

redux-pending

Redux middleware for async actions with pending state.
JavaScript
6
star
16

tw

Teamwork CLI and Node.js API
JavaScript
6
star
17

gulp-cache-money

A gulp caching system that saves to disk.
JavaScript
6
star
18

boh

A simple, smart build tool.
JavaScript
4
star
19

Javascript-Improved

My take on improving some of Javascript's functionality
JavaScript
4
star
20

json.stringify2

A 112% faster implementation of a stripped down native JSON.stringify.
JavaScript
4
star
21

wrestle

A simple REST API testing framework that works in the browser or the command line.
JavaScript
4
star
22

prompt

TypeScript
3
star
23

instate

A application state manager built for React.
JavaScript
3
star
24

bindings

Official bindings for µWebSockets
C++
3
star
25

examist

Final Year Project for NUI Galway CS&IT 2016.
HTML
3
star
26

Image-Filters

Learning image filtering with Javascript's canvas
2
star
27

chat-api-client

Javascript API for Teamwork Chat.
JavaScript
2
star
28

prettyearth-wallpapers

A quick script to download wallpapers all the beautiful places on earth from Google Maps.
JavaScript
2
star
29

chromecoms

Making messaging between content and background scripts manageable.
JavaScript
2
star
30

offlog

A standalone static blog generator in your browser.
JavaScript
1
star
31

history-of-ufc-fighters

http://adriancooney.github.io/history-of-ufc-fighters
JavaScript
1
star
32

Canvas.js

(Yet another) canvas drawing library
JavaScript
1
star
33

spook

HTML 5 Game for CT404.
JavaScript
1
star
34

noodlebox

Javascript toolbox.
JavaScript
1
star
35

When.js

Simple user friendly event managing.
JavaScript
1
star
36

gibingo

TypeScript
1
star
37

HandleDeleteButton

A small library to dynamically handle the iOS keyboard delete/backspace button.
Objective-C
1
star
38

prone

CLI tool to await for services to be up.
JavaScript
1
star
39

ct326-programming

Java
1
star
40

chat-bot-poker

Sprint Planning Poker Chat Bot
JavaScript
1
star
41

koamotive

The Koa Express. A Koa-Express hybrid.
JavaScript
1
star
42

chat-bot

Chat Bots
JavaScript
1
star
43

machine-learning-data-mining

Machine Learning & Data Mining
Jupyter Notebook
1
star
44

Playwrite.js

Writing english to do stuff.
JavaScript
1
star
45

massmural

CT231 project code. Please don't try to break it.
JavaScript
1
star
46

hinge

Hinge - A web server framework for Node.js
JavaScript
1
star