能否在Chrome DevTools设置自定义CPU节流?含Lighthouse参数验证咨询
Great question! Let's break down your concerns one by one:
1. Does Chrome 63's DevTools Performance panel support custom CPU throttling (like 20x)?
Out of the box, Chrome 63's Performance panel only offers the three preset options: No throttling, 4x slowdown, and 6x slowdown. There's no native UI to input a custom multiplier like 20x directly in the panel.
2. Can custom throttling be achieved via chrome.exe launch flags or Node.js libraries?
Chrome.exe launch flags
Unfortunately, there's no direct launch flag in Chrome 63 to set a custom CPU throttling multiplier. Flags like --force-low-power-mode or --disable-highres-timers affect performance in general but don't let you specify an exact 20x slowdown.
Node.js libraries (e.g., Puppeteer)
Yes, you can use Puppeteer (a Node.js library that controls Chrome via the DevTools Protocol) to set any custom CPU throttling rate. Note that you'll need a Puppeteer version compatible with Chrome 63 (likely Puppeteer v1.x, since newer versions require newer Chrome builds).
Here's a quick example:
const puppeteer = require('puppeteer'); (async () => { // Launch Chrome 63 (specify executable path if needed) const browser = await puppeteer.launch({ executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe', headless: false, // Open visible browser to verify defaultViewport: null }); const page = await browser.newPage(); // Set 20x CPU throttling await page.emulateCPUThrottling(20); // Navigate to your test page await page.goto('https://example.com'); // Run your tests or record performance profiles here // ... await browser.close(); })();
3. How to verify if Lighthouse's modified CPU_THROTTLE_METRICS (set to 20) is working?
If you've modified Lighthouse's default CPU_THROTTLE_METRICS from 4 to 20, here are three reliable ways to confirm it's active:
- Check verbose logs: Run Lighthouse with the
--verboseflag. Look for a log line likeCPU throttling rate: 20—this confirms the multiplier was applied. - Inspect the Lighthouse report JSON: Export the report as JSON (using
--output jsonflag) and look for theconfigSettings.cpuThrottlingMultiplierfield. It should show20. - Manual performance validation: Record a Performance profile while Lighthouse runs. Compare the execution time of key tasks (e.g., script evaluation, layout) against a non-throttled run. A task that takes 100ms normally should take ~2000ms with 20x throttling, which confirms the setting is working.
内容的提问来源于stack exchange,提问作者ScriptyChris

