-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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(audit-mode): do not require a URL #5495
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ const Connection = require('./gather/connections/connection.js'); // eslint-disa | |
class Runner { | ||
/** | ||
* @param {Connection} connection | ||
* @param {{config: LH.Config, url: string, driverMock?: Driver}} opts | ||
* @param {{config: LH.Config, url?: string, driverMock?: Driver}} opts | ||
* @return {Promise<LH.RunnerResult|undefined>} | ||
*/ | ||
static async run(connection, opts) { | ||
|
@@ -37,19 +37,6 @@ class Runner { | |
*/ | ||
const lighthouseRunWarnings = []; | ||
|
||
// 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. '${rawRequestedUrl}' provided.`); | ||
} | ||
|
||
let parsedURL; | ||
try { | ||
parsedURL = new URL(opts.url); | ||
} catch (e) { | ||
throw new Error('The url provided should have a proper protocol and hostname.'); | ||
} | ||
|
||
const sentryContext = Sentry.getContext(); | ||
// @ts-ignore TODO(bckenny): Sentry type checking | ||
Sentry.captureBreadcrumb({ | ||
|
@@ -59,27 +46,43 @@ class Runner { | |
data: sentryContext && sentryContext.extra, | ||
}); | ||
|
||
// If the URL isn't https and is also not localhost complain to the user. | ||
if (parsedURL.protocol !== 'https:' && parsedURL.hostname !== 'localhost') { | ||
log.warn('Lighthouse', 'The URL provided should be on HTTPS'); | ||
log.warn('Lighthouse', 'Performance stats will be skewed redirecting from HTTP to HTTPS.'); | ||
} | ||
|
||
// canonicalize URL with any trailing slashes neccessary | ||
const requestedUrl = parsedURL.href; | ||
|
||
// User can run -G solo, -A solo, or -GA together | ||
// -G and -A will run partial lighthouse pipelines, | ||
// and -GA will run everything plus save artifacts to disk | ||
|
||
// Gather phase | ||
// Either load saved artifacts off disk or from the browser | ||
let artifacts; | ||
let requestedUrl; | ||
if (settings.auditMode && !settings.gatherMode) { | ||
// No browser required, just load the artifacts from disk. | ||
const path = Runner._getArtifactsPath(settings); | ||
artifacts = await assetSaver.loadArtifacts(path); | ||
requestedUrl = artifacts.URL.requestedUrl; | ||
|
||
if (!requestedUrl) { | ||
throw new Error('Cannot run audit mode on empty URL'); | ||
} | ||
if (opts.url && opts.url !== requestedUrl) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might throw a wrench in the type checking works, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
throw new Error('Cannot run audit mode on different URL'); | ||
} | ||
} else { | ||
if (typeof opts.url !== 'string' || opts.url.length === 0) { | ||
throw new Error(`You must provide a url to the runner. '${opts.url}' provided.`); | ||
} | ||
|
||
try { | ||
// Use canonicalized URL (with trailing slashes and such) | ||
requestedUrl = new URL(opts.url).href; | ||
} catch (e) { | ||
// Prepend https:// if user was lazy and just went with an unqualified URL | ||
try { | ||
requestedUrl = new URL(`https://${opts.url}`).href; | ||
} catch (e) { | ||
throw new Error('The url provided should have a proper protocol and hostname.'); | ||
} | ||
} | ||
|
||
artifacts = await Runner._gatherArtifactsFromBrowser(requestedUrl, opts, connection); | ||
// -G means save these to ./latest-run, etc. | ||
if (settings.gatherMode) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update comment too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done