Skip to content
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

Add chrome hostname to CriConnection & eslint fix #2728

Merged
merged 9 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lighthouse-cli/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const Driver = require('../lighthouse-core/gather/driver.js');
import {GetValidOutputOptions, OutputMode} from './printer';

export interface Flags {
port: number, chromeFlags: string, output: any, outputPath: string, interactive: boolean,
saveArtifacts: boolean, saveAssets: boolean, view: boolean, maxWaitForLoad: number,
logLevel: string
port: number, chromeFlags: string, output: any, outputPath: string,
interactive: boolean, saveArtifacts: boolean, saveAssets: boolean, view: boolean,
maxWaitForLoad: number, logLevel: string, host: string
}

export function getFlags(manualArgv?: string) {
Expand Down Expand Up @@ -53,7 +53,7 @@ export function getFlags(manualArgv?: string) {
.group(
[
'save-assets', 'save-artifacts', 'list-all-audits', 'list-trace-categories',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port', 'host',
'max-wait-for-load'
],
'Configuration:')
Expand All @@ -77,6 +77,7 @@ export function getFlags(manualArgv?: string) {
CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
`,
'perf': 'Use a performance-test-only configuration',
'host': 'The host to use for the debugging protocol.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should copy this to https://github.com/GoogleChrome/lighthouse/blob/master/readme.md#cli-options, too (like #2757 just did for CHROME_PATH)

'port': 'The port to use for the debugging protocol. Use 0 for a random port',
'max-wait-for-load':
'The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue. WARNING: Very high values can lead to large traces and instability',
Expand Down Expand Up @@ -107,6 +108,7 @@ Example: --output-path=./lighthouse-results.html`,
.default('disable-cpu-throttling', false)
.default('output', GetValidOutputOptions()[OutputMode.domhtml])
.default('port', 0)
.default('host', 'localhost')
.default('max-wait-for-load', Driver.MAX_WAIT_FOR_FULLY_LOADED)
.check((argv: {listAllAudits?: boolean, listTraceCategories?: boolean, _: Array<any>}) => {
// Make sure lighthouse has been passed a url, or at least one of --list-all-audits
Expand Down
9 changes: 4 additions & 5 deletions lighthouse-core/gather/connections/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ const WebSocket = require('ws');
const http = require('http');
const log = require('lighthouse-logger');

const hostname = 'localhost';
const DEFAULT_HOSTNAME = 'localhost';
const CONNECT_TIMEOUT = 10000;
const DEFAULT_PORT = 9222;

class CriConnection extends Connection {
/**
* @param {number=} port Optional port number. Defaults to 9222;
* @param {string=} hostname Optional hostname. Defaults to localhost.
* @constructor
*/
constructor(port) {
constructor(port = DEFAULT_PORT, hostname = DEFAULT_HOSTNAME) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these still need to be saved on this.port and this.hostname (cause of the test failures)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad...

super();

this.port = port || DEFAULT_PORT;
}

/**
Expand Down Expand Up @@ -77,7 +76,7 @@ class CriConnection extends Connection {
_runJsonCommand(command) {
return new Promise((resolve, reject) => {
const request = http.get({
hostname: hostname,
hostname: this.hostname,
port: this.port,
path: '/json/' + command
}, response => {
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = function(url, flags = {}, configJSON) {
// Use ConfigParser to generate a valid config file
const config = new Config(configJSON, flags.configPath);

const connection = new ChromeProtocol(flags.port);
const connection = new ChromeProtocol(flags.port, flags.host);

// kick off a lighthouse run
return Runner.run(connection, {url, flags, config})
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-viewer/app/src/github-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ class GithubApi {
const filename = Object.keys(json.files)
.find(filename => filename.endsWith(GithubApi.LH_JSON_EXT));
if (!filename) {
throw new Error(`Failed to find a Lighthouse report (*${GithubApi.LH_JSON_EXT}) in gist ${id}`);
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this change from the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was to fix a conflict that was introduced from a different PR somewhere along the road.

`Failed to find a Lighthouse report (*${GithubApi.LH_JSON_EXT}) in gist ${id}`
);
}
const f = json.files[filename];
if (f.truncated) {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Configuration:
http://peter.sh/experiments/chromium-command-line-switches/. [default: ""]
--perf Use a performance-test-only configuration [boolean]
--port The port to use for the debugging protocol. Use 0 for a random port [default: 9222]
--host The host to use for the debugging protocol.
host [default: localhost]
--max-wait-for-load The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue.
WARNING: Very high values can lead to large traces and instability [default: 25000]

Expand Down