Skip to content

Commit

Permalink
Enable disabling network throttling.
Browse files Browse the repository at this point in the history
Due to some oddness of how chrome handles h2 and h2 push when network
throttling is enabled, it is useful to be able to disable this.

To accomplish this goal, I added a new flag to the CLI, and then
modified the driver classes to take an options value and store it on the
class instance. The options are proxied down from the CLI flags ... into
the core lighthouse module and then directly into cri driver
constructor.
  • Loading branch information
samccone committed Oct 19, 2016
1 parent 9969f3a commit f6bc48e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lighthouse-cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const cli = yargs
'list-all-audits',
'list-trace-categories',
'config-path',
'perf'
'perf',
'disable-network-throttling',
], 'Configuration:')
.describe({
'mobile': 'Emulates a Nexus 5X',
Expand All @@ -74,6 +75,7 @@ const cli = yargs
'perf': 'Use a performance-test-only configuration',
'skip-autolaunch': 'Skip autolaunch of chrome when accessing port 9222 fails',
'select-chrome': 'Choose chrome location to use when multiple installations are found',
'disable-network-throttling': 'Disable network throttling when running audits.',
})

.group([
Expand Down Expand Up @@ -161,7 +163,7 @@ const cleanup = {
}
};

function launchChromeAndRun(addresses) {
function launchChromeAndRun(addresses: Array<string>) {
const launcher = new ChromeLauncher({
autoSelectChrome: !cli.selectChrome,
});
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/drivers/cri.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const port = process.env.PORT || 9222;
const log = require('../../lib/log.js');

class CriDriver extends Driver {
constructor() {
super();
constructor(opts) {
super(opts);

/**
* Chrome remote interface instance.
Expand Down
17 changes: 14 additions & 3 deletions lighthouse-core/gather/drivers/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ const PAUSE_AFTER_LOAD = 500;

class Driver {

constructor() {
constructor(opts) {
opts = opts || {};

this.disableNetworkThrottling = opts._disableNetworkThrottling || false;

this._traceEvents = [];
this._traceCategories = Driver.traceCategories;
this._eventEmitter = null;
this.opts = opts;
}

static get traceCategories() {
Expand Down Expand Up @@ -492,7 +497,13 @@ class Driver {
beginEmulation() {
return Promise.all([
emulation.enableNexus5X(this),
emulation.enableNetworkThrottling(this)
() => {
if (this.opts['disable-network-throttling']) {
return Promise.resolve();
}

return emulation.enableNetworkThrottling();
}
]);
}

Expand All @@ -512,7 +523,7 @@ class Driver {
*/
goOnline(options) {
return this.sendCommand('Network.enable').then(_ => {
if (options.flags.mobile) {
if (options.flags.mobile && !this.opts['disable-network-throttling']) {
return emulation.enableNetworkThrottling(this);
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/drivers/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const EventEmitter = require('events').EventEmitter;

class ExtensionDriver extends Driver {

constructor() {
super();
constructor(opts) {
super(opts);
this._tabId = null;

this._eventEmitter = new EventEmitter();
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = function(url, flags, configJSON) {
// Use ConfigParser to generate a valid config file
const config = new Config(configJSON, flags.configPath);

const driver = new ChromeProtocol();
const driver = new ChromeProtocol(flags);

// kick off a lighthouse run
resolve(Runner.run(driver, {url, flags, config}));
Expand Down

0 comments on commit f6bc48e

Please sign in to comment.