-
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
core(fr): convert main-document-content gatherer #12470
Conversation
* @param {number} [timeout] | ||
* @return {Promise<string>} | ||
*/ | ||
static async getRequestContent(session, requestId, timeout = 1000) { |
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.
This felt like the most convenient location for this function. I'm open to other suggestions though.
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.
This was my first thought as well, but it does feel a bit weird to introduce session
into this file.
My other thought was on NetworkMonitor
. How does that feel to you?
I think I could go either way.
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.
It also feels weird to create a new NetworkMonitor(session)
just to use this function with session
. I think I prefer leaving as is.
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.
if it's a gathering helper method it seems like it should live under driver/
, but it seems like it should just go in a new file if none of the existing helper modules are a good home for it? If the stricter timeout is important so we want people getting response content this way, it should preferably not be tucked in somewhere that's already relatively large and has an important separate purpose or people are just going to call Network.getResponseBody
directly because they won't know it's there
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.
actually, looking at the original PR (#4718), the stricter Network.getResponseBody
timeout was specifically for working around using the protocol via the extension chrome.debugger
API and there wasn't an issue in devtools/CLI. The extension doesn't use the protocol anymore, so should we just get rid of the getRequestContent
method and everyone can call sendCommand('Network.getResponseBody', {requestId})
directly?
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.
it should preferably not be tucked in somewhere that's already relatively large and has an important separate purpose or people are just going to call Network.getResponseBody directly because they won't know it's there
This was my concern with mingling session work in this file as well. You've boosted me beyond "could go either way" to "should probably stay in driver/ somewhere" :)
so should we just get rid of the getRequestContent method and everyone can call sendCommand('Network.getResponseBody', {requestId}) directly?
I would lean no. Defaulting this to a low timeout is a good thing, and the detail with NetworkRequest.getRequestIdForBackend
is easy to forget, so bundling those together at least is necessary (otherwise your exact same argument of missing an argument tucked away somewhere is likely to happen here).
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.
ah yeah, I missed NetworkRequest.getRequestIdForBackend
in there.
The timeout still seems like cruft (should the comment point to this discussion now since #4718 can't happen anymore? :P) but it's pre-existing so 🤷
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.
It also feels weird to create a new NetworkMonitor(session) just to use this function with session. I think I prefer leaving as is.
I was thinking just a static method like it is here. The alternative I see is a solo file.
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.
I have moved it to a new file, network.js
tsconfig.json
Outdated
@@ -52,6 +52,7 @@ | |||
"lighthouse-core/test/gather/gatherers/http-redirect-test.js", | |||
"lighthouse-core/test/gather/gatherers/js-usage-test.js", | |||
"lighthouse-core/test/gather/gatherers/link-elements-test.js", | |||
"lighthouse-core/test/gather/gatherers/main-document-content-test.js", |
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.
Type checking would be a pain, and we probably won't need this test once afterPass
is deprecated.
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.
nooooo, but you've been so great about all the tests so far, and this is a nice opportunity to expand! :D
* @param {number} [timeout] | ||
* @return {Promise<string>} | ||
*/ | ||
static async getRequestContent(session, requestId, timeout = 1000) { |
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.
while we're in the reorg mode...WDYT about fetchResponseBodyFromCache
?
fetch
to signal that it's an operation that takes some time over the protcol, not just a getterFromCache
to signify that it's not re-requesting anything, it's just trying to get it from memory cache (FromMemory
orFromMemoryCache
alternates?)ResponseBody
because it is weird that we say we're getting the request content when it's the response content, request is sort of implicit in all of these operations
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.
maybe fetch
should be reserved for things fetched over the network, though?
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.
maybe fetch should be reserved for things fetched over the network, though?
That was the point of FromCache
, an alternate suggestion? fetchFromCache
has a weaker "over the network" connection to me than get
's connection to "returns immediately"
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.
I guess I always found the name descriptive enough except for the request
part you mentioned, so getResponseContent
seems ok to me :)
If it was on NetworkRequest
I could definitely see the issue with get
sounding like just a local variable, but between the async
and being in a driver/*
file, I'd just assume it's doing something over the protocol, but maybe that's just because I already know how it works.
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.
how's about getResponseContentFromCache
then? the current method makes it sound like the content will be available much more often than it actually is (if we're making wishes I'd also want to have this | undefined
like our DOM utilities do when this thing throws).
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.
impl looks great!
lighthouse-core/test/gather/gatherers/main-document-content-test.js
Outdated
Show resolved
Hide resolved
lighthouse-core/test/gather/gatherers/main-document-content-test.js
Outdated
Show resolved
Hide resolved
jest.mock('../../../computed/network-records.js'); | ||
|
||
describe('FR compat', () => { | ||
/** @type {MainDocumentContent} */ |
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.
a trick I like, is to just double initialize these (in declaration and beforeEach) to avoid duplicating the type annotation
e.g. let gatherer = new MainDocumentGatherer();
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.
(don't need to change it, just offering an alternative that comes in handy when the types get more complex :)
tsconfig.json
Outdated
@@ -52,6 +52,7 @@ | |||
"lighthouse-core/test/gather/gatherers/http-redirect-test.js", | |||
"lighthouse-core/test/gather/gatherers/js-usage-test.js", | |||
"lighthouse-core/test/gather/gatherers/link-elements-test.js", | |||
"lighthouse-core/test/gather/gatherers/main-document-content-test.js", |
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.
nooooo, but you've been so great about all the tests so far, and this is a nice opportunity to expand! :D
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.
B-E-A-UTIFUL
@@ -127,11 +127,34 @@ function mockDriverModule(driverProvider) { | |||
}; | |||
} | |||
|
|||
function createMockContext() { |
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.
nice 👍
const devtoolsLog | ||
= /** @type {LH.DevtoolsLog} */ (require('../../fixtures/traces/lcp-m78.devtools.log.json')); | ||
|
||
describe('FR compat', () => { |
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.
Co-authored-by: Patrick Hulce <[email protected]>
I'm going to merge because I want to use |
|
Ref #11313