diff --git a/docs/understanding-results.md b/docs/understanding-results.md index b23a15e8ccaf..8146d95aa0a4 100644 --- a/docs/understanding-results.md +++ b/docs/understanding-results.md @@ -13,8 +13,8 @@ The top-level Lighthouse Result object (LHR) is what the lighthouse node module | lighthouseVersion | The version of Lighthouse with which this result were generated. | | fetchTime | The ISO-8601 timestamp of when the result was generated. | | userAgent | The user agent string of the version of Chrome that was used by Lighthouse. | -| initialUrl | The URL that was supplied to Lighthouse and initially navigated to. | -| url | The URL that Lighthouse ended up auditing after redirects were followed. | +| requestedUrl | The URL that was supplied to Lighthouse and initially navigated to. | +| finalUrl | The URL that Lighthouse ended up auditing after redirects were followed. | | [audits](#audits) | An object containing the results of the audits. | | [runtimeConfig](#runtime-config) | An object containing information about the configuration used by Lighthouse. | | [timing](#timing) | An object containing information about how long Lighthouse spent auditing. | @@ -28,8 +28,8 @@ The top-level Lighthouse Result object (LHR) is what the lighthouse node module "lighthouseVersion": "2.4.0", "fetchTime": "2017-10-05T20:50:54.185Z", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3233.0 Safari/537.36", - "initialUrl": "http://example.com", - "url": "https://www.example.com/", + "requestedUrl": "http://example.com", + "finalUrl": "https://www.example.com/", "score": 50, "audits": {...}, "runtimeConfig": {...}, diff --git a/lighthouse-cli/test/smokehouse/a11y/expectations.js b/lighthouse-cli/test/smokehouse/a11y/expectations.js index 9f53b79dc1bc..77518a99c0e3 100644 --- a/lighthouse-cli/test/smokehouse/a11y/expectations.js +++ b/lighthouse-cli/test/smokehouse/a11y/expectations.js @@ -10,8 +10,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/a11y/a11y_tester.html', - url: 'http://localhost:10200/a11y/a11y_tester.html', + requestedUrl: 'http://localhost:10200/a11y/a11y_tester.html', + finalUrl: 'http://localhost:10200/a11y/a11y_tester.html', audits: { 'accesskeys': { score: 0, diff --git a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js index 52d6ee624473..520be08d425c 100644 --- a/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js +++ b/lighthouse-cli/test/smokehouse/byte-efficiency/expectations.js @@ -13,8 +13,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/byte-efficiency/tester.html', - url: 'http://localhost:10200/byte-efficiency/tester.html', + requestedUrl: 'http://localhost:10200/byte-efficiency/tester.html', + finalUrl: 'http://localhost:10200/byte-efficiency/tester.html', audits: { 'unminified-css': { extendedInfo: { diff --git a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js index eeaece514a9b..02c27886d141 100644 --- a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js +++ b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js @@ -10,8 +10,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html', - url: 'http://localhost:10200/dobetterweb/dbw_tester.html', + requestedUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html', + finalUrl: 'http://localhost:10200/dobetterweb/dbw_tester.html', audits: { 'errors-in-console': { score: 0, diff --git a/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js b/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js index 2866857a0d4e..5a9a54534414 100644 --- a/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js +++ b/lighthouse-cli/test/smokehouse/offline-local/offline-expectations.js @@ -12,8 +12,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/online-only.html', - url: 'http://localhost:10200/online-only.html', + requestedUrl: 'http://localhost:10200/online-only.html', + finalUrl: 'http://localhost:10200/online-only.html', audits: { 'is-on-https': { score: 1, @@ -105,8 +105,8 @@ module.exports = [ }, { - initialUrl: 'http://localhost:10503/offline-ready.html', - url: 'http://localhost:10503/offline-ready.html', + requestedUrl: 'http://localhost:10503/offline-ready.html', + finalUrl: 'http://localhost:10503/offline-ready.html', audits: { 'is-on-https': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/perf/expectations.js b/lighthouse-cli/test/smokehouse/perf/expectations.js index 50ff11f68bf5..fd579f083102 100644 --- a/lighthouse-cli/test/smokehouse/perf/expectations.js +++ b/lighthouse-cli/test/smokehouse/perf/expectations.js @@ -10,8 +10,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/preload.html', - url: 'http://localhost:10200/preload.html', + requestedUrl: 'http://localhost:10200/preload.html', + finalUrl: 'http://localhost:10200/preload.html', audits: { 'speed-index': { score: '>=0.80', @@ -56,8 +56,8 @@ module.exports = [ }, }, { - initialUrl: 'http://localhost:10200/perf/fonts.html', - url: 'http://localhost:10200/perf/fonts.html', + requestedUrl: 'http://localhost:10200/perf/fonts.html', + finalUrl: 'http://localhost:10200/perf/fonts.html', audits: { 'font-display': { score: 0, diff --git a/lighthouse-cli/test/smokehouse/pwa-expectations.js b/lighthouse-cli/test/smokehouse/pwa-expectations.js index 2d820f772b12..09b8d2e3fae5 100644 --- a/lighthouse-cli/test/smokehouse/pwa-expectations.js +++ b/lighthouse-cli/test/smokehouse/pwa-expectations.js @@ -11,8 +11,8 @@ */ module.exports = [ { - initialUrl: 'https://airhorner.com', - url: 'https://airhorner.com/', + requestedUrl: 'https://airhorner.com', + finalUrl: 'https://airhorner.com/', audits: { 'is-on-https': { score: 1, @@ -116,8 +116,8 @@ module.exports = [ }, { - initialUrl: 'https://www.chromestatus.com/', - url: 'https://www.chromestatus.com/features', + requestedUrl: 'https://www.chromestatus.com/', + finalUrl: 'https://www.chromestatus.com/features', audits: { 'is-on-https': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/pwa2-expectations.js b/lighthouse-cli/test/smokehouse/pwa2-expectations.js index d482f64a0e64..63530bd19473 100644 --- a/lighthouse-cli/test/smokehouse/pwa2-expectations.js +++ b/lighthouse-cli/test/smokehouse/pwa2-expectations.js @@ -11,8 +11,8 @@ */ module.exports = [ { - initialUrl: 'https://jakearchibald.github.io/svgomg/', - url: 'https://jakearchibald.github.io/svgomg/', + requestedUrl: 'https://jakearchibald.github.io/svgomg/', + finalUrl: 'https://jakearchibald.github.io/svgomg/', audits: { 'is-on-https': { score: 1, @@ -118,8 +118,8 @@ module.exports = [ }, { - initialUrl: 'https://shop.polymer-project.org/', - url: 'https://shop.polymer-project.org/', + requestedUrl: 'https://shop.polymer-project.org/', + finalUrl: 'https://shop.polymer-project.org/', audits: { 'is-on-https': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/pwa3-expectations.js b/lighthouse-cli/test/smokehouse/pwa3-expectations.js index ad7de011d2fa..3f3004ce39d3 100644 --- a/lighthouse-cli/test/smokehouse/pwa3-expectations.js +++ b/lighthouse-cli/test/smokehouse/pwa3-expectations.js @@ -11,8 +11,8 @@ */ module.exports = [ { - initialUrl: 'https://pwa.rocks', - url: 'https://pwa.rocks/', + requestedUrl: 'https://pwa.rocks', + finalUrl: 'https://pwa.rocks/', audits: { 'is-on-https': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/redirects/expectations.js b/lighthouse-cli/test/smokehouse/redirects/expectations.js index 085edd8e116e..459d7f33b662 100644 --- a/lighthouse-cli/test/smokehouse/redirects/expectations.js +++ b/lighthouse-cli/test/smokehouse/redirects/expectations.js @@ -12,8 +12,8 @@ const cacheBuster = Number(new Date()); module.exports = [ { - initialUrl: `http://localhost:10200/online-only.html?delay=500&redirect=%2Foffline-only.html%3Fcb=${cacheBuster}%26delay=500%26redirect%3D%2Fredirects-final.html`, - url: 'http://localhost:10200/redirects-final.html', + requestedUrl: `http://localhost:10200/online-only.html?delay=500&redirect=%2Foffline-only.html%3Fcb=${cacheBuster}%26delay=500%26redirect%3D%2Fredirects-final.html`, + finalUrl: 'http://localhost:10200/redirects-final.html', audits: { 'redirects': { score: '<1', @@ -27,8 +27,8 @@ module.exports = [ }, }, { - initialUrl: `http://localhost:10200/online-only.html?delay=300&redirect=%2Fredirects-final.html`, - url: 'http://localhost:10200/redirects-final.html', + requestedUrl: `http://localhost:10200/online-only.html?delay=300&redirect=%2Fredirects-final.html`, + finalUrl: 'http://localhost:10200/redirects-final.html', audits: { 'redirects': { score: 1, diff --git a/lighthouse-cli/test/smokehouse/seo/expectations.js b/lighthouse-cli/test/smokehouse/seo/expectations.js index 133a00476a77..3125cbc76101 100644 --- a/lighthouse-cli/test/smokehouse/seo/expectations.js +++ b/lighthouse-cli/test/smokehouse/seo/expectations.js @@ -33,8 +33,8 @@ const passHeaders = headersParam([[ */ module.exports = [ { - initialUrl: BASE_URL + 'seo-tester.html?' + passHeaders, - url: BASE_URL + 'seo-tester.html?' + passHeaders, + requestedUrl: BASE_URL + 'seo-tester.html?' + passHeaders, + finalUrl: BASE_URL + 'seo-tester.html?' + passHeaders, audits: { 'viewport': { score: 1, @@ -78,8 +78,8 @@ module.exports = [ }, }, { - initialUrl: BASE_URL + 'seo-failure-cases.html?status_code=403&' + failureHeaders, - url: BASE_URL + 'seo-failure-cases.html?status_code=403&' + failureHeaders, + requestedUrl: BASE_URL + 'seo-failure-cases.html?status_code=403&' + failureHeaders, + finalUrl: BASE_URL + 'seo-failure-cases.html?status_code=403&' + failureHeaders, audits: { 'viewport': { score: 0, diff --git a/lighthouse-cli/test/smokehouse/smokehouse.js b/lighthouse-cli/test/smokehouse/smokehouse.js index aaf213702690..8510b4c0bdb1 100755 --- a/lighthouse-cli/test/smokehouse/smokehouse.js +++ b/lighthouse-cli/test/smokehouse/smokehouse.js @@ -194,8 +194,8 @@ function findDifference(path, actual, expected) { /** * Collate results into comparisons of actual and expected scores on each audit. - * @param {{url: string, audits: !Array}} actual - * @param {{url: string, audits: !Array}} expected + * @param {{finalUrl: string, audits: !Array}} actual + * @param {{finalUrl: string, audits: !Array}} expected * @return {{finalUrl: !Object, audits: !Array}} */ function collateResults(actual, expected) { @@ -221,9 +221,9 @@ function collateResults(actual, expected) { return { finalUrl: { category: 'final url', - actual: actual.url, - expected: expected.url, - equal: actual.url === expected.url, + actual: actual.finalUrl, + expected: expected.finalUrl, + equal: actual.finalUrl === expected.finalUrl, }, audits: collatedAudits, }; @@ -316,10 +316,10 @@ const expectations = require(resolveLocalOrCwd(cli['expectations-path'])); let passingCount = 0; let failingCount = 0; expectations.forEach(expected => { - console.log(`Doing a run of '${expected.initialUrl}'...`); - const results = runLighthouse(expected.initialUrl, configPath, cli.debug); + console.log(`Doing a run of '${expected.requestedUrl}'...`); + const results = runLighthouse(expected.requestedUrl, configPath, cli.debug); - console.log(`Asserting expected results match those found. (${expected.initialUrl})`); + console.log(`Asserting expected results match those found. (${expected.requestedUrl})`); const collated = collateResults(results, expected); const counts = report(collated); passingCount += counts.passed; diff --git a/lighthouse-cli/test/smokehouse/tricky-tti/expectations.js b/lighthouse-cli/test/smokehouse/tricky-tti/expectations.js index dd4c539b2853..f63c66e6cc97 100644 --- a/lighthouse-cli/test/smokehouse/tricky-tti/expectations.js +++ b/lighthouse-cli/test/smokehouse/tricky-tti/expectations.js @@ -10,8 +10,8 @@ */ module.exports = [ { - initialUrl: 'http://localhost:10200/tricky-tti.html', - url: 'http://localhost:10200/tricky-tti.html', + requestedUrl: 'http://localhost:10200/tricky-tti.html', + finalUrl: 'http://localhost:10200/tricky-tti.html', audits: { 'first-cpu-idle': { score: '<75', diff --git a/lighthouse-core/audits/works-offline.js b/lighthouse-core/audits/works-offline.js index 4a5371384b88..17733b13744f 100644 --- a/lighthouse-core/audits/works-offline.js +++ b/lighthouse-core/audits/works-offline.js @@ -32,9 +32,9 @@ class WorksOffline extends Audit { let debugString; const passed = artifacts.Offline === 200; if (!passed && - !URL.equalWithExcludedFragments(artifacts.URL.initialUrl, artifacts.URL.finalUrl)) { + !URL.equalWithExcludedFragments(artifacts.URL.requestedUrl, artifacts.URL.finalUrl)) { debugString = 'WARNING: You may be failing this check because your test URL ' + - `(${artifacts.URL.initialUrl}) was redirected to "${artifacts.URL.finalUrl}". ` + + `(${artifacts.URL.requestedUrl}) was redirected to "${artifacts.URL.finalUrl}". ` + 'Try testing the second URL directly.'; } diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index 44e119116c1a..25d3a65c9812 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -19,7 +19,6 @@ module.exports = { networkQuietThresholdMs: 1000, cpuQuietThresholdMs: 1000, gatherers: [ - 'url', 'scripts', 'css-usage', 'viewport', diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index ef9848687e3d..0f47faa32cfa 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -81,7 +81,7 @@ class GatherRunner { /** * Loads options.url with specified options. If the main document URL * redirects, options.url will be updated accordingly. As such, options.url - * will always represent the post-redirected URL. options.initialUrl is the + * will always represent the post-redirected URL. options.requestedUrl is the * pre-redirect starting URL. * @param {Driver} driver * @param {LH.Gatherer.PassContext} passContext @@ -99,14 +99,14 @@ class GatherRunner { /** * @param {Driver} driver * @param {GathererResults} gathererResults - * @param {{url: string, settings: LH.Config.Settings}} options + * @param {{requestedUrl: string, settings: LH.Config.Settings}} options * @return {Promise} */ static setupDriver(driver, gathererResults, options) { log.log('status', 'Initializing…'); const resetStorage = !options.settings.disableStorageReset; // Enable emulation based on settings - return driver.assertNoSameOriginServiceWorkerClients(options.url) + return driver.assertNoSameOriginServiceWorkerClients(options.requestedUrl) .then(_ => driver.getUserAgent()) .then(userAgent => { gathererResults.UserAgent = [userAgent]; @@ -118,7 +118,7 @@ class GatherRunner { .then(_ => driver.registerPerformanceObserver()) .then(_ => driver.dismissJavaScriptDialogs()) .then(_ => { - if (resetStorage) return driver.clearDataForOrigin(options.url); + if (resetStorage) return driver.clearDataForOrigin(options.requestedUrl); }); } @@ -399,7 +399,7 @@ class GatherRunner { /** * @param {Array} passes - * @param {{driver: Driver, url: string, settings: LH.Config.Settings}} options + * @param {{driver: Driver, requestedUrl: string, settings: LH.Config.Settings}} options * @return {Promise} */ static run(passes, options) { @@ -414,6 +414,7 @@ class GatherRunner { const gathererResults = { LighthouseRunWarnings: [], fetchTime: [(new Date()).toJSON()], + URL: [{requestedUrl: options.requestedUrl, finalUrl: ''}], }; return driver.connect() @@ -422,10 +423,15 @@ class GatherRunner { // Run each pass .then(_ => { - // If the main document redirects, we'll update this to keep track - let urlAfterRedirects = options.url; return passes.reduce((chain, passConfig, passIndex) => { - const passContext = Object.assign({}, options, {passConfig}); + const passContext = { + driver: options.driver, + // If the main document redirects, we'll update this to keep track + url: options.requestedUrl, + settings: options.settings, + passConfig, + }; + return chain .then(_ => driver.setThrottling(options.settings, passConfig)) .then(_ => GatherRunner.beforePass(passContext, gathererResults)) @@ -441,12 +447,11 @@ class GatherRunner { } if (passIndex === 0) { - urlAfterRedirects = passContext.url; + // Copy redirected URL to artifact in the first pass only. + gathererResults.URL[0].finalUrl = passContext.url; } }); - }, Promise.resolve()).then(_ => { - options.url = urlAfterRedirects; - }); + }, Promise.resolve()); }) .then(_ => GatherRunner.disposeDriver(driver)) .then(_ => GatherRunner.collectArtifacts(gathererResults, tracingData, options.settings)) diff --git a/lighthouse-core/gather/gatherers/url.js b/lighthouse-core/gather/gatherers/url.js deleted file mode 100644 index 23911f13324b..000000000000 --- a/lighthouse-core/gather/gatherers/url.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @license Copyright 2016 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -const Gatherer = require('./gatherer'); - -class URL extends Gatherer { - /** - * @param {LH.Gatherer.PassContext} passContext - * @return {LH.Artifacts['URL']} - */ - afterPass(passContext) { - // Instead of the originally inputted URL (options.initialUrl), we want the resolved - // post-redirect URL (which is here at options.url) - return { - // @ts-ignore TODO(bckenny): fix url/initialUrl on passContext - initialUrl: passContext.initialUrl, - finalUrl: passContext.url, - }; - } -} - -module.exports = URL; diff --git a/lighthouse-core/lib/file-namer.js b/lighthouse-core/lib/file-namer.js index 6b1e513c1d86..f4671b8269d9 100644 --- a/lighthouse-core/lib/file-namer.js +++ b/lighthouse-core/lib/file-namer.js @@ -16,11 +16,11 @@ * Generate a filenamePrefix of hostname_YYYY-MM-DD_HH-MM-SS * Date/time uses the local timezone, however Node has unreliable ICU * support, so we must construct a YYYY-MM-DD date format manually. :/ - * @param {{url: string, fetchTime: string}} lhr + * @param {{finalUrl: string, fetchTime: string}} lhr * @return {string} */ function getFilenamePrefix(lhr) { - const hostname = new (getUrlConstructor())(lhr.url).hostname; + const hostname = new (getUrlConstructor())(lhr.finalUrl).hostname; const date = (lhr.fetchTime && new Date(lhr.fetchTime)) || new Date(); const timeStr = date.toLocaleTimeString('en-US', {hour12: false}); diff --git a/lighthouse-core/report/html/renderer/report-renderer.js b/lighthouse-core/report/html/renderer/report-renderer.js index 9ad97e5f1042..3e410ca310a6 100644 --- a/lighthouse-core/report/html/renderer/report-renderer.js +++ b/lighthouse-core/report/html/renderer/report-renderer.js @@ -59,8 +59,8 @@ class ReportRenderer { this._dom.find('.lh-config__timestamp', header).textContent = Util.formatDateTime(report.fetchTime); const url = this._dom.find('.lh-metadata__url', header); - url.href = report.url; - url.textContent = report.url; + url.href = report.finalUrl; + url.textContent = report.finalUrl; this._dom.find('.lh-env__item__ua', header).textContent = report.userAgent; @@ -259,8 +259,8 @@ ReportRenderer.GroupJSON; // eslint-disable-line no-unused-expressions * userAgent: string, * fetchTime: string, * timing: {total: number}, - * initialUrl: string, - * url: string, + * requestedUrl: string, + * finalUrl: string, * runWarnings: (!Array|undefined), * artifacts: {traces: {defaultPass: {traceEvents: !Array}}}, * audits: !Object, diff --git a/lighthouse-core/report/html/renderer/report-ui-features.js b/lighthouse-core/report/html/renderer/report-ui-features.js index ab07e52c76f7..5c67fee05e50 100644 --- a/lighthouse-core/report/html/renderer/report-ui-features.js +++ b/lighthouse-core/report/html/renderer/report-ui-features.js @@ -331,7 +331,7 @@ class ReportUIFeatures { */ _saveFile(blob) { const filename = getFilenamePrefix({ - url: this.json.url, + finalUrl: this.json.finalUrl, fetchTime: this.json.fetchTime, }); diff --git a/lighthouse-core/runner.js b/lighthouse-core/runner.js index 1ad6949a58c4..310c34f5cf59 100644 --- a/lighthouse-core/runner.js +++ b/lighthouse-core/runner.js @@ -24,7 +24,7 @@ const Connection = require('./gather/connections/connection.js'); // eslint-disa class Runner { /** * @param {Connection} connection - * @param {{config: LH.Config, url: string, initialUrl?: string, driverMock?: Driver}} opts + * @param {{config: LH.Config, url: string, driverMock?: Driver}} opts * @return {Promise} */ static async run(connection, opts) { @@ -38,9 +38,9 @@ class Runner { */ const lighthouseRunWarnings = []; - // save the initialUrl provided by the user - opts.initialUrl = opts.url; - if (typeof opts.initialUrl !== 'string' || opts.initialUrl.length === 0) { + // save the requestedUrl provided by the user + const rawRequestedUrl = opts.url; + if (typeof rawRequestedUrl !== 'string' || rawRequestedUrl.length === 0) { throw new Error('You must provide a url to the runner'); } @@ -67,7 +67,7 @@ class Runner { } // canonicalize URL with any trailing slashes neccessary - opts.url = parsedURL.href; + const requestedUrl = parsedURL.href; // User can run -G solo, -A solo, or -GA together // -G and -A will run partial lighthouse pipelines, @@ -81,7 +81,7 @@ class Runner { const path = Runner._getArtifactsPath(settings); artifacts = await assetSaver.loadArtifacts(path); } else { - artifacts = await Runner._gatherArtifactsFromBrowser(opts, connection); + artifacts = await Runner._gatherArtifactsFromBrowser(requestedUrl, opts, connection); // -G means save these to ./latest-run, etc. if (settings.gatherMode) { const path = Runner._getArtifactsPath(settings); @@ -123,8 +123,8 @@ class Runner { userAgent: artifacts.UserAgent, lighthouseVersion, fetchTime: artifacts.fetchTime, - initialUrl: opts.initialUrl, - url: opts.url, + requestedUrl: requestedUrl, + finalUrl: artifacts.URL.finalUrl, runWarnings: lighthouseRunWarnings, audits: resultsById, runtimeConfig: Runner.getRuntimeConfig(settings), @@ -144,11 +144,12 @@ class Runner { /** * Establish connection, load page and collect all required artifacts - * @param {{config: LH.Config, url: string, initialUrl?: string, driverMock?: Driver}} runnerOpts + * @param {string} requestedUrl + * @param {{config: LH.Config, driverMock?: Driver}} runnerOpts * @param {Connection} connection * @return {Promise} */ - static async _gatherArtifactsFromBrowser(runnerOpts, connection) { + static async _gatherArtifactsFromBrowser(requestedUrl, runnerOpts, connection) { if (!runnerOpts.config.passes) { throw new Error('No browser artifacts are either provided or requested.'); } @@ -156,13 +157,10 @@ class Runner { const driver = runnerOpts.driverMock || new Driver(connection); const gatherOpts = { driver, - initialUrl: runnerOpts.initialUrl, - url: runnerOpts.url, + requestedUrl, settings: runnerOpts.config.settings, }; const artifacts = await GatherRunner.run(runnerOpts.config.passes, gatherOpts); - // TODO(bckenny): transition to using finalUrl in artifacts rather than on opts. - runnerOpts.url = gatherOpts.url; return artifacts; } diff --git a/lighthouse-core/test/audits/works-offline-test.js b/lighthouse-core/test/audits/works-offline-test.js index e5490184be0e..bdbf13e1346a 100644 --- a/lighthouse-core/test/audits/works-offline-test.js +++ b/lighthouse-core/test/audits/works-offline-test.js @@ -16,17 +16,17 @@ describe('Offline: works-offline audit', () => { it('correctly audits a 200 code', () => { const output = Audit.audit({ Offline: 200, - URL: {initialUrl: URL, finalUrl: URL}, + URL: {requestedUrl: URL, finalUrl: URL}, }); assert.equal(output.rawValue, true); assert.ok(!output.debugString); }); - it('warns if initial url does not match final url', () => { + it('warns if requested url does not match final url', () => { const output = Audit.audit({ Offline: 404, - URL: {initialUrl: URL, finalUrl: `${URL}/features`}, + URL: {requestedUrl: URL, finalUrl: `${URL}/features`}, }); assert.equal(output.rawValue, false); @@ -36,7 +36,7 @@ describe('Offline: works-offline audit', () => { it('correctly audits a non-200 code', () => { const output = Audit.audit({ Offline: 203, - URL: {initialUrl: URL, finalUrl: URL}, + URL: {requestedUrl: URL, finalUrl: URL}, }); assert.equal(output.rawValue, false); diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index 56e5c8c3450a..0d7cffa860bd 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -68,7 +68,7 @@ describe('Config', () => { const configJson = { passes: [{ passName: unlikelyPassName, - gatherers: ['url'], + gatherers: ['viewport'], }, { passName: unlikelyPassName, gatherers: ['viewport-dimensions'], @@ -112,7 +112,7 @@ describe('Config', () => { const configJSON = { passes: [{ gatherers: [ - 'url', + 'viewport-dimensions', 'viewport', ], }], diff --git a/lighthouse-core/test/fixtures/artifacts/empty-artifacts/artifacts.json b/lighthouse-core/test/fixtures/artifacts/empty-artifacts/artifacts.json index 0967ef424bce..00d0ee379892 100644 --- a/lighthouse-core/test/fixtures/artifacts/empty-artifacts/artifacts.json +++ b/lighthouse-core/test/fixtures/artifacts/empty-artifacts/artifacts.json @@ -1 +1,6 @@ -{} +{ + "URL": { + "requestedUrl": "https://example.com/", + "finalUrl": "https://example.com/" + } +} diff --git a/lighthouse-core/test/fixtures/artifacts/perflog/artifacts.json b/lighthouse-core/test/fixtures/artifacts/perflog/artifacts.json index b136167bbcb0..777cdf1b619f 100644 --- a/lighthouse-core/test/fixtures/artifacts/perflog/artifacts.json +++ b/lighthouse-core/test/fixtures/artifacts/perflog/artifacts.json @@ -6,7 +6,7 @@ "UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36", "fetchTime": "2018-03-13T00:55:45.840Z", "URL": { - "initialUrl": "https://www.reddit.com/r/nba", + "requestedUrl": "https://www.reddit.com/r/nba", "finalUrl": "https://www.reddit.com/r/nba" }, "Viewport": null, diff --git a/lighthouse-core/test/gather/gather-runner-test.js b/lighthouse-core/test/gather/gather-runner-test.js index 6e9bab457ff2..81a38578776b 100644 --- a/lighthouse-core/test/gather/gather-runner-test.js +++ b/lighthouse-core/test/gather/gather-runner-test.js @@ -86,7 +86,7 @@ function getMockedEmulationDriver(emulationFn, netThrottleFn, cpuThrottleFn, } describe('GatherRunner', function() { - it('loads a page and updates URL on redirect', () => { + it('loads a page and updates passContext.URL on redirect', () => { const url1 = 'https://example.com'; const url2 = 'https://example.com/interstitial'; const driver = { @@ -95,14 +95,14 @@ describe('GatherRunner', function() { }, }; - const options = { - url: url1, + const passContext = { + requestedUrl: url1, settings: {}, passConfig: {}, }; - return GatherRunner.loadPage(driver, options).then(_ => { - assert.equal(options.url, url2); + return GatherRunner.loadPage(driver, passContext).then(_ => { + assert.equal(passContext.url, url2); }); }); @@ -118,6 +118,24 @@ describe('GatherRunner', function() { }); }); + it('collects requested and final URLs as an artifact', () => { + const requestedUrl = 'https://example.com'; + const finalUrl = 'https://example.com/interstitial'; + const driver = Object.assign({}, fakeDriver, { + gotoURL() { + return Promise.resolve(finalUrl); + }, + }); + const config = new Config({passes: [{}]}); + const settings = {}; + const options = {requestedUrl, driver, config, settings}; + + return GatherRunner.run(config.passes, options).then(artifacts => { + assert.deepStrictEqual(artifacts.URL, {requestedUrl, finalUrl}, + 'did not find expected URL artifact'); + }); + }); + it('sets up the driver to begin emulation when all emulation flags are undefined', () => { const tests = { calledDeviceEmulation: false, @@ -514,7 +532,7 @@ describe('GatherRunner', function() { return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings, config, }).then(_ => { @@ -535,7 +553,7 @@ describe('GatherRunner', function() { passName: 'secondPass', gatherers: [{instance: new TestGatherer()}], }]; - const options = {driver: fakeDriver, url: 'https://example.com', settings: {}, config: {}}; + const options = {driver: fakeDriver, requestedUrl: 'https://example.com', settings: {}, config: {}}; return GatherRunner.run(passes, options) .then(artifacts => { @@ -558,7 +576,7 @@ describe('GatherRunner', function() { passName: 'secondPass', gatherers: [{instance: new TestGatherer()}], }]; - const options = {driver: fakeDriver, url: 'https://example.com', settings: {}, config: {}}; + const options = {driver: fakeDriver, requestedUrl: 'https://example.com', settings: {}, config: {}}; return GatherRunner.run(passes, options) .then(artifacts => { @@ -667,7 +685,7 @@ describe('GatherRunner', function() { const artifacts = await GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, }); @@ -721,7 +739,7 @@ describe('GatherRunner', function() { return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, config: new Config({}), }).then(artifacts => { @@ -755,7 +773,7 @@ describe('GatherRunner', function() { const passes = [{blankDuration: 0, gatherers}]; return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, config: new Config({}), }).then(artifacts => { @@ -881,7 +899,7 @@ describe('GatherRunner', function() { return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, config: new Config({}), }).then(artifacts => { @@ -917,7 +935,7 @@ describe('GatherRunner', function() { return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, config: new Config({}), }).then( @@ -937,7 +955,7 @@ describe('GatherRunner', function() { return GatherRunner.run(passes, { driver: fakeDriver, - url: 'https://example.com', + requestedUrl: 'https://example.com', settings: {}, config: new Config({}), }).then(_ => assert.ok(false), _ => assert.ok(true)); diff --git a/lighthouse-core/test/gather/gatherers/url-test.js b/lighthouse-core/test/gather/gatherers/url-test.js deleted file mode 100644 index b18fb55e578c..000000000000 --- a/lighthouse-core/test/gather/gatherers/url-test.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @license Copyright 2016 Google Inc. All Rights Reserved. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - */ -'use strict'; - -/* eslint-env mocha */ - -const URLGather = require('../../../gather/gatherers/url'); -const assert = require('assert'); - -describe('URL gatherer', () => { - it('returns the correct URL from options', () => { - const urlGather = new URLGather(); - const url = 'https://example.com'; - const artifact = urlGather.afterPass({ - url: url, - }); - - return assert.equal(artifact.finalUrl, url); - }); -}); diff --git a/lighthouse-core/test/index-test.js b/lighthouse-core/test/index-test.js index bfbb821c0b9d..1340e6b78cd4 100644 --- a/lighthouse-core/test/index-test.js +++ b/lighthouse-core/test/index-test.js @@ -73,7 +73,7 @@ describe('Module Tests', function() { return lighthouse('SOME_URL', {}, { passes: [{ gatherers: [ - 'url', + 'viewport', ], }], audits: [ @@ -88,7 +88,7 @@ describe('Module Tests', function() { }); it('should return formatted LHR when given no categories', function() { - const exampleUrl = 'https://example.com/'; + const exampleUrl = 'https://www.reddit.com/r/nba'; return lighthouse(exampleUrl, { output: 'html', }, { @@ -103,8 +103,8 @@ describe('Module Tests', function() { assert.ok(results.artifacts.ViewportDimensions, 'did not set artifacts'); assert.ok(results.lhr.lighthouseVersion); assert.ok(results.lhr.fetchTime); - assert.equal(results.lhr.url, exampleUrl); - assert.equal(results.lhr.initialUrl, exampleUrl); + assert.equal(results.lhr.finalUrl, exampleUrl); + assert.equal(results.lhr.requestedUrl, exampleUrl); assert.ok(Array.isArray(results.lhr.reportCategories)); assert.equal(results.lhr.reportCategories.length, 0); assert.ok(results.lhr.audits.viewport); diff --git a/lighthouse-core/test/lib/file-namer-test.js b/lighthouse-core/test/lib/file-namer-test.js index 49749dd4cc74..0d253aa06868 100644 --- a/lighthouse-core/test/lib/file-namer-test.js +++ b/lighthouse-core/test/lib/file-namer-test.js @@ -12,7 +12,7 @@ const getFilenamePrefix = require('../../lib/file-namer').getFilenamePrefix; describe('file-namer helper', () => { it('generates filename prefixes', () => { const results = { - url: 'https://testexample.com', + finalUrl: 'https://testexample.com', fetchTime: '2017-01-06T02:34:56.217Z', }; const str = getFilenamePrefix(results); diff --git a/lighthouse-core/test/report/html/renderer/report-renderer-test.js b/lighthouse-core/test/report/html/renderer/report-renderer-test.js index fe0d330abc3d..0fb8f255e944 100644 --- a/lighthouse-core/test/report/html/renderer/report-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/report-renderer-test.js @@ -97,10 +97,10 @@ describe('ReportRenderer', () => { assert.ok(header.querySelector('.lh-config__timestamp').textContent.match(TIMESTAMP_REGEX), 'formats the generated datetime'); - assert.equal(header.querySelector('.lh-metadata__url').textContent, sampleResults.url); + assert.equal(header.querySelector('.lh-metadata__url').textContent, sampleResults.finalUrl); const url = header.querySelector('.lh-metadata__url'); - assert.equal(url.textContent, sampleResults.url); - assert.equal(url.href, sampleResults.url); + assert.equal(url.textContent, sampleResults.finalUrl); + assert.equal(url.href, sampleResults.finalUrl); const userAgent = header.querySelector('.lh-env__item__ua'); assert.equal(userAgent.textContent, sampleResults.userAgent, 'user agent populated'); diff --git a/lighthouse-core/test/results/artifacts/artifacts.json b/lighthouse-core/test/results/artifacts/artifacts.json index 5a684636b3f6..471ce90596c9 100644 --- a/lighthouse-core/test/results/artifacts/artifacts.json +++ b/lighthouse-core/test/results/artifacts/artifacts.json @@ -3,7 +3,7 @@ "UserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36", "fetchTime": "2018-03-13T00:55:45.840Z", "URL": { - "initialUrl": "http://localhost:10200/dobetterweb/dbw_tester.html", + "requestedUrl": "http://localhost:10200/dobetterweb/dbw_tester.html", "finalUrl": "http://localhost:10200/dobetterweb/dbw_tester.html" }, "Scripts": { diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index e00451e5da4d..5a8425ef1b5c 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -2,8 +2,8 @@ "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36", "lighthouseVersion": "3.0.0-alpha", "fetchTime": "2018-03-13T00:55:45.840Z", - "initialUrl": "http://localhost/dobetterweb/dbw_tester.html", - "url": "http://localhost/dobetterweb/dbw_tester.html", + "requestedUrl": "http://localhost/dobetterweb/dbw_tester.html", + "finalUrl": "http://localhost:10200/dobetterweb/dbw_tester.html", "runWarnings": [], "audits": { "is-on-https": { diff --git a/lighthouse-core/test/runner-test.js b/lighthouse-core/test/runner-test.js index 19306ee3e21c..b7c128f74a5c 100644 --- a/lighthouse-core/test/runner-test.js +++ b/lighthouse-core/test/runner-test.js @@ -149,7 +149,7 @@ describe('Runner', () => { }); it('accepts audit options', () => { - const url = 'https://example.com'; + const url = 'https://example.com/'; const calls = []; class EavesdropAudit extends Audit { @@ -179,7 +179,7 @@ describe('Runner', () => { }); return Runner.run({}, {url, config}).then(results => { - assert.equal(results.lhr.initialUrl, url); + assert.equal(results.lhr.requestedUrl, url); assert.equal(results.lhr.audits['eavesdrop-audit'].rawValue, true); // assert that the options we received matched expectations assert.deepEqual(calls, [{x: 1}, {x: 2}]); @@ -187,7 +187,7 @@ describe('Runner', () => { }); it('accepts trace artifacts as paths and outputs appropriate data', () => { - const url = 'https://example.com'; + const url = 'https://example.com/'; const config = new Config({ settings: { @@ -399,7 +399,7 @@ describe('Runner', () => { }); it('returns data even if no config categories are provided', () => { - const url = 'https://example.com'; + const url = 'https://example.com/'; const config = new Config({ passes: [{ gatherers: ['viewport-dimensions'], @@ -412,7 +412,7 @@ describe('Runner', () => { return Runner.run(null, {url, config, driverMock}).then(results => { assert.ok(results.lhr.lighthouseVersion); assert.ok(results.lhr.fetchTime); - assert.equal(results.lhr.initialUrl, url); + assert.equal(results.lhr.requestedUrl, url); assert.equal(gatherRunnerRunSpy.called, true, 'GatherRunner.run was not called'); assert.equal(results.lhr.audits['content-width'].name, 'content-width'); }); @@ -420,7 +420,7 @@ describe('Runner', () => { it('returns reportCategories', () => { - const url = 'https://example.com'; + const url = 'https://example.com/'; const config = new Config({ passes: [{ gatherers: ['viewport-dimensions'], @@ -442,7 +442,7 @@ describe('Runner', () => { return Runner.run(null, {url, config, driverMock}).then(results => { assert.ok(results.lhr.lighthouseVersion); assert.ok(results.lhr.fetchTime); - assert.equal(results.lhr.initialUrl, url); + assert.equal(results.lhr.requestedUrl, url); assert.equal(gatherRunnerRunSpy.called, true, 'GatherRunner.run was not called'); assert.equal(results.lhr.audits['content-width'].name, 'content-width'); assert.equal(results.lhr.audits['content-width'].score, 1); @@ -508,7 +508,7 @@ describe('Runner', () => { const config = new Config({ passes: [{ passName: 'firstPass', - gatherers: ['url', 'viewport-dimensions'], + gatherers: ['viewport', 'viewport-dimensions'], }], audits: [ diff --git a/typings/artifacts.d.ts b/typings/artifacts.d.ts index 9a2d5712ede7..ce363045b5ab 100644 --- a/typings/artifacts.d.ts +++ b/typings/artifacts.d.ts @@ -20,6 +20,8 @@ declare global { traces: {[passName: string]: Trace}; devtoolsLogs: {[passName: string]: DevtoolsLog}; settings: Config.Settings; + /** The URL initially requested and the post-redirects URL that was actually loaded. */ + URL: {requestedUrl: string, finalUrl: string}; // Remaining are provided by default gatherers. /** The results of running the aXe accessibility tests on the page. */ @@ -88,8 +90,6 @@ declare global { TagsBlockingFirstPaint: Artifacts.TagBlockingFirstPaint[]; /** The value of the 's content attribute, or null. */ ThemeColor: string|null; - /** The URL initially supplied to be loaded and the post-redirects URL that was loaded. */ - URL: {initialUrl: string, finalUrl: string}; /** The value of the 's content attribute, or null. */ Viewport: string|null; /** The dimensions and devicePixelRatio of the loaded viewport. */ diff --git a/typings/lhr.d.ts b/typings/lhr.d.ts index 024d702871da..79201e2b8495 100644 --- a/typings/lhr.d.ts +++ b/typings/lhr.d.ts @@ -11,9 +11,9 @@ declare global { */ export interface Result { /** The URL that was supplied to Lighthouse and initially navigated to. */ - initialUrl: string; + requestedUrl: string; /** The post-redirects URL that Lighthouse loaded. */ - url: string; + finalUrl: string; /** The ISO-8601 timestamp of when the results were generated. */ fetchTime: string; /** The version of Lighthouse with which these results were generated. */