@paulirish/trace_engine 0.0.51 → 0.0.52
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/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
- package/core/platform/StringUtilities.js +4 -1
- package/core/platform/StringUtilities.js.map +1 -1
- package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/core/platform/platform-tsconfig.json +1 -1
- package/generated/protocol.d.ts +150 -31
- package/locales/en-US.json +3 -0
- package/locales/en-XL.json +3 -0
- package/models/cpu_profile/cpu_profile-tsconfig.json +1 -1
- package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/extras/ScriptDuplication.d.ts +5 -2
- package/models/trace/extras/ScriptDuplication.js +4 -2
- package/models/trace/extras/ScriptDuplication.js.map +1 -1
- package/models/trace/extras/StackTraceForEvent.js +80 -47
- package/models/trace/extras/StackTraceForEvent.js.map +1 -1
- package/models/trace/extras/ThirdParties.d.ts +13 -12
- package/models/trace/extras/ThirdParties.js +50 -19
- package/models/trace/extras/ThirdParties.js.map +1 -1
- package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/extras/extras-tsconfig.json +1 -1
- package/models/trace/extras/extras.d.ts +98 -6
- package/models/trace/extras/extras.js +98 -6
- package/models/trace/handlers/AsyncJSCallsHandler.d.ts +5 -0
- package/models/trace/handlers/AsyncJSCallsHandler.js +12 -9
- package/models/trace/handlers/AsyncJSCallsHandler.js.map +1 -1
- package/models/trace/handlers/ScreenshotsHandler.js +1 -0
- package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
- package/models/trace/handlers/ScriptsHandler.js +9 -3
- package/models/trace/handlers/ScriptsHandler.js.map +1 -1
- package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/handlers/handlers-tsconfig.json +1 -1
- package/models/trace/handlers/helpers.js +9 -0
- package/models/trace/handlers/helpers.js.map +1 -1
- package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/helpers/helpers-tsconfig.json +1 -1
- package/models/trace/insights/CLSCulprits.d.ts +6 -1
- package/models/trace/insights/CLSCulprits.js +11 -2
- package/models/trace/insights/CLSCulprits.js.map +1 -1
- package/models/trace/insights/Cache.d.ts +0 -1
- package/models/trace/insights/Cache.js +1 -1
- package/models/trace/insights/Cache.js.map +1 -1
- package/models/trace/insights/Common.js +3 -0
- package/models/trace/insights/Common.js.map +1 -1
- package/models/trace/insights/DocumentLatency.js +1 -0
- package/models/trace/insights/DocumentLatency.js.map +1 -1
- package/models/trace/insights/DuplicatedJavaScript.js +9 -3
- package/models/trace/insights/DuplicatedJavaScript.js.map +1 -1
- package/models/trace/insights/ImageDelivery.d.ts +0 -1
- package/models/trace/insights/ImageDelivery.js +1 -1
- package/models/trace/insights/ImageDelivery.js.map +1 -1
- package/models/trace/insights/LegacyJavaScript.js +5 -2
- package/models/trace/insights/LegacyJavaScript.js.map +1 -1
- package/models/trace/insights/ThirdParties.d.ts +1 -1
- package/models/trace/insights/ThirdParties.js +6 -6
- package/models/trace/insights/ThirdParties.js.map +1 -1
- package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/insights/insights-tsconfig.json +1 -1
- package/models/trace/insights/types.d.ts +9 -0
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/lantern/core/core-tsconfig.json +1 -1
- package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/graph/graph-tsconfig.json +1 -1
- package/models/trace/lantern/lantern-tsconfig.json +1 -1
- package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/metrics/metrics-tsconfig.json +1 -1
- package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/simulation/simulation-tsconfig.json +1 -1
- package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/lantern/types/types-tsconfig.json +1 -1
- package/models/trace/trace-tsconfig.json +1 -1
- package/models/trace/types/TraceEvents.d.ts +2 -4
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +1 -1
- package/models/trace/types/types-tsconfig.json +1 -1
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +2 -2
package/generated/protocol.d.ts
CHANGED
|
@@ -6284,6 +6284,13 @@ export declare namespace Emulation {
|
|
|
6284
6284
|
*/
|
|
6285
6285
|
enabled: boolean;
|
|
6286
6286
|
}
|
|
6287
|
+
interface SetSmallViewportHeightDifferenceOverrideRequest {
|
|
6288
|
+
/**
|
|
6289
|
+
* This will cause an element of size 100svh to be `difference` pixels smaller than an element
|
|
6290
|
+
* of size 100lvh.
|
|
6291
|
+
*/
|
|
6292
|
+
difference: integer;
|
|
6293
|
+
}
|
|
6287
6294
|
}
|
|
6288
6295
|
/**
|
|
6289
6296
|
* This domain provides experimental commands only supported in headless mode.
|
|
@@ -10141,6 +10148,35 @@ export declare namespace Network {
|
|
|
10141
10148
|
identifier: RequestId;
|
|
10142
10149
|
timestamp: MonotonicTime;
|
|
10143
10150
|
}
|
|
10151
|
+
/**
|
|
10152
|
+
* Fired when data is sent to tcp direct socket stream.
|
|
10153
|
+
*/
|
|
10154
|
+
interface DirectTCPSocketChunkSentEvent {
|
|
10155
|
+
identifier: RequestId;
|
|
10156
|
+
data: binary;
|
|
10157
|
+
timestamp: MonotonicTime;
|
|
10158
|
+
}
|
|
10159
|
+
/**
|
|
10160
|
+
* Fired when data is received from tcp direct socket stream.
|
|
10161
|
+
*/
|
|
10162
|
+
interface DirectTCPSocketChunkReceivedEvent {
|
|
10163
|
+
identifier: RequestId;
|
|
10164
|
+
data: binary;
|
|
10165
|
+
timestamp: MonotonicTime;
|
|
10166
|
+
}
|
|
10167
|
+
/**
|
|
10168
|
+
* Fired when there is an error
|
|
10169
|
+
* when writing to tcp direct socket stream.
|
|
10170
|
+
* For example, if user writes illegal type like string
|
|
10171
|
+
* instead of ArrayBuffer or ArrayBufferView.
|
|
10172
|
+
* There's no reporting for reading, because
|
|
10173
|
+
* we cannot know errors on the other side.
|
|
10174
|
+
*/
|
|
10175
|
+
interface DirectTCPSocketChunkErrorEvent {
|
|
10176
|
+
identifier: RequestId;
|
|
10177
|
+
errorMessage: string;
|
|
10178
|
+
timestamp: MonotonicTime;
|
|
10179
|
+
}
|
|
10144
10180
|
/**
|
|
10145
10181
|
* Fired when additional information about a requestWillBeSent event is available from the
|
|
10146
10182
|
* network stack. Not every requestWillBeSent event will have an additional
|
|
@@ -12068,7 +12104,8 @@ export declare namespace Page {
|
|
|
12068
12104
|
RequestedByWebViewClient = "RequestedByWebViewClient",
|
|
12069
12105
|
PostMessageByWebViewClient = "PostMessageByWebViewClient",
|
|
12070
12106
|
CacheControlNoStoreDeviceBoundSessionTerminated = "CacheControlNoStoreDeviceBoundSessionTerminated",
|
|
12071
|
-
|
|
12107
|
+
CacheLimitPrunedOnModerateMemoryPressure = "CacheLimitPrunedOnModerateMemoryPressure",
|
|
12108
|
+
CacheLimitPrunedOnCriticalMemoryPressure = "CacheLimitPrunedOnCriticalMemoryPressure"
|
|
12072
12109
|
}
|
|
12073
12110
|
/**
|
|
12074
12111
|
* Types of not restored reasons for back-forward cache.
|
|
@@ -12286,15 +12323,17 @@ export declare namespace Page {
|
|
|
12286
12323
|
*/
|
|
12287
12324
|
recommendedId?: string;
|
|
12288
12325
|
}
|
|
12289
|
-
interface
|
|
12326
|
+
interface GetAdScriptAncestryIdsRequest {
|
|
12290
12327
|
frameId: FrameId;
|
|
12291
12328
|
}
|
|
12292
|
-
interface
|
|
12329
|
+
interface GetAdScriptAncestryIdsResponse extends ProtocolResponseWithError {
|
|
12293
12330
|
/**
|
|
12294
|
-
*
|
|
12295
|
-
*
|
|
12331
|
+
* The ancestry chain of ad script identifiers leading to this frame's
|
|
12332
|
+
* creation, ordered from the most immediate script (in the frame creation
|
|
12333
|
+
* stack) to more distant ancestors (that created the immediately preceding
|
|
12334
|
+
* script). Only sent if frame is labelled as an ad and ids are available.
|
|
12296
12335
|
*/
|
|
12297
|
-
|
|
12336
|
+
adScriptAncestryIds: AdScriptId[];
|
|
12298
12337
|
}
|
|
12299
12338
|
interface GetFrameTreeResponse extends ProtocolResponseWithError {
|
|
12300
12339
|
/**
|
|
@@ -13060,6 +13099,10 @@ export declare namespace Page {
|
|
|
13060
13099
|
* closed.
|
|
13061
13100
|
*/
|
|
13062
13101
|
interface JavascriptDialogClosedEvent {
|
|
13102
|
+
/**
|
|
13103
|
+
* Frame id.
|
|
13104
|
+
*/
|
|
13105
|
+
frameId: FrameId;
|
|
13063
13106
|
/**
|
|
13064
13107
|
* Whether dialog was confirmed.
|
|
13065
13108
|
*/
|
|
@@ -13078,6 +13121,10 @@ export declare namespace Page {
|
|
|
13078
13121
|
* Frame url.
|
|
13079
13122
|
*/
|
|
13080
13123
|
url: string;
|
|
13124
|
+
/**
|
|
13125
|
+
* Frame id.
|
|
13126
|
+
*/
|
|
13127
|
+
frameId: FrameId;
|
|
13081
13128
|
/**
|
|
13082
13129
|
* Message that will be displayed by the dialog.
|
|
13083
13130
|
*/
|
|
@@ -13892,6 +13939,28 @@ export declare namespace Storage {
|
|
|
13892
13939
|
*/
|
|
13893
13940
|
bytesUsed: integer;
|
|
13894
13941
|
}
|
|
13942
|
+
/**
|
|
13943
|
+
* Represents a dictionary object passed in as privateAggregationConfig to
|
|
13944
|
+
* run or selectURL.
|
|
13945
|
+
*/
|
|
13946
|
+
interface SharedStoragePrivateAggregationConfig {
|
|
13947
|
+
/**
|
|
13948
|
+
* The chosen aggregation service deployment.
|
|
13949
|
+
*/
|
|
13950
|
+
aggregationCoordinatorOrigin?: string;
|
|
13951
|
+
/**
|
|
13952
|
+
* The context ID provided.
|
|
13953
|
+
*/
|
|
13954
|
+
contextId?: string;
|
|
13955
|
+
/**
|
|
13956
|
+
* Configures the maximum size allowed for filtering IDs.
|
|
13957
|
+
*/
|
|
13958
|
+
filteringIdMaxBytes: integer;
|
|
13959
|
+
/**
|
|
13960
|
+
* The limit on the number of contributions in the final report.
|
|
13961
|
+
*/
|
|
13962
|
+
maxContributions?: integer;
|
|
13963
|
+
}
|
|
13895
13964
|
/**
|
|
13896
13965
|
* Pair of reporting metadata details for a candidate URL for `selectURL()`.
|
|
13897
13966
|
*/
|
|
@@ -13919,57 +13988,90 @@ export declare namespace Storage {
|
|
|
13919
13988
|
interface SharedStorageAccessParams {
|
|
13920
13989
|
/**
|
|
13921
13990
|
* Spec of the module script URL.
|
|
13922
|
-
* Present only for
|
|
13991
|
+
* Present only for SharedStorageAccessMethods: addModule and
|
|
13992
|
+
* createWorklet.
|
|
13923
13993
|
*/
|
|
13924
13994
|
scriptSourceUrl?: string;
|
|
13995
|
+
/**
|
|
13996
|
+
* String denoting "context-origin", "script-origin", or a custom
|
|
13997
|
+
* origin to be used as the worklet's data origin.
|
|
13998
|
+
* Present only for SharedStorageAccessMethod: createWorklet.
|
|
13999
|
+
*/
|
|
14000
|
+
dataOrigin?: string;
|
|
13925
14001
|
/**
|
|
13926
14002
|
* Name of the registered operation to be run.
|
|
13927
|
-
* Present only for
|
|
13928
|
-
* SharedStorageAccessType.documentSelectURL.
|
|
14003
|
+
* Present only for SharedStorageAccessMethods: run and selectURL.
|
|
13929
14004
|
*/
|
|
13930
14005
|
operationName?: string;
|
|
14006
|
+
/**
|
|
14007
|
+
* Whether or not to keep the worket alive for future run or selectURL
|
|
14008
|
+
* calls.
|
|
14009
|
+
* Present only for SharedStorageAccessMethods: run and selectURL.
|
|
14010
|
+
*/
|
|
14011
|
+
keepAlive?: boolean;
|
|
14012
|
+
/**
|
|
14013
|
+
* Configures the private aggregation options.
|
|
14014
|
+
* Present only for SharedStorageAccessMethods: run and selectURL.
|
|
14015
|
+
*/
|
|
14016
|
+
privateAggregationConfig?: SharedStoragePrivateAggregationConfig;
|
|
13931
14017
|
/**
|
|
13932
14018
|
* The operation's serialized data in bytes (converted to a string).
|
|
13933
|
-
* Present only for
|
|
13934
|
-
*
|
|
14019
|
+
* Present only for SharedStorageAccessMethods: run and selectURL.
|
|
14020
|
+
* TODO(crbug.com/401011862): Consider updating this parameter to binary.
|
|
13935
14021
|
*/
|
|
13936
14022
|
serializedData?: string;
|
|
13937
14023
|
/**
|
|
13938
14024
|
* Array of candidate URLs' specs, along with any associated metadata.
|
|
13939
|
-
* Present only for
|
|
14025
|
+
* Present only for SharedStorageAccessMethod: selectURL.
|
|
13940
14026
|
*/
|
|
13941
14027
|
urlsWithMetadata?: SharedStorageUrlWithMetadata[];
|
|
14028
|
+
/**
|
|
14029
|
+
* Spec of the URN:UUID generated for a selectURL call.
|
|
14030
|
+
* Present only for SharedStorageAccessMethod: selectURL.
|
|
14031
|
+
*/
|
|
14032
|
+
urnUuid?: string;
|
|
13942
14033
|
/**
|
|
13943
14034
|
* Key for a specific entry in an origin's shared storage.
|
|
13944
|
-
* Present only for
|
|
13945
|
-
*
|
|
13946
|
-
* SharedStorageAccessType.documentDelete,
|
|
13947
|
-
* SharedStorageAccessType.workletSet,
|
|
13948
|
-
* SharedStorageAccessType.workletAppend,
|
|
13949
|
-
* SharedStorageAccessType.workletDelete,
|
|
13950
|
-
* SharedStorageAccessType.workletGet,
|
|
13951
|
-
* SharedStorageAccessType.headerSet,
|
|
13952
|
-
* SharedStorageAccessType.headerAppend, and
|
|
13953
|
-
* SharedStorageAccessType.headerDelete.
|
|
14035
|
+
* Present only for SharedStorageAccessMethods: set, append, delete, and
|
|
14036
|
+
* get.
|
|
13954
14037
|
*/
|
|
13955
14038
|
key?: string;
|
|
13956
14039
|
/**
|
|
13957
14040
|
* Value for a specific entry in an origin's shared storage.
|
|
13958
|
-
* Present only for
|
|
13959
|
-
* SharedStorageAccessType.documentAppend,
|
|
13960
|
-
* SharedStorageAccessType.workletSet,
|
|
13961
|
-
* SharedStorageAccessType.workletAppend,
|
|
13962
|
-
* SharedStorageAccessType.headerSet, and
|
|
13963
|
-
* SharedStorageAccessType.headerAppend.
|
|
14041
|
+
* Present only for SharedStorageAccessMethods: set and append.
|
|
13964
14042
|
*/
|
|
13965
14043
|
value?: string;
|
|
13966
14044
|
/**
|
|
13967
14045
|
* Whether or not to set an entry for a key if that key is already present.
|
|
13968
|
-
* Present only for
|
|
13969
|
-
* SharedStorageAccessType.workletSet, and
|
|
13970
|
-
* SharedStorageAccessType.headerSet.
|
|
14046
|
+
* Present only for SharedStorageAccessMethod: set.
|
|
13971
14047
|
*/
|
|
13972
14048
|
ignoreIfPresent?: boolean;
|
|
14049
|
+
/**
|
|
14050
|
+
* If the method is called on a worklet, or as part of
|
|
14051
|
+
* a worklet script, it will have an ID for the associated worklet.
|
|
14052
|
+
* Present only for SharedStorageAccessMethods: addModule, createWorklet,
|
|
14053
|
+
* run, selectURL, and any other SharedStorageAccessMethod when the
|
|
14054
|
+
* SharedStorageAccessScope is worklet.
|
|
14055
|
+
*/
|
|
14056
|
+
workletId?: string;
|
|
14057
|
+
/**
|
|
14058
|
+
* Name of the lock to be acquired, if present.
|
|
14059
|
+
* Optionally present only for SharedStorageAccessMethods: batchUpdate,
|
|
14060
|
+
* set, append, delete, and clear.
|
|
14061
|
+
*/
|
|
14062
|
+
withLock?: string;
|
|
14063
|
+
/**
|
|
14064
|
+
* If the method has been called as part of a batchUpdate, then this
|
|
14065
|
+
* number identifies the batch to which it belongs.
|
|
14066
|
+
* Optionally present only for SharedStorageAccessMethods:
|
|
14067
|
+
* batchUpdate (required), set, append, delete, and clear.
|
|
14068
|
+
*/
|
|
14069
|
+
batchUpdateId?: string;
|
|
14070
|
+
/**
|
|
14071
|
+
* Number of modifier methods sent in batch.
|
|
14072
|
+
* Present only for SharedStorageAccessMethod: batchUpdate.
|
|
14073
|
+
*/
|
|
14074
|
+
batchSize?: integer;
|
|
13973
14075
|
}
|
|
13974
14076
|
const enum StorageBucketsDurability {
|
|
13975
14077
|
Relaxed = "relaxed",
|
|
@@ -14069,6 +14171,10 @@ export declare namespace Storage {
|
|
|
14069
14171
|
limit: number;
|
|
14070
14172
|
maxEventStates: number;
|
|
14071
14173
|
}
|
|
14174
|
+
interface AttributionReportingNamedBudgetDef {
|
|
14175
|
+
name: string;
|
|
14176
|
+
budget: integer;
|
|
14177
|
+
}
|
|
14072
14178
|
interface AttributionReportingSourceRegistration {
|
|
14073
14179
|
time: Network.TimeSinceEpoch;
|
|
14074
14180
|
/**
|
|
@@ -14094,6 +14200,9 @@ export declare namespace Storage {
|
|
|
14094
14200
|
aggregatableDebugReportingConfig: AttributionReportingAggregatableDebugReportingConfig;
|
|
14095
14201
|
scopesData?: AttributionScopesData;
|
|
14096
14202
|
maxEventLevelReports: integer;
|
|
14203
|
+
namedBudgets: AttributionReportingNamedBudgetDef[];
|
|
14204
|
+
debugReporting: boolean;
|
|
14205
|
+
eventLevelEpsilon: number;
|
|
14097
14206
|
}
|
|
14098
14207
|
const enum AttributionReportingSourceRegistrationResult {
|
|
14099
14208
|
Success = "success",
|
|
@@ -14145,6 +14254,10 @@ export declare namespace Storage {
|
|
|
14145
14254
|
dedupKey?: UnsignedInt64AsBase10;
|
|
14146
14255
|
filters: AttributionReportingFilterPair;
|
|
14147
14256
|
}
|
|
14257
|
+
interface AttributionReportingNamedBudgetCandidate {
|
|
14258
|
+
name?: string;
|
|
14259
|
+
filters: AttributionReportingFilterPair;
|
|
14260
|
+
}
|
|
14148
14261
|
interface AttributionReportingTriggerRegistration {
|
|
14149
14262
|
filters: AttributionReportingFilterPair;
|
|
14150
14263
|
debugKey?: UnsignedInt64AsBase10;
|
|
@@ -14159,6 +14272,7 @@ export declare namespace Storage {
|
|
|
14159
14272
|
triggerContextId?: string;
|
|
14160
14273
|
aggregatableDebugReportingConfig: AttributionReportingAggregatableDebugReportingConfig;
|
|
14161
14274
|
scopes: string[];
|
|
14275
|
+
namedBudgets: AttributionReportingNamedBudgetCandidate[];
|
|
14162
14276
|
}
|
|
14163
14277
|
const enum AttributionReportingEventLevelResult {
|
|
14164
14278
|
Success = "success",
|
|
@@ -14468,6 +14582,11 @@ export declare namespace Storage {
|
|
|
14468
14582
|
*/
|
|
14469
14583
|
matchedUrls: string[];
|
|
14470
14584
|
}
|
|
14585
|
+
interface SetProtectedAudienceKAnonymityRequest {
|
|
14586
|
+
owner: string;
|
|
14587
|
+
name: string;
|
|
14588
|
+
hashes: binary[];
|
|
14589
|
+
}
|
|
14471
14590
|
/**
|
|
14472
14591
|
* A cache's contents have been modified.
|
|
14473
14592
|
*/
|
package/locales/en-US.json
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
"generated/Deprecation.ts | CanRequestURLHTTPContainingNewline": {
|
|
6
6
|
"message": "Resource requests whose URLs contained both removed whitespace \\(n|r|t) characters and less-than characters (<) are blocked. Please remove newlines and encode less-than characters from places like element attribute values in order to load these resources."
|
|
7
7
|
},
|
|
8
|
+
"generated/Deprecation.ts | CharsetAutoDetectionISO2022JP": {
|
|
9
|
+
"message": "Auto-detection of ISO-2022-JP character set is deprecated and it will be disabled in the near future. Please specify character set in the Content Type header or by using a meta tag (https://developer.mozilla.org/en-US/docs/Glossary/Character_encoding)."
|
|
10
|
+
},
|
|
8
11
|
"generated/Deprecation.ts | ChromeLoadTimesConnectionInfo": {
|
|
9
12
|
"message": "chrome.loadTimes() is deprecated, instead use standardized API: Navigation Timing 2."
|
|
10
13
|
},
|
package/locales/en-XL.json
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
"generated/Deprecation.ts | CanRequestURLHTTPContainingNewline": {
|
|
6
6
|
"message": "R\u0302e\u0301s\u0302o\u0301u\u0302r\u0301c\u0302e\u0301 r\u0302e\u0301q\u0302u\u0301e\u0302s\u0301t\u0302s\u0301 w\u0302h\u0301o\u0302s\u0301e\u0302 U\u0301R\u0302L\u0301s\u0302 c\u0301o\u0302n\u0301t\u0302a\u0301i\u0302n\u0301e\u0302d\u0301 b\u0302o\u0301t\u0302h\u0301 r\u0302e\u0301m\u0302o\u0301v\u0302e\u0301d\u0302 w\u0301h\u0302i\u0301t\u0302e\u0301s\u0302p\u0301a\u0302c\u0301e\u0302 \\(n|r|t) c\u0301h\u0302a\u0301r\u0302a\u0301c\u0302t\u0301e\u0302r\u0301s\u0302 a\u0301n\u0302d\u0301 l\u0302e\u0301s\u0302s\u0301-t\u0302h\u0301a\u0302n\u0301 c\u0302h\u0301a\u0302r\u0301a\u0302c\u0301t\u0302e\u0301r\u0302s\u0301 (<) a\u0302r\u0301e\u0302 b\u0301l\u0302o\u0301c\u0302k\u0301e\u0302d\u0301. P\u0302l\u0301e\u0302a\u0301s\u0302e\u0301 r\u0302e\u0301m\u0302o\u0301v\u0302e\u0301 n\u0302e\u0301w\u0302l\u0301i\u0302n\u0301e\u0302s\u0301 a\u0302n\u0301d\u0302 e\u0301n\u0302c\u0301o\u0302d\u0301e\u0302 l\u0301e\u0302s\u0301s\u0302-t\u0301h\u0302a\u0301n\u0302 c\u0301h\u0302a\u0301r\u0302a\u0301c\u0302t\u0301e\u0302r\u0301s\u0302 f\u0301r\u0302o\u0301m\u0302 p\u0301l\u0302a\u0301c\u0302e\u0301s\u0302 l\u0301i\u0302k\u0301e\u0302 e\u0301l\u0302e\u0301m\u0302e\u0301n\u0302t\u0301 a\u0302t\u0301t\u0302r\u0301i\u0302b\u0301u\u0302t\u0301e\u0302 v\u0301a\u0302l\u0301u\u0302e\u0301s\u0302 i\u0301n\u0302 o\u0301r\u0302d\u0301e\u0302r\u0301 t\u0302o\u0301 l\u0302o\u0301a\u0302d\u0301 t\u0302h\u0301e\u0302s\u0301e\u0302 r\u0301e\u0302s\u0301o\u0302u\u0301r\u0302c\u0301e\u0302s\u0301."
|
|
7
7
|
},
|
|
8
|
+
"generated/Deprecation.ts | CharsetAutoDetectionISO2022JP": {
|
|
9
|
+
"message": "A\u0302u\u0301t\u0302o\u0301-d\u0302e\u0301t\u0302e\u0301c\u0302t\u0301i\u0302o\u0301n\u0302 o\u0301f\u0302 I\u0301S\u0302O\u0301-2022-J\u0302P\u0301 c\u0302h\u0301a\u0302r\u0301a\u0302c\u0301t\u0302e\u0301r\u0302 s\u0301e\u0302t\u0301 i\u0302s\u0301 d\u0302e\u0301p\u0302r\u0301e\u0302c\u0301a\u0302t\u0301e\u0302d\u0301 a\u0302n\u0301d\u0302 i\u0301t\u0302 w\u0301i\u0302l\u0301l\u0302 b\u0301e\u0302 d\u0301i\u0302s\u0301a\u0302b\u0301l\u0302e\u0301d\u0302 i\u0301n\u0302 t\u0301h\u0302e\u0301 n\u0302e\u0301a\u0302r\u0301 f\u0302u\u0301t\u0302u\u0301r\u0302e\u0301. P\u0302l\u0301e\u0302a\u0301s\u0302e\u0301 s\u0302p\u0301e\u0302c\u0301i\u0302f\u0301y\u0302 c\u0301h\u0302a\u0301r\u0302a\u0301c\u0302t\u0301e\u0302r\u0301 s\u0302e\u0301t\u0302 i\u0301n\u0302 t\u0301h\u0302e\u0301 C\u0302o\u0301n\u0302t\u0301e\u0302n\u0301t\u0302 T\u0301y\u0302p\u0301e\u0302 h\u0301e\u0302a\u0301d\u0302e\u0301r\u0302 o\u0301r\u0302 b\u0301y\u0302 u\u0301s\u0302i\u0301n\u0302g\u0301 a\u0302 m\u0301e\u0302t\u0301a\u0302 t\u0301a\u0302g\u0301 (h\u0302t\u0301t\u0302p\u0301s\u0302://d\u0301e\u0302v\u0301e\u0302l\u0301o\u0302p\u0301e\u0302r\u0301.m\u0302o\u0301z\u0302i\u0301l\u0302l\u0301a\u0302.o\u0301r\u0302g\u0301/e\u0302n\u0301-U\u0302S\u0301/d\u0302o\u0301c\u0302s\u0301/G\u0302l\u0301o\u0302s\u0301s\u0302a\u0301r\u0302y\u0301/C\u0302h\u0301a\u0302r\u0301a\u0302c\u0301t\u0302e\u0301r\u0302_e\u0301n\u0302c\u0301o\u0302d\u0301i\u0302n\u0301g\u0302)."
|
|
10
|
+
},
|
|
8
11
|
"generated/Deprecation.ts | ChromeLoadTimesConnectionInfo": {
|
|
9
12
|
"message": "chrome.loadTimes() i\u0302s\u0301 d\u0302e\u0301p\u0302r\u0301e\u0302c\u0301a\u0302t\u0301e\u0302d\u0301, i\u0302n\u0301s\u0302t\u0301e\u0302a\u0301d\u0302 u\u0301s\u0302e\u0301 s\u0302t\u0301a\u0302n\u0301d\u0302a\u0301r\u0302d\u0301i\u0302z\u0301e\u0302d\u0301 A\u0302P\u0301I\u0302: N\u0301a\u0302v\u0301i\u0302g\u0301a\u0302t\u0301i\u0302o\u0301n\u0302 T\u0301i\u0302m\u0301i\u0302n\u0301g\u0302 2."
|
|
10
13
|
},
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"noFallthroughCasesInSwitch": true,
|
|
18
18
|
"noImplicitOverride": true,
|
|
19
19
|
"noImplicitReturns": true,
|
|
20
|
-
"noUnusedLocals":
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
21
|
"noUnusedParameters": true,
|
|
22
22
|
"outDir": ".",
|
|
23
23
|
"rootDir": "../../../../../../front_end/models/cpu_profile",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"noFallthroughCasesInSwitch": true,
|
|
18
18
|
"noImplicitOverride": true,
|
|
19
19
|
"noImplicitReturns": true,
|
|
20
|
-
"noUnusedLocals":
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
21
|
"noUnusedParameters": true,
|
|
22
22
|
"outDir": ".",
|
|
23
23
|
"rootDir": "../../../../../../front_end/models/cpu_profile",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"noFallthroughCasesInSwitch": true,
|
|
18
18
|
"noImplicitOverride": true,
|
|
19
19
|
"noImplicitReturns": true,
|
|
20
|
-
"noUnusedLocals":
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
21
|
"noUnusedParameters": true,
|
|
22
22
|
"outDir": ".",
|
|
23
23
|
"rootDir": "../../../../../../front_end/models/trace",
|
|
@@ -26,7 +26,10 @@ export type ScriptDuplication = Map<string, {
|
|
|
26
26
|
estimatedDuplicateBytes: number;
|
|
27
27
|
duplicates: Array<{
|
|
28
28
|
script: Handlers.ModelHandlers.Scripts.Script;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The number of bytes in the script bundle that map back to this module,
|
|
31
|
+
* in terms of estimated impact on transfer size.
|
|
32
|
+
*/
|
|
30
33
|
attributedSize: number;
|
|
31
34
|
}>;
|
|
32
35
|
}>;
|
|
@@ -43,7 +46,7 @@ export declare function getNodeModuleName(source: string): string;
|
|
|
43
46
|
* 2. `duplication` keys correspond to authored files, except all files within the same
|
|
44
47
|
* node_module package are aggregated under the same entry.
|
|
45
48
|
*/
|
|
46
|
-
export declare function computeScriptDuplication(scriptsData: Handlers.ModelHandlers.Scripts.ScriptsData): {
|
|
49
|
+
export declare function computeScriptDuplication(scriptsData: Handlers.ModelHandlers.Scripts.ScriptsData, compressionRatios: Map<string, number>): {
|
|
47
50
|
duplication: ScriptDuplication;
|
|
48
51
|
duplicationGroupedByNodeModules: ScriptDuplication;
|
|
49
52
|
};
|
|
@@ -107,7 +107,7 @@ function sorted(duplication) {
|
|
|
107
107
|
* 2. `duplication` keys correspond to authored files, except all files within the same
|
|
108
108
|
* node_module package are aggregated under the same entry.
|
|
109
109
|
*/
|
|
110
|
-
export function computeScriptDuplication(scriptsData) {
|
|
110
|
+
export function computeScriptDuplication(scriptsData, compressionRatios) {
|
|
111
111
|
const sourceDatasMap = new Map();
|
|
112
112
|
// Determine size of each `sources` entry.
|
|
113
113
|
for (const script of scriptsData.scripts) {
|
|
@@ -144,9 +144,11 @@ export function computeScriptDuplication(scriptsData) {
|
|
|
144
144
|
data = { estimatedDuplicateBytes: 0, duplicates: [] };
|
|
145
145
|
duplication.set(sourceData.source, data);
|
|
146
146
|
}
|
|
147
|
+
const compressionRatio = script.request ? compressionRatios.get(script.request?.args.data.requestId) ?? 1 : 1;
|
|
148
|
+
const transferSize = Math.round(sourceData.resourceSize * compressionRatio);
|
|
147
149
|
data.duplicates.push({
|
|
148
150
|
script,
|
|
149
|
-
attributedSize:
|
|
151
|
+
attributedSize: transferSize,
|
|
150
152
|
});
|
|
151
153
|
}
|
|
152
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScriptDuplication.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/extras/ScriptDuplication.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEpD,qDAAqD;AACrD,MAAM,6BAA6B,GAAG,IAAI,GAAG,GAAG,CAAC;AACjD,sEAAsE;AACtE,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAOpC,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,6CAA6C;IAC7C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEnC,6FAA6F;IAC7F,MAAM,oBAAoB,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;IAChE,IAAI,oBAAoB,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,0BAA0B;IAC1B,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd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AAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAC,CAAC;gBACpD,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC3C,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;gBACnB,MAAM;gBACN,cAAc,EAAE,UAAU,CAAC,YAAY;aACxC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,+BAA+B,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IAExE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAClC,oBAAoB,CAAC,+BAA+B,CAAC,CAAC;IAEtD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC;QAChC,+BAA+B,EAAE,MAAM,CAAC,+BAA+B,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 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 * as Handlers from '../handlers/handlers.js';\n\n// Ignore modules smaller than an absolute threshold.\nconst ABSOLUTE_SIZE_THRESHOLD_BYTES = 1024 * 0.5;\n// Ignore modules smaller than a % size of largest copy of the module.\nconst RELATIVE_SIZE_THRESHOLD = 0.1;\n\ninterface SourceData {\n source: string;\n resourceSize: number;\n}\n\nexport function normalizeSource(source: string): string {\n // Trim trailing question mark - b/c webpack.\n source = source.replace(/\\?$/, '');\n\n // Normalize paths for dependencies by only keeping everything after the last `node_modules`.\n const lastNodeModulesIndex = source.lastIndexOf('node_modules');\n if (lastNodeModulesIndex !== -1) {\n source = source.substring(lastNodeModulesIndex);\n }\n\n return source;\n}\n\nfunction shouldIgnoreSource(source: string): boolean {\n // Ignore bundle overhead.\n if (source.includes('webpack/bootstrap')) {\n return true;\n }\n if (source.includes('(webpack)/buildin')) {\n return true;\n }\n\n // Ignore webpack module shims, i.e. aliases of the form `module.exports = window.jQuery`\n if (source.includes('external ')) {\n return true;\n }\n\n return false;\n}\n\n/**\n * The key is a source map `sources` entry (these are URLs/file paths), but normalized\n * via `normalizeSource`.\n *\n * The value is an object with an entry for every script that has a source map which\n * denotes that this source was used, along with the estimated resource size it takes\n * up in the script.\n */\nexport type ScriptDuplication = Map<string, {\n /**\n * This is the sum of all (but one) `attributedSize` in `scripts`.\n *\n * One copy of this module is treated as the canonical version - the rest will\n * have non-zero `wastedBytes`. The canonical copy is the first entry of\n * `scripts`.\n *\n * In the case of all copies being the same version, all sizes are\n * equal and the selection doesn't matter (ignoring compression ratios). When\n * the copies are different versions, it does matter. Ideally the newest\n * version would be the canonical copy, but version information is not present.\n * Instead, size is used as a heuristic for latest version. This makes the\n * value here conserative in its estimation.\n */\n estimatedDuplicateBytes: number,\n duplicates: Array<{\n script: Handlers.ModelHandlers.Scripts.Script,\n /** The number of bytes in the script bundle that map back to this module. */\n attributedSize: number,\n }>,\n}>;\n\n/**\n * Sorts each array within @see ScriptDuplication by attributedSize, drops information\n * on sources that are too small, and calculates esimatedDuplicateBytes.\n */\nexport function normalizeDuplication(duplication: ScriptDuplication): void {\n for (const [key, data] of duplication) {\n // Sort by resource size.\n data.duplicates.sort((a, b) => b.attributedSize - a.attributedSize);\n\n // Ignore modules smaller than a % size of largest.\n if (data.duplicates.length > 1) {\n const largestResourceSize = data.duplicates[0].attributedSize;\n data.duplicates = data.duplicates.filter(duplicate => {\n const percentSize = duplicate.attributedSize / largestResourceSize;\n return percentSize >= RELATIVE_SIZE_THRESHOLD;\n });\n }\n\n // Ignore modules smaller than an absolute threshold.\n data.duplicates = data.duplicates.filter(duplicate => duplicate.attributedSize >= ABSOLUTE_SIZE_THRESHOLD_BYTES);\n\n // Delete any that now don't have multiple entries.\n if (data.duplicates.length <= 1) {\n duplication.delete(key);\n continue;\n }\n\n data.estimatedDuplicateBytes = data.duplicates.slice(1).reduce((acc, cur) => acc + cur.attributedSize, 0);\n }\n}\n\nfunction indexOfOrLength(haystack: string, needle: string, startPosition = 0): number {\n const index = haystack.indexOf(needle, startPosition);\n return index === -1 ? haystack.length : index;\n}\n\nexport function getNodeModuleName(source: string): string {\n const sourceSplit = source.split('node_modules/');\n source = sourceSplit[sourceSplit.length - 1];\n\n const indexFirstSlash = indexOfOrLength(source, '/');\n if (source[0] === '@') {\n return source.slice(0, indexOfOrLength(source, '/', indexFirstSlash + 1));\n }\n\n return source.slice(0, indexFirstSlash);\n}\n\nfunction groupByNodeModules(duplication: ScriptDuplication): ScriptDuplication {\n const groupedDuplication: ScriptDuplication = new Map();\n for (const [source, data] of duplication) {\n if (!source.includes('node_modules')) {\n groupedDuplication.set(source, data);\n continue;\n }\n\n const nodeModuleKey = 'node_modules/' + getNodeModuleName(source);\n const aggregatedData = groupedDuplication.get(nodeModuleKey) ?? {\n duplicates: [],\n // This is calculated in normalizeDuplication.\n estimatedDuplicateBytes: 0,\n };\n groupedDuplication.set(nodeModuleKey, aggregatedData);\n\n for (const {script, attributedSize} of data.duplicates) {\n let duplicate = aggregatedData.duplicates.find(d => d.script === script);\n if (!duplicate) {\n duplicate = {script, attributedSize: 0};\n aggregatedData.duplicates.push(duplicate);\n }\n duplicate.attributedSize += attributedSize;\n }\n }\n\n return groupedDuplication;\n}\n\n/**\n * Sort by estimated savings.\n */\nfunction sorted(duplication: ScriptDuplication): ScriptDuplication {\n return new Map([...duplication].sort((a, b) => b[1].estimatedDuplicateBytes - a[1].estimatedDuplicateBytes));\n}\n\n/**\n * Returns 2 @see ScriptDuplication for the given collection of script contents + source maps:\n *\n * 1. `duplication` keys correspond to authored files\n * 2. `duplication` keys correspond to authored files, except all files within the same\n * node_module package are aggregated under the same entry.\n */\nexport function computeScriptDuplication(scriptsData: Handlers.ModelHandlers.Scripts.ScriptsData):\n {duplication: ScriptDuplication, duplicationGroupedByNodeModules: ScriptDuplication} {\n const sourceDatasMap = new Map<Handlers.ModelHandlers.Scripts.Script, SourceData[]>();\n\n // Determine size of each `sources` entry.\n for (const script of scriptsData.scripts) {\n if (!script.content || !script.sourceMap) {\n continue;\n }\n\n const sizes = Handlers.ModelHandlers.Scripts.getScriptGeneratedSizes(script);\n if (!sizes) {\n continue;\n }\n\n if ('errorMessage' in sizes) {\n console.error(sizes.errorMessage);\n continue;\n }\n\n const sourceDataArray: SourceData[] = [];\n sourceDatasMap.set(script, sourceDataArray);\n\n const sources = script.sourceMap.sourceURLs();\n for (let i = 0; i < sources.length; i++) {\n if (shouldIgnoreSource(sources[i])) {\n continue;\n }\n\n const sourceSize = sizes.files[sources[i]];\n sourceDataArray.push({\n source: normalizeSource(sources[i]),\n resourceSize: sourceSize,\n });\n }\n }\n\n const duplication: ScriptDuplication = new Map();\n for (const [script, sourceDataArray] of sourceDatasMap) {\n for (const sourceData of sourceDataArray) {\n let data = duplication.get(sourceData.source);\n if (!data) {\n data = {estimatedDuplicateBytes: 0, duplicates: []};\n duplication.set(sourceData.source, data);\n }\n data.duplicates.push({\n script,\n attributedSize: sourceData.resourceSize,\n });\n }\n }\n\n const duplicationGroupedByNodeModules = groupByNodeModules(duplication);\n\n normalizeDuplication(duplication);\n normalizeDuplication(duplicationGroupedByNodeModules);\n\n return {\n duplication: sorted(duplication),\n duplicationGroupedByNodeModules: sorted(duplicationGroupedByNodeModules),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ScriptDuplication.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/extras/ScriptDuplication.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AAEpD,qDAAqD;AACrD,MAAM,6BAA6B,GAAG,IAAI,GAAG,GAAG,CAAC;AACjD,sEAAsE;AACtE,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAOpC,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,6CAA6C;IAC7C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEnC,6FAA6F;IAC7F,M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AAE,MAAM,CAAC,+BAA+B,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 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 * as Handlers from '../handlers/handlers.js';\n\n// Ignore modules smaller than an absolute threshold.\nconst ABSOLUTE_SIZE_THRESHOLD_BYTES = 1024 * 0.5;\n// Ignore modules smaller than a % size of largest copy of the module.\nconst RELATIVE_SIZE_THRESHOLD = 0.1;\n\ninterface SourceData {\n source: string;\n resourceSize: number;\n}\n\nexport function normalizeSource(source: string): string {\n // Trim trailing question mark - b/c webpack.\n source = source.replace(/\\?$/, '');\n\n // Normalize paths for dependencies by only keeping everything after the last `node_modules`.\n const lastNodeModulesIndex = source.lastIndexOf('node_modules');\n if (lastNodeModulesIndex !== -1) {\n source = source.substring(lastNodeModulesIndex);\n }\n\n return source;\n}\n\nfunction shouldIgnoreSource(source: string): boolean {\n // Ignore bundle overhead.\n if (source.includes('webpack/bootstrap')) {\n return true;\n }\n if (source.includes('(webpack)/buildin')) {\n return true;\n }\n\n // Ignore webpack module shims, i.e. aliases of the form `module.exports = window.jQuery`\n if (source.includes('external ')) {\n return true;\n }\n\n return false;\n}\n\n/**\n * The key is a source map `sources` entry (these are URLs/file paths), but normalized\n * via `normalizeSource`.\n *\n * The value is an object with an entry for every script that has a source map which\n * denotes that this source was used, along with the estimated resource size it takes\n * up in the script.\n */\nexport type ScriptDuplication = Map<string, {\n /**\n * This is the sum of all (but one) `attributedSize` in `scripts`.\n *\n * One copy of this module is treated as the canonical version - the rest will\n * have non-zero `wastedBytes`. The canonical copy is the first entry of\n * `scripts`.\n *\n * In the case of all copies being the same version, all sizes are\n * equal and the selection doesn't matter (ignoring compression ratios). When\n * the copies are different versions, it does matter. Ideally the newest\n * version would be the canonical copy, but version information is not present.\n * Instead, size is used as a heuristic for latest version. This makes the\n * value here conserative in its estimation.\n */\n estimatedDuplicateBytes: number,\n duplicates: Array<{\n script: Handlers.ModelHandlers.Scripts.Script,\n /**\n * The number of bytes in the script bundle that map back to this module,\n * in terms of estimated impact on transfer size.\n */\n attributedSize: number,\n }>,\n}>;\n\n/**\n * Sorts each array within @see ScriptDuplication by attributedSize, drops information\n * on sources that are too small, and calculates esimatedDuplicateBytes.\n */\nexport function normalizeDuplication(duplication: ScriptDuplication): void {\n for (const [key, data] of duplication) {\n // Sort by resource size.\n data.duplicates.sort((a, b) => b.attributedSize - a.attributedSize);\n\n // Ignore modules smaller than a % size of largest.\n if (data.duplicates.length > 1) {\n const largestResourceSize = data.duplicates[0].attributedSize;\n data.duplicates = data.duplicates.filter(duplicate => {\n const percentSize = duplicate.attributedSize / largestResourceSize;\n return percentSize >= RELATIVE_SIZE_THRESHOLD;\n });\n }\n\n // Ignore modules smaller than an absolute threshold.\n data.duplicates = data.duplicates.filter(duplicate => duplicate.attributedSize >= ABSOLUTE_SIZE_THRESHOLD_BYTES);\n\n // Delete any that now don't have multiple entries.\n if (data.duplicates.length <= 1) {\n duplication.delete(key);\n continue;\n }\n\n data.estimatedDuplicateBytes = data.duplicates.slice(1).reduce((acc, cur) => acc + cur.attributedSize, 0);\n }\n}\n\nfunction indexOfOrLength(haystack: string, needle: string, startPosition = 0): number {\n const index = haystack.indexOf(needle, startPosition);\n return index === -1 ? haystack.length : index;\n}\n\nexport function getNodeModuleName(source: string): string {\n const sourceSplit = source.split('node_modules/');\n source = sourceSplit[sourceSplit.length - 1];\n\n const indexFirstSlash = indexOfOrLength(source, '/');\n if (source[0] === '@') {\n return source.slice(0, indexOfOrLength(source, '/', indexFirstSlash + 1));\n }\n\n return source.slice(0, indexFirstSlash);\n}\n\nfunction groupByNodeModules(duplication: ScriptDuplication): ScriptDuplication {\n const groupedDuplication: ScriptDuplication = new Map();\n for (const [source, data] of duplication) {\n if (!source.includes('node_modules')) {\n groupedDuplication.set(source, data);\n continue;\n }\n\n const nodeModuleKey = 'node_modules/' + getNodeModuleName(source);\n const aggregatedData = groupedDuplication.get(nodeModuleKey) ?? {\n duplicates: [],\n // This is calculated in normalizeDuplication.\n estimatedDuplicateBytes: 0,\n };\n groupedDuplication.set(nodeModuleKey, aggregatedData);\n\n for (const {script, attributedSize} of data.duplicates) {\n let duplicate = aggregatedData.duplicates.find(d => d.script === script);\n if (!duplicate) {\n duplicate = {script, attributedSize: 0};\n aggregatedData.duplicates.push(duplicate);\n }\n duplicate.attributedSize += attributedSize;\n }\n }\n\n return groupedDuplication;\n}\n\n/**\n * Sort by estimated savings.\n */\nfunction sorted(duplication: ScriptDuplication): ScriptDuplication {\n return new Map([...duplication].sort((a, b) => b[1].estimatedDuplicateBytes - a[1].estimatedDuplicateBytes));\n}\n\n/**\n * Returns 2 @see ScriptDuplication for the given collection of script contents + source maps:\n *\n * 1. `duplication` keys correspond to authored files\n * 2. `duplication` keys correspond to authored files, except all files within the same\n * node_module package are aggregated under the same entry.\n */\nexport function computeScriptDuplication(\n scriptsData: Handlers.ModelHandlers.Scripts.ScriptsData, compressionRatios: Map<string, number>):\n {duplication: ScriptDuplication, duplicationGroupedByNodeModules: ScriptDuplication} {\n const sourceDatasMap = new Map<Handlers.ModelHandlers.Scripts.Script, SourceData[]>();\n\n // Determine size of each `sources` entry.\n for (const script of scriptsData.scripts) {\n if (!script.content || !script.sourceMap) {\n continue;\n }\n\n const sizes = Handlers.ModelHandlers.Scripts.getScriptGeneratedSizes(script);\n if (!sizes) {\n continue;\n }\n\n if ('errorMessage' in sizes) {\n console.error(sizes.errorMessage);\n continue;\n }\n\n const sourceDataArray: SourceData[] = [];\n sourceDatasMap.set(script, sourceDataArray);\n\n const sources = script.sourceMap.sourceURLs();\n for (let i = 0; i < sources.length; i++) {\n if (shouldIgnoreSource(sources[i])) {\n continue;\n }\n\n const sourceSize = sizes.files[sources[i]];\n sourceDataArray.push({\n source: normalizeSource(sources[i]),\n resourceSize: sourceSize,\n });\n }\n }\n\n const duplication: ScriptDuplication = new Map();\n for (const [script, sourceDataArray] of sourceDatasMap) {\n for (const sourceData of sourceDataArray) {\n let data = duplication.get(sourceData.source);\n if (!data) {\n data = {estimatedDuplicateBytes: 0, duplicates: []};\n duplication.set(sourceData.source, data);\n }\n const compressionRatio = script.request ? compressionRatios.get(script.request?.args.data.requestId) ?? 1 : 1;\n const transferSize = Math.round(sourceData.resourceSize * compressionRatio);\n data.duplicates.push({\n script,\n attributedSize: transferSize,\n });\n }\n }\n\n const duplicationGroupedByNodeModules = groupByNodeModules(duplication);\n\n normalizeDuplication(duplication);\n normalizeDuplication(duplicationGroupedByNodeModules);\n\n return {\n duplication: sorted(duplication),\n duplicationGroupedByNodeModules: sorted(duplicationGroupedByNodeModules),\n };\n}\n"]}
|