Unable to connect Lighthouse to a remote browser
See original GitHub issueIssue: unable to connect Lighthouse to a remote browser. Description:
I’m trying to connect Lighthouse to a remote chromium or chrome. While Playwright and Puppeteer can successfully connect to it, Lighthouse is returning a connection error:
I’ve also tried different lighthouse hostnames and ports:
hostname: `ws://my-moon-server-ip:4444/playwright/chromium`;
Hostname: `ws://my-moon-server-ip:4444/devtools/chrome-87-0-f81f52b1-231c-4ea9-9bdf-e927d1ea0769`;
port: 4444
I had similar error, eg:
Lighthouse is connecting only on local browser, eg:
const browser = await playwright.chromium.launch({ args: ['--remote-debugging-port=9222'], });
I think I’m missing some step. How do I properly connect Lighthouse to a remote browser?
Thanks in advance.
Check the code
const lighthouse = require('lighthouse');
const puppeteer = require('puppeteer');
const reportGenerator = require('lighthouse/lighthouse-core/report/report-generator');
const playwright = require('playwright');
const fs = require('fs');
const driver = require('../../lib/utils/driver');
const run = async () => {
try {
const testUrl = 'http://google.com';
const MOON_HOST = 'my-moon-server-ip';
const MOON_PORT = 4444;
const playwrightUrl = `ws://${MOON_HOST}:${MOON_PORT}/playwright/chromium`;
const chromeSessionID = await driver.getSession();
const devtoolsUrl = `ws://${MOON_HOST}:${MOON_PORT}/devtools/${chromeSessionID}`;
let options = {
// hostname: devtoolsUrl,
// hostname: playwrightUrl,
// port: 4444,
logLevel: 'info',
disableDeviceEmulation: true,
chromeFlags: [
'--no-sandbox',
'--headless',
'--disable-dev-shm-usage',
'--disable-mobile-emulation',
'--ignore-certificate-errors',
],
};
// REMOTE playwright eg.
const browserPlaywright = await playwright.chromium.connect({
wsEndpoint: playwrightUrl,
});
// REMOTE puppeteer eg.
const browserPuppeteer = await puppeteer.connect({
browserWSEndpoint: devtoolsUrl,
});
// LOCAL
const browser = await playwright.chromium.launch({
args: ['--remote-debugging-port=9222'],
});
const page = await browser.newPage();
await page.goto(testUrl);
await page.screenshot({ path: 'output/screenshot.png' });
// Run Lighthouse
const { lhr } = await lighthouse(testUrl, options);
await browser.close();
const report = reportGenerator.generateReport(lhr, 'json');
fs.writeFileSync('./output/lighthouse-report.json', report);
} catch (err) {
console.log(err);
}
};
run();
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
GoogleChrome/lighthouse - Gitter
I am using chrome-aws-lambda and I keep getting ECONNREFUSED error at the lighthouse(url, options, config) step. Error: connect ECONNREFUSED 127.0.0.1:9222 ...
Read more >Run Google Lighthouse on Debian server - Stack Overflow
I'm trying to get Google Lighthouse CLI work on my Debian server. I use the following instruction to run headless Chrome: ...
Read more >Cross-tenant management experiences - Azure Lighthouse
Azure Lighthouse enables and enhances cross-tenant experiences in many Azure services.
Read more >Using Google Lighthouse to audit your web application
We will look at how you can use Google Lighthouse to effectively assess the performance of your web application and deliver a superior...
Read more >How do I access Managed Device console ports via ...
Providing secure remote access to serial and USB ports of connected Managed Devices is a key feature of Opengear Nodes. Lighthouse...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you already tried the below?
I can’t imagine any other variation working successfully, so I’d start there 😃
Ah, so Moon isn’t actually a remote browser. The short answer is you can’t do this yet without writing a custom browser connection class that looks like https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/gather/connections/cri.js#L83 (or you implementing some proxy layer to translate Moon). Lighthouse is written to communicate with Chrome and not a generic browser or WebDriver API.
#11313 will make this possible to just use your puppeteer page, but for now it’s fairly custom.