-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Revamp of the offline.js gatherer #578
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
Conversation
| offlineResponseCode: -1 | ||
| }; | ||
| }); | ||
| return driver.gotoURL(options.url, {waitForLoad: true}) |
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.
So I think that this initial navigation to options.url is wasteful, since the config.json for this pass specifies "loadPage": true. That being said, when I used node lighthouse-cli <url> --audit-whitelist=works-offline to just run this one specific audit, I did end up needing to explicitly add in the initial navigation.
It may be because this is currently in a beforePass function. I don't think I could move this code to afterPass, since by the time that's called, tracingData is already set. Is there some other lifecycle function that I could use instead that would allow me to take advantage of "loadPage": true?
|
(I'm looking into the Travis CI build failure.) |
|
Travis CI should be happy, and I tried to follow the model of using pre-recorded tracing data to drive the modified test cases. Happy to adjust the tests further based on any feedback. |
|
Looking at the network record is definitely a much better way of doing this, but in general we really want to avoid doing navigation inside gatherers. Ideally this gather can just be I see two issues with the current master:
The second one will definitely have to be fixed before this will work, as it will break anything depending on network records from the first pass. Not sure what to do about the first one at this time, but I'd personally rather we (temporarily) break audit whitelisting for some gathers than start navigating in gatherers. |
| assert.deepEqual(offlineGather.artifact, {offlineResponseCode: 200}); | ||
| }); | ||
| it('returns an artifact set to -1 when offline loading fails', () => { | ||
| offlineGather.afterPass({url: 'https://do-not-match.com'}, tracingData); |
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.
We should avoid testing with real network in the unit tests. The fixed smoke/end-to-end test in #518 should cover these two test cases. As far as unit testing goes, I'd say the only real thing that needs to be checked is any corner case(s) of url matching (trailing slash and...anything else?)
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, if the gatherer doesn't do any navigation these would be good tests, just processing static network records :)
Instead of flipping the network back on, I'd be in favor of leaving network listening after the first pass, and then in here, we'd work from the end of the network records to find a matching item. |
|
Brendan is landing some items that will enable us to take this PR in easier. Thanks for the patience! |
2138876 to
bde0b39
Compare
|
@jeffposnick PTAL Updated PR to take advantage of #610. Simpler and seems to support more sites than master (for instance, fixes #611). There are some failure cases, like airhorner now reports that it doesn't work offline. I believe this is due to a flaw in gather-runner ordering. I'll make a separate PR for that. |
|
also breaks under the smoketest. I'll take a look at that too :) May be the same issue as airhorner |
2e209ea to
fa6e524
Compare
|
updated, should be good to go. |
| } | ||
|
|
||
| static goOnline(driver) { | ||
| return driver.sendCommand('Network.emulateNetworkConditions', Offline.config({offline: false})); |
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.
lets move these to the driver
|
Your version of the code seems to give the correct results, and thanks for rewriting it using a cleaner approach! I can still reliably trigger But given that I can reproduce the same error against the current |
|
(I filed #621 to track the priority-related issues I'm seeing.) |
really weird. I was hoping that doing it this way would avoid any |
|
After investigating more, @brendankenny, the errors I'm seeing don't appear to be related to the code in this PR. So they can be investigated independently. |
done, though it's a little ugly with the |
| afterPass(options, tracingData) { | ||
| const navigationRecord = tracingData.networkRecords.filter(record => { | ||
| // If options.url is just an origin without a path, Chrome will implicitly | ||
| // add in a path of '/'. |
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 actually took care of this part a bit ago: https://github.com/GoogleChrome/lighthouse/blob/ee92529ba/lighthouse-core/runner.js#L50-L51
can be simplified to just ...
return record._url === options.url && record._fetchedViaServiceWorker;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.
good point. also updated to use the non-underscored getter versions of these properties
|
works for me. lgtm |
459dae7 to
c06b2f3
Compare
c06b2f3 to
ceb5f36
Compare
|
Thanks @jeffposnick! Sorry this took so long. |
|
Thanks for taking it over, @brendankenny! |
R: @paulirish @samccone @paullewis etc.
This updates the logic in the
offline.jsgatherer. Instead of the XHR-based approach, which is prone to false-negatives for more complicated service workers, it goes through the steps needed to perform a full navigation to the target URL while the network is disconnected, and confirms that any successful responses were actually due to the service worker.I've got a couple of inline comments that it would be great to get some feedback on, mainly due to my ignorance about Lighthouse's overall setup.
Closes #425