From e7a76f8f261161449fee944ba14c192917c916bc Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 30 Dec 2019 13:47:17 -0800 Subject: [PATCH 1/5] core: warn if document was redirected --- lighthouse-core/gather/gather-runner.js | 20 ++++++++++++++++++++ lighthouse-core/lib/i18n/locales/en-US.json | 3 +++ lighthouse-core/lib/i18n/locales/en-XL.json | 3 +++ 3 files changed, 26 insertions(+) diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 8e094289a9fe..4da3af7248c2 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -14,6 +14,19 @@ const NetworkRecorder = require('../lib/network-recorder.js'); const constants = require('../config/constants.js'); const i18n = require('../lib/i18n/i18n.js'); +const UIStrings = { + /** + * @description Warning that the web page redirected during testing and that may have affected the load. + * @example {https://example.com/requested/page} requested + * @example {https://example.com/final/resolved/page} final + */ + warningRedirected: 'The page may not be loading as expected because your test URL ' + + `({requested}) was redirected to {final}. ` + + 'Try testing the second URL directly.', +}; + +const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings); + /** @typedef {import('../gather/driver.js')} Driver */ /** @typedef {import('./gatherers/gatherer.js').PhaseResult} PhaseResult */ @@ -491,6 +504,12 @@ class GatherRunner { // Copy redirected URL to artifact. baseArtifacts.URL.finalUrl = passContext.url; + if (baseArtifacts.URL.requestedUrl !== baseArtifacts.URL.finalUrl) { + baseArtifacts.LighthouseRunWarnings.push(str_(UIStrings.warningRedirected, { + requested: baseArtifacts.URL.requestedUrl, + final: baseArtifacts.URL.finalUrl, + })); + } // Fetch the manifest, if it exists. baseArtifacts.WebAppManifest = await GatherRunner.getWebAppManifest(passContext); @@ -672,3 +691,4 @@ class GatherRunner { } module.exports = GatherRunner; +module.exports.UIStrings = UIStrings; diff --git a/lighthouse-core/lib/i18n/locales/en-US.json b/lighthouse-core/lib/i18n/locales/en-US.json index 8aca1302f53b..e9ce7b02e1ba 100644 --- a/lighthouse-core/lib/i18n/locales/en-US.json +++ b/lighthouse-core/lib/i18n/locales/en-US.json @@ -1373,6 +1373,9 @@ "lighthouse-core/config/default-config.js | seoMobileGroupTitle": { "message": "Mobile Friendly" }, + "lighthouse-core/gather/gather-runner.js | warningRedirected": { + "message": "The page may not be loading as expected because your test URL ({requested}) was redirected to {final}. Try testing the second URL directly." + }, "lighthouse-core/lib/i18n/i18n.js | columnCacheTTL": { "message": "Cache TTL" }, diff --git a/lighthouse-core/lib/i18n/locales/en-XL.json b/lighthouse-core/lib/i18n/locales/en-XL.json index 3daf14887193..816bd7837bb4 100644 --- a/lighthouse-core/lib/i18n/locales/en-XL.json +++ b/lighthouse-core/lib/i18n/locales/en-XL.json @@ -1373,6 +1373,9 @@ "lighthouse-core/config/default-config.js | seoMobileGroupTitle": { "message": "M̂ób̂íl̂é F̂ŕîén̂d́l̂ý" }, + "lighthouse-core/gather/gather-runner.js | warningRedirected": { + "message": "T̂h́ê ṕâǵê ḿâý n̂ót̂ b́ê ĺôád̂ín̂ǵ âś êx́p̂éĉt́êd́ b̂éĉáûśê ýôúr̂ t́êśt̂ ÚR̂Ĺ ({requested}) ŵáŝ ŕêd́îŕêćt̂éd̂ t́ô {final}. T́r̂ý t̂éŝt́îńĝ t́ĥé ŝéĉón̂d́ ÛŔL̂ d́îŕêćt̂ĺŷ." + }, "lighthouse-core/lib/i18n/i18n.js | columnCacheTTL": { "message": "Ĉáĉh́ê T́T̂Ĺ" }, From ed5707066f66643b4421afca96dc4e97be8ec95d Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 30 Dec 2019 14:02:02 -0800 Subject: [PATCH 2/5] smoke test --- .../smokehouse/test-definitions/redirects/expectations.js | 6 ++++++ types/smokehouse.d.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js index 06b66ac63746..68a37e3b3156 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/redirects/expectations.js @@ -27,6 +27,9 @@ const expectations = [ }, }, }, + runWarnings: [ + /The page may not be loading as expected because your test URL \(.*online-only.html.*\) was redirected to .*redirects-final.html. Try testing the second URL directly./, + ], }, }, { @@ -44,6 +47,9 @@ const expectations = [ }, }, }, + runWarnings: [ + /The page may not be loading as expected because your test URL \(.*online-only.html.*\) was redirected to .*redirects-final.html. Try testing the second URL directly./, + ], }, }, ]; diff --git a/types/smokehouse.d.ts b/types/smokehouse.d.ts index 070015b1fccc..caa4e7746e5b 100644 --- a/types/smokehouse.d.ts +++ b/types/smokehouse.d.ts @@ -9,7 +9,7 @@ audits: Record; requestedUrl: string; finalUrl: string; - runWarnings?: Array; + runWarnings?: Array; runtimeError?: { code?: any; message?: any; From 9f1333c8b3e191fcb72e8ac4afe77aba2c301afc Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 30 Dec 2019 16:02:53 -0800 Subject: [PATCH 3/5] fragment --- lighthouse-core/gather/gather-runner.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/gather/gather-runner.js b/lighthouse-core/gather/gather-runner.js index 4da3af7248c2..09694b9b7601 100644 --- a/lighthouse-core/gather/gather-runner.js +++ b/lighthouse-core/gather/gather-runner.js @@ -13,6 +13,7 @@ const NetworkAnalyzer = require('../lib/dependency-graph/simulator/network-analy const NetworkRecorder = require('../lib/network-recorder.js'); const constants = require('../config/constants.js'); const i18n = require('../lib/i18n/i18n.js'); +const URL = require('../lib/url-shim.js'); const UIStrings = { /** @@ -504,7 +505,8 @@ class GatherRunner { // Copy redirected URL to artifact. baseArtifacts.URL.finalUrl = passContext.url; - if (baseArtifacts.URL.requestedUrl !== baseArtifacts.URL.finalUrl) { + /* eslint-disable max-len */ + if (!URL.equalWithExcludedFragments(baseArtifacts.URL.requestedUrl, baseArtifacts.URL.finalUrl)) { baseArtifacts.LighthouseRunWarnings.push(str_(UIStrings.warningRedirected, { requested: baseArtifacts.URL.requestedUrl, final: baseArtifacts.URL.finalUrl, From 04145aaf85db68c1980abf9490e94dc8898cb5c1 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 30 Dec 2019 16:07:41 -0800 Subject: [PATCH 4/5] fix test --- lighthouse-core/test/gather/fake-driver.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lighthouse-core/test/gather/fake-driver.js b/lighthouse-core/test/gather/fake-driver.js index 108a40aa6d78..fe5fa8ba97fb 100644 --- a/lighthouse-core/test/gather/fake-driver.js +++ b/lighthouse-core/test/gather/fake-driver.js @@ -24,8 +24,9 @@ function makeFakeDriver({protocolGetVersionResponse}) { disconnect() { return Promise.resolve(); }, - gotoURL() { - return Promise.resolve('https://www.reddit.com/r/nba'); + /** @param {string} url */ + gotoURL(url) { + return Promise.resolve(url); }, beginEmulation() { return Promise.resolve(); From 984237b2e980788bc195578716d765e6f833fd56 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 30 Dec 2019 16:29:52 -0800 Subject: [PATCH 5/5] fix pwa test --- .../test/smokehouse/test-definitions/pwa/pwa-expectations.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js index 85616240be77..230a70d0d506 100644 --- a/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js +++ b/lighthouse-cli/test/smokehouse/test-definitions/pwa/pwa-expectations.js @@ -89,7 +89,7 @@ module.exports = [ { lhr: { - requestedUrl: 'https://www.chromestatus.com/', + requestedUrl: 'https://www.chromestatus.com/features', finalUrl: 'https://www.chromestatus.com/features', audits: { 'is-on-https': { @@ -102,7 +102,7 @@ module.exports = [ score: 1, }, 'works-offline': { - score: 0, + score: 1, }, 'offline-start-url': { score: 1,