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

core: warn if document was redirected #10157

Merged
merged 5 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand All @@ -102,7 +102,7 @@ module.exports = [
score: 1,
},
'works-offline': {
score: 0,
score: 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This does work offline. Was this meant to be testing something subtle re: redirection? I'm assuming not, since no comments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing it didn't always work offline, this test might be 4 years old :)

},
'offline-start-url': {
score: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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./,
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a non-deterministic component of this that warrants a regex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this first one - yes, cacheBuster is a new Date. The second - no. Still good for eliding the URL query params that don't matter.

],
},
},
{
Expand All @@ -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./,
],
},
},
];
Expand Down
22 changes: 22 additions & 0 deletions lighthouse-core/gather/gather-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ 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 = {
/**
* @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 */

Expand Down Expand Up @@ -491,6 +505,13 @@ class GatherRunner {

// Copy redirected URL to artifact.
baseArtifacts.URL.finalUrl = passContext.url;
/* eslint-disable max-len */
if (!URL.equalWithExcludedFragments(baseArtifacts.URL.requestedUrl, baseArtifacts.URL.finalUrl)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#10218 is going to throw a major wrench into all the places where we detect redirects like this 😆

but a problem for another day

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);
Expand Down Expand Up @@ -672,3 +693,4 @@ class GatherRunner {
}

module.exports = GatherRunner;
module.exports.UIStrings = UIStrings;
3 changes: 3 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/lib/i18n/locales/en-XL.json
Original file line number Diff line number Diff line change
Expand Up @@ -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̂Ĺ"
},
Expand Down
5 changes: 3 additions & 2 deletions lighthouse-core/test/gather/fake-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion types/smokehouse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
audits: Record<string, any>;
requestedUrl: string;
finalUrl: string;
runWarnings?: Array<string>;
runWarnings?: Array<string|RegExp>;
runtimeError?: {
code?: any;
message?: any;
Expand Down