Skip to content

Commit

Permalink
Add hostname CLI flag and option for CriConnection (#2728)
Browse files Browse the repository at this point in the history
* fixes #2727
hostname expressed as second parameter to avoid breaking existing
implementations
  • Loading branch information
FrederickGeek8 authored and paulirish committed Aug 14, 2017
1 parent e72483b commit 0455283
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lighthouse-cli/cli-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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
logLevel: string, hostname: string
}

export function getFlags(manualArgv?: string) {
Expand Down Expand Up @@ -54,7 +54,7 @@ export function getFlags(manualArgv?: string) {
[
'save-assets', 'save-artifacts', 'list-all-audits', 'list-trace-categories',
'additional-trace-categories', 'config-path', 'chrome-flags', 'perf', 'port',
'max-wait-for-load'
'hostname', 'max-wait-for-load'
],
'Configuration:')
.describe({
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',
'hostname': 'The hostname to use for the debugging protocol.',
'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('hostname', '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
11 changes: 6 additions & 5 deletions lighthouse-core/gather/connections/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ 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) {
super();

this.port = port || DEFAULT_PORT;
this.port = port;
this.hostname = hostname;
}

/**
Expand Down Expand Up @@ -77,7 +78,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.hostname);

// kick off a lighthouse run
return Runner.run(connection, {url, flags, config})
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Configuration:
[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]
--hostname The hostname to use for the debugging protocol. [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

0 comments on commit 0455283

Please sign in to comment.