lighthouse 11.6.0-dev.20240312 → 11.6.0-dev.20240313
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,15 +12,7 @@ declare class CSSUsage extends BaseGatherer {
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {LH.Crdp.CSS.StyleSheetAddedEvent} event
|
|
14
14
|
*/
|
|
15
|
-
_onStylesheetAdded(event: LH.Crdp.CSS.StyleSheetAddedEvent):
|
|
16
|
-
/**
|
|
17
|
-
* @param {LH.Gatherer.Context} context
|
|
18
|
-
*/
|
|
19
|
-
startCSSUsageTracking(context: LH.Gatherer.Context): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* @param {LH.Gatherer.Context} context
|
|
22
|
-
*/
|
|
23
|
-
stopCSSUsageTracking(context: LH.Gatherer.Context): Promise<void>;
|
|
15
|
+
_onStylesheetAdded(event: LH.Crdp.CSS.StyleSheetAddedEvent): void;
|
|
24
16
|
/**
|
|
25
17
|
* @param {LH.Gatherer.Context} context
|
|
26
18
|
*/
|
|
@@ -36,7 +36,7 @@ class CSSUsage extends BaseGatherer {
|
|
|
36
36
|
/**
|
|
37
37
|
* @param {LH.Crdp.CSS.StyleSheetAddedEvent} event
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
_onStylesheetAdded(event) {
|
|
40
40
|
if (!this._session) throw new Error('Session not initialized');
|
|
41
41
|
const styleSheetId = event.header.styleSheetId;
|
|
42
42
|
const sheetPromise = this._session.sendCommand('CSS.getStyleSheetText', {styleSheetId})
|
|
@@ -66,41 +66,43 @@ class CSSUsage extends BaseGatherer {
|
|
|
66
66
|
/**
|
|
67
67
|
* @param {LH.Gatherer.Context} context
|
|
68
68
|
*/
|
|
69
|
-
async
|
|
69
|
+
async startInstrumentation(context) {
|
|
70
70
|
const session = context.driver.defaultSession;
|
|
71
71
|
this._session = session;
|
|
72
|
-
|
|
72
|
+
|
|
73
|
+
// Calling `CSS.enable` will emit events for stylesheets currently on the page.
|
|
74
|
+
// We want to ignore these events in navigation mode because they are not relevant to the
|
|
75
|
+
// navigation that is about to happen. Adding the event listener *after* calling `CSS.enable`
|
|
76
|
+
// ensures that the events for pre-existing stylesheets are ignored.
|
|
77
|
+
const isNavigation = context.gatherMode === 'navigation';
|
|
78
|
+
if (!isNavigation) {
|
|
79
|
+
session.on('CSS.styleSheetAdded', this._onStylesheetAdded);
|
|
80
|
+
}
|
|
73
81
|
|
|
74
82
|
await session.sendCommand('DOM.enable');
|
|
75
83
|
await session.sendCommand('CSS.enable');
|
|
76
84
|
await session.sendCommand('CSS.startRuleUsageTracking');
|
|
85
|
+
|
|
86
|
+
if (isNavigation) {
|
|
87
|
+
session.on('CSS.styleSheetAdded', this._onStylesheetAdded);
|
|
88
|
+
}
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
|
|
80
92
|
/**
|
|
81
93
|
* @param {LH.Gatherer.Context} context
|
|
82
94
|
*/
|
|
83
|
-
async
|
|
95
|
+
async stopInstrumentation(context) {
|
|
84
96
|
const session = context.driver.defaultSession;
|
|
85
97
|
const coverageResponse = await session.sendCommand('CSS.stopRuleUsageTracking');
|
|
86
98
|
this._ruleUsage = coverageResponse.ruleUsage;
|
|
87
99
|
session.off('CSS.styleSheetAdded', this._onStylesheetAdded);
|
|
88
|
-
}
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
async startInstrumentation(context) {
|
|
94
|
-
if (context.gatherMode !== 'timespan') return;
|
|
95
|
-
await this.startCSSUsageTracking(context);
|
|
96
|
-
}
|
|
101
|
+
// Ensure we finish fetching all stylesheet contents before disabling the CSS domain
|
|
102
|
+
await Promise.all(this._sheetPromises.values());
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*/
|
|
101
|
-
async stopInstrumentation(context) {
|
|
102
|
-
if (context.gatherMode !== 'timespan') return;
|
|
103
|
-
await this.stopCSSUsageTracking(context);
|
|
104
|
+
await session.sendCommand('CSS.disable');
|
|
105
|
+
await session.sendCommand('DOM.disable');
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|
|
@@ -108,17 +110,16 @@ class CSSUsage extends BaseGatherer {
|
|
|
108
110
|
* @return {Promise<LH.Artifacts['CSSUsage']>}
|
|
109
111
|
*/
|
|
110
112
|
async getArtifact(context) {
|
|
111
|
-
const session = context.driver.defaultSession;
|
|
112
113
|
const executionContext = context.driver.executionContext;
|
|
113
114
|
|
|
114
|
-
if (context.gatherMode
|
|
115
|
-
await this.
|
|
115
|
+
if (context.gatherMode === 'snapshot') {
|
|
116
|
+
await this.startInstrumentation(context);
|
|
116
117
|
|
|
117
118
|
// Force style to recompute.
|
|
118
119
|
// Doesn't appear to be necessary in newer versions of Chrome.
|
|
119
120
|
await executionContext.evaluateAsync('getComputedStyle(document.body)');
|
|
120
121
|
|
|
121
|
-
await this.
|
|
122
|
+
await this.stopInstrumentation(context);
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
/** @type {Map<string, LH.Artifacts.CSSStyleSheetInfo>} */
|
|
@@ -140,9 +141,6 @@ class CSSUsage extends BaseGatherer {
|
|
|
140
141
|
dedupedStylesheets.set(sheet.content, sheet);
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
await session.sendCommand('CSS.disable');
|
|
144
|
-
await session.sendCommand('DOM.disable');
|
|
145
|
-
|
|
146
144
|
if (!this._ruleUsage) throw new Error('Issue collecting rule usages');
|
|
147
145
|
|
|
148
146
|
return {
|
|
@@ -124,9 +124,7 @@ class RootCauses extends BaseGatherer {
|
|
|
124
124
|
rootCauses.layoutShifts[layoutShiftEvents.indexOf(event)] = r;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
// ...but we don't give gatherers their own session so this stomps on others.
|
|
129
|
-
// await driver.defaultSession.sendCommand('DOM.disable');
|
|
127
|
+
await driver.defaultSession.sendCommand('DOM.disable');
|
|
130
128
|
await driver.defaultSession.sendCommand('CSS.disable');
|
|
131
129
|
|
|
132
130
|
return rootCauses;
|
package/package.json
CHANGED