Skip to content

Instantly share code, notes, and snippets.

@paulirish
Last active January 20, 2023 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulirish/be0d71ec65696c1384b414dd7c4a66ac to your computer and use it in GitHub Desktop.
Save paulirish/be0d71ec65696c1384b414dd7c4a66ac to your computer and use it in GitHub Desktop.
Generate Lighthouse script from Recorder panel
/**
* To use:
* Export a Recording panel recording as JSON. Run this:
* node generate-pptr-lh-script-from-json.mjs yourjson.json
* It'll save a `yourjson.json.pptr.js`
* That script is dependent on:
* lighthouse@9.5.0-dev.20221024
* puppeteer@19.4.1
* Run that script. It'll save a `flow.report.html`. View that.
* It's one of these: https://web.dev/lighthouse-user-flows/
*/
import fs from 'node:fs';
import {stringify, LighthouseStringifyExtension} from '@puppeteer/replay';
const filename = process.argv[2];
const flow = JSON.parse(fs.readFileSync(filename, 'utf-8'));
const scriptContents = await stringify(flow, {
extension: new LighthouseStringifyExtension(),
});
fs.writeFileSync(`${filename}.pptr.cjs`, scriptContents, 'utf-8');
console.log('Puppeteer+Lighthouse script written to: ', `${filename}.pptr.cjs`);
@paulirish
Copy link
Author

And sneak peek.. but soon, there will be a new option in the Recorder panel which will replace this gist and directly provide you the yourrecording.pptr.js script:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment