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(fr): extract driver preparation methods #12445

Merged
merged 3 commits into from May 7, 2021
Merged

Conversation

patrickhulce
Copy link
Collaborator

Summary
Starts to extract pieces from gather-runner for shared FR usage.

This creates a driver/prepare.js whose goal is to prepare a target for gathering (setup global protocol domains, hung usage handling, throttling, emulation, etc). This one is a little murkier where it should belong. I can see an argument for runner-helpers.js instead, and I can see an argument for a completely new place that previously didn't exist. I chose driver/prepare because it is aligned with this logic previously living in the driver monolith, felt weird to put it in the fraggle-rock folder and have legacy gather-runner reaching into it. If there are strong opinions about another place, it's just a filename/path, so speak up :)

Related Issues/PRs
ref #11313

@patrickhulce patrickhulce requested a review from a team as a code owner May 5, 2021 17:33
@patrickhulce patrickhulce requested review from connorjclark and removed request for a team May 5, 2021 17:33
@google-cla google-cla bot added the cla: yes label May 5, 2021

// `Debugger.setSkipAllPauses` is reset after every navigation, so retrigger it on main frame navigations.
// See https://bugs.chromium.org/p/chromium/issues/detail?id=990945&q=setSkipAllPauses&can=2
session.on('Page.frameNavigated', event => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

* @return {Promise<void>}
*/
async function shimRequestIdleCallbackOnNewDocument(driver, settings) {
await driver.executionContext.evaluateOnNewDocument(pageFunctions.wrapRequestIdleCallback, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same impl

* @return {Promise<void>}
*/
async function dismissJavaScriptDialogs(session) {
session.on('Page.javascriptDialogOpening', data => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same exact impl

const warning = await storage.getImportantStorageWarning(session, navigation.url);
if (warning) warnings.push(warning);
await storage.clearDataForOrigin(session, navigation.url);
await storage.clearBrowserCaches(session);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's new that these two clear are colocated. I couldn't think of a compelling reason why you'd only want to clear the data but not the caches, and we previously only cleared the caches on the same passes as the ones we cleared data so from protocol message log perspective it should behave the same as before.

* @param {LH.Config.Settings} settings
* @param {Pick<LH.Config.NavigationDefn, 'disableThrottling'|'disableStorageReset'|'blockedUrlPatterns'> & {url: string}} navigation
*/
async function prepareNetworkForNavigation(session, settings, navigation) {
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 is effectively the same as setupPassNetwork previously

* @param {LH.Gatherer.FRTransitionalDriver} driver
* @param {LH.Config.Settings} settings
*/
async function prepareTargetForNavigationMode(driver, settings) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the same as setupDriver but with storage reset extracted to prepareTargetForIndividualNavigation

/** @type {Array<LH.IcuMessage>} */
const warnings = [];

const shouldResetStorage = !settings.disableStorageReset && !navigation.disableStorageReset;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

storage reset was moved here for three main reasons:

  1. It requires a URL, so it's already specific to a navigation intent, doesn't make sense as a general target setup.
  2. If we're trying to clear storage, then we should clear before each navigation. We've come a long way in 5 years of Lighthouse and have clarity that passes/navigations are not going to be how we solve flows, we're solving flows with FR, so additional navigations should be reloading the same situation unless configured otherwise :)
  3. It does not change the default config sequence anyway, only if you had custom config combinations of recordTrace: false, useThrottling: true will it matter.

@@ -115,7 +115,7 @@ async function cleanBrowserCaches(session) {

module.exports = {
clearDataForOrigin,
cleanBrowserCaches,
clearBrowserCaches,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just consistency I noticed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants