@paulirish/trace_engine 0.0.24 → 0.0.26
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.
- package/core/platform/TypedArrayUtilities.d.ts +7 -0
- package/core/platform/TypedArrayUtilities.js +41 -0
- package/core/platform/TypedArrayUtilities.js.map +1 -1
- package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/core/platform/platform-tsconfig.json +0 -1
- package/generated/protocol.d.ts +73 -18
- package/models/cpu_profile/cpu_profile-tsconfig.json +0 -1
- package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/LanternComputationData.d.ts +8 -0
- package/models/trace/LanternComputationData.js +368 -0
- package/models/trace/LanternComputationData.js.map +1 -0
- package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/extras/extras-tsconfig.json +0 -1
- package/models/trace/handlers/AuctionWorkletsHandler.js +1 -1
- package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
- package/models/trace/handlers/EnhancedTracesHandler.d.ts +46 -0
- package/models/trace/handlers/EnhancedTracesHandler.js +137 -0
- package/models/trace/handlers/EnhancedTracesHandler.js.map +1 -0
- package/models/trace/handlers/LayoutShiftsHandler.d.ts +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.js +3 -3
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.js +39 -13
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/ModelHandlers.d.ts +1 -0
- package/models/trace/handlers/ModelHandlers.js +1 -0
- package/models/trace/handlers/ModelHandlers.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.js +2 -2
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +1 -2
- package/models/trace/handlers/PageLoadMetricsHandler.js +2 -35
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/ScreenshotsHandler.js +1 -2
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
- package/models/trace/handlers/UserInteractionsHandler.d.ts +6 -0
- package/models/trace/handlers/UserInteractionsHandler.js +17 -2
- package/models/trace/handlers/UserInteractionsHandler.js.map +1 -1
- package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/handlers/handlers-tsconfig.json +1 -1
- package/models/trace/helpers/SyntheticEvents.d.ts +1 -0
- package/models/trace/helpers/SyntheticEvents.js +12 -0
- package/models/trace/helpers/SyntheticEvents.js.map +1 -1
- package/models/trace/helpers/Timing.d.ts +17 -6
- package/models/trace/helpers/Timing.js +17 -76
- package/models/trace/helpers/Timing.js.map +1 -1
- package/models/trace/helpers/Trace.js +1 -2
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/helpers/helpers-tsconfig.json +0 -1
- package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/insights/insights-tsconfig.json +0 -1
- package/models/trace/lantern/BaseNode.d.ts +91 -0
- package/models/trace/lantern/BaseNode.js +268 -0
- package/models/trace/lantern/BaseNode.js.map +1 -0
- package/models/trace/lantern/CPUNode.d.ts +24 -0
- package/models/trace/lantern/CPUNode.js +64 -0
- package/models/trace/lantern/CPUNode.js.map +1 -0
- package/models/trace/lantern/LanternError.d.ts +3 -0
- package/models/trace/lantern/LanternError.js +7 -0
- package/models/trace/lantern/LanternError.js.map +1 -0
- package/models/trace/lantern/MetricsModule.d.ts +11 -0
- package/models/trace/lantern/MetricsModule.js +14 -0
- package/models/trace/lantern/MetricsModule.js.map +1 -0
- package/models/trace/lantern/NetworkNode.d.ts +22 -0
- package/models/trace/lantern/NetworkNode.js +83 -0
- package/models/trace/lantern/NetworkNode.js.map +1 -0
- package/models/trace/lantern/PageDependencyGraph.d.ts +43 -0
- package/models/trace/lantern/PageDependencyGraph.js +509 -0
- package/models/trace/lantern/PageDependencyGraph.js.map +1 -0
- package/models/trace/lantern/SimulationModule.d.ts +17 -0
- package/models/trace/lantern/SimulationModule.js +13 -0
- package/models/trace/lantern/SimulationModule.js.map +1 -0
- package/models/trace/lantern/bundle-tsconfig.json +1 -0
- package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +42 -0
- package/models/trace/lantern/lantern-tsconfig.json +64 -0
- package/models/trace/lantern/lantern.d.ts +29 -0
- package/models/trace/lantern/lantern.js +33 -0
- package/models/trace/lantern/lantern.js.map +1 -0
- package/models/trace/lantern/metrics/FirstContentfulPaint.d.ts +42 -0
- package/models/trace/lantern/metrics/FirstContentfulPaint.js +137 -0
- package/models/trace/lantern/metrics/FirstContentfulPaint.js.map +1 -0
- package/models/trace/lantern/metrics/Interactive.d.ts +12 -0
- package/models/trace/lantern/metrics/Interactive.js +68 -0
- package/models/trace/lantern/metrics/Interactive.js.map +1 -0
- package/models/trace/lantern/metrics/LargestContentfulPaint.d.ts +16 -0
- package/models/trace/lantern/metrics/LargestContentfulPaint.js +70 -0
- package/models/trace/lantern/metrics/LargestContentfulPaint.js.map +1 -0
- package/models/trace/lantern/metrics/MaxPotentialFID.d.ts +14 -0
- package/models/trace/lantern/metrics/MaxPotentialFID.js +49 -0
- package/models/trace/lantern/metrics/MaxPotentialFID.js.map +1 -0
- package/models/trace/lantern/metrics/Metric.d.ts +26 -0
- package/models/trace/lantern/metrics/Metric.js +71 -0
- package/models/trace/lantern/metrics/Metric.js.map +1 -0
- package/models/trace/lantern/metrics/SpeedIndex.d.ts +25 -0
- package/models/trace/lantern/metrics/SpeedIndex.js +102 -0
- package/models/trace/lantern/metrics/SpeedIndex.js.map +1 -0
- package/models/trace/lantern/metrics/TBTUtils.d.ts +31 -0
- package/models/trace/lantern/metrics/TBTUtils.js +65 -0
- package/models/trace/lantern/metrics/TBTUtils.js.map +1 -0
- package/models/trace/lantern/metrics/TotalBlockingTime.d.ts +16 -0
- package/models/trace/lantern/metrics/TotalBlockingTime.js +79 -0
- package/models/trace/lantern/metrics/TotalBlockingTime.js.map +1 -0
- package/models/trace/lantern/metrics/metrics.d.ts +15 -0
- package/models/trace/lantern/metrics/metrics.js +12 -0
- package/models/trace/lantern/metrics/metrics.js.map +1 -0
- package/models/trace/lantern/simulation/ConnectionPool.d.ts +26 -0
- package/models/trace/lantern/simulation/ConnectionPool.js +116 -0
- package/models/trace/lantern/simulation/ConnectionPool.js.map +1 -0
- package/models/trace/lantern/simulation/Constants.d.ts +31 -0
- package/models/trace/lantern/simulation/Constants.js +43 -0
- package/models/trace/lantern/simulation/Constants.js.map +1 -0
- package/models/trace/lantern/simulation/DNSCache.d.ts +22 -0
- package/models/trace/lantern/simulation/DNSCache.js +48 -0
- package/models/trace/lantern/simulation/DNSCache.js.map +1 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.d.ts +112 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.js +486 -0
- package/models/trace/lantern/simulation/NetworkAnalyzer.js.map +1 -0
- package/models/trace/lantern/simulation/SimulationTimingMap.d.ts +71 -0
- package/models/trace/lantern/simulation/SimulationTimingMap.js +134 -0
- package/models/trace/lantern/simulation/SimulationTimingMap.js.map +1 -0
- package/models/trace/lantern/simulation/Simulator.d.ts +82 -0
- package/models/trace/lantern/simulation/Simulator.js +449 -0
- package/models/trace/lantern/simulation/Simulator.js.map +1 -0
- package/models/trace/lantern/simulation/TCPConnection.d.ts +48 -0
- package/models/trace/lantern/simulation/TCPConnection.js +158 -0
- package/models/trace/lantern/simulation/TCPConnection.js.map +1 -0
- package/models/trace/lantern/simulation/simulation.d.ts +21 -0
- package/models/trace/lantern/simulation/simulation.js +11 -0
- package/models/trace/lantern/simulation/simulation.js.map +1 -0
- package/models/trace/lantern/types/lantern.d.ts +205 -0
- package/models/trace/lantern/types/lantern.js +5 -0
- package/models/trace/lantern/types/lantern.js.map +1 -0
- package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/root-causes/root-causes-tsconfig.json +0 -1
- package/models/trace/trace-tsconfig.json +4 -1
- package/models/trace/trace.d.ts +3 -1
- package/models/trace/trace.js +3 -1
- package/models/trace/trace.js.map +1 -1
- package/models/trace/types/Extensions.d.ts +2 -3
- package/models/trace/types/Extensions.js +2 -11
- package/models/trace/types/Extensions.js.map +1 -1
- package/models/trace/types/File.d.ts +28 -5
- package/models/trace/types/File.js +36 -1
- package/models/trace/types/File.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +50 -0
- package/models/trace/types/TraceEvents.js +33 -0
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -1
- package/models/trace/types/types-tsconfig.json +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"compilerOptions":{"composite":true,"outDir":".","baseUrl":".","rootDir":"../../../../../../../front_end/models/trace/lantern"},"files":["../../../../../../../front_end/models/trace/lantern/lantern.ts"],"references":[{"path":"./lantern-tsconfig.json"}]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"composite": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"inlineSources": true,
|
|
10
|
+
"lib": [
|
|
11
|
+
"esnext",
|
|
12
|
+
"dom",
|
|
13
|
+
"dom.iterable"
|
|
14
|
+
],
|
|
15
|
+
"module": "esnext",
|
|
16
|
+
"noEmitOnError": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noImplicitOverride": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"outDir": ".",
|
|
22
|
+
"rootDir": "../../../../../../../front_end/models/trace/lantern",
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"sourceMap": true,
|
|
25
|
+
"strict": true,
|
|
26
|
+
"target": "esnext",
|
|
27
|
+
"tsBuildInfoFile": "devtools_entrypoint-bundle-typescript-tsconfig.json.tsbuildinfo",
|
|
28
|
+
"typeRoots": [],
|
|
29
|
+
"useUnknownInCatchVariables": false
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"../../../../../../../front_end/models/trace/lantern/lantern.ts",
|
|
33
|
+
"../../../../../../../front_end/legacy/legacy-defs.d.ts",
|
|
34
|
+
"../../../../../../../front_end/global_typings/global_defs.d.ts",
|
|
35
|
+
"../../../../../../../node_modules/@types/filesystem/index.d.ts"
|
|
36
|
+
],
|
|
37
|
+
"references": [
|
|
38
|
+
{
|
|
39
|
+
"path": "./lantern-tsconfig.json"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"checkJs": true,
|
|
5
|
+
"composite": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"inlineSources": true,
|
|
10
|
+
"lib": [
|
|
11
|
+
"esnext",
|
|
12
|
+
"dom",
|
|
13
|
+
"dom.iterable"
|
|
14
|
+
],
|
|
15
|
+
"module": "esnext",
|
|
16
|
+
"noEmitOnError": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"noImplicitOverride": true,
|
|
19
|
+
"noImplicitReturns": true,
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"outDir": ".",
|
|
22
|
+
"rootDir": "../../../../../../../front_end/models/trace/lantern",
|
|
23
|
+
"skipLibCheck": true,
|
|
24
|
+
"sourceMap": true,
|
|
25
|
+
"strict": true,
|
|
26
|
+
"target": "esnext",
|
|
27
|
+
"tsBuildInfoFile": "lantern-tsconfig.json.tsbuildinfo",
|
|
28
|
+
"typeRoots": [],
|
|
29
|
+
"useUnknownInCatchVariables": false
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"../../../../../../../front_end/models/trace/lantern/BaseNode.ts",
|
|
33
|
+
"../../../../../../../front_end/models/trace/lantern/CPUNode.ts",
|
|
34
|
+
"../../../../../../../front_end/models/trace/lantern/LanternError.ts",
|
|
35
|
+
"../../../../../../../front_end/models/trace/lantern/MetricsModule.ts",
|
|
36
|
+
"../../../../../../../front_end/models/trace/lantern/NetworkNode.ts",
|
|
37
|
+
"../../../../../../../front_end/models/trace/lantern/PageDependencyGraph.ts",
|
|
38
|
+
"../../../../../../../front_end/models/trace/lantern/SimulationModule.ts",
|
|
39
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts",
|
|
40
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/Interactive.ts",
|
|
41
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts",
|
|
42
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/MaxPotentialFID.ts",
|
|
43
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/Metric.ts",
|
|
44
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/SpeedIndex.ts",
|
|
45
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/TBTUtils.ts",
|
|
46
|
+
"../../../../../../../front_end/models/trace/lantern/metrics/TotalBlockingTime.ts",
|
|
47
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/ConnectionPool.ts",
|
|
48
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/Constants.ts",
|
|
49
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/DNSCache.ts",
|
|
50
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/NetworkAnalyzer.ts",
|
|
51
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/SimulationTimingMap.ts",
|
|
52
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/Simulator.ts",
|
|
53
|
+
"../../../../../../../front_end/models/trace/lantern/simulation/TCPConnection.ts",
|
|
54
|
+
"../../../../../../../front_end/models/trace/lantern/types/lantern.ts",
|
|
55
|
+
"../../../../../../../front_end/legacy/legacy-defs.d.ts",
|
|
56
|
+
"../../../../../../../front_end/global_typings/global_defs.d.ts",
|
|
57
|
+
"../../../../../../../node_modules/@types/filesystem/index.d.ts"
|
|
58
|
+
],
|
|
59
|
+
"references": [
|
|
60
|
+
{
|
|
61
|
+
"path": "../types/bundle-tsconfig.json"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as Metrics from './MetricsModule.js';
|
|
2
|
+
import * as Simulation from './SimulationModule.js';
|
|
3
|
+
export { BaseNode, type Node } from './BaseNode.js';
|
|
4
|
+
export { CPUNode } from './CPUNode.js';
|
|
5
|
+
export { LanternError as Error } from './LanternError.js';
|
|
6
|
+
export { NetworkNode } from './NetworkNode.js';
|
|
7
|
+
export { PageDependencyGraph } from './PageDependencyGraph.js';
|
|
8
|
+
export type { NetworkRequest, ParsedURL, ResourcePriority, ResourceTiming, ResourceType, Trace, TraceEvent, } from './types/lantern.js';
|
|
9
|
+
export declare const NetworkRequestTypes: {
|
|
10
|
+
readonly XHR: "XHR";
|
|
11
|
+
readonly Fetch: "Fetch";
|
|
12
|
+
readonly EventSource: "EventSource";
|
|
13
|
+
readonly Script: "Script";
|
|
14
|
+
readonly Stylesheet: "Stylesheet";
|
|
15
|
+
readonly Image: "Image";
|
|
16
|
+
readonly Media: "Media";
|
|
17
|
+
readonly Font: "Font";
|
|
18
|
+
readonly Document: "Document";
|
|
19
|
+
readonly TextTrack: "TextTrack";
|
|
20
|
+
readonly WebSocket: "WebSocket";
|
|
21
|
+
readonly Other: "Other";
|
|
22
|
+
readonly Manifest: "Manifest";
|
|
23
|
+
readonly SignedExchange: "SignedExchange";
|
|
24
|
+
readonly Ping: "Ping";
|
|
25
|
+
readonly Preflight: "Preflight";
|
|
26
|
+
readonly CSPViolationReport: "CSPViolationReport";
|
|
27
|
+
readonly Prefetch: "Prefetch";
|
|
28
|
+
};
|
|
29
|
+
export { Metrics, Simulation, };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
// TODO(crbug.com/348449529): refactor to proper devtools module
|
|
5
|
+
import * as Metrics from './MetricsModule.js';
|
|
6
|
+
import * as Simulation from './SimulationModule.js';
|
|
7
|
+
export { BaseNode } from './BaseNode.js';
|
|
8
|
+
export { CPUNode } from './CPUNode.js';
|
|
9
|
+
export { LanternError as Error } from './LanternError.js';
|
|
10
|
+
export { NetworkNode } from './NetworkNode.js';
|
|
11
|
+
export { PageDependencyGraph } from './PageDependencyGraph.js';
|
|
12
|
+
export const NetworkRequestTypes = {
|
|
13
|
+
XHR: 'XHR',
|
|
14
|
+
Fetch: 'Fetch',
|
|
15
|
+
EventSource: 'EventSource',
|
|
16
|
+
Script: 'Script',
|
|
17
|
+
Stylesheet: 'Stylesheet',
|
|
18
|
+
Image: 'Image',
|
|
19
|
+
Media: 'Media',
|
|
20
|
+
Font: 'Font',
|
|
21
|
+
Document: 'Document',
|
|
22
|
+
TextTrack: 'TextTrack',
|
|
23
|
+
WebSocket: 'WebSocket',
|
|
24
|
+
Other: 'Other',
|
|
25
|
+
Manifest: 'Manifest',
|
|
26
|
+
SignedExchange: 'SignedExchange',
|
|
27
|
+
Ping: 'Ping',
|
|
28
|
+
Preflight: 'Preflight',
|
|
29
|
+
CSPViolationReport: 'CSPViolationReport',
|
|
30
|
+
Prefetch: 'Prefetch',
|
|
31
|
+
};
|
|
32
|
+
export { Metrics, Simulation, };
|
|
33
|
+
//# sourceMappingURL=lantern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lantern.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/lantern/lantern.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,gEAAgE;AAEhE,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAC,QAAQ,EAAY,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,YAAY,IAAI,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAC,mBAAmB,EAAC,MAAM,0BAA0B,CAAC;AAW7D,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;IACpB,cAAc,EAAE,gBAAgB;IAChC,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;IACtB,kBAAkB,EAAE,oBAAoB;IACxC,QAAQ,EAAE,UAAU;CACZ,CAAC;AAEX,OAAO,EACL,OAAO,EACP,UAAU,GACX,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n// TODO(crbug.com/348449529): refactor to proper devtools module\n\nimport * as Metrics from './MetricsModule.js';\nimport * as Simulation from './SimulationModule.js';\n\nexport {BaseNode, type Node} from './BaseNode.js';\nexport {CPUNode} from './CPUNode.js';\nexport {LanternError as Error} from './LanternError.js';\nexport {NetworkNode} from './NetworkNode.js';\nexport {PageDependencyGraph} from './PageDependencyGraph.js';\nexport type {\n NetworkRequest,\n ParsedURL,\n ResourcePriority,\n ResourceTiming,\n ResourceType,\n Trace,\n TraceEvent,\n} from './types/lantern.js';\n\nexport const NetworkRequestTypes = {\n XHR: 'XHR',\n Fetch: 'Fetch',\n EventSource: 'EventSource',\n Script: 'Script',\n Stylesheet: 'Stylesheet',\n Image: 'Image',\n Media: 'Media',\n Font: 'Font',\n Document: 'Document',\n TextTrack: 'TextTrack',\n WebSocket: 'WebSocket',\n Other: 'Other',\n Manifest: 'Manifest',\n SignedExchange: 'SignedExchange',\n Ping: 'Ping',\n Preflight: 'Preflight',\n CSPViolationReport: 'CSPViolationReport',\n Prefetch: 'Prefetch',\n} as const;\n\nexport {\n Metrics,\n Simulation,\n};\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Node } from '../BaseNode.js';
|
|
2
|
+
import { type CPUNode } from '../CPUNode.js';
|
|
3
|
+
import { type NetworkNode } from '../NetworkNode.js';
|
|
4
|
+
import type * as Lantern from '../types/lantern.js';
|
|
5
|
+
import { Metric } from './Metric.js';
|
|
6
|
+
interface FirstPaintBasedGraphOpts<T> {
|
|
7
|
+
/**
|
|
8
|
+
* The timestamp used to filter out tasks that occured after our paint of interest.
|
|
9
|
+
* Typically this is First Contentful Paint or First Meaningful Paint.
|
|
10
|
+
*/
|
|
11
|
+
cutoffTimestamp: number;
|
|
12
|
+
/**
|
|
13
|
+
* The function that determines which resources should be considered *possibly*
|
|
14
|
+
* render-blocking.
|
|
15
|
+
*/
|
|
16
|
+
treatNodeAsRenderBlocking: (node: NetworkNode<T>) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The function that determines which CPU nodes should also be included in our
|
|
19
|
+
* blocking node IDs set, beyond what getRenderBlockingNodeData() already includes.
|
|
20
|
+
*/
|
|
21
|
+
additionalCpuNodesToTreatAsRenderBlocking?: (node: CPUNode) => boolean;
|
|
22
|
+
}
|
|
23
|
+
declare class FirstContentfulPaint extends Metric {
|
|
24
|
+
static get coefficients(): Lantern.Simulation.MetricCoefficients;
|
|
25
|
+
/**
|
|
26
|
+
* Computes the set of URLs that *appeared* to be render-blocking based on our filter,
|
|
27
|
+
* *but definitely were not* render-blocking based on the timing of their EvaluateScript task.
|
|
28
|
+
* It also computes the set of corresponding CPU node ids that were needed for the paint at the
|
|
29
|
+
* given timestamp.
|
|
30
|
+
*/
|
|
31
|
+
static getRenderBlockingNodeData<T = unknown>(graph: Node, { cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking }: FirstPaintBasedGraphOpts<T>): {
|
|
32
|
+
definitelyNotRenderBlockingScriptUrls: Set<string>;
|
|
33
|
+
renderBlockingCpuNodeIds: Set<string>;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Computes the graph required for the first paint of interest.
|
|
37
|
+
*/
|
|
38
|
+
static getFirstPaintBasedGraph<T>(dependencyGraph: Node, { cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking }: FirstPaintBasedGraphOpts<T>): Node<T>;
|
|
39
|
+
static getOptimisticGraph<T>(dependencyGraph: Node<T>, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node<T>;
|
|
40
|
+
static getPessimisticGraph<T>(dependencyGraph: Node<T>, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node<T>;
|
|
41
|
+
}
|
|
42
|
+
export { FirstContentfulPaint };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import { BaseNode } from '../BaseNode.js';
|
|
5
|
+
import { Metric } from './Metric.js';
|
|
6
|
+
class FirstContentfulPaint extends Metric {
|
|
7
|
+
static get coefficients() {
|
|
8
|
+
return {
|
|
9
|
+
intercept: 0,
|
|
10
|
+
optimistic: 0.5,
|
|
11
|
+
pessimistic: 0.5,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Computes the set of URLs that *appeared* to be render-blocking based on our filter,
|
|
16
|
+
* *but definitely were not* render-blocking based on the timing of their EvaluateScript task.
|
|
17
|
+
* It also computes the set of corresponding CPU node ids that were needed for the paint at the
|
|
18
|
+
* given timestamp.
|
|
19
|
+
*/
|
|
20
|
+
static getRenderBlockingNodeData(graph, { cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking }) {
|
|
21
|
+
/** A map of blocking script URLs to the earliest EvaluateScript task node that executed them. */
|
|
22
|
+
const scriptUrlToNodeMap = new Map();
|
|
23
|
+
const cpuNodes = [];
|
|
24
|
+
graph.traverse(node => {
|
|
25
|
+
if (node.type === BaseNode.types.CPU) {
|
|
26
|
+
// A task is *possibly* render blocking if it *started* before cutoffTimestamp.
|
|
27
|
+
// We use startTime here because the paint event can be *inside* the task that was render blocking.
|
|
28
|
+
if (node.startTime <= cutoffTimestamp) {
|
|
29
|
+
cpuNodes.push(node);
|
|
30
|
+
}
|
|
31
|
+
// Build our script URL map to find the earliest EvaluateScript task node.
|
|
32
|
+
const scriptUrls = node.getEvaluateScriptURLs();
|
|
33
|
+
for (const url of scriptUrls) {
|
|
34
|
+
// Use the earliest CPU node we find.
|
|
35
|
+
const existing = scriptUrlToNodeMap.get(url) || node;
|
|
36
|
+
scriptUrlToNodeMap.set(url, node.startTime < existing.startTime ? node : existing);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
cpuNodes.sort((a, b) => a.startTime - b.startTime);
|
|
41
|
+
// A script is *possibly* render blocking if it finished loading before cutoffTimestamp.
|
|
42
|
+
const possiblyRenderBlockingScriptUrls = Metric.getScriptUrls(graph, node => {
|
|
43
|
+
// The optimistic LCP treatNodeAsRenderBlocking fn wants to exclude some images in the graph,
|
|
44
|
+
// but here it only receives scripts to evaluate. It's a no-op in this case, but it will
|
|
45
|
+
// matter below in the getFirstPaintBasedGraph clone operation.
|
|
46
|
+
return node.endTime <= cutoffTimestamp && treatNodeAsRenderBlocking(node);
|
|
47
|
+
});
|
|
48
|
+
// A script is *definitely not* render blocking if its EvaluateScript task started after cutoffTimestamp.
|
|
49
|
+
const definitelyNotRenderBlockingScriptUrls = new Set();
|
|
50
|
+
const renderBlockingCpuNodeIds = new Set();
|
|
51
|
+
for (const url of possiblyRenderBlockingScriptUrls) {
|
|
52
|
+
// Lookup the CPU node that had the earliest EvaluateScript for this URL.
|
|
53
|
+
const cpuNodeForUrl = scriptUrlToNodeMap.get(url);
|
|
54
|
+
// If we can't find it at all, we can't conclude anything, so just skip it.
|
|
55
|
+
if (!cpuNodeForUrl) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// If we found it and it was in our `cpuNodes` set that means it finished before cutoffTimestamp, so it really is render-blocking.
|
|
59
|
+
if (cpuNodes.includes(cpuNodeForUrl)) {
|
|
60
|
+
renderBlockingCpuNodeIds.add(cpuNodeForUrl.id);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// We couldn't find the evaluate script in the set of CPU nodes that ran before our paint, so
|
|
64
|
+
// it must not have been necessary for the paint.
|
|
65
|
+
definitelyNotRenderBlockingScriptUrls.add(url);
|
|
66
|
+
}
|
|
67
|
+
// The first layout, first paint, and first ParseHTML are almost always necessary for first paint,
|
|
68
|
+
// so we always include those CPU nodes.
|
|
69
|
+
const firstLayout = cpuNodes.find(node => node.didPerformLayout());
|
|
70
|
+
if (firstLayout) {
|
|
71
|
+
renderBlockingCpuNodeIds.add(firstLayout.id);
|
|
72
|
+
}
|
|
73
|
+
const firstPaint = cpuNodes.find(node => node.childEvents.some(e => e.name === 'Paint'));
|
|
74
|
+
if (firstPaint) {
|
|
75
|
+
renderBlockingCpuNodeIds.add(firstPaint.id);
|
|
76
|
+
}
|
|
77
|
+
const firstParse = cpuNodes.find(node => node.childEvents.some(e => e.name === 'ParseHTML'));
|
|
78
|
+
if (firstParse) {
|
|
79
|
+
renderBlockingCpuNodeIds.add(firstParse.id);
|
|
80
|
+
}
|
|
81
|
+
// If a CPU filter was passed in, we also want to include those extra nodes.
|
|
82
|
+
if (additionalCpuNodesToTreatAsRenderBlocking) {
|
|
83
|
+
cpuNodes.filter(additionalCpuNodesToTreatAsRenderBlocking).forEach(node => renderBlockingCpuNodeIds.add(node.id));
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
definitelyNotRenderBlockingScriptUrls,
|
|
87
|
+
renderBlockingCpuNodeIds,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Computes the graph required for the first paint of interest.
|
|
92
|
+
*/
|
|
93
|
+
static getFirstPaintBasedGraph(dependencyGraph, { cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking }) {
|
|
94
|
+
const rbData = this.getRenderBlockingNodeData(dependencyGraph, {
|
|
95
|
+
cutoffTimestamp,
|
|
96
|
+
treatNodeAsRenderBlocking,
|
|
97
|
+
additionalCpuNodesToTreatAsRenderBlocking,
|
|
98
|
+
});
|
|
99
|
+
const { definitelyNotRenderBlockingScriptUrls, renderBlockingCpuNodeIds } = rbData;
|
|
100
|
+
return dependencyGraph.cloneWithRelationships(node => {
|
|
101
|
+
if (node.type === BaseNode.types.NETWORK) {
|
|
102
|
+
// Exclude all nodes that ended after cutoffTimestamp (except for the main document which we always consider necessary)
|
|
103
|
+
// endTime is negative if request does not finish, make sure startTime isn't after cutoffTimestamp in this case.
|
|
104
|
+
const endedAfterPaint = node.endTime > cutoffTimestamp || node.startTime > cutoffTimestamp;
|
|
105
|
+
if (endedAfterPaint && !node.isMainDocument()) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const url = node.request.url;
|
|
109
|
+
// If the URL definitely wasn't render-blocking then we filter it out.
|
|
110
|
+
if (definitelyNotRenderBlockingScriptUrls.has(url)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
// Lastly, build up the FCP graph of all nodes we consider render blocking
|
|
114
|
+
return treatNodeAsRenderBlocking(node);
|
|
115
|
+
}
|
|
116
|
+
// If it's a CPU node, just check if it was blocking.
|
|
117
|
+
return renderBlockingCpuNodeIds.has(node.id);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
static getOptimisticGraph(dependencyGraph, processedNavigation) {
|
|
121
|
+
return this.getFirstPaintBasedGraph(dependencyGraph, {
|
|
122
|
+
cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,
|
|
123
|
+
// In the optimistic graph we exclude resources that appeared to be render blocking but were
|
|
124
|
+
// initiated by a script. While they typically have a very high importance and tend to have a
|
|
125
|
+
// significant impact on the page's content, these resources don't technically block rendering.
|
|
126
|
+
treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority() && node.initiatorType !== 'script',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
static getPessimisticGraph(dependencyGraph, processedNavigation) {
|
|
130
|
+
return this.getFirstPaintBasedGraph(dependencyGraph, {
|
|
131
|
+
cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,
|
|
132
|
+
treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority(),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export { FirstContentfulPaint };
|
|
137
|
+
//# sourceMappingURL=FirstContentfulPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FirstContentfulPaint.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts"],"names":[],"mappings":"AAAA,4DA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,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport {type CPUNode} from '../CPUNode.js';\nimport {type NetworkNode} from '../NetworkNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {Metric} from './Metric.js';\n\ninterface FirstPaintBasedGraphOpts<T> {\n /**\n * The timestamp used to filter out tasks that occured after our paint of interest.\n * Typically this is First Contentful Paint or First Meaningful Paint.\n */\n cutoffTimestamp: number;\n /**\n * The function that determines which resources should be considered *possibly*\n * render-blocking.\n */\n treatNodeAsRenderBlocking: (node: NetworkNode<T>) => boolean;\n /**\n * The function that determines which CPU nodes should also be included in our\n * blocking node IDs set, beyond what getRenderBlockingNodeData() already includes.\n */\n additionalCpuNodesToTreatAsRenderBlocking?: (node: CPUNode) => boolean;\n}\n\nclass FirstContentfulPaint extends Metric {\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n /**\n * Computes the set of URLs that *appeared* to be render-blocking based on our filter,\n * *but definitely were not* render-blocking based on the timing of their EvaluateScript task.\n * It also computes the set of corresponding CPU node ids that were needed for the paint at the\n * given timestamp.\n */\n static getRenderBlockingNodeData<T = unknown>(\n graph: Node,\n {cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking}:\n FirstPaintBasedGraphOpts<T>,\n ): {definitelyNotRenderBlockingScriptUrls: Set<string>, renderBlockingCpuNodeIds: Set<string>} {\n /** A map of blocking script URLs to the earliest EvaluateScript task node that executed them. */\n const scriptUrlToNodeMap = new Map<string, CPUNode>();\n\n const cpuNodes: CPUNode[] = [];\n graph.traverse(node => {\n if (node.type === BaseNode.types.CPU) {\n // A task is *possibly* render blocking if it *started* before cutoffTimestamp.\n // We use startTime here because the paint event can be *inside* the task that was render blocking.\n if (node.startTime <= cutoffTimestamp) {\n cpuNodes.push(node);\n }\n\n // Build our script URL map to find the earliest EvaluateScript task node.\n const scriptUrls = node.getEvaluateScriptURLs();\n for (const url of scriptUrls) {\n // Use the earliest CPU node we find.\n const existing = scriptUrlToNodeMap.get(url) || node;\n scriptUrlToNodeMap.set(url, node.startTime < existing.startTime ? node : existing);\n }\n }\n });\n\n cpuNodes.sort((a, b) => a.startTime - b.startTime);\n\n // A script is *possibly* render blocking if it finished loading before cutoffTimestamp.\n const possiblyRenderBlockingScriptUrls = Metric.getScriptUrls(graph, node => {\n // The optimistic LCP treatNodeAsRenderBlocking fn wants to exclude some images in the graph,\n // but here it only receives scripts to evaluate. It's a no-op in this case, but it will\n // matter below in the getFirstPaintBasedGraph clone operation.\n return node.endTime <= cutoffTimestamp && treatNodeAsRenderBlocking(node);\n });\n\n // A script is *definitely not* render blocking if its EvaluateScript task started after cutoffTimestamp.\n const definitelyNotRenderBlockingScriptUrls = new Set<string>();\n const renderBlockingCpuNodeIds = new Set<string>();\n for (const url of possiblyRenderBlockingScriptUrls) {\n // Lookup the CPU node that had the earliest EvaluateScript for this URL.\n const cpuNodeForUrl = scriptUrlToNodeMap.get(url);\n\n // If we can't find it at all, we can't conclude anything, so just skip it.\n if (!cpuNodeForUrl) {\n continue;\n }\n\n // If we found it and it was in our `cpuNodes` set that means it finished before cutoffTimestamp, so it really is render-blocking.\n if (cpuNodes.includes(cpuNodeForUrl)) {\n renderBlockingCpuNodeIds.add(cpuNodeForUrl.id);\n continue;\n }\n\n // We couldn't find the evaluate script in the set of CPU nodes that ran before our paint, so\n // it must not have been necessary for the paint.\n definitelyNotRenderBlockingScriptUrls.add(url);\n }\n\n // The first layout, first paint, and first ParseHTML are almost always necessary for first paint,\n // so we always include those CPU nodes.\n const firstLayout = cpuNodes.find(node => node.didPerformLayout());\n if (firstLayout) {\n renderBlockingCpuNodeIds.add(firstLayout.id);\n }\n const firstPaint = cpuNodes.find(node => node.childEvents.some(e => e.name === 'Paint'));\n if (firstPaint) {\n renderBlockingCpuNodeIds.add(firstPaint.id);\n }\n const firstParse = cpuNodes.find(node => node.childEvents.some(e => e.name === 'ParseHTML'));\n if (firstParse) {\n renderBlockingCpuNodeIds.add(firstParse.id);\n }\n\n // If a CPU filter was passed in, we also want to include those extra nodes.\n if (additionalCpuNodesToTreatAsRenderBlocking) {\n cpuNodes.filter(additionalCpuNodesToTreatAsRenderBlocking).forEach(node => renderBlockingCpuNodeIds.add(node.id));\n }\n\n return {\n definitelyNotRenderBlockingScriptUrls,\n renderBlockingCpuNodeIds,\n };\n }\n\n /**\n * Computes the graph required for the first paint of interest.\n */\n static getFirstPaintBasedGraph<T>(\n dependencyGraph: Node,\n {cutoffTimestamp, treatNodeAsRenderBlocking, additionalCpuNodesToTreatAsRenderBlocking}:\n FirstPaintBasedGraphOpts<T>,\n ): Node<T> {\n const rbData = this.getRenderBlockingNodeData(dependencyGraph, {\n cutoffTimestamp,\n treatNodeAsRenderBlocking,\n additionalCpuNodesToTreatAsRenderBlocking,\n });\n const {definitelyNotRenderBlockingScriptUrls, renderBlockingCpuNodeIds} = rbData;\n\n return dependencyGraph.cloneWithRelationships(node => {\n if (node.type === BaseNode.types.NETWORK) {\n // Exclude all nodes that ended after cutoffTimestamp (except for the main document which we always consider necessary)\n // endTime is negative if request does not finish, make sure startTime isn't after cutoffTimestamp in this case.\n const endedAfterPaint = node.endTime > cutoffTimestamp || node.startTime > cutoffTimestamp;\n if (endedAfterPaint && !node.isMainDocument()) {\n return false;\n }\n\n const url = node.request.url;\n // If the URL definitely wasn't render-blocking then we filter it out.\n if (definitelyNotRenderBlockingScriptUrls.has(url)) {\n return false;\n }\n\n // Lastly, build up the FCP graph of all nodes we consider render blocking\n return treatNodeAsRenderBlocking(node);\n }\n // If it's a CPU node, just check if it was blocking.\n return renderBlockingCpuNodeIds.has(node.id);\n });\n }\n\n static override getOptimisticGraph<T>(\n dependencyGraph: Node<T>, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node<T> {\n return this.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,\n // In the optimistic graph we exclude resources that appeared to be render blocking but were\n // initiated by a script. While they typically have a very high importance and tend to have a\n // significant impact on the page's content, these resources don't technically block rendering.\n treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority() && node.initiatorType !== 'script',\n });\n }\n\n static override getPessimisticGraph<T>(\n dependencyGraph: Node<T>, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node<T> {\n return this.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: processedNavigation.timestamps.firstContentfulPaint,\n treatNodeAsRenderBlocking: node => node.hasRenderBlockingPriority(),\n });\n }\n}\n\nexport {FirstContentfulPaint};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Node } from '../BaseNode.js';
|
|
2
|
+
import type * as Lantern from '../types/lantern.js';
|
|
3
|
+
import { type Extras, Metric } from './Metric.js';
|
|
4
|
+
declare class Interactive extends Metric {
|
|
5
|
+
static get coefficients(): Lantern.Simulation.MetricCoefficients;
|
|
6
|
+
static getOptimisticGraph<T>(dependencyGraph: Node<T>): Node<T>;
|
|
7
|
+
static getPessimisticGraph<T>(dependencyGraph: Node<T>): Node<T>;
|
|
8
|
+
static getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras): Lantern.Simulation.Result;
|
|
9
|
+
static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
|
|
10
|
+
static getLastLongTaskEndTime(nodeTimings: Lantern.Simulation.Result['nodeTimings'], duration?: number): number;
|
|
11
|
+
}
|
|
12
|
+
export { Interactive };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import { BaseNode } from '../BaseNode.js';
|
|
5
|
+
import { Metric } from './Metric.js';
|
|
6
|
+
// Any CPU task of 20 ms or more will end up being a critical long task on mobile
|
|
7
|
+
const CRITICAL_LONG_TASK_THRESHOLD = 20;
|
|
8
|
+
class Interactive extends Metric {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
static get coefficients() {
|
|
11
|
+
return {
|
|
12
|
+
intercept: 0,
|
|
13
|
+
optimistic: 0.45,
|
|
14
|
+
pessimistic: 0.55,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static getOptimisticGraph(dependencyGraph) {
|
|
18
|
+
// Adjust the critical long task threshold for microseconds
|
|
19
|
+
const minimumCpuTaskDuration = CRITICAL_LONG_TASK_THRESHOLD * 1000;
|
|
20
|
+
return dependencyGraph.cloneWithRelationships(node => {
|
|
21
|
+
// Include everything that might be a long task
|
|
22
|
+
if (node.type === BaseNode.types.CPU) {
|
|
23
|
+
return node.duration > minimumCpuTaskDuration;
|
|
24
|
+
}
|
|
25
|
+
// Include all scripts and high priority requests, exclude all images
|
|
26
|
+
const isImage = node.request.resourceType === 'Image';
|
|
27
|
+
const isScript = node.request.resourceType === 'Script';
|
|
28
|
+
return (!isImage && (isScript || node.request.priority === 'High' || node.request.priority === 'VeryHigh'));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static getPessimisticGraph(dependencyGraph) {
|
|
32
|
+
return dependencyGraph;
|
|
33
|
+
}
|
|
34
|
+
static getEstimateFromSimulation(simulationResult, extras) {
|
|
35
|
+
if (!extras.lcpResult) {
|
|
36
|
+
throw new Error('missing lcpResult');
|
|
37
|
+
}
|
|
38
|
+
const lastTaskAt = Interactive.getLastLongTaskEndTime(simulationResult.nodeTimings);
|
|
39
|
+
const minimumTime = extras.optimistic ? extras.lcpResult.optimisticEstimate.timeInMs :
|
|
40
|
+
extras.lcpResult.pessimisticEstimate.timeInMs;
|
|
41
|
+
return {
|
|
42
|
+
timeInMs: Math.max(minimumTime, lastTaskAt),
|
|
43
|
+
nodeTimings: simulationResult.nodeTimings,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
static async compute(data, extras) {
|
|
47
|
+
const lcpResult = extras?.lcpResult;
|
|
48
|
+
if (!lcpResult) {
|
|
49
|
+
throw new Error('LCP is required to calculate the Interactive metric');
|
|
50
|
+
}
|
|
51
|
+
const metricResult = await super.compute(data, extras);
|
|
52
|
+
metricResult.timing = Math.max(metricResult.timing, lcpResult.timing);
|
|
53
|
+
return metricResult;
|
|
54
|
+
}
|
|
55
|
+
static getLastLongTaskEndTime(nodeTimings, duration = 50) {
|
|
56
|
+
return Array.from(nodeTimings.entries())
|
|
57
|
+
.filter(([node, timing]) => {
|
|
58
|
+
if (node.type !== BaseNode.types.CPU) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return timing.duration > duration;
|
|
62
|
+
})
|
|
63
|
+
.map(([_, timing]) => timing.endTime)
|
|
64
|
+
.reduce((max, x) => Math.max(max || 0, x || 0), 0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export { Interactive };
|
|
68
|
+
//# sourceMappingURL=Interactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interactive.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/Interactive.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,EAAC,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAc,MAAM,EAAC,MAAM,aAAa,CAAC;AAEhD,iFAAiF;AACjF,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,MAAM,WAAY,SAAQ,MAAM;IAC9B,gEAAgE;IAChE,MAAM,KAAc,YAAY;QAC9B,OAAO;YACL,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,IAAI;YAChB,WAAW,EAAE,IAAI;SAClB,CAAC;IACJ,CAAC;IAED,M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romium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {BaseNode, type Node} from '../BaseNode.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {type Extras, Metric} from './Metric.js';\n\n// Any CPU task of 20 ms or more will end up being a critical long task on mobile\nconst CRITICAL_LONG_TASK_THRESHOLD = 20;\n\nclass Interactive extends Metric {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.45,\n pessimistic: 0.55,\n };\n }\n\n static override getOptimisticGraph<T>(dependencyGraph: Node<T>): Node<T> {\n // Adjust the critical long task threshold for microseconds\n const minimumCpuTaskDuration = CRITICAL_LONG_TASK_THRESHOLD * 1000;\n\n return dependencyGraph.cloneWithRelationships(node => {\n // Include everything that might be a long task\n if (node.type === BaseNode.types.CPU) {\n return node.duration > minimumCpuTaskDuration;\n }\n\n // Include all scripts and high priority requests, exclude all images\n const isImage = node.request.resourceType === 'Image';\n const isScript = node.request.resourceType === 'Script';\n return (!isImage && (isScript || node.request.priority === 'High' || node.request.priority === 'VeryHigh'));\n });\n }\n\n static override getPessimisticGraph<T>(dependencyGraph: Node<T>): Node<T> {\n return dependencyGraph;\n }\n\n static override getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result, extras: Extras):\n Lantern.Simulation.Result {\n if (!extras.lcpResult) {\n throw new Error('missing lcpResult');\n }\n\n const lastTaskAt = Interactive.getLastLongTaskEndTime(simulationResult.nodeTimings);\n const minimumTime = extras.optimistic ? extras.lcpResult.optimisticEstimate.timeInMs :\n extras.lcpResult.pessimisticEstimate.timeInMs;\n return {\n timeInMs: Math.max(minimumTime, lastTaskAt),\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override async compute(\n data: Lantern.Simulation.MetricComputationDataInput,\n extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result> {\n const lcpResult = extras?.lcpResult;\n if (!lcpResult) {\n throw new Error('LCP is required to calculate the Interactive metric');\n }\n\n const metricResult = await super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, lcpResult.timing);\n return metricResult;\n }\n\n static getLastLongTaskEndTime(nodeTimings: Lantern.Simulation.Result['nodeTimings'], duration = 50): number {\n return Array.from(nodeTimings.entries())\n .filter(([node, timing]) => {\n if (node.type !== BaseNode.types.CPU) {\n return false;\n }\n return timing.duration > duration;\n })\n .map(([_, timing]) => timing.endTime)\n .reduce((max, x) => Math.max(max || 0, x || 0), 0);\n }\n}\n\nexport {Interactive};\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Node } from '../BaseNode.js';
|
|
2
|
+
import type * as Lantern from '../types/lantern.js';
|
|
3
|
+
import { type Extras, Metric } from './Metric.js';
|
|
4
|
+
declare class LargestContentfulPaint extends Metric {
|
|
5
|
+
static get coefficients(): Lantern.Simulation.MetricCoefficients;
|
|
6
|
+
/**
|
|
7
|
+
* Low priority image nodes are usually offscreen and very unlikely to be the
|
|
8
|
+
* resource that is required for LCP. Our LCP graphs include everything except for these images.
|
|
9
|
+
*/
|
|
10
|
+
static isNotLowPriorityImageNode(node: Node): boolean;
|
|
11
|
+
static getOptimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node;
|
|
12
|
+
static getPessimisticGraph(dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node;
|
|
13
|
+
static getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result): Lantern.Simulation.Result;
|
|
14
|
+
static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
|
|
15
|
+
}
|
|
16
|
+
export { LargestContentfulPaint };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Copyright 2024 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
import { LanternError } from '../LanternError.js';
|
|
5
|
+
import { FirstContentfulPaint } from './FirstContentfulPaint.js';
|
|
6
|
+
import { Metric } from './Metric.js';
|
|
7
|
+
class LargestContentfulPaint extends Metric {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
9
|
+
static get coefficients() {
|
|
10
|
+
return {
|
|
11
|
+
intercept: 0,
|
|
12
|
+
optimistic: 0.5,
|
|
13
|
+
pessimistic: 0.5,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Low priority image nodes are usually offscreen and very unlikely to be the
|
|
18
|
+
* resource that is required for LCP. Our LCP graphs include everything except for these images.
|
|
19
|
+
*/
|
|
20
|
+
static isNotLowPriorityImageNode(node) {
|
|
21
|
+
if (node.type !== 'network') {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const isImage = node.request.resourceType === 'Image';
|
|
25
|
+
const isLowPriority = node.request.priority === 'Low' || node.request.priority === 'VeryLow';
|
|
26
|
+
return !isImage || !isLowPriority;
|
|
27
|
+
}
|
|
28
|
+
static getOptimisticGraph(dependencyGraph, processedNavigation) {
|
|
29
|
+
const lcp = processedNavigation.timestamps.largestContentfulPaint;
|
|
30
|
+
if (!lcp) {
|
|
31
|
+
throw new LanternError('NO_LCP');
|
|
32
|
+
}
|
|
33
|
+
return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
|
|
34
|
+
cutoffTimestamp: lcp,
|
|
35
|
+
treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
static getPessimisticGraph(dependencyGraph, processedNavigation) {
|
|
39
|
+
const lcp = processedNavigation.timestamps.largestContentfulPaint;
|
|
40
|
+
if (!lcp) {
|
|
41
|
+
throw new LanternError('NO_LCP');
|
|
42
|
+
}
|
|
43
|
+
return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {
|
|
44
|
+
cutoffTimestamp: lcp,
|
|
45
|
+
treatNodeAsRenderBlocking: _ => true,
|
|
46
|
+
// For pessimistic LCP we'll include *all* layout nodes
|
|
47
|
+
additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
static getEstimateFromSimulation(simulationResult) {
|
|
51
|
+
const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())
|
|
52
|
+
.filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))
|
|
53
|
+
.map(entry => entry[1].endTime);
|
|
54
|
+
return {
|
|
55
|
+
timeInMs: Math.max(...nodeTimesNotOffscreenImages),
|
|
56
|
+
nodeTimings: simulationResult.nodeTimings,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
static async compute(data, extras) {
|
|
60
|
+
const fcpResult = extras?.fcpResult;
|
|
61
|
+
if (!fcpResult) {
|
|
62
|
+
throw new Error('FCP is required to calculate the LCP metric');
|
|
63
|
+
}
|
|
64
|
+
const metricResult = await super.compute(data, extras);
|
|
65
|
+
metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);
|
|
66
|
+
return metricResult;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export { LargestContentfulPaint };
|
|
70
|
+
//# sourceMappingURL=LargestContentfulPaint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LargestContentfulPaint.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAC,oBAAoB,EAAC,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAc,MAAM,EAAC,MAAM,aAAa,CAAC;AAEhD,MAAM,sBAAuB,SAAQ,MAAM;IACzC,gEA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IAAI;YACpC,uDAAuD;YACvD,yCAAyC,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE;SAC3E,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAU,yBAAyB,CAAC,gBAA2C;QACnF,MAAM,2BAA2B,GAAG,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aAC7C,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;aAC3E,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAExE,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,2BAA2B,CAAC;YAClD,WAAW,EAAE,gBAAgB,CAAC,WAAW;SAC1C,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,KAAK,CAAC,OAAO,CACzB,IAAmD,EACnD,MAAmC;QACrC,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAC;QACpC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvD,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACtE,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED,OAAO,EAAC,sBAAsB,EAAC,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport {type Node} from '../BaseNode.js';\nimport {LanternError} from '../LanternError.js';\nimport type * as Lantern from '../types/lantern.js';\n\nimport {FirstContentfulPaint} from './FirstContentfulPaint.js';\nimport {type Extras, Metric} from './Metric.js';\n\nclass LargestContentfulPaint extends Metric {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n static override get coefficients(): Lantern.Simulation.MetricCoefficients {\n return {\n intercept: 0,\n optimistic: 0.5,\n pessimistic: 0.5,\n };\n }\n\n /**\n * Low priority image nodes are usually offscreen and very unlikely to be the\n * resource that is required for LCP. Our LCP graphs include everything except for these images.\n */\n static isNotLowPriorityImageNode(node: Node): boolean {\n if (node.type !== 'network') {\n return true;\n }\n const isImage = node.request.resourceType === 'Image';\n const isLowPriority = node.request.priority === 'Low' || node.request.priority === 'VeryLow';\n return !isImage || !isLowPriority;\n }\n\n static override getOptimisticGraph(\n dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new LanternError('NO_LCP');\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: LargestContentfulPaint.isNotLowPriorityImageNode,\n });\n }\n\n static override getPessimisticGraph(\n dependencyGraph: Node, processedNavigation: Lantern.Simulation.ProcessedNavigation): Node {\n const lcp = processedNavigation.timestamps.largestContentfulPaint;\n if (!lcp) {\n throw new LanternError('NO_LCP');\n }\n\n return FirstContentfulPaint.getFirstPaintBasedGraph(dependencyGraph, {\n cutoffTimestamp: lcp,\n treatNodeAsRenderBlocking: _ => true,\n // For pessimistic LCP we'll include *all* layout nodes\n additionalCpuNodesToTreatAsRenderBlocking: node => node.didPerformLayout(),\n });\n }\n\n static override getEstimateFromSimulation(simulationResult: Lantern.Simulation.Result): Lantern.Simulation.Result {\n const nodeTimesNotOffscreenImages = Array.from(simulationResult.nodeTimings.entries())\n .filter(entry => LargestContentfulPaint.isNotLowPriorityImageNode(entry[0]))\n .map(entry => entry[1].endTime);\n\n return {\n timeInMs: Math.max(...nodeTimesNotOffscreenImages),\n nodeTimings: simulationResult.nodeTimings,\n };\n }\n\n static override async compute(\n data: Lantern.Simulation.MetricComputationDataInput,\n extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result> {\n const fcpResult = extras?.fcpResult;\n if (!fcpResult) {\n throw new Error('FCP is required to calculate the LCP metric');\n }\n\n const metricResult = await super.compute(data, extras);\n metricResult.timing = Math.max(metricResult.timing, fcpResult.timing);\n return metricResult;\n }\n}\n\nexport {LargestContentfulPaint};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Node } from '../BaseNode.js';
|
|
2
|
+
import type * as Lantern from '../types/lantern.js';
|
|
3
|
+
import { type Extras, Metric } from './Metric.js';
|
|
4
|
+
declare class MaxPotentialFID extends Metric {
|
|
5
|
+
static get coefficients(): Lantern.Simulation.MetricCoefficients;
|
|
6
|
+
static getOptimisticGraph(dependencyGraph: Node): Node;
|
|
7
|
+
static getPessimisticGraph(dependencyGraph: Node): Node;
|
|
8
|
+
static getEstimateFromSimulation(simulation: Lantern.Simulation.Result, extras: Extras): Lantern.Simulation.Result;
|
|
9
|
+
static compute(data: Lantern.Simulation.MetricComputationDataInput, extras?: Omit<Extras, 'optimistic'>): Promise<Lantern.Metrics.Result>;
|
|
10
|
+
static getTimingsAfterFCP(nodeTimings: Lantern.Simulation.Result['nodeTimings'], fcpTimeInMs: number): Array<{
|
|
11
|
+
duration: number;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export { MaxPotentialFID };
|