-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Keep track of the document URL post-redirects #582
Changes from all commits
587f91f
55ce003
eae105e
f63f320
dd035f5
60e99ea
6cffdcf
8d11ab8
813f23b
1e120a5
46f4241
81e4d2f
ae10a7b
6bbbc2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,6 @@ class ExtensionDriver extends Driver { | |
|
||
_detachCleanup() { | ||
this._tabId = null; | ||
this.url = null; | ||
chrome.debugger.onEvent.removeListener(this._onEvent); | ||
chrome.debugger.onDetach.removeListener(this._onUnexpectedDetach); | ||
this._eventEmitter.removeAllListeners(); | ||
|
@@ -60,8 +59,8 @@ class ExtensionDriver extends Driver { | |
} | ||
|
||
return this.queryCurrentTab_() | ||
.then(tabId => { | ||
this._tabId = tabId; | ||
.then(tab => { | ||
const tabId = this._tabId = tab.id; | ||
chrome.debugger.onEvent.addListener(this._onEvent); | ||
chrome.debugger.onDetach.addListener(this._onUnexpectedDetach); | ||
|
||
|
@@ -142,18 +141,16 @@ class ExtensionDriver extends Driver { | |
return reject(chrome.runtime.lastError); | ||
} | ||
|
||
this.url = tabs[0].url; | ||
resolve(tabs[0].id); | ||
resolve(tabs[0]); | ||
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. while you're in here, should this be caching the tab found and always resolving on it in subsequent calls? Seems bad that a call to 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. could be storing 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.
Thinking about it, I don't think it's a risk. (Although I admit it's a bit odd.) |
||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Used by lighthouse-background to kick off the run on the current page | ||
*/ | ||
getCurrentTabURL() { | ||
if (this.url === undefined || this.url === null) { | ||
return this.queryCurrentTab_().then(_ => this.url); | ||
} | ||
|
||
return Promise.resolve(this.url); | ||
return this.queryCurrentTab_().then(tab => tab.url); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ class GatherRunner { | |
.then(_ => new Promise((resolve, reject) => setTimeout(resolve, 300))) | ||
// Begin tracing and network recording if required. | ||
.then(_ => options.config.trace && driver.beginTrace()) | ||
.then(_ => options.config.network && driver.beginNetworkCollect()) | ||
.then(_ => options.config.network && driver.beginNetworkCollect(options)) | ||
// Navigate. | ||
.then(_ => driver.gotoURL(options.url, { | ||
waitForLoad: true, | ||
|
@@ -196,18 +196,25 @@ class GatherRunner { | |
|
||
// Run each pass | ||
.then(_ => { | ||
return passes.reduce((chain, config) => { | ||
// If the main document redirects, we'll update this to keep track | ||
let urlAfterRedirects; | ||
return passes.reduce((chain, config, passIndex) => { | ||
const runOptions = Object.assign({}, options, {config}); | ||
return chain | ||
.then(_ => GatherRunner.beforePass(runOptions)) | ||
.then(_ => GatherRunner.pass(runOptions)) | ||
.then(_ => GatherRunner.afterPass(runOptions)) | ||
.then(loadData => { | ||
// Merge pass trace and network data into tracingData. | ||
config.trace && Object.assign(tracingData.traces, loadData.traces); | ||
config.network && (tracingData.networkRecords = loadData.networkRecords); | ||
}); | ||
}, Promise.resolve()); | ||
.then(_ => GatherRunner.beforePass(runOptions)) | ||
.then(_ => GatherRunner.pass(runOptions)) | ||
.then(_ => GatherRunner.afterPass(runOptions)) | ||
.then(loadData => { | ||
// Merge pass trace and network data into tracingData. | ||
config.trace && Object.assign(tracingData.traces, loadData.traces); | ||
config.network && (tracingData.networkRecords = loadData.networkRecords); | ||
if (passIndex === 0) { | ||
urlAfterRedirects = runOptions.url; | ||
} | ||
}); | ||
}, Promise.resolve()).then(_ => { | ||
options.url = urlAfterRedirects; | ||
}); | ||
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. since you no longer alter the options object in this loop you can simplify this again: .then(_ => {
// If the main document redirects, we'll update this to keep track
let urlAfterRedirects;
return passes.reduce((chain, config, passIndex) => {
const runOptions = Object.assign({}, options, {config});
return chain
.then(_ => GatherRunner.beforePass(runOptions))
.then(_ => GatherRunner.pass(runOptions))
.then(_ => GatherRunner.afterPass(runOptions))
.then(loadData => {
// Merge pass trace and network data into tracingData.
config.trace && Object.assign(tracingData.traces, loadData.traces);
config.network && (tracingData.networkRecords = loadData.networkRecords);
if (passIndex === 0) {
urlAfterRedirects = runOptions.url;
}
});
}, Promise.resolve()).then(_ => {
options.url = urlAfterRedirects;
});
}) (technically you could even set 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.
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.
K one more reason to do #604 ;) |
||
}) | ||
.then(_ => { | ||
// We dont need to hold up the reporting for the reload/disconnect, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ | |
|
||
const Gatherer = require('./gatherer'); | ||
|
||
/** | ||
* This gatherer changes the options.url so that its pass loads the http page. | ||
* After load it detects if its on a crypographic scheme. | ||
* TODO: Instead of abusing a loadPage pass for this test, it could likely just do an XHR instead | ||
*/ | ||
class HTTPRedirect extends Gatherer { | ||
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. Actually wondering if we should be surfacing this. For example, redirecting to an m. incurs a perf penalty, which should be captured in TTI etc, but as a meta piece of data highlighting the number of redirects might be helpful. 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. redirects do show up (but aren't especially highlighted) in the critical request chains though timing info isn't included |
||
|
||
constructor() { | ||
|
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.
should we file a bug for this? I'm thinking either network recording should always happen, getting rid of
config.network
, or network recording should always happen but the results are discarded ifconfig.network
isfalse
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.
seems important for gatherers/audits to be able to assume they don't have to do any work to get the actual url of the current page
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.
filed #604