-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using lighthouse in combination with Puppeteer #4403
Comments
This should work: const chromeLauncher = require('chrome-launcher');
const puppeteer = require('puppeteer');
const lighthouse = require('lighthouse');
const request = require('request');
const util = require('util');
(async() => {
const URL = 'https://www.chromestatus.com/features';
const opts = {
//chromeFlags: ['--headless'],
logLevel: 'info',
output: 'json'
};
// Launch chrome using chrome-launcher.
const chrome = await chromeLauncher.launch(opts);
opts.port = chrome.port;
// Connect to it using puppeteer.connect().
const resp = await util.promisify(request)(`http://localhost:${opts.port}/json/version`);
const {webSocketDebuggerUrl} = JSON.parse(resp.body);
const browser = await puppeteer.connect({browserWSEndpoint: webSocketDebuggerUrl});
// Run Lighthouse.
const lhr = await lighthouse(URL, opts, null);
console.log(`Lighthouse score: ${lhr.score}`);
await browser.disconnect();
await chrome.kill();
})(); |
Hey @ebidel thank you very much, this is perfect. I couldn't find this snippet in the doc, did I miss it ? Should I make a PR to add it ? |
@Antonhansel what's the use case for using chrome-launcher? Why not just launch chrome using puppeteer? |
Got a PR up: #4408 |
Good |
@ebidel can I use Java to achieve same results as per solution you had provided ? |
Not sure. All of these projects are Node-based. |
When I run the code, I get the following error:
Not sure how to solve this issue... |
@tsenguunchik that seems like an old chrome version, see puppeteer/puppeteer#2700 |
@ebidel I've seen your puppeteer in conjunction with lighthouse, and I've written to find that lighthouse runs console. log (lhr. score) and the result is undefined |
There's no longer an overall score in the lighthouse results object. |
@ebidel oh! But how do I feel about using the lighthouse command line tool or using the lighthouse test project in the project and how do I feel about the results that I test with the Google Extension Tool and generally have a greater number than the lighthouse test with the Google Extension Tool? How to format config, for example, I want to configure userAgent. |
Sorry, I'm not really sure what you're asking. The DevTools integration has some setting customizations, bur if you want more configuration control over runs, the CLI is your best option. |
@ebidel If I want to customize the configuration of test items and browser's userAgent, what is the configuration format? |
@ebidel Hello, I introduced lighthouse to test github.com in my own project, but the final report data and the results obtained by testing with Google Extension Tool are inconsistent. Why? |
https://github.com/GoogleChrome/lighthouse/blob/master/docs/puppeteer.md and this https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/auth and #9722 (not landed yet) do we need anything else to close this? |
Hey @connorjclark Thank you for handling this 👍 👏 |
Hello,
I'm would like to launch a chrome instance, connect
puppeteer
to it to login, and then startlighthouse
, is that possible ? I couldn't find a way to connectpuppeteer
to a chrome instance started withchrome-launcher
.I've tried something like this but with no success
because I'm missing the browser id after
browser/
and it doesn't seem to be exposed bylighthouse
I've seen issues where it says to manually connect before running
lighthouse
on a website where login is mandatory. Is there any other fully automated way to do this ?The text was updated successfully, but these errors were encountered: