forked from GoogleChrome/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspector-issues.js
112 lines (100 loc) · 3.23 KB
/
inspector-issues.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview Capture IssueAdded events
*/
import BaseGatherer from '../base-gatherer.js';
import {NetworkRecords} from '../../computed/network-records.js';
import DevtoolsLog from './devtools-log.js';
class InspectorIssues extends BaseGatherer {
/** @type {LH.Gatherer.GathererMeta<'DevtoolsLog'>} */
meta = {
supportedModes: ['timespan', 'navigation'],
dependencies: {DevtoolsLog: DevtoolsLog.symbol},
};
constructor() {
super();
/** @type {Array<LH.Crdp.Audits.InspectorIssue>} */
this._issues = [];
this._onIssueAdded = this.onIssueAdded.bind(this);
}
/**
* @param {LH.Crdp.Audits.IssueAddedEvent} entry
*/
onIssueAdded(entry) {
this._issues.push(entry.issue);
}
/**
* @param {LH.Gatherer.Context} context
*/
async startInstrumentation(context) {
const session = context.driver.defaultSession;
session.on('Audits.issueAdded', this._onIssueAdded);
await session.sendCommand('Audits.enable');
}
/**
* @param {LH.Gatherer.Context} context
*/
async stopInstrumentation(context) {
const session = context.driver.defaultSession;
session.off('Audits.issueAdded', this._onIssueAdded);
await session.sendCommand('Audits.disable');
}
/**
* @param {LH.Gatherer.Context<'DevtoolsLog'>} context
* @return {Promise<LH.Artifacts['InspectorIssues']>}
*/
async getArtifact(context) {
const devtoolsLog = context.dependencies.DevtoolsLog;
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
/** @type {LH.Artifacts.InspectorIssues} */
const artifact = {
attributionReportingIssue: [],
blockedByResponseIssue: [],
bounceTrackingIssue: [],
clientHintIssue: [],
contentSecurityPolicyIssue: [],
corsIssue: [],
deprecationIssue: [],
federatedAuthRequestIssue: [],
genericIssue: [],
heavyAdIssue: [],
lowTextContrastIssue: [],
mixedContentIssue: [],
navigatorUserAgentIssue: [],
propertyRuleIssue: [],
quirksModeIssue: [],
cookieIssue: [],
sharedArrayBufferIssue: [],
stylesheetLoadingIssue: [],
federatedAuthUserInfoRequestIssue: [],
};
const keys = /** @type {Array<keyof LH.Artifacts['InspectorIssues']>} */(Object.keys(artifact));
for (const key of keys) {
/** @type {`${key}Details`} */
const detailsKey = `${key}Details`;
const allDetails = this._issues.map(issue => issue.details[detailsKey]);
for (const detail of allDetails) {
if (!detail) {
continue;
}
// Duplicate issues can occur for the same request; only use the one with a matching networkRequest.
const requestId = 'request' in detail && detail.request && detail.request.requestId;
if (requestId) {
if (networkRecords.find(req => req.requestId === requestId)) {
// @ts-expect-error - detail types are not all compatible
artifact[key].push(detail);
}
} else {
// @ts-expect-error - detail types are not all compatible
artifact[key].push(detail);
}
}
}
return artifact;
}
}
export default InspectorIssues;