-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.js
31 lines (21 loc) · 868 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const puppeteer = require('puppeteer');
const filesize = require('filesize');
const fs = require('fs').promises;
const { getHeapSnapshot } = require('../index');
init();
async function init() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://yonatan.dev');
const client = await page.target().createCDPSession();
const chunks = [];
client.on('HeapProfiler.addHeapSnapshotChunk', ({ chunk }) => {
chunks.push(chunk);
});
await client.send('HeapProfiler.takeHeapSnapshot', { reportProgress: false });
const heapSnapshot = await getHeapSnapshot(chunks);
console.log(filesize(heapSnapshot.totalSize));
await fs.writeFile('Heap.heapsnapshot', chunks.join(''));
// you can load `Heap.heapsnapshot` in Chrome's Memory tab to review the snapshot manually
await browser.close();
}