Last active
January 20, 2023 21:25
-
-
Save paulirish/be0d71ec65696c1384b414dd7c4a66ac to your computer and use it in GitHub Desktop.
Generate Lighthouse script from Recorder panel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: