blob: 8d3bf750a7f2b38e1ba515eeaf3d5304f0c069f6 [file] [log] [blame]
Jan Schefflerd6c1d402021-02-26 16:56:381// Copyright 2021 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
Blink Reformat4c46d092018-04-07 15:32:375/*
6 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Tim van der Lippe76961572021-04-06 10:48:0735import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3036import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2837import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2738import * as Platform from '../../core/platform/platform.js';
Wolfgang Beyer6a4cbb42022-05-16 13:02:2939import * as Root from '../../core/root/root.js';
Tim van der Lippee00b92f2021-03-31 16:52:1740import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0541import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5942import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5643import * as HAR from '../../models/har/har.js';
Sigurd Schneider055e2e32021-04-12 11:10:4244import * as IssuesManager from '../../models/issues_manager/issues_manager.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2745import * as Logs from '../../models/logs/logs.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3746import * as Persistence from '../../models/persistence/persistence.js';
Tim van der Lippefca98ed2021-04-08 14:10:1447import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1648import * as NetworkForward from '../../panels/network/forward/forward.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3749import * as Sources from '../../panels/sources/sources.js';
Tim van der Lippe8499fe22021-04-12 16:42:4750import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1451import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3652import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0753import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippefddcf402021-04-19 13:00:2954import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1355
Kriti Sapra2d85f882021-08-18 09:01:3056import networkLogViewStyles from './networkLogView.css.js';
57
Jack Franklin3a802602022-07-13 08:39:4258import {
59 Events,
60 NetworkGroupNode,
61 NetworkRequestNode,
62 type NetworkLogViewInterface,
63 type NetworkNode,
64 type EventTypes,
65} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3066import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
67import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Franklin3a802602022-07-13 08:39:4268
Jack Frankline839c0c2022-05-03 08:47:4469import {
70 NetworkTimeBoundary,
71 NetworkTransferDurationCalculator,
72 NetworkTransferTimeCalculator,
Jack Franklin3a802602022-07-13 08:39:4273 type NetworkTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4474} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3075
Simon Zünd34490692021-03-01 08:25:1876const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5577 /**
78 *@description Text in Network Log View of the Network panel
79 */
Victor Porof66878d62021-07-16 13:12:3780 invertFilter: 'Invert',
81 /**
82 *@description Tooltip for the 'invert' checkbox in the Network panel.
83 */
84 invertsFilter: 'Inverts the search filter',
85 /**
86 *@description Text in Network Log View of the Network panel
87 */
Christy Chencac3f102021-02-03 10:07:5588 hideDataUrls: 'Hide data URLs',
89 /**
90 *@description Data urlfilter ui element title in Network Log View of the Network panel
91 */
92 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
93 /**
94 *@description Aria accessible name in Network Log View of the Network panel
95 */
96 resourceTypesToInclude: 'Resource types to include',
97 /**
98 *@description Label for a filter in the Network panel
99 */
100 hasBlockedCookies: 'Has blocked cookies',
101 /**
Jack Franklin28577db2021-10-14 08:12:53102 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
Simon Zünd562d32c2021-02-17 09:22:54103 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
104 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:55105 */
106 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
107 /**
108 *@description Label for a filter in the Network panel
109 */
110 blockedRequests: 'Blocked Requests',
111 /**
112 *@description Tooltip for a filter in the Network panel
113 */
114 onlyShowBlockedRequests: 'Only show blocked requests',
115 /**
Danil Somsikov721956a2021-07-07 08:17:27116 *@description Label for a filter in the Network panel
117 */
118 thirdParty: '3rd-party requests',
119 /**
120 *@description Tooltip for a filter in the Network panel
121 */
122 onlyShowThirdPartyRequests: 'Shows only requests with origin different from page origin',
123 /**
Christy Chencac3f102021-02-03 10:07:55124 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
125 */
126 dropHarFilesHere: 'Drop HAR files here',
127 /**
128 *@description Recording text text content in Network Log View of the Network panel
129 */
130 recordingNetworkActivity: 'Recording network activity…',
131 /**
132 *@description Text in Network Log View of the Network panel
133 *@example {Ctrl + R} PH1
134 */
135 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
136 /**
Peter Marshall266ab2e2021-02-16 17:30:49137 *@description Shown in the Network Log View of the Network panel when the user has not yet
Jack Franklin28577db2021-10-14 08:12:53138 * recorded any network activity. This is an instruction to the user to start recording in order to
Peter Marshall266ab2e2021-02-16 17:30:49139 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55140 *@example {Ctrl + E} PH1
141 */
Wolfgang Beyerf4237472021-08-18 14:55:41142 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55143 /**
144 *@description Text that is usually a hyperlink to more documentation
145 */
146 learnMore: 'Learn more',
147 /**
148 *@description Text to announce to screen readers that network data is available.
149 */
150 networkDataAvailable: 'Network Data Available',
151 /**
152 *@description Text in Network Log View of the Network panel
153 *@example {3} PH1
154 *@example {5} PH2
155 */
156 sSRequests: '{PH1} / {PH2} requests',
157 /**
Andres Olivares7fbed142021-03-01 16:22:23158 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
Jack Franklin28577db2021-10-14 08:12:53159 * resources transferred during a selected time frame over the compressed size of all resources transferred during
Andres Olivares7fbed142021-03-01 16:22:23160 * the whole network log.
161 *@example {5 B} PH1
162 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55163 */
164 sSTransferred: '{PH1} / {PH2} transferred',
165 /**
Andres Olivares7fbed142021-03-01 16:22:23166 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
Jack Franklin28577db2021-10-14 08:12:53167 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55168 *@example {10} PH1
169 *@example {15} PH2
170 */
171 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
172 /**
Peter Marshall2c3fb302021-02-19 12:47:04173 * @description Text in Network Log View of the Network panel. Appears when a particular network
174 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
175 * total size (PH2).
176 * @example {40MB} PH1
177 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55178 */
179 sSResources: '{PH1} / {PH2} resources',
180 /**
181 *@description Text in Network Log View of the Network panel
182 *@example {40} PH1
183 *@example {50} PH2
184 */
185 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
186 /**
187 *@description Text in Network Log View of the Network panel
188 *@example {6} PH1
189 */
190 sRequests: '{PH1} requests',
191 /**
Andres Olivares0a863ab2021-02-19 15:21:23192 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
193 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55194 *@example {4 B} PH1
195 */
196 sTransferred: '{PH1} transferred',
197 /**
Andres Olivares0a863ab2021-02-19 15:21:23198 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
199 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55200 *@example {4} PH1
201 */
202 sBTransferredOverNetwork: '{PH1} B transferred over network',
203 /**
204 *@description Text in Network Log View of the Network panel
205 *@example {4} PH1
206 */
207 sResources: '{PH1} resources',
208 /**
209 *@description Text in Network Log View of the Network panel
210 *@example {10} PH1
211 */
212 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
213 /**
214 *@description Text in Network Log View of the Network panel
215 *@example {120ms} PH1
216 */
217 finishS: 'Finish: {PH1}',
218 /**
219 *@description Text in Network Log View of the Network panel
220 *@example {3000ms} PH1
221 */
222 domcontentloadedS: 'DOMContentLoaded: {PH1}',
223 /**
224 *@description Text in Network Log View of the Network panel
225 *@example {40ms} PH1
226 */
227 loadS: 'Load: {PH1}',
228 /**
229 *@description Text for copying
230 */
231 copy: 'Copy',
232 /**
233 *@description Text in Network Log View of the Network panel
234 */
235 copyRequestHeaders: 'Copy request headers',
236 /**
237 *@description Text in Network Log View of the Network panel
238 */
239 copyResponseHeaders: 'Copy response headers',
240 /**
241 *@description Text in Network Log View of the Network panel
242 */
243 copyResponse: 'Copy response',
244 /**
245 *@description Text in Network Log View of the Network panel
246 */
Peter Marshallf625dc82021-03-02 08:10:57247 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55248 /**
Peter Marshall3ec813d2021-03-01 19:40:25249 * @description A context menu command in the Network panel, for copying to the clipboard.
250 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55251 */
Peter Marshallb8bd00f2021-02-24 08:25:18252 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55253 /**
Peter Marshall3ec813d2021-03-01 19:40:25254 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
255 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55256 */
Peter Marshallb8bd00f2021-02-24 08:25:18257 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55258 /**
Peter Marshall3ec813d2021-03-01 19:40:25259 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21260 * the developer's clipboard. The command allows the developer to replay this specific network
Jack Franklin28577db2021-10-14 08:12:53261 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
262 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55263 */
Peter Marshallb8bd00f2021-02-24 08:25:18264 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55265 /**
Peter Marshallec861882021-02-16 11:14:21266 *@description Text in Network Log View of the Network panel. An action that copies a command to
267 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
268 *translatable).
Christy Chencac3f102021-02-03 10:07:55269 */
Peter Marshallb8bd00f2021-02-24 08:25:18270 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55271 /**
Peter Marshallec861882021-02-16 11:14:21272 *@description Text in Network Log View of the Network panel. An action that copies a command to
273 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55274 */
Peter Marshallb8bd00f2021-02-24 08:25:18275 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55276 /**
Peter Marshallec861882021-02-16 11:14:21277 *@description Text in Network Log View of the Network panel. An action that copies a command to
278 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55279 */
Peter Marshallb8bd00f2021-02-24 08:25:18280 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55281 /**
Peter Marshallec861882021-02-16 11:14:21282 *@description Text in Network Log View of the Network panel. An action that copies a command to
283 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
284 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55285 */
Peter Marshallb8bd00f2021-02-24 08:25:18286 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55287 /**
Peter Marshallec861882021-02-16 11:14:21288 *@description Text in Network Log View of the Network panel. An action that copies a command to
289 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
290 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55291 */
Peter Marshallb8bd00f2021-02-24 08:25:18292 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55293 /**
Peter Marshallec861882021-02-16 11:14:21294 *@description Text in Network Log View of the Network panel. An action that copies a command to
295 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
296 *translatable).
Christy Chencac3f102021-02-03 10:07:55297 */
Peter Marshallb8bd00f2021-02-24 08:25:18298 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55299 /**
Peter Marshallec861882021-02-16 11:14:21300 *@description Text in Network Log View of the Network panel. An action that copies a command to
301 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55302 */
Peter Marshallb8bd00f2021-02-24 08:25:18303 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55304 /**
Peter Marshallec861882021-02-16 11:14:21305 *@description Text in Network Log View of the Network panel. An action that copies a command to
306 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
307 *translatable).
Christy Chencac3f102021-02-03 10:07:55308 */
Peter Marshallb8bd00f2021-02-24 08:25:18309 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55310 /**
Peter Marshallec861882021-02-16 11:14:21311 *@description Text in Network Log View of the Network panel. An action that copies a command to
312 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
313 *translatable).
Christy Chencac3f102021-02-03 10:07:55314 */
Peter Marshallb8bd00f2021-02-24 08:25:18315 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55316 /**
Peter Marshallb8bd00f2021-02-24 08:25:18317 * @description Text in Network Log View of the Network panel. An action that copies data to the
318 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
Jack Franklin28577db2021-10-14 08:12:53319 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55320 */
Peter Marshallb8bd00f2021-02-24 08:25:18321 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55322 /**
323 *@description A context menu item in the Network Log View of the Network panel
324 */
Peter Marshallb8bd00f2021-02-24 08:25:18325 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55326 /**
327 *@description A context menu item in the Network Log View of the Network panel
328 */
329 clearBrowserCache: 'Clear browser cache',
330 /**
331 *@description A context menu item in the Network Log View of the Network panel
332 */
333 clearBrowserCookies: 'Clear browser cookies',
334 /**
335 *@description A context menu item in the Network Log View of the Network panel
336 */
337 blockRequestUrl: 'Block request URL',
338 /**
339 *@description A context menu item in the Network Log View of the Network panel
340 *@example {example.com} PH1
341 */
342 unblockS: 'Unblock {PH1}',
343 /**
344 *@description A context menu item in the Network Log View of the Network panel
345 */
346 blockRequestDomain: 'Block request domain',
347 /**
Jack Franklin28577db2021-10-14 08:12:53348 *@description Text to replay an XHR request
Christy Chencac3f102021-02-03 10:07:55349 */
350 replayXhr: 'Replay XHR',
351 /**
352 *@description Text in Network Log View of the Network panel
353 */
354 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
355 /**
356 *@description Text in Network Log View of the Network panel
357 */
358 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37359 /**
360 *@description A context menu item in the Network Log View of the Network panel
361 * for creating a header override
362 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41363 overrideHeaders: 'Override headers',
Christy Chencac3f102021-02-03 10:07:55364};
Tim van der Lippef596ca02021-03-31 10:02:47365const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55366const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46367
368const enum FetchStyle {
369 Browser = 0,
370 NodeJs = 1,
371}
372
Simon Zünd940cb1f2021-09-16 11:46:09373export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
374 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53375 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
376 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
377 private readonly networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
378 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
379 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
380 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
381 private rawRowHeight: number;
382 private readonly progressBarContainer: Element;
383 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
384 private rowHeightInternal: number;
385 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
386 private readonly durationCalculator: NetworkTransferDurationCalculator;
387 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30388 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53389 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
390 private mainRequestLoadTime: number;
391 private mainRequestDOMContentLoadedTime: number;
392 private filters: Filter[];
393 private timeFilter: Filter|null;
394 private hoveredNodeInternal: NetworkNode|null;
395 private recordingHint: Element|null;
396 private refreshRequestId: number|null;
397 private highlightedNode: NetworkRequestNode|null;
398 private readonly linkifierInternal: Components.Linkifier.Linkifier;
399 private recording: boolean;
400 private needsRefresh: boolean;
401 private readonly headerHeightInternal: number;
402 private readonly groupLookups: Map<string, GroupLookupInterface>;
403 private activeGroupLookup: GroupLookupInterface|null;
404 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
405 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
406 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
407 private resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
408 private readonly onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
409 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
410 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI;
411 private readonly filterParser: TextUtils.TextUtils.FilterParser;
412 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
413 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
414 private readonly summaryToolbar: UI.Toolbar.Toolbar;
415 private readonly filterBar: UI.FilterBar.FilterBar;
416 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38417
418 constructor(
419 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
420 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37421 super();
422 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37423
424 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05425 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37426
Jack Franklin28577db2021-10-14 08:12:53427 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('networkInvertFilter', false);
428 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
429 this.networkShowIssuesOnlySetting =
Paul Lewis2d7d65c2020-03-16 17:26:30430 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
Jack Franklin28577db2021-10-14 08:12:53431 this.networkOnlyBlockedRequestsSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30432 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
Jack Franklin28577db2021-10-14 08:12:53433 this.networkOnlyThirdPartySetting =
Danil Somsikov721956a2021-07-07 08:17:27434 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
Jack Franklin28577db2021-10-14 08:12:53435 this.networkResourceTypeFiltersSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30436 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37437
Jack Franklin28577db2021-10-14 08:12:53438 this.rawRowHeight = 0;
439 this.progressBarContainer = progressBarContainer;
440 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
441 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37442
Jan Schefflerd6c1d402021-02-26 16:56:38443 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53444 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
445 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37446 }
Jack Franklin28577db2021-10-14 08:12:53447 this.rawRowHeight = 0;
448 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37449 updateRowHeight.call(this);
450
Jack Franklin28577db2021-10-14 08:12:53451 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
452 this.durationCalculator = new NetworkTransferDurationCalculator();
453 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37454
Danil Somsikov2a4c4e02022-10-07 12:31:30455 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53456 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30457 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37458
Jack Franklin28577db2021-10-14 08:12:53459 this.staleRequests = new Set();
460 this.mainRequestLoadTime = -1;
461 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37462
Jack Franklin28577db2021-10-14 08:12:53463 this.filters = [];
464 this.timeFilter = null;
465 this.hoveredNodeInternal = null;
466 this.recordingHint = null;
467 this.refreshRequestId = null;
468 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37469
Jack Franklin28577db2021-10-14 08:12:53470 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37471
Jack Franklin28577db2021-10-14 08:12:53472 this.recording = false;
473 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37474
Jack Franklin28577db2021-10-14 08:12:53475 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37476
Jack Franklin28577db2021-10-14 08:12:53477 this.groupLookups = new Map();
478 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37479
Jack Franklin28577db2021-10-14 08:12:53480 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37481
Jack Franklin28577db2021-10-14 08:12:53482 this.textFilterUI = new UI.FilterBar.TextFilterUI();
483 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
484 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37485
Jack Franklin28577db2021-10-14 08:12:53486 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
487 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting);
488 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38489 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53490 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
491 filterBar.addFilter(this.invertFilterUI);
Victor Porof66878d62021-07-16 13:12:37492
Jack Franklin28577db2021-10-14 08:12:53493 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
494 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting);
495 this.dataURLFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38496 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53497 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
498 filterBar.addFilter(this.dataURLFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37499
500 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13501 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38502 .map(
503 category =>
504 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Jack Franklin28577db2021-10-14 08:12:53505 this.resourceCategoryFilterUI =
506 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55507 UI.ARIAUtils.setAccessibleName(
Jack Franklin28577db2021-10-14 08:12:53508 this.resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
509 this.resourceCategoryFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38510 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53511 filterBar.addFilter(this.resourceCategoryFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37512
Jack Franklin28577db2021-10-14 08:12:53513 this.onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
514 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this.networkShowIssuesOnlySetting);
515 this.onlyIssuesFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38516 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53517 UI.Tooltip.Tooltip.install(this.onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
518 filterBar.addFilter(this.onlyIssuesFilterUI);
Jan Scheffler1ae7c9e2019-12-03 15:48:37519
Jack Franklin28577db2021-10-14 08:12:53520 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55521 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Jack Franklin28577db2021-10-14 08:12:53522 this.networkOnlyBlockedRequestsSetting);
523 this.onlyBlockedRequestsUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38524 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53525 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
526 filterBar.addFilter(this.onlyBlockedRequestsUI);
Sigurd Schneidera2afe0b2020-03-03 15:27:13527
Jack Franklin28577db2021-10-14 08:12:53528 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
529 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting);
530 this.onlyThirdPartyFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38531 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53532 UI.Tooltip.Tooltip.install(this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
533 filterBar.addFilter(this.onlyThirdPartyFilterUI);
Danil Somsikov721956a2021-07-07 08:17:27534
Jack Franklin28577db2021-10-14 08:12:53535 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
536 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38537 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
538 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37539
Danil Somsikov2a4c4e02022-10-07 12:31:30540 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38541 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30542 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49543 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53544 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37545
Jack Franklin28577db2021-10-14 08:12:53546 this.summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
547 this.summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37548
Tim van der Lippe0ed1d2b2020-02-04 13:45:13549 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38550 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37551
Paul Lewis2d7d65c2020-03-16 17:26:30552 Common.Settings.Settings.instance()
553 .moduleSetting('networkColorCodeResourceTypes')
Jan Scheffler17b8fb42021-08-12 12:28:38554 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37555
Sigurd Schneiderb9f6c792021-05-31 10:57:24556 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27557 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38558 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27559 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38560 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
561 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37562
Jan Scheffler17b8fb42021-08-12 12:28:38563 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30564 Common.Settings.Settings.instance()
565 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38566 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37567
Jack Franklin28577db2021-10-14 08:12:53568 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03569
Jack Franklin28577db2021-10-14 08:12:53570 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
571 if (this.textFilterSetting.get()) {
572 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03573 }
Blink Reformat4c46d092018-04-07 15:32:37574 }
575
Jan Scheffler17b8fb42021-08-12 12:28:38576 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30577 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38578 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37579 }
580
Jan Scheffler17b8fb42021-08-12 12:28:38581 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16582 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37583 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38584 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
585 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50586 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
587 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37588 });
589 } else {
590 values.sort();
591 }
592 }
593
Jan Scheffler17b8fb42021-08-12 12:28:38594 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37595 return !filter(request);
596 }
597
Jan Scheffler17b8fb42021-08-12 12:28:38598 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34599 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37600 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34601 }
Blink Reformat4c46d092018-04-07 15:32:37602
603 return regex.test(request.path() + '/' + request.name());
604 }
605
Jan Scheffler17b8fb42021-08-12 12:28:38606 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37607 const result = [domain];
608 let indexOfPeriod = domain.indexOf('.');
609 while (indexOfPeriod !== -1) {
610 result.push('*' + domain.substring(indexOfPeriod));
611 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
612 }
613 return result;
614 }
615
Jan Scheffler17b8fb42021-08-12 12:28:38616 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17617 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38618 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37619 }
620
Jan Scheffler17b8fb42021-08-12 12:28:38621 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37622 return regex.test(request.domain);
623 }
624
Jan Scheffler17b8fb42021-08-12 12:28:38625 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37626 return !request.finished;
627 }
628
Jan Scheffler17b8fb42021-08-12 12:28:38629 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37630 return request.cached();
631 }
632
Jan Scheffler17b8fb42021-08-12 12:28:38633 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05634 return request.fetchedViaServiceWorker;
635 }
636
Jan Scheffler17b8fb42021-08-12 12:28:38637 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05638 return request.initiatedByServiceWorker();
639 }
640
Jan Scheffler17b8fb42021-08-12 12:28:38641 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37642 return request.responseHeaderValue(value) !== undefined;
643 }
644
Jan Scheffler17b8fb42021-08-12 12:28:38645 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
646 boolean {
Jack Franklin28577db2021-10-14 08:12:53647 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51648 // filter via `includes` instead of strict equality.
649 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
650 }
651
Jan Scheffler17b8fb42021-08-12 12:28:38652 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37653 return request.requestMethod === value;
654 }
655
Jan Scheffler17b8fb42021-08-12 12:28:38656 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37657 return request.priority() === value;
658 }
659
Jan Scheffler17b8fb42021-08-12 12:28:38660 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37661 return request.mimeType === value;
662 }
663
Jan Scheffler17b8fb42021-08-12 12:28:38664 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16665 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
666 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37667 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28668 }
Sigurd Schneider30722582021-06-16 06:54:16669 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37670 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28671 }
Sigurd Schneider30722582021-06-16 06:54:16672 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37673 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28674 }
Sigurd Schneider30722582021-06-16 06:54:16675 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37676 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34677 }
Blink Reformat4c46d092018-04-07 15:32:37678
679 return false;
680 }
681
Jan Scheffler17b8fb42021-08-12 12:28:38682 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37683 return request.scheme === value;
684 }
685
Jan Scheffler17b8fb42021-08-12 12:28:38686 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41687 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
688 }
689
Jan Scheffler17b8fb42021-08-12 12:28:38690 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41691 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
692 }
693
Jan Scheffler17b8fb42021-08-12 12:28:38694 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54695 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
696 }
697
Jan Scheffler17b8fb42021-08-12 12:28:38698 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41699 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
700 }
701
Jan Scheffler17b8fb42021-08-12 12:28:38702 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41703 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37704 }
705
Jan Scheffler17b8fb42021-08-12 12:28:38706 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41707 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37708 }
709
Jan Scheffler17b8fb42021-08-12 12:28:38710 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41711 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37712 }
713
Jan Scheffler17b8fb42021-08-12 12:28:38714 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37715 return request.transferSize >= value;
716 }
717
Jan Scheffler17b8fb42021-08-12 12:28:38718 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24719 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37720 }
721
Sigurd Schneider576ca9a2021-07-16 05:58:04722 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58723 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37724 }
725
Jan Scheffler17b8fb42021-08-12 12:28:38726 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03727 return request.resourceType().name() === value;
728 }
729
Jan Scheffler17b8fb42021-08-12 12:28:38730 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17731 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03732 return regex.test(request.url());
733 }
734
Jan Scheffler17b8fb42021-08-12 12:28:38735 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38736 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34737 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37738 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34739 }
740 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37741 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34742 }
Blink Reformat4c46d092018-04-07 15:32:37743 return true;
744 }
745
Jan Scheffler17b8fb42021-08-12 12:28:38746 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13747 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37748 }
749
Jan Scheffler17b8fb42021-08-12 12:28:38750 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13751 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37752 }
753
Jan Scheffler17b8fb42021-08-12 12:28:38754 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37755 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38756 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34757 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40758 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37759 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08760 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34761 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13762 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37763 }
764
Jan Scheffler17b8fb42021-08-12 12:28:38765 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37766 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34767 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37768 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34769 }
Simon Zünd99961242021-09-08 11:02:12770 const file = items[0].getAsFile();
771 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03772 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34773 }
Blink Reformat4c46d092018-04-07 15:32:37774 }
775
Jan Schefflerd6c1d402021-02-26 16:56:38776 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13777 const outputStream = new Common.StringOutputStream.StringOutputStream();
778 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37779 const success = await reader.read(outputStream);
780 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37781 const error = reader.error();
782 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38783 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37784 }
Blink Reformat4c46d092018-04-07 15:32:37785 return;
786 }
787 let harRoot;
788 try {
789 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56790 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37791 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38792 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37793 return;
794 }
Tim van der Lippe09cf5032021-04-29 15:08:09795 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37796 }
797
Jan Scheffler17b8fb42021-08-12 12:28:38798 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36799 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37800 }
801
Jan Scheffler17b8fb42021-08-12 12:28:38802 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53803 if (this.activeGroupLookup) {
804 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34805 }
Jack Franklin28577db2021-10-14 08:12:53806 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
807 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38808 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37809 }
810
Jan Scheffler17b8fb42021-08-12 12:28:38811 private computeRowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53812 return Math.round(this.rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
Blink Reformat4c46d092018-04-07 15:32:37813 }
814
Jan Schefflerd6c1d402021-02-26 16:56:38815 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37816 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37817 }
818
Jan Schefflerd6c1d402021-02-26 16:56:38819 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53820 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37821 }
822
Jan Schefflerd6c1d402021-02-26 16:56:38823 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53824 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38825 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37826 }
827
Danil Somsikov2a4c4e02022-10-07 12:31:30828 columns(): NetworkLogViewColumns {
829 return this.columnsInternal;
830 }
831
Jan Schefflerd6c1d402021-02-26 16:56:38832 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37833 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov0bde8db2022-10-24 14:13:36834 if (networkManager.target().parentTarget()?.type() === SDK.Target.Type.Frame) {
Blink Reformat4c46d092018-04-07 15:32:37835 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34836 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13837 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37838 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38839 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37840 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38841 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37842 }
843 }
844
Jan Schefflerd6c1d402021-02-26 16:56:38845 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov0bde8db2022-10-24 14:13:36846 if (networkManager.target().parentTarget()?.type() !== SDK.Target.Type.Frame) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13847 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37848 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38849 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37850 resourceTreeModel.removeEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38851 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37852 }
853 }
854 }
855
Jan Schefflerd6c1d402021-02-26 16:56:38856 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53857 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13858 }
859
Jan Schefflerd6c1d402021-02-26 16:56:38860 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37861 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53862 this.timeFilter = null;
863 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37864 } else {
Jack Franklin28577db2021-10-14 08:12:53865 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
866 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37867 }
Jan Scheffler17b8fb42021-08-12 12:28:38868 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37869 }
870
Jan Schefflerd6c1d402021-02-26 16:56:38871 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53872 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37873 }
874
Jan Scheffler17b8fb42021-08-12 12:28:38875 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:53876 this.suggestionBuilder.clear();
877 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
878 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16879 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:53880 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16881 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:53882 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16883 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:53884 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
885 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
886 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
887 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Blink Reformat4c46d092018-04-07 15:32:37888 }
889
Simon Zünda2bae2e2021-09-16 07:57:13890 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:37891 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:53892 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:38893 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:53894 this.textFilterSetting.set(this.textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37895 }
896
Jan Schefflerd6c1d402021-02-26 16:56:38897 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:53898 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:12899 }
900
Jan Scheffler17b8fb42021-08-12 12:28:38901 private showRecordingHint(): void {
902 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:53903 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
904 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18905
Jack Franklin28577db2021-10-14 08:12:53906 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38907 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04908 const reloadShortcut =
909 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
910 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:53911 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:04912 reloadShortcutNode.textContent = reloadShortcut.title();
913 }
914
Blink Reformat4c46d092018-04-07 15:32:37915 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55916 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18917 if (reloadShortcutNode) {
918 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55919 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
920 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18921 }
Blink Reformat4c46d092018-04-07 15:32:37922 } else {
923 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17924 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37925 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55926 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:41927 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37928 }
Kayce Basques5444c1b2019-02-15 20:32:53929 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13930 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35931 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55932 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11933
Jan Scheffler17b8fb42021-08-12 12:28:38934 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37935 }
936
Jan Scheffler17b8fb42021-08-12 12:28:38937 private hideRecordingHint(): void {
938 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:53939 if (this.recordingHint) {
940 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34941 }
Michael Liao7322dee2021-04-07 18:33:30942 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:53943 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37944 }
945
Jan Scheffler17b8fb42021-08-12 12:28:38946 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:30947 this.columnsInternal.setHidden(value);
Jack Franklin28577db2021-10-14 08:12:53948 UI.ARIAUtils.setHidden(this.summaryToolbar.element, value);
Amanda Baker6761aae2019-11-05 18:59:11949 }
950
Jan Schefflerd6c1d402021-02-26 16:56:38951 elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:53952 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34953 {
Blink Reformat4c46d092018-04-07 15:32:37954 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34955 }
Jack Franklin28577db2021-10-14 08:12:53956 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:37957 }
958
Jan Schefflerd6c1d402021-02-26 16:56:38959 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:38960 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:37961 }
962
Jan Scheffler17b8fb42021-08-12 12:28:38963 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:53964 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38965 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34966 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37967 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34968 }
Blink Reformat4c46d092018-04-07 15:32:37969 });
Jack Franklin28577db2021-10-14 08:12:53970 this.dataGrid.setStickToBottom(true);
971 this.dataGrid.setName('networkLog');
972 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
973 this.dataGrid.element.classList.add('network-log-grid');
974 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
975 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
976 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
977 this.dataGrid.element.addEventListener('keydown', event => {
978 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
979 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('span.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:43980 if (initiatorLink) {
981 (initiatorLink as HTMLElement).focus();
982 }
983 }
ergunshee4a6132021-11-05 16:21:25984
Jack Franklin5e685be2022-10-17 14:27:09985 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05986 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05987 event.consume(true);
988 }
989 });
ergunshee4a6132021-11-05 16:21:25990 this.dataGrid.element.addEventListener('keyup', event => {
991 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
992 const request = (this.dataGrid.selectedNode as NetworkNode).request();
993 if (!request) {
994 return;
995 }
996
997 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
998 SDK.NetworkManager.NetworkManager.replayRequest(request);
999 }
1000 }
1001 });
Jack Franklin28577db2021-10-14 08:12:531002 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1003 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1004 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371005 }
1006
Jan Scheffler17b8fb42021-08-12 12:28:381007 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381008 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531009 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371010 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381011 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371012 }
1013
Jan Schefflerd6c1d402021-02-26 16:56:381014 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531015 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371016 }
1017
Jan Scheffler17b8fb42021-08-12 12:28:381018 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531019 if (this.hoveredNodeInternal) {
1020 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341021 }
Jack Franklin28577db2021-10-14 08:12:531022 this.hoveredNodeInternal = node;
1023 if (this.hoveredNodeInternal) {
1024 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341025 }
Blink Reformat4c46d092018-04-07 15:32:371026 }
1027
Jan Scheffler17b8fb42021-08-12 12:28:381028 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381029 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531030 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371031 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341032 }
Blink Reformat4c46d092018-04-07 15:32:371033 }
1034
Jan Scheffler17b8fb42021-08-12 12:28:381035 private updateSummaryBar(): void {
1036 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371037
1038 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201039 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371040 let selectedNodeNumber = 0;
1041 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201042 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371043 let baseTime = -1;
1044 let maxTime = -1;
1045
1046 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271047 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371048 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341049 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371050 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341051 }
Blink Reformat4c46d092018-04-07 15:32:371052 nodeCount++;
1053 const requestTransferSize = request.transferSize;
1054 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201055 const requestResourceSize = request.resourceSize;
1056 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371057 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371058 selectedNodeNumber++;
1059 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201060 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371061 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131062 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371063 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1064 // inspected url.
1065 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131066 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
1067 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:371068 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341069 }
1070 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371071 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341072 }
Blink Reformat4c46d092018-04-07 15:32:371073 }
1074
1075 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381076 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371077 return;
1078 }
1079
Jack Franklin28577db2021-10-14 08:12:531080 this.summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381081 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131082 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501083 toolbarText.setTitle(title ? title : chunk);
Jack Franklin28577db2021-10-14 08:12:531084 this.summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381085 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501086 };
Blink Reformat4c46d092018-04-07 15:32:371087
1088 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551089 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Jack Franklin28577db2021-10-14 08:12:531090 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501091 appendChunk(
Christy Chencac3f102021-02-03 10:07:551092 i18nString(UIStrings.sSTransferred, {
1093 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381094 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551095 }),
1096 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531097 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501098 appendChunk(
Christy Chencac3f102021-02-03 10:07:551099 i18nString(UIStrings.sSResources, {
1100 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381101 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551102 }),
1103 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371104 } else {
Christy Chencac3f102021-02-03 10:07:551105 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Jack Franklin28577db2021-10-14 08:12:531106 this.summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251107 appendChunk(
Christy Chencac3f102021-02-03 10:07:551108 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1109 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531110 this.summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251111 appendChunk(
Christy Chencac3f102021-02-03 10:07:551112 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1113 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371114 }
Dan Beam87466b52018-12-01 18:41:201115
Blink Reformat4c46d092018-04-07 15:32:371116 if (baseTime !== -1 && maxTime !== -1) {
Jack Franklin28577db2021-10-14 08:12:531117 this.summaryToolbar.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581118 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531119 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
1120 this.summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551121 const domContentLoadedText = i18nString(
1122 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531123 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581124 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371125 }
Jack Franklin28577db2021-10-14 08:12:531126 if (this.mainRequestLoadTime !== -1) {
1127 this.summaryToolbar.appendSeparator();
1128 const loadText =
1129 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581130 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371131 }
1132 }
Blink Reformat4c46d092018-04-07 15:32:371133 }
1134
Jan Schefflerd6c1d402021-02-26 16:56:381135 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531136 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371137 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341138 }
Blink Reformat4c46d092018-04-07 15:32:371139
Jack Franklin28577db2021-10-14 08:12:531140 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371141
Jack Franklin28577db2021-10-14 08:12:531142 if (this.isShowing() && !this.refreshRequestId) {
1143 this.refreshRequestId = this.element.window().requestAnimationFrame(this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 }
Blink Reformat4c46d092018-04-07 15:32:371145 }
1146
Jan Schefflerd6c1d402021-02-26 16:56:381147 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301148 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371149 }
1150
Jan Schefflerd6c1d402021-02-26 16:56:381151 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301152 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371153 }
1154
Jan Schefflerd6c1d402021-02-26 16:56:381155 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301156 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371157 }
1158
Jan Scheffler17b8fb42021-08-12 12:28:381159 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531160 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381161 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341162 }
Blink Reformat4c46d092018-04-07 15:32:371163 }
1164
Jan Scheffler17b8fb42021-08-12 12:28:381165 private invalidateAllItems(deferUpdate?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531166 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341167 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371168 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341169 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381170 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341171 }
Blink Reformat4c46d092018-04-07 15:32:371172 }
1173
Jan Schefflerd6c1d402021-02-26 16:56:381174 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531175 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371176 }
1177
Jan Schefflerd6c1d402021-02-26 16:56:381178 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531179 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371180 }
1181
Jan Schefflerd6c1d402021-02-26 16:56:381182 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531183 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371184 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341185 }
Blink Reformat4c46d092018-04-07 15:32:371186
Jack Franklin28577db2021-10-14 08:12:531187 if (this.calculatorInternal !== x) {
1188 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301189 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371190 }
Jack Franklin28577db2021-10-14 08:12:531191 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371192
Jack Franklin28577db2021-10-14 08:12:531193 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301194 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301196 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 }
Blink Reformat4c46d092018-04-07 15:32:371198
Jan Scheffler17b8fb42021-08-12 12:28:381199 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371200 }
1201
Jan Scheffler17b8fb42021-08-12 12:28:381202 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271203 event: Common.EventTarget
1204 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531205 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371206 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 }
Blink Reformat4c46d092018-04-07 15:32:371208
Simon Zünd1a930492021-07-30 08:22:271209 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371210 if (time) {
Jack Franklin28577db2021-10-14 08:12:531211 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301212 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371213 }
1214 }
1215
Jan Scheffler17b8fb42021-08-12 12:28:381216 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531217 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371218 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341219 }
Simon Zünd1a930492021-07-30 08:22:271220 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371221 if (data) {
Jack Franklin28577db2021-10-14 08:12:531222 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301223 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371224 }
1225 }
1226
Jan Schefflerd6c1d402021-02-26 16:56:381227 wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381228 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301229 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301230 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371231 }
1232
Jan Schefflerd6c1d402021-02-26 16:56:381233 willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301234 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371235 }
1236
Jan Schefflerd6c1d402021-02-26 16:56:381237 onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531238 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371239 }
1240
Jan Schefflerd6c1d402021-02-26 16:56:381241 flatNodesList(): NetworkNode[] {
1242 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531243 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381244 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1245 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371246 }
1247
Jan Scheffler17b8fb42021-08-12 12:28:381248 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531249 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351250 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381251 }
Brandon Goddard44934902020-03-25 16:03:181252 this.updateNodeBackground();
1253 }
1254
Jan Scheffler17b8fb42021-08-12 12:28:381255 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181256 this.element.classList.remove('grid-focused');
1257 this.updateNodeBackground();
1258 }
1259
Jan Schefflerd6c1d402021-02-26 16:56:381260 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531261 if (this.dataGrid.selectedNode) {
1262 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051263 }
1264 }
1265
Jan Schefflerd6c1d402021-02-26 16:56:381266 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051267 if (isSelected) {
1268 this.element.classList.remove('no-node-selected');
1269 } else {
1270 this.element.classList.add('no-node-selected');
1271 }
1272 }
1273
Jan Schefflerd6c1d402021-02-26 16:56:381274 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301275 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371276 }
1277
Jan Scheffler17b8fb42021-08-12 12:28:381278 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531279 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371280
Jack Franklin28577db2021-10-14 08:12:531281 if (this.refreshRequestId) {
1282 this.element.window().cancelAnimationFrame(this.refreshRequestId);
1283 this.refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:371284 }
1285
1286 this.removeAllNodeHighlights();
1287
Jack Franklin28577db2021-10-14 08:12:531288 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1289 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1290 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1291 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371292
Jan Schefflerd6c1d402021-02-26 16:56:381293 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1294 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371295
Jan Schefflerd6c1d402021-02-26 16:56:381296 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371297
Jack Franklin28577db2021-10-14 08:12:531298 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371299 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531300 while (this.staleRequests.size) {
1301 const request = this.staleRequests.values().next().value;
1302 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371303 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341304 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381305 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341306 }
Blink Reformat4c46d092018-04-07 15:32:371307 staleNodes.add(node);
1308 }
1309
1310 for (const node of staleNodes) {
Jan Scheffler17b8fb42021-08-12 12:28:381311 const isFilteredOut = !this.applyFilter(node);
Jack Franklin28577db2021-10-14 08:12:531312 if (isFilteredOut && node === this.hoveredNodeInternal) {
Jan Scheffler17b8fb42021-08-12 12:28:381313 this.setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341314 }
Blink Reformat4c46d092018-04-07 15:32:371315
Tim van der Lippe1d6e57a2019-09-30 11:55:341316 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371317 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341318 }
Blink Reformat4c46d092018-04-07 15:32:371319 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531320 this.timeCalculatorInternal.updateBoundaries(request);
1321 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381322 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371323 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1324 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371325 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341326 }
Tim van der Lippe224a8622020-09-23 12:14:371327 if (isFilteredOut) {
1328 filteredNetworkRequests.add(node);
1329 } else {
1330 filteredNetworkRequests.delete(node);
1331 }
Blink Reformat4c46d092018-04-07 15:32:371332 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1333 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381334 let parent: NetworkNode|
1335 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1336 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1337 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111338 if (!parent) {
1339 continue;
1340 }
Blink Reformat4c46d092018-04-07 15:32:371341 parent.removeChild(node);
1342 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381343 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371344 grandparent.removeChild(parent);
1345 parent = grandparent;
1346 }
1347 }
1348
Tim van der Lippe1d6e57a2019-09-30 11:55:341349 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371350 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341351 }
Blink Reformat4c46d092018-04-07 15:32:371352
1353 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531354 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371355 nodesToRefresh.push(newParent);
1356 }
1357 nodesToInsert.set(node, newParent);
1358 }
1359
Tim van der Lippe1d6e57a2019-09-30 11:55:341360 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381361 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341362 }
Blink Reformat4c46d092018-04-07 15:32:371363
Tim van der Lippe1d6e57a2019-09-30 11:55:341364 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371365 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341366 }
Blink Reformat4c46d092018-04-07 15:32:371367
Jan Scheffler17b8fb42021-08-12 12:28:381368 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371369
Tim van der Lippe1d6e57a2019-09-30 11:55:341370 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301371 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341372 }
Blink Reformat4c46d092018-04-07 15:32:371373
Jack Franklin28577db2021-10-14 08:12:531374 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381375 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371376 }
1377
Jan Scheffler17b8fb42021-08-12 12:28:381378 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371379 }
1380
Jan Scheffler17b8fb42021-08-12 12:28:381381 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531382 if (!this.activeGroupLookup) {
1383 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341384 }
Blink Reformat4c46d092018-04-07 15:32:371385
Jack Franklin28577db2021-10-14 08:12:531386 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341387 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531388 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341389 }
Blink Reformat4c46d092018-04-07 15:32:371390 return groupNode;
1391 }
1392
Jan Scheffler17b8fb42021-08-12 12:28:381393 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151394 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371395
Jan Scheffler17b8fb42021-08-12 12:28:381396 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301397 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371398
Jack Franklin28577db2021-10-14 08:12:531399 this.timeFilter = null;
1400 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371401
Jack Franklin28577db2021-10-14 08:12:531402 this.timeCalculatorInternal.setWindow(null);
1403 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371404
Jack Franklin28577db2021-10-14 08:12:531405 if (this.activeGroupLookup) {
1406 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341407 }
Jack Franklin28577db2021-10-14 08:12:531408 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381409 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371410
Jack Franklin28577db2021-10-14 08:12:531411 this.mainRequestLoadTime = -1;
1412 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371413
Jack Franklin28577db2021-10-14 08:12:531414 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381415 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531416 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371417 this.scheduleRefresh();
1418 }
1419
Jan Schefflerd6c1d402021-02-26 16:56:381420 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531421 this.textFilterUI.setValue(filterString);
1422 this.dataURLFilterUI.setChecked(false);
1423 this.onlyIssuesFilterUI.setChecked(false);
1424 this.onlyBlockedRequestsUI.setChecked(false);
1425 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371426 }
1427
Jan Scheffler17b8fb42021-08-12 12:28:381428 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301429 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371430 networkRequestToNode.set(request, node);
1431 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371432
Tim van der Lippe1d6e57a2019-09-30 11:55:341433 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381434 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341435 }
Blink Reformat4c46d092018-04-07 15:32:371436 return node;
1437 }
1438
Kateryna Prokopenko460f5492021-08-27 08:20:281439 private onRequestUpdated(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1440 const request = event.data;
Jan Scheffler17b8fb42021-08-12 12:28:381441 this.refreshRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371442 }
1443
Jan Scheffler17b8fb42021-08-12 12:28:381444 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1445 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161446 .forEach(
Jack Franklin28577db2021-10-14 08:12:531447 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1448 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1449 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1450 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1451 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1452 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1453 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371454
1455 const priority = request.priority();
1456 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531457 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161458 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371459 }
1460
1461 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531462 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161463 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371464 }
1465
1466 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531467 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161468 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371469 }
1470
1471 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161472 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1473 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531474 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371475 }
1476
1477 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511478 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531479 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511480 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531481 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511482 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341483 }
Jan Scheffler341eea52019-12-12 09:08:411484
1485 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531486 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1487 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1488 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371489 }
1490
Jan Scheffler341eea52019-12-12 09:08:411491 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531492 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1493 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1494 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1495 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411496 }
1497
Jack Franklin28577db2021-10-14 08:12:531498 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371499 this.scheduleRefresh();
1500 }
1501
Jan Schefflerd6c1d402021-02-26 16:56:381502 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531503 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371504 }
1505
Jan Schefflerd6c1d402021-02-26 16:56:381506 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301507 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371508 }
1509
Jan Schefflerd6c1d402021-02-26 16:56:381510 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1511 void {
Blink Reformat4c46d092018-04-07 15:32:371512 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551513 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371514 const footerSection = copyMenu.footerSection();
1515 if (request) {
1516 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131517 UI.UIUtils.copyLinkAddressLabel(),
1518 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1519 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371520 if (request.requestHeadersText()) {
1521 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381522 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371523 }
1524
1525 if (request.responseHeadersText) {
1526 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381527 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371528 }
1529
1530 if (request.finished) {
1531 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381532 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371533 }
1534
Tim van der Lippeb4faf5a2020-11-06 15:02:021535 const initiator = request.initiator();
1536
1537 if (initiator) {
1538 const stack = initiator.stack;
1539 if (stack) {
1540 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531541 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021542 // any callFrames, but its parent frames do.
1543 const stackTraceText = computeStackTraceText(stack);
1544 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551545 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021546 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1547 });
1548 }
1549 }
1550 }
1551
Harley Libcf41f92018-09-10 18:01:131552 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131553 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371554 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381555 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371556 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461557 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1558 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291559 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461560 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1561 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371562 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381563 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131564 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381565 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1566 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461567 footerSection.appendItem(
1568 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1569 footerSection.appendItem(
1570 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381571 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this.copyAllCurlCommand.bind(this, 'win'));
1572 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371573 } else {
Harley Libcf41f92018-09-10 18:01:131574 footerSection.appendItem(
Danil Somsikova4b089c2021-11-09 14:32:091575 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
1576 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461577 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1578 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291579 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461580 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1581 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131582 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381583 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Danil Somsikova4b089c2021-11-09 14:32:091584 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461585 footerSection.appendItem(
1586 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1587 footerSection.appendItem(
1588 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381589 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371590 }
1591 } else {
Christy Chencac3f102021-02-03 10:07:551592 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371593 }
Jan Scheffler17b8fb42021-08-12 12:28:381594 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this.copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371595
Christy Chencac3f102021-02-03 10:07:551596 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291597 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.HEADER_OVERRIDES)) {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411598 contextMenu.saveSection().appendItem(
1599 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291600 }
Wolfgang Beyerc6fe2be2022-11-03 15:39:411601
Jan Scheffler17b8fb42021-08-12 12:28:381602 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371603 contextMenu.editSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381604 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371605
1606 if (request) {
1607 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211608 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371609 let patterns = manager.blockedPatterns();
1610
Jan Schefflerd6c1d402021-02-26 16:56:381611 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201612 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121613 manager.setBlockedPatterns(patterns);
1614 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031615 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121616 }
1617
Jan Schefflerd6c1d402021-02-26 16:56:381618 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121619 patterns = patterns.filter(pattern => pattern.url !== url);
1620 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031621 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121622 }
1623
Blink Reformat4c46d092018-04-07 15:32:371624 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1625 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1626 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551627 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371628 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311629 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371630 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551631 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371632 }
1633
1634 const domain = request.parsedURL.domain();
1635 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1636 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551637 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371638 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311639 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371640 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551641 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371642 }
1643
Tim van der Lippe0ed1d2b2020-02-04 13:45:131644 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371645 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551646 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371647 }
Blink Reformat4c46d092018-04-07 15:32:371648 }
1649 }
1650
Jan Scheffler17b8fb42021-08-12 12:28:381651 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271652 return Logs.NetworkLog.NetworkLog.instance()
1653 .requests()
Sigurd Schneider576ca9a2021-07-16 05:58:041654 .filter(NetworkLogView.getHTTPRequestsFilter)
Sigurd Schneidercf5b8302021-04-23 07:52:271655 .filter(request => {
1656 return request.finished ||
1657 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1658 });
Blink Reformat4c46d092018-04-07 15:32:371659 }
1660
Jan Scheffler17b8fb42021-08-12 12:28:381661 private async copyAll(): Promise<void> {
1662 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131663 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371664 }
1665
Jan Scheffler17b8fb42021-08-12 12:28:381666 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351667 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131668 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371669 }
1670
Jan Scheffler17b8fb42021-08-12 12:28:381671 private async copyAllCurlCommand(platform: string): Promise<void> {
1672 const commands = await this.generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131673 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371674 }
1675
Danil Somsikov59f4c612021-09-08 10:58:461676 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1677 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131678 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371679 }
1680
Danil Somsikov59f4c612021-09-08 10:58:461681 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
1682 const commands = await this.generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131683 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371684 }
1685
Jan Scheffler17b8fb42021-08-12 12:28:381686 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1687 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131688 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371689 }
1690
Jan Scheffler17b8fb42021-08-12 12:28:381691 private async copyAllPowerShellCommand(): Promise<void> {
1692 const commands = await this.generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131693 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371694 }
1695
Jan Schefflerd6c1d402021-02-26 16:56:381696 async exportAll(): Promise<void> {
Sigurd Schneiderb9f6c792021-05-31 10:57:241697 const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget();
Tim van der Lippe224a8622020-09-23 12:14:371698 if (!mainTarget) {
1699 return;
1700 }
1701 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131702 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321703 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131704 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371705
Kateryna Prokopenko380fdfa2022-03-16 16:39:321706 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371707 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341708 }
Blink Reformat4c46d092018-04-07 15:32:371709
Tim van der Lippe0ed1d2b2020-02-04 13:45:131710 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531711 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381712 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371713 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031714 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371715 }
1716
Wolfgang Beyer5b433b02022-05-12 13:57:371717 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411718 const requestLocation =
1719 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271720 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1721 if (networkPersistanceManager.project()) {
1722 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411723 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371724 } else { // If folder for local overrides has not been provided yet
1725 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async(): Promise<void> => {
1726 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271727 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411728 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371729 });
1730 }
1731 }
1732
Jan Scheffler17b8fb42021-08-12 12:28:381733 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551734 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211735 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341736 }
Blink Reformat4c46d092018-04-07 15:32:371737 }
1738
Jan Scheffler17b8fb42021-08-12 12:28:381739 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551740 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211741 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341742 }
Blink Reformat4c46d092018-04-07 15:32:371743 }
1744
Jan Scheffler17b8fb42021-08-12 12:28:381745 private removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371746 this.removeAllNodeHighlights();
Blink Reformat4c46d092018-04-07 15:32:371747 }
1748
Jan Scheffler17b8fb42021-08-12 12:28:381749 private applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371750 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531751 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371752 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341753 }
Christy Chen1825c612021-02-25 10:28:441754 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531755 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371756 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341757 }
Jack Franklin28577db2021-10-14 08:12:531758 if (this.dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371759 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341760 }
Jack Franklin28577db2021-10-14 08:12:531761 if (this.onlyIssuesFilterUI.checked() &&
Juba Borgohain2af14942022-03-02 12:46:151762 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.Cookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371763 return false;
1764 }
Jack Franklin28577db2021-10-14 08:12:531765 if (this.onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131766 return false;
1767 }
Jack Franklin28577db2021-10-14 08:12:531768 if (this.onlyThirdPartyFilterUI.checked() && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271769 return false;
1770 }
Jack Franklin28577db2021-10-14 08:12:531771 for (let i = 0; i < this.filters.length; ++i) {
1772 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371773 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341774 }
Blink Reformat4c46d092018-04-07 15:32:371775 }
1776 return true;
1777 }
1778
Danil Somsikov7a392fb2021-09-13 11:09:461779 private isValidUrl(url: string): boolean {
1780 try {
1781 new URL(url);
1782 return true;
1783 } catch (e) {
1784 return false;
1785 }
1786 }
1787
Jan Scheffler17b8fb42021-08-12 12:28:381788 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531789 // A query string can have multiple filters, some of them regular
1790 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371791 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:531792 // checkbox therefore inverts each one of those individual filters.
1793 const descriptors = this.filterParser.parse(query);
1794 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:371795 const key = descriptor.key;
1796 const text = descriptor.text || '';
1797 const regex = descriptor.regex;
1798 let filter;
1799 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171800 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:381801 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
1802 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371803 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:381804 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:461805 } else if (this.isValidUrl(text)) {
1806 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:371807 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381808 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:171809 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371810 }
Victor Porof66878d62021-07-16 13:12:371811 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:381812 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:371813 }
1814 return filter;
Blink Reformat4c46d092018-04-07 15:32:371815 });
1816 }
1817
Jan Scheffler17b8fb42021-08-12 12:28:381818 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371819 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:161820 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:381821 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371822
Sigurd Schneider30722582021-06-16 06:54:161823 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:381824 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371825
Simon Zünd6dedde52021-08-03 09:04:511826 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:381827 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:511828
Sigurd Schneider30722582021-06-16 06:54:161829 case NetworkForward.UIFilter.FilterType.Is:
1830 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:381831 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341832 }
Sigurd Schneider30722582021-06-16 06:54:161833 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:381834 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341835 }
Sigurd Schneider30722582021-06-16 06:54:161836 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:381837 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341838 }
Sigurd Schneider30722582021-06-16 06:54:161839 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:381840 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341841 }
Blink Reformat4c46d092018-04-07 15:32:371842 break;
1843
Sigurd Schneider30722582021-06-16 06:54:161844 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:381845 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:371846
Sigurd Schneider30722582021-06-16 06:54:161847 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:381848 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371849
Sigurd Schneider30722582021-06-16 06:54:161850 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:381851 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371852
Sigurd Schneider30722582021-06-16 06:54:161853 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:381854 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:161855 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371856
Sigurd Schneider30722582021-06-16 06:54:161857 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:381858 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371859
Sigurd Schneider30722582021-06-16 06:54:161860 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381861 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371862
Sigurd Schneider30722582021-06-16 06:54:161863 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381864 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371865
Sigurd Schneider30722582021-06-16 06:54:161866 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381867 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371868
Sigurd Schneider30722582021-06-16 06:54:161869 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381870 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411871
Sigurd Schneider30722582021-06-16 06:54:161872 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381873 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411874
Sigurd Schneider30722582021-06-16 06:54:161875 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:381876 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:541877
Sigurd Schneider30722582021-06-16 06:54:161878 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381879 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411880
Sigurd Schneider30722582021-06-16 06:54:161881 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:381882 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:501883 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371884
Sigurd Schneider30722582021-06-16 06:54:161885 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:381886 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031887
Sigurd Schneider30722582021-06-16 06:54:161888 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:381889 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031890
Sigurd Schneider30722582021-06-16 06:54:161891 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:381892 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371893 }
1894 return null;
1895 }
1896
Jan Scheffler17b8fb42021-08-12 12:28:381897 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371898 let multiplier = 1;
1899 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541900 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371901 value = value.substring(0, value.length - 1);
1902 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541903 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371904 value = value.substring(0, value.length - 1);
1905 }
1906 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341907 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371908 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341909 }
Jan Scheffler17b8fb42021-08-12 12:28:381910 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371911 }
1912
Jan Scheffler17b8fb42021-08-12 12:28:381913 private filterRequests(): void {
1914 this.removeAllHighlights();
1915 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371916 }
1917
Jan Scheffler17b8fb42021-08-12 12:28:381918 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371919 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371920 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341921 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371922 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341923 }
Brandon Goddard5e4244d2020-04-08 22:08:471924 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:531925 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:471926 // reveal and expand parent to ensure child is revealable.
1927 if (node.parent && node.parent instanceof NetworkGroupNode) {
1928 node.parent.reveal();
1929 node.parent.expand();
1930 }
Blink Reformat4c46d092018-04-07 15:32:371931 node.reveal();
1932 return node;
1933 }
1934
Jan Schefflerd6c1d402021-02-26 16:56:381935 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:381936 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341937 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:381938 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341939 }
Blink Reformat4c46d092018-04-07 15:32:371940 }
1941
Sigurd Schneider722301e2021-06-15 13:41:201942 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:071943 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
1944 if (request) {
1945 this.revealAndHighlightRequest(request);
1946 }
1947 }
1948
Sigurd Schneider14d3e9f2021-06-14 08:29:011949 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
1950 void {
chait pinnamaneni6bc1c122020-10-30 17:30:521951 const defaultOptions = {clearFilter: true};
1952 const {clearFilter} = options || defaultOptions;
1953 if (clearFilter) {
1954 this.setTextFilterValue('');
1955 }
Jan Scheffler17b8fb42021-08-12 12:28:381956 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341957 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371958 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341959 }
Blink Reformat4c46d092018-04-07 15:32:371960 }
1961
Jan Schefflerd6c1d402021-02-26 16:56:381962 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:531963 if (this.highlightedNode) {
1964 this.highlightedNode.element().classList.remove('highlighted-row');
1965 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:371966 }
1967 }
1968
Jan Scheffler17b8fb42021-08-12 12:28:381969 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131970 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:531971 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:371972 }
1973
Jan Scheffler17b8fb42021-08-12 12:28:381974 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131975 return requests.filter(request => !request.isBlobRequest());
1976 }
1977
Danil Somsikov59f4c612021-09-08 10:58:461978 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:381979 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371980 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371981 'method',
1982 'path',
1983 'scheme',
1984 'version',
Blink Reformat4c46d092018-04-07 15:32:371985
1986 // Unsafe headers
1987 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371988 'accept-charset',
1989 'accept-encoding',
1990 'access-control-request-headers',
1991 'access-control-request-method',
1992 'connection',
1993 'content-length',
1994 'cookie',
1995 'cookie2',
1996 'date',
1997 'dnt',
1998 'expect',
1999 'host',
2000 'keep-alive',
2001 'origin',
2002 'referer',
2003 'te',
2004 'trailer',
2005 'transfer-encoding',
2006 'upgrade',
2007 'via',
Blink Reformat4c46d092018-04-07 15:32:372008 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372009 'user-agent',
2010 ]);
Blink Reformat4c46d092018-04-07 15:32:372011
Jan Schefflerd6c1d402021-02-26 16:56:382012 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372013
2014 const url = JSON.stringify(request.url());
2015
2016 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382017 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372018 const name = header.name;
2019
Tim van der Lippe224a8622020-09-23 12:14:372020 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372021 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342022 }
Blink Reformat4c46d092018-04-07 15:32:372023
2024 return result;
2025 }, new Headers());
2026
Jan Schefflerd6c1d402021-02-26 16:56:382027 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342028 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412029 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342030 }
Blink Reformat4c46d092018-04-07 15:32:372031
Sigurd Schneider0e88b912020-05-08 08:28:232032 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372033 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412034 'include' :
2035 'omit';
Blink Reformat4c46d092018-04-07 15:32:372036
2037 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2038
2039 const referrer = referrerHeader ? referrerHeader.value : void 0;
2040
2041 const referrerPolicy = request.referrerPolicy() || void 0;
2042
2043 const requestBody = await request.requestFormData();
2044
Jan Schefflerd6c1d402021-02-26 16:56:382045 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412046 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372047 referrer,
2048 referrerPolicy,
2049 body: requestBody,
2050 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372051 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372052 };
2053
Danil Somsikov59f4c612021-09-08 10:58:462054 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292055 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462056 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532057 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462058 // following properties are not implemented in Node.js.
2059 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292060 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462061 extraHeaders['cookie'] = cookieHeader.value;
2062 }
2063 if (referrer) {
2064 delete fetchOptions.referrer;
2065 extraHeaders['Referer'] = referrer;
2066 }
2067 if (referrer) {
2068 delete fetchOptions.referrerPolicy;
2069 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2070 }
2071 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292072 fetchOptions.headers = {
2073 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462074 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292075 };
2076 }
2077 } else {
2078 fetchOptions.credentials = credentials;
2079 }
2080
Jan Scheffler172d5212020-01-02 14:42:562081 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372082 return `fetch(${url}, ${options});`;
2083 }
2084
Danil Somsikov59f4c612021-09-08 10:58:462085 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382086 Promise<string> {
2087 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462088 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132089 return commands.join(' ;\n');
2090 }
2091
Wolfgang Beyer26b7e892022-08-16 11:02:352092 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382093 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362094 // Most of these headers are derived from the URL and are automatically added by cURL.
2095 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:382096 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372097
Jan Schefflerd6c1d402021-02-26 16:56:382098 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372099 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:382100 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:372101
Jan Schefflerd6c1d402021-02-26 16:56:382102 Because cmd.exe parser and MS Crt arguments parsers use some of the
2103 same escape characters, they can interact with each other in
2104 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372105
Jan Schefflerd6c1d402021-02-26 16:56:382106 Replace \ with \\ first because it is an escape character for certain
2107 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372108
Jan Schefflerd6c1d402021-02-26 16:56:382109 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372110
Jan Schefflerd6c1d402021-02-26 16:56:382111 Then escape all characters we are not sure about with ^ to ensure it
2112 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372113
Jan Schefflerd6c1d402021-02-26 16:56:382114 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352115 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382116 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2117 parser); So we can get cmd.exe parser to escape the character after it,
2118 if it is followed by a valid beginning character of an ENV variable.
2119 This ensures we do not try and double escape another ^ if it was placed
2120 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372121
Jan Schefflerd6c1d402021-02-26 16:56:382122 Lastly we replace new lines with ^ and TWO new lines because the first
2123 new line is there to enact the escape command the second is the character
2124 to escape (in this case new line).
2125 */
Blink Reformat4c46d092018-04-07 15:32:372126 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2127 return encapsChars +
2128 str.replace(/\\/g, '\\\\')
2129 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542130 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372131 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542132 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372133 encapsChars;
2134 }
2135
Jan Schefflerd6c1d402021-02-26 16:56:382136 function escapeStringPosix(str: string): string {
2137 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222138 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122139 let hexString = code.toString(16);
2140 // Zero pad to four digits to comply with ANSI-C Quoting:
2141 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342142 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122143 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342144 }
Joey Arhar2d21f712019-05-20 21:07:122145
2146 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372147 }
2148
Mathias Bynensf06e8c02020-02-28 13:58:282149 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372150 // Use ANSI-C quoting syntax.
2151 return '$\'' +
2152 str.replace(/\\/g, '\\\\')
2153 .replace(/\'/g, '\\\'')
2154 .replace(/\n/g, '\\n')
2155 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282156 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372157 '\'';
Blink Reformat4c46d092018-04-07 15:32:372158 }
Mathias Bynensf06e8c02020-02-28 13:58:282159 // Use single quote syntax.
2160 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372161 }
2162
2163 // cURL command expected to run on the same platform that DevTools run
2164 // (it may be different from the inspected page platform).
2165 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2166
2167 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2168
2169 let inferredMethod = 'GET';
2170 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372171 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082172 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272173 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532174 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272175 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372176 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372177 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372178 }
2179
2180 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292181 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372182 }
2183
2184 const requestHeaders = request.requestHeaders();
2185 for (let i = 0; i < requestHeaders.length; i++) {
2186 const header = requestHeaders[i];
2187 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372188 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372189 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342190 }
Wolfgang Beyer26b7e892022-08-16 11:02:352191 if (header.value.trim()) {
2192 command.push('-H ' + escapeString(name + ': ' + header.value));
2193 } else {
2194 // A header passed with -H with no value or only whitespace as its
2195 // value tells curl to not set the header at all. To post an empty
2196 // header, you have to terminate it with a semicolon.
2197 command.push('-H ' + escapeString(name + ';'));
2198 }
Blink Reformat4c46d092018-04-07 15:32:372199 }
2200 command = command.concat(data);
2201 command.push('--compressed');
2202
Tim van der Lippe1d6e57a2019-09-30 11:55:342203 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372204 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342205 }
Jan Scheffler172d5212020-01-02 14:42:562206 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372207 }
2208
Jan Scheffler17b8fb42021-08-12 12:28:382209 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string):
2210 Promise<string> {
2211 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352212 const commands =
2213 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342214 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132215 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342216 }
Mathias Bynensf06e8c02020-02-28 13:58:282217 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132218 }
2219
Jan Scheffler17b8fb42021-08-12 12:28:382220 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562221 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242222 const ignoredHeaders = new Set<string>([
2223 'host',
2224 'connection',
2225 'proxy-connection',
2226 'content-length',
2227 'expect',
2228 'range',
2229 'content-type',
2230 'user-agent',
2231 'cookie',
2232 ]);
Blink Reformat4c46d092018-04-07 15:32:372233
Jan Schefflerd6c1d402021-02-26 16:56:382234 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372235 return '"' +
2236 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2237 }
2238
Brandon Walderman153b8d72021-06-28 18:45:242239 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2240 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2241 // command does not allow setting these headers through the -Headers parameter. See docs at:
2242 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2243 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2244 const requestHeaders = request.requestHeaders();
2245 const props = [];
2246
2247 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2248 if (userAgentHeader) {
2249 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2250 }
2251
2252 for (const cookie of request.includedRequestCookies()) {
2253 const name = escapeString(cookie.name());
2254 const value = escapeString(cookie.value());
2255 const domain = escapeString(cookie.domain());
2256 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2257 }
2258
2259 if (props.length) {
2260 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2261 }
2262
2263 return null;
2264 }
2265
Jan Scheffler172d5212020-01-02 14:42:562266 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372267
2268 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562269 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372270 }
2271
Brandon Walderman153b8d72021-06-28 18:45:242272 const session = generatePowerShellSession(request);
2273 if (session) {
2274 command.push('-WebSession $session');
2275 }
2276
Blink Reformat4c46d092018-04-07 15:32:372277 const requestHeaders = request.requestHeaders();
2278 const headerNameValuePairs = [];
2279 for (const header of requestHeaders) {
2280 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342281 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372282 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342283 }
Blink Reformat4c46d092018-04-07 15:32:372284 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2285 }
2286 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562287 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372288 }
2289
2290 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2291 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562292 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372293 }
2294
2295 const formData = await request.requestFormData();
2296 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372297 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342298 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562299 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342300 } else {
Jan Scheffler172d5212020-01-02 14:42:562301 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342302 }
Blink Reformat4c46d092018-04-07 15:32:372303 }
2304
Brandon Walderman153b8d72021-06-28 18:45:242305 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2306 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2307 // compatibility only.
2308 const prelude = session || '';
2309 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372310 }
Harley Libcf41f92018-09-10 18:01:132311
Jan Scheffler17b8fb42021-08-12 12:28:382312 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2313 const nonBlobRequests = this.filterOutBlobRequests(requests);
2314 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132315 return commands.join(';\r\n');
2316 }
Joey Arhara86c14e2019-03-12 03:20:502317
Jan Schefflerd6c1d402021-02-26 16:56:382318 static getDCLEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052319 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-3');
Joey Arhara86c14e2019-03-12 03:20:502320 }
2321
Jan Schefflerd6c1d402021-02-26 16:56:382322 static getLoadEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052323 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-1');
Joey Arhara86c14e2019-03-12 03:20:502324 }
Paul Lewis56509652019-12-06 12:51:582325}
Blink Reformat4c46d092018-04-07 15:32:372326
Jan Schefflerd6c1d402021-02-26 16:56:382327export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022328 let stackTraceText = '';
2329 for (const frame of stackTrace.callFrames) {
2330 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2331 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2332 }
2333 if (stackTrace.parent) {
2334 stackTraceText += computeStackTraceText(stackTrace.parent);
2335 }
2336 return stackTraceText;
2337}
2338
Jan Schefflerd6c1d402021-02-26 16:56:382339const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2340const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372341
Jan Schefflerd6c1d402021-02-26 16:56:382342export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372343 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222344}
2345
Paul Lewis56509652019-12-06 12:51:582346export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372347 'http': true,
2348 'https': true,
2349 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382350 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372351};
2352
Sigurd Schneider576ca9a2021-07-16 05:58:042353const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382354
2355export interface GroupLookupInterface {
2356 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2357 reset(): void;
2358}
2359
2360export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;