如何在桌面模式下运行 lighthouse-puppeteer?
我正在尝试使用灯塔的基本代码进行测试。 但如果我运行此代码,则会显示“移动”模式。(m.naver.com) (我写了一个“www.naver.com”,但是,m.naver.com 被重定向)
我想在桌面上运行。我在哪里修改代码? 我尽力寻找解决方案,但我做不到。所以请分享您的解决方案。谢谢。
代码主页: https://github.com/addyosmani/puppeteer-webperf
import lighthouse from 'lighthouse';
import puppeteer from 'puppeteer';
import chromeLauncher from 'chrome-launcher';
import reportGenerator from 'lighthouse/report/generator/report-generator.js';
import request from 'request';
import util from 'util';
import fs from 'fs';
const options = {
logLevel: 'info',
disableDeviceEmulation: true,
chromeFlags: ['--emulated-form-factor=desktop']
};
async function lighthouseFromPuppeteer(url, options, config = null) {
// Launch chrome using chrome-launcher
const chrome = await chromeLauncher.launch(options);
options.port = chrome.port;
// Connect chrome-launcher to puppeteer
const resp = await util.promisify(request)(`http://localhost:${options.port}/json/version`);
const { webSocketDebuggerUrl } = JSON.parse(resp.body);
const browser = await puppeteer.connect({ browserWSEndpoint: webSocketDebuggerUrl });
// Run Lighthouse
const { lhr } = await lighthouse(url, options, config);
await browser.disconnect();
await chrome.kill();
const html = reportGenerator.generateReport(lhr, 'html');
fs.writeFile('report.html', html, function (err) {
if (err) throw err;
});
const json = reportGenerator.generateReport(lhr, 'json');
const audits = JSON.parse(json).audits; // Lighthouse audits
const first_contentful_paint = audits['first-contentful-paint'].displayValue;
const total_blocking_time = audits['total-blocking-time'].displayValue;
const time_to_interactive = audits['interactive'].displayValue;
console.log(`\n
Lighthouse metrics:
I'm trying to test using this basic code of lighthouse.
but If I run this code, There are shown with "Mobile" mode.(m.naver.com)
(I wrote a "www.naver.com" but, m.naver.com was redirected)
I want to run at Desktop. Where do I revise the code?
I try to do my best to find a solution, but I couldn't. So Please share your solution. Thanks.
code homepage : https://github.com/addyosmani/puppeteer-webperf
import lighthouse from 'lighthouse';
import puppeteer from 'puppeteer';
import chromeLauncher from 'chrome-launcher';
import reportGenerator from 'lighthouse/report/generator/report-generator.js';
import request from 'request';
import util from 'util';
import fs from 'fs';
const options = {
logLevel: 'info',
disableDeviceEmulation: true,
chromeFlags: ['--emulated-form-factor=desktop']
};
async function lighthouseFromPuppeteer(url, options, config = null) {
// Launch chrome using chrome-launcher
const chrome = await chromeLauncher.launch(options);
options.port = chrome.port;
// Connect chrome-launcher to puppeteer
const resp = await util.promisify(request)(`http://localhost:${options.port}/json/version`);
const { webSocketDebuggerUrl } = JSON.parse(resp.body);
const browser = await puppeteer.connect({ browserWSEndpoint: webSocketDebuggerUrl });
// Run Lighthouse
const { lhr } = await lighthouse(url, options, config);
await browser.disconnect();
await chrome.kill();
const html = reportGenerator.generateReport(lhr, 'html');
fs.writeFile('report.html', html, function (err) {
if (err) throw err;
});
const json = reportGenerator.generateReport(lhr, 'json');
const audits = JSON.parse(json).audits; // Lighthouse audits
const first_contentful_paint = audits['first-contentful-paint'].displayValue;
const total_blocking_time = audits['total-blocking-time'].displayValue;
const time_to_interactive = audits['interactive'].displayValue;
console.log(`\n
Lighthouse metrics:
???? First Contentful Paint: ${first_contentful_paint},
⌛️ Total Blocking Time: ${total_blocking_time},
???? Time To Interactive: ${time_to_interactive}`);
}
lighthouseFromPuppeteer("https://www.naver.com", options);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)