首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >灯塔默认给出移动端的性能评分,如何获得桌面端的性能评分?以编程方式使用节点模块

灯塔默认给出移动端的性能评分,如何获得桌面端的性能评分?以编程方式使用节点模块
EN

Stack Overflow用户
提问于 2020-07-03 18:30:21
回答 1查看 88关注 0票数 0

需要在下面的代码中添加什么参数才能获得Desktop的性能分数?

代码语言:javascript
复制
const fs = require('fs');
    const lighthouse = require('lighthouse');
    const chromeLauncher = require('chrome-launcher');
    const log = require('lighthouse-logger');
    
    
    (async () => {
        log.setLevel('info');
        const chrome = await chromeLauncher.launch({ chromeFlags: ['--headless'] });
        const options = { output: 'json', onlyCategories: ['performance'], port: chrome.port };
        const runnerResult = await lighthouse('url', options);
    
        // `.report` is the HTML report as a string
        const reportJson = runnerResult.report;
        fs.writeFileSync('lhreport.json', reportJson);
    
        // `.lhr` is the Lighthouse Result as a JS object
        console.log('Report is done for', runnerResult.lhr.finalUrl);
        console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
    
        await chrome.kill();
    })();
EN

回答 1

Stack Overflow用户

发布于 2020-11-23 19:28:58

在options对象中添加以下属性:

代码语言:javascript
复制
emulatedFormFactor: "desktop"
代码语言:javascript
复制
const options = { output: 'json', emulatedFormFactor:"desktop", vonlyCategories: ['performance'], port: chrome.port };
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62713535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档