blob: ebd4121ac105210123190e5dc1cd6b72f550f557 [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';
Tim van der Lippee00b92f2021-03-31 16:52:1739import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0540import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5941import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5642import * as HAR from '../../models/har/har.js';
Sigurd Schneider055e2e32021-04-12 11:10:4243import * as IssuesManager from '../../models/issues_manager/issues_manager.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2744import * as Logs from '../../models/logs/logs.js';
Tim van der Lippefca98ed2021-04-08 14:10:1445import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1646import * as NetworkForward from '../../panels/network/forward/forward.js';
Tim van der Lippe8499fe22021-04-12 16:42:4747import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1448import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3649import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0750import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippefddcf402021-04-19 13:00:2951import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1352
Kriti Sapra2d85f882021-08-18 09:01:3053import networkLogViewStyles from './networkLogView.css.js';
54
Simon Zünd940cb1f2021-09-16 11:46:0955import type {NetworkLogViewInterface, NetworkNode, EventTypes} from './NetworkDataGridNode.js';
Tim van der Lippec2cbf322021-07-26 14:35:3356import {Events, NetworkGroupNode, NetworkRequestNode} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3057import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
58import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Franklina75ae7c2021-05-11 13:22:5459import type {NetworkTimeCalculator} from './NetworkTimeCalculator.js';
Tim van der Lippec2cbf322021-07-26 14:35:3360import {NetworkTimeBoundary, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3061
Simon Zünd34490692021-03-01 08:25:1862const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5563 /**
64 *@description Text in Network Log View of the Network panel
65 */
Victor Porof66878d62021-07-16 13:12:3766 invertFilter: 'Invert',
67 /**
68 *@description Tooltip for the 'invert' checkbox in the Network panel.
69 */
70 invertsFilter: 'Inverts the search filter',
71 /**
72 *@description Text in Network Log View of the Network panel
73 */
Christy Chencac3f102021-02-03 10:07:5574 hideDataUrls: 'Hide data URLs',
75 /**
76 *@description Data urlfilter ui element title in Network Log View of the Network panel
77 */
78 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
79 /**
80 *@description Aria accessible name in Network Log View of the Network panel
81 */
82 resourceTypesToInclude: 'Resource types to include',
83 /**
84 *@description Label for a filter in the Network panel
85 */
86 hasBlockedCookies: 'Has blocked cookies',
87 /**
Jack Franklin28577db2021-10-14 08:12:5388 *@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:5489 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
90 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:5591 */
92 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
93 /**
94 *@description Label for a filter in the Network panel
95 */
96 blockedRequests: 'Blocked Requests',
97 /**
98 *@description Tooltip for a filter in the Network panel
99 */
100 onlyShowBlockedRequests: 'Only show blocked requests',
101 /**
Danil Somsikov721956a2021-07-07 08:17:27102 *@description Label for a filter in the Network panel
103 */
104 thirdParty: '3rd-party requests',
105 /**
106 *@description Tooltip for a filter in the Network panel
107 */
108 onlyShowThirdPartyRequests: 'Shows only requests with origin different from page origin',
109 /**
Christy Chencac3f102021-02-03 10:07:55110 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
111 */
112 dropHarFilesHere: 'Drop HAR files here',
113 /**
114 *@description Recording text text content in Network Log View of the Network panel
115 */
116 recordingNetworkActivity: 'Recording network activity…',
117 /**
118 *@description Text in Network Log View of the Network panel
119 *@example {Ctrl + R} PH1
120 */
121 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
122 /**
Peter Marshall266ab2e2021-02-16 17:30:49123 *@description Shown in the Network Log View of the Network panel when the user has not yet
Jack Franklin28577db2021-10-14 08:12:53124 * recorded any network activity. This is an instruction to the user to start recording in order to
Peter Marshall266ab2e2021-02-16 17:30:49125 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55126 *@example {Ctrl + E} PH1
127 */
Wolfgang Beyerf4237472021-08-18 14:55:41128 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55129 /**
130 *@description Text that is usually a hyperlink to more documentation
131 */
132 learnMore: 'Learn more',
133 /**
134 *@description Text to announce to screen readers that network data is available.
135 */
136 networkDataAvailable: 'Network Data Available',
137 /**
138 *@description Text in Network Log View of the Network panel
139 *@example {3} PH1
140 *@example {5} PH2
141 */
142 sSRequests: '{PH1} / {PH2} requests',
143 /**
Andres Olivares7fbed142021-03-01 16:22:23144 *@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:53145 * resources transferred during a selected time frame over the compressed size of all resources transferred during
Andres Olivares7fbed142021-03-01 16:22:23146 * the whole network log.
147 *@example {5 B} PH1
148 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55149 */
150 sSTransferred: '{PH1} / {PH2} transferred',
151 /**
Andres Olivares7fbed142021-03-01 16:22:23152 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
Jack Franklin28577db2021-10-14 08:12:53153 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55154 *@example {10} PH1
155 *@example {15} PH2
156 */
157 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
158 /**
Peter Marshall2c3fb302021-02-19 12:47:04159 * @description Text in Network Log View of the Network panel. Appears when a particular network
160 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
161 * total size (PH2).
162 * @example {40MB} PH1
163 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55164 */
165 sSResources: '{PH1} / {PH2} resources',
166 /**
167 *@description Text in Network Log View of the Network panel
168 *@example {40} PH1
169 *@example {50} PH2
170 */
171 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
172 /**
173 *@description Text in Network Log View of the Network panel
174 *@example {6} PH1
175 */
176 sRequests: '{PH1} requests',
177 /**
Andres Olivares0a863ab2021-02-19 15:21:23178 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
179 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55180 *@example {4 B} PH1
181 */
182 sTransferred: '{PH1} transferred',
183 /**
Andres Olivares0a863ab2021-02-19 15:21:23184 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
185 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55186 *@example {4} PH1
187 */
188 sBTransferredOverNetwork: '{PH1} B transferred over network',
189 /**
190 *@description Text in Network Log View of the Network panel
191 *@example {4} PH1
192 */
193 sResources: '{PH1} resources',
194 /**
195 *@description Text in Network Log View of the Network panel
196 *@example {10} PH1
197 */
198 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
199 /**
200 *@description Text in Network Log View of the Network panel
201 *@example {120ms} PH1
202 */
203 finishS: 'Finish: {PH1}',
204 /**
205 *@description Text in Network Log View of the Network panel
206 *@example {3000ms} PH1
207 */
208 domcontentloadedS: 'DOMContentLoaded: {PH1}',
209 /**
210 *@description Text in Network Log View of the Network panel
211 *@example {40ms} PH1
212 */
213 loadS: 'Load: {PH1}',
214 /**
215 *@description Text for copying
216 */
217 copy: 'Copy',
218 /**
219 *@description Text in Network Log View of the Network panel
220 */
221 copyRequestHeaders: 'Copy request headers',
222 /**
223 *@description Text in Network Log View of the Network panel
224 */
225 copyResponseHeaders: 'Copy response headers',
226 /**
227 *@description Text in Network Log View of the Network panel
228 */
229 copyResponse: 'Copy response',
230 /**
231 *@description Text in Network Log View of the Network panel
232 */
Peter Marshallf625dc82021-03-02 08:10:57233 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55234 /**
Peter Marshall3ec813d2021-03-01 19:40:25235 * @description A context menu command in the Network panel, for copying to the clipboard.
236 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55237 */
Peter Marshallb8bd00f2021-02-24 08:25:18238 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55239 /**
Peter Marshall3ec813d2021-03-01 19:40:25240 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
241 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55242 */
Peter Marshallb8bd00f2021-02-24 08:25:18243 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55244 /**
Peter Marshall3ec813d2021-03-01 19:40:25245 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21246 * the developer's clipboard. The command allows the developer to replay this specific network
Jack Franklin28577db2021-10-14 08:12:53247 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
248 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55249 */
Peter Marshallb8bd00f2021-02-24 08:25:18250 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55251 /**
Peter Marshallec861882021-02-16 11:14:21252 *@description Text in Network Log View of the Network panel. An action that copies a command to
253 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
254 *translatable).
Christy Chencac3f102021-02-03 10:07:55255 */
Peter Marshallb8bd00f2021-02-24 08:25:18256 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55257 /**
Peter Marshallec861882021-02-16 11:14:21258 *@description Text in Network Log View of the Network panel. An action that copies a command to
259 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55260 */
Peter Marshallb8bd00f2021-02-24 08:25:18261 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55262 /**
Peter Marshallec861882021-02-16 11:14:21263 *@description Text in Network Log View of the Network panel. An action that copies a command to
264 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55265 */
Peter Marshallb8bd00f2021-02-24 08:25:18266 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55267 /**
Peter Marshallec861882021-02-16 11:14:21268 *@description Text in Network Log View of the Network panel. An action that copies a command to
269 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
270 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55271 */
Peter Marshallb8bd00f2021-02-24 08:25:18272 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55273 /**
Peter Marshallec861882021-02-16 11:14:21274 *@description Text in Network Log View of the Network panel. An action that copies a command to
275 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
276 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55277 */
Peter Marshallb8bd00f2021-02-24 08:25:18278 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55279 /**
Peter Marshallec861882021-02-16 11:14:21280 *@description Text in Network Log View of the Network panel. An action that copies a command to
281 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
282 *translatable).
Christy Chencac3f102021-02-03 10:07:55283 */
Peter Marshallb8bd00f2021-02-24 08:25:18284 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55285 /**
Peter Marshallec861882021-02-16 11:14:21286 *@description Text in Network Log View of the Network panel. An action that copies a command to
287 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55288 */
Peter Marshallb8bd00f2021-02-24 08:25:18289 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55290 /**
Peter Marshallec861882021-02-16 11:14:21291 *@description Text in Network Log View of the Network panel. An action that copies a command to
292 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
293 *translatable).
Christy Chencac3f102021-02-03 10:07:55294 */
Peter Marshallb8bd00f2021-02-24 08:25:18295 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55296 /**
Peter Marshallec861882021-02-16 11:14:21297 *@description Text in Network Log View of the Network panel. An action that copies a command to
298 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
299 *translatable).
Christy Chencac3f102021-02-03 10:07:55300 */
Peter Marshallb8bd00f2021-02-24 08:25:18301 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55302 /**
Peter Marshallb8bd00f2021-02-24 08:25:18303 * @description Text in Network Log View of the Network panel. An action that copies data to the
304 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
Jack Franklin28577db2021-10-14 08:12:53305 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55306 */
Peter Marshallb8bd00f2021-02-24 08:25:18307 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55308 /**
309 *@description A context menu item in the Network Log View of the Network panel
310 */
Peter Marshallb8bd00f2021-02-24 08:25:18311 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55312 /**
313 *@description A context menu item in the Network Log View of the Network panel
314 */
315 clearBrowserCache: 'Clear browser cache',
316 /**
317 *@description A context menu item in the Network Log View of the Network panel
318 */
319 clearBrowserCookies: 'Clear browser cookies',
320 /**
321 *@description A context menu item in the Network Log View of the Network panel
322 */
323 blockRequestUrl: 'Block request URL',
324 /**
325 *@description A context menu item in the Network Log View of the Network panel
326 *@example {example.com} PH1
327 */
328 unblockS: 'Unblock {PH1}',
329 /**
330 *@description A context menu item in the Network Log View of the Network panel
331 */
332 blockRequestDomain: 'Block request domain',
333 /**
Jack Franklin28577db2021-10-14 08:12:53334 *@description Text to replay an XHR request
Christy Chencac3f102021-02-03 10:07:55335 */
336 replayXhr: 'Replay XHR',
337 /**
338 *@description Text in Network Log View of the Network panel
339 */
340 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
341 /**
342 *@description Text in Network Log View of the Network panel
343 */
344 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
345};
Tim van der Lippef596ca02021-03-31 10:02:47346const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55347const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46348
349const enum FetchStyle {
350 Browser = 0,
351 NodeJs = 1,
352}
353
Simon Zünd940cb1f2021-09-16 11:46:09354export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
355 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53356 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
357 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
358 private readonly networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
359 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
360 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
361 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
362 private rawRowHeight: number;
363 private readonly progressBarContainer: Element;
364 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
365 private rowHeightInternal: number;
366 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
367 private readonly durationCalculator: NetworkTransferDurationCalculator;
368 private calculatorInternal: NetworkTransferTimeCalculator;
369 private readonly columns: NetworkLogViewColumns;
370 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
371 private mainRequestLoadTime: number;
372 private mainRequestDOMContentLoadedTime: number;
373 private filters: Filter[];
374 private timeFilter: Filter|null;
375 private hoveredNodeInternal: NetworkNode|null;
376 private recordingHint: Element|null;
377 private refreshRequestId: number|null;
378 private highlightedNode: NetworkRequestNode|null;
379 private readonly linkifierInternal: Components.Linkifier.Linkifier;
380 private recording: boolean;
381 private needsRefresh: boolean;
382 private readonly headerHeightInternal: number;
383 private readonly groupLookups: Map<string, GroupLookupInterface>;
384 private activeGroupLookup: GroupLookupInterface|null;
385 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
386 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
387 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
388 private resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
389 private readonly onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
390 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
391 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI;
392 private readonly filterParser: TextUtils.TextUtils.FilterParser;
393 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
394 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
395 private readonly summaryToolbar: UI.Toolbar.Toolbar;
396 private readonly filterBar: UI.FilterBar.FilterBar;
397 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38398
399 constructor(
400 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
401 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37402 super();
403 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37404
405 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05406 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37407
Jack Franklin28577db2021-10-14 08:12:53408 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('networkInvertFilter', false);
409 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
410 this.networkShowIssuesOnlySetting =
Paul Lewis2d7d65c2020-03-16 17:26:30411 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
Jack Franklin28577db2021-10-14 08:12:53412 this.networkOnlyBlockedRequestsSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30413 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
Jack Franklin28577db2021-10-14 08:12:53414 this.networkOnlyThirdPartySetting =
Danil Somsikov721956a2021-07-07 08:17:27415 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
Jack Franklin28577db2021-10-14 08:12:53416 this.networkResourceTypeFiltersSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30417 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37418
Jack Franklin28577db2021-10-14 08:12:53419 this.rawRowHeight = 0;
420 this.progressBarContainer = progressBarContainer;
421 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
422 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37423
Jan Schefflerd6c1d402021-02-26 16:56:38424 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53425 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
426 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37427 }
Jack Franklin28577db2021-10-14 08:12:53428 this.rawRowHeight = 0;
429 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37430 updateRowHeight.call(this);
431
Jack Franklin28577db2021-10-14 08:12:53432 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
433 this.durationCalculator = new NetworkTransferDurationCalculator();
434 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37435
Jack Franklin28577db2021-10-14 08:12:53436 this.columns = new NetworkLogViewColumns(
437 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
438 this.columns.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37439
Jack Franklin28577db2021-10-14 08:12:53440 this.staleRequests = new Set();
441 this.mainRequestLoadTime = -1;
442 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37443
Jack Franklin28577db2021-10-14 08:12:53444 this.filters = [];
445 this.timeFilter = null;
446 this.hoveredNodeInternal = null;
447 this.recordingHint = null;
448 this.refreshRequestId = null;
449 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37450
Jack Franklin28577db2021-10-14 08:12:53451 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37452
Jack Franklin28577db2021-10-14 08:12:53453 this.recording = false;
454 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37455
Jack Franklin28577db2021-10-14 08:12:53456 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37457
Jack Franklin28577db2021-10-14 08:12:53458 this.groupLookups = new Map();
459 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37460
Jack Franklin28577db2021-10-14 08:12:53461 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37462
Jack Franklin28577db2021-10-14 08:12:53463 this.textFilterUI = new UI.FilterBar.TextFilterUI();
464 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
465 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37466
Jack Franklin28577db2021-10-14 08:12:53467 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
468 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting);
469 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38470 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53471 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
472 filterBar.addFilter(this.invertFilterUI);
Victor Porof66878d62021-07-16 13:12:37473
Jack Franklin28577db2021-10-14 08:12:53474 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
475 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting);
476 this.dataURLFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38477 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53478 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
479 filterBar.addFilter(this.dataURLFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37480
481 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13482 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38483 .map(
484 category =>
485 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Jack Franklin28577db2021-10-14 08:12:53486 this.resourceCategoryFilterUI =
487 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55488 UI.ARIAUtils.setAccessibleName(
Jack Franklin28577db2021-10-14 08:12:53489 this.resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
490 this.resourceCategoryFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38491 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53492 filterBar.addFilter(this.resourceCategoryFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37493
Jack Franklin28577db2021-10-14 08:12:53494 this.onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
495 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this.networkShowIssuesOnlySetting);
496 this.onlyIssuesFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38497 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53498 UI.Tooltip.Tooltip.install(this.onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
499 filterBar.addFilter(this.onlyIssuesFilterUI);
Jan Scheffler1ae7c9e2019-12-03 15:48:37500
Jack Franklin28577db2021-10-14 08:12:53501 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55502 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Jack Franklin28577db2021-10-14 08:12:53503 this.networkOnlyBlockedRequestsSetting);
504 this.onlyBlockedRequestsUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38505 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53506 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
507 filterBar.addFilter(this.onlyBlockedRequestsUI);
Sigurd Schneidera2afe0b2020-03-03 15:27:13508
Jack Franklin28577db2021-10-14 08:12:53509 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
510 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting);
511 this.onlyThirdPartyFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38512 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53513 UI.Tooltip.Tooltip.install(this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
514 filterBar.addFilter(this.onlyThirdPartyFilterUI);
Danil Somsikov721956a2021-07-07 08:17:27515
Jack Franklin28577db2021-10-14 08:12:53516 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
517 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38518 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
519 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37520
Jack Franklin28577db2021-10-14 08:12:53521 this.dataGrid = this.columns.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38522 this.setupDataGrid();
Jack Franklin28577db2021-10-14 08:12:53523 this.columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49524 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53525 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37526
Jack Franklin28577db2021-10-14 08:12:53527 this.summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
528 this.summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37529
Tim van der Lippe0ed1d2b2020-02-04 13:45:13530 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38531 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37532
Paul Lewis2d7d65c2020-03-16 17:26:30533 Common.Settings.Settings.instance()
534 .moduleSetting('networkColorCodeResourceTypes')
Jan Scheffler17b8fb42021-08-12 12:28:38535 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37536
Sigurd Schneiderb9f6c792021-05-31 10:57:24537 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27538 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38539 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27540 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38541 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
542 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37543
Jan Scheffler17b8fb42021-08-12 12:28:38544 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30545 Common.Settings.Settings.instance()
546 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38547 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37548
Jack Franklin28577db2021-10-14 08:12:53549 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03550
Jack Franklin28577db2021-10-14 08:12:53551 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
552 if (this.textFilterSetting.get()) {
553 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03554 }
Blink Reformat4c46d092018-04-07 15:32:37555 }
556
Jan Scheffler17b8fb42021-08-12 12:28:38557 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30558 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38559 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37560 }
561
Jan Scheffler17b8fb42021-08-12 12:28:38562 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16563 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37564 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38565 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
566 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50567 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
568 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37569 });
570 } else {
571 values.sort();
572 }
573 }
574
Jan Scheffler17b8fb42021-08-12 12:28:38575 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37576 return !filter(request);
577 }
578
Jan Scheffler17b8fb42021-08-12 12:28:38579 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34580 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37581 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34582 }
Blink Reformat4c46d092018-04-07 15:32:37583
584 return regex.test(request.path() + '/' + request.name());
585 }
586
Jan Scheffler17b8fb42021-08-12 12:28:38587 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37588 const result = [domain];
589 let indexOfPeriod = domain.indexOf('.');
590 while (indexOfPeriod !== -1) {
591 result.push('*' + domain.substring(indexOfPeriod));
592 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
593 }
594 return result;
595 }
596
Jan Scheffler17b8fb42021-08-12 12:28:38597 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17598 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38599 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37600 }
601
Jan Scheffler17b8fb42021-08-12 12:28:38602 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37603 return regex.test(request.domain);
604 }
605
Jan Scheffler17b8fb42021-08-12 12:28:38606 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37607 return !request.finished;
608 }
609
Jan Scheffler17b8fb42021-08-12 12:28:38610 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37611 return request.cached();
612 }
613
Jan Scheffler17b8fb42021-08-12 12:28:38614 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05615 return request.fetchedViaServiceWorker;
616 }
617
Jan Scheffler17b8fb42021-08-12 12:28:38618 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05619 return request.initiatedByServiceWorker();
620 }
621
Jan Scheffler17b8fb42021-08-12 12:28:38622 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37623 return request.responseHeaderValue(value) !== undefined;
624 }
625
Jan Scheffler17b8fb42021-08-12 12:28:38626 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
627 boolean {
Jack Franklin28577db2021-10-14 08:12:53628 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51629 // filter via `includes` instead of strict equality.
630 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
631 }
632
Jan Scheffler17b8fb42021-08-12 12:28:38633 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37634 return request.requestMethod === value;
635 }
636
Jan Scheffler17b8fb42021-08-12 12:28:38637 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37638 return request.priority() === value;
639 }
640
Jan Scheffler17b8fb42021-08-12 12:28:38641 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37642 return request.mimeType === value;
643 }
644
Jan Scheffler17b8fb42021-08-12 12:28:38645 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16646 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
647 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37648 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28649 }
Sigurd Schneider30722582021-06-16 06:54:16650 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37651 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28652 }
Sigurd Schneider30722582021-06-16 06:54:16653 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37654 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28655 }
Sigurd Schneider30722582021-06-16 06:54:16656 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37657 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34658 }
Blink Reformat4c46d092018-04-07 15:32:37659
660 return false;
661 }
662
Jan Scheffler17b8fb42021-08-12 12:28:38663 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37664 return request.scheme === value;
665 }
666
Jan Scheffler17b8fb42021-08-12 12:28:38667 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41668 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
669 }
670
Jan Scheffler17b8fb42021-08-12 12:28:38671 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41672 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
673 }
674
Jan Scheffler17b8fb42021-08-12 12:28:38675 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54676 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
677 }
678
Jan Scheffler17b8fb42021-08-12 12:28:38679 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41680 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
681 }
682
Jan Scheffler17b8fb42021-08-12 12:28:38683 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41684 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37685 }
686
Jan Scheffler17b8fb42021-08-12 12:28:38687 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41688 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37689 }
690
Jan Scheffler17b8fb42021-08-12 12:28:38691 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41692 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37693 }
694
Jan Scheffler17b8fb42021-08-12 12:28:38695 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37696 return request.transferSize >= value;
697 }
698
Jan Scheffler17b8fb42021-08-12 12:28:38699 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24700 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37701 }
702
Sigurd Schneider576ca9a2021-07-16 05:58:04703 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58704 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37705 }
706
Jan Scheffler17b8fb42021-08-12 12:28:38707 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03708 return request.resourceType().name() === value;
709 }
710
Jan Scheffler17b8fb42021-08-12 12:28:38711 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17712 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03713 return regex.test(request.url());
714 }
715
Jan Scheffler17b8fb42021-08-12 12:28:38716 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38717 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34718 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37719 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34720 }
721 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37722 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34723 }
Blink Reformat4c46d092018-04-07 15:32:37724 return true;
725 }
726
Jan Scheffler17b8fb42021-08-12 12:28:38727 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13728 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37729 }
730
Jan Scheffler17b8fb42021-08-12 12:28:38731 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13732 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37733 }
734
Jan Scheffler17b8fb42021-08-12 12:28:38735 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37736 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38737 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34738 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40739 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37740 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08741 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34742 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13743 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37744 }
745
Jan Scheffler17b8fb42021-08-12 12:28:38746 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37747 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34748 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37749 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34750 }
Simon Zünd99961242021-09-08 11:02:12751 const file = items[0].getAsFile();
752 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03753 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34754 }
Blink Reformat4c46d092018-04-07 15:32:37755 }
756
Jan Schefflerd6c1d402021-02-26 16:56:38757 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13758 const outputStream = new Common.StringOutputStream.StringOutputStream();
759 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37760 const success = await reader.read(outputStream);
761 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37762 const error = reader.error();
763 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38764 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37765 }
Blink Reformat4c46d092018-04-07 15:32:37766 return;
767 }
768 let harRoot;
769 try {
770 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56771 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37772 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38773 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37774 return;
775 }
Tim van der Lippe09cf5032021-04-29 15:08:09776 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37777 }
778
Jan Scheffler17b8fb42021-08-12 12:28:38779 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36780 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37781 }
782
Jan Scheffler17b8fb42021-08-12 12:28:38783 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53784 if (this.activeGroupLookup) {
785 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34786 }
Jack Franklin28577db2021-10-14 08:12:53787 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
788 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38789 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37790 }
791
Jan Scheffler17b8fb42021-08-12 12:28:38792 private computeRowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53793 return Math.round(this.rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
Blink Reformat4c46d092018-04-07 15:32:37794 }
795
Jan Schefflerd6c1d402021-02-26 16:56:38796 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37797 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37798 }
799
Jan Schefflerd6c1d402021-02-26 16:56:38800 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53801 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37802 }
803
Jan Schefflerd6c1d402021-02-26 16:56:38804 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53805 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38806 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37807 }
808
Jan Schefflerd6c1d402021-02-26 16:56:38809 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37810 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34811 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37812 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34813 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13814 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37815 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38816 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37817 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38818 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37819 }
820 }
821
Jan Schefflerd6c1d402021-02-26 16:56:38822 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37823 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13824 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37825 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38826 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37827 resourceTreeModel.removeEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38828 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37829 }
830 }
831 }
832
Jan Schefflerd6c1d402021-02-26 16:56:38833 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53834 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13835 }
836
Jan Schefflerd6c1d402021-02-26 16:56:38837 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37838 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53839 this.timeFilter = null;
840 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37841 } else {
Jack Franklin28577db2021-10-14 08:12:53842 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
843 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37844 }
Jan Scheffler17b8fb42021-08-12 12:28:38845 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37846 }
847
Jan Schefflerd6c1d402021-02-26 16:56:38848 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53849 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37850 }
851
Jan Scheffler17b8fb42021-08-12 12:28:38852 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:53853 this.suggestionBuilder.clear();
854 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
855 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16856 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:53857 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16858 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:53859 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16860 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:53861 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
862 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
863 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
864 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Blink Reformat4c46d092018-04-07 15:32:37865 }
866
Simon Zünda2bae2e2021-09-16 07:57:13867 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:37868 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:53869 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:38870 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:53871 this.textFilterSetting.set(this.textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37872 }
873
Jan Schefflerd6c1d402021-02-26 16:56:38874 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:53875 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:12876 }
877
Jan Scheffler17b8fb42021-08-12 12:28:38878 private showRecordingHint(): void {
879 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:53880 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
881 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18882
Jack Franklin28577db2021-10-14 08:12:53883 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38884 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04885 const reloadShortcut =
886 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
887 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:53888 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:04889 reloadShortcutNode.textContent = reloadShortcut.title();
890 }
891
Blink Reformat4c46d092018-04-07 15:32:37892 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55893 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18894 if (reloadShortcutNode) {
895 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55896 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
897 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18898 }
Blink Reformat4c46d092018-04-07 15:32:37899 } else {
900 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17901 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37902 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55903 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:41904 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37905 }
Kayce Basques5444c1b2019-02-15 20:32:53906 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13907 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35908 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55909 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11910
Jan Scheffler17b8fb42021-08-12 12:28:38911 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37912 }
913
Jan Scheffler17b8fb42021-08-12 12:28:38914 private hideRecordingHint(): void {
915 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:53916 if (this.recordingHint) {
917 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34918 }
Michael Liao7322dee2021-04-07 18:33:30919 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:53920 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37921 }
922
Jan Scheffler17b8fb42021-08-12 12:28:38923 private setHidden(value: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53924 this.columns.setHidden(value);
925 UI.ARIAUtils.setHidden(this.summaryToolbar.element, value);
Amanda Baker6761aae2019-11-05 18:59:11926 }
927
Jan Schefflerd6c1d402021-02-26 16:56:38928 elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:53929 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34930 {
Blink Reformat4c46d092018-04-07 15:32:37931 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34932 }
Jack Franklin28577db2021-10-14 08:12:53933 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:37934 }
935
Jan Schefflerd6c1d402021-02-26 16:56:38936 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:38937 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:37938 }
939
Jan Scheffler17b8fb42021-08-12 12:28:38940 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:53941 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38942 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34943 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37944 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34945 }
Blink Reformat4c46d092018-04-07 15:32:37946 });
Jack Franklin28577db2021-10-14 08:12:53947 this.dataGrid.setStickToBottom(true);
948 this.dataGrid.setName('networkLog');
949 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
950 this.dataGrid.element.classList.add('network-log-grid');
951 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
952 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
953 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
954 this.dataGrid.element.addEventListener('keydown', event => {
955 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
956 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('span.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:43957 if (initiatorLink) {
958 (initiatorLink as HTMLElement).focus();
959 }
960 }
ergunshee4a6132021-11-05 16:21:25961
Brandon Goddard88d885a2019-10-31 16:11:05962 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05963 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05964 event.consume(true);
965 }
966 });
ergunshee4a6132021-11-05 16:21:25967 this.dataGrid.element.addEventListener('keyup', event => {
968 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
969 const request = (this.dataGrid.selectedNode as NetworkNode).request();
970 if (!request) {
971 return;
972 }
973
974 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
975 SDK.NetworkManager.NetworkManager.replayRequest(request);
976 }
977 }
978 });
Jack Franklin28577db2021-10-14 08:12:53979 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
980 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
981 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:37982 }
983
Jan Scheffler17b8fb42021-08-12 12:28:38984 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:38985 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:53986 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:37987 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:38988 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:37989 }
990
Jan Schefflerd6c1d402021-02-26 16:56:38991 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:53992 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:37993 }
994
Jan Scheffler17b8fb42021-08-12 12:28:38995 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53996 if (this.hoveredNodeInternal) {
997 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34998 }
Jack Franklin28577db2021-10-14 08:12:53999 this.hoveredNodeInternal = node;
1000 if (this.hoveredNodeInternal) {
1001 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341002 }
Blink Reformat4c46d092018-04-07 15:32:371003 }
1004
Jan Scheffler17b8fb42021-08-12 12:28:381005 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381006 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531007 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371008 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341009 }
Blink Reformat4c46d092018-04-07 15:32:371010 }
1011
Jan Scheffler17b8fb42021-08-12 12:28:381012 private updateSummaryBar(): void {
1013 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371014
1015 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201016 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371017 let selectedNodeNumber = 0;
1018 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201019 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371020 let baseTime = -1;
1021 let maxTime = -1;
1022
1023 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271024 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371025 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341026 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371027 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341028 }
Blink Reformat4c46d092018-04-07 15:32:371029 nodeCount++;
1030 const requestTransferSize = request.transferSize;
1031 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201032 const requestResourceSize = request.resourceSize;
1033 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371034 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371035 selectedNodeNumber++;
1036 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201037 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371038 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131039 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371040 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1041 // inspected url.
1042 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131043 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
1044 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:371045 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341046 }
1047 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371048 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341049 }
Blink Reformat4c46d092018-04-07 15:32:371050 }
1051
1052 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381053 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371054 return;
1055 }
1056
Jack Franklin28577db2021-10-14 08:12:531057 this.summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381058 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131059 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501060 toolbarText.setTitle(title ? title : chunk);
Jack Franklin28577db2021-10-14 08:12:531061 this.summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381062 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501063 };
Blink Reformat4c46d092018-04-07 15:32:371064
1065 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551066 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Jack Franklin28577db2021-10-14 08:12:531067 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501068 appendChunk(
Christy Chencac3f102021-02-03 10:07:551069 i18nString(UIStrings.sSTransferred, {
1070 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381071 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551072 }),
1073 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531074 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501075 appendChunk(
Christy Chencac3f102021-02-03 10:07:551076 i18nString(UIStrings.sSResources, {
1077 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381078 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551079 }),
1080 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371081 } else {
Christy Chencac3f102021-02-03 10:07:551082 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Jack Franklin28577db2021-10-14 08:12:531083 this.summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251084 appendChunk(
Christy Chencac3f102021-02-03 10:07:551085 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1086 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531087 this.summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251088 appendChunk(
Christy Chencac3f102021-02-03 10:07:551089 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1090 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371091 }
Dan Beam87466b52018-12-01 18:41:201092
Blink Reformat4c46d092018-04-07 15:32:371093 if (baseTime !== -1 && maxTime !== -1) {
Jack Franklin28577db2021-10-14 08:12:531094 this.summaryToolbar.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581095 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531096 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
1097 this.summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551098 const domContentLoadedText = i18nString(
1099 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531100 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581101 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371102 }
Jack Franklin28577db2021-10-14 08:12:531103 if (this.mainRequestLoadTime !== -1) {
1104 this.summaryToolbar.appendSeparator();
1105 const loadText =
1106 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581107 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371108 }
1109 }
Blink Reformat4c46d092018-04-07 15:32:371110 }
1111
Jan Schefflerd6c1d402021-02-26 16:56:381112 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531113 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371114 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341115 }
Blink Reformat4c46d092018-04-07 15:32:371116
Jack Franklin28577db2021-10-14 08:12:531117 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371118
Jack Franklin28577db2021-10-14 08:12:531119 if (this.isShowing() && !this.refreshRequestId) {
1120 this.refreshRequestId = this.element.window().requestAnimationFrame(this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341121 }
Blink Reformat4c46d092018-04-07 15:32:371122 }
1123
Jan Schefflerd6c1d402021-02-26 16:56:381124 addFilmStripFrames(times: number[]): void {
Jack Franklin28577db2021-10-14 08:12:531125 this.columns.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371126 }
1127
Jan Schefflerd6c1d402021-02-26 16:56:381128 selectFilmStripFrame(time: number): void {
Jack Franklin28577db2021-10-14 08:12:531129 this.columns.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371130 }
1131
Jan Schefflerd6c1d402021-02-26 16:56:381132 clearFilmStripFrame(): void {
Jack Franklin28577db2021-10-14 08:12:531133 this.columns.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371134 }
1135
Jan Scheffler17b8fb42021-08-12 12:28:381136 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531137 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381138 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341139 }
Blink Reformat4c46d092018-04-07 15:32:371140 }
1141
Jan Scheffler17b8fb42021-08-12 12:28:381142 private invalidateAllItems(deferUpdate?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531143 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371145 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341146 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381147 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341148 }
Blink Reformat4c46d092018-04-07 15:32:371149 }
1150
Jan Schefflerd6c1d402021-02-26 16:56:381151 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531152 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371153 }
1154
Jan Schefflerd6c1d402021-02-26 16:56:381155 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531156 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371157 }
1158
Jan Schefflerd6c1d402021-02-26 16:56:381159 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531160 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371161 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341162 }
Blink Reformat4c46d092018-04-07 15:32:371163
Jack Franklin28577db2021-10-14 08:12:531164 if (this.calculatorInternal !== x) {
1165 this.calculatorInternal = x;
1166 this.columns.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371167 }
Jack Franklin28577db2021-10-14 08:12:531168 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371169
Jack Franklin28577db2021-10-14 08:12:531170 if (this.calculatorInternal.startAtZero) {
1171 this.columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341172 } else {
Jack Franklin28577db2021-10-14 08:12:531173 this.columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341174 }
Blink Reformat4c46d092018-04-07 15:32:371175
Jan Scheffler17b8fb42021-08-12 12:28:381176 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371177 }
1178
Jan Scheffler17b8fb42021-08-12 12:28:381179 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271180 event: Common.EventTarget
1181 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531182 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371183 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341184 }
Blink Reformat4c46d092018-04-07 15:32:371185
Simon Zünd1a930492021-07-30 08:22:271186 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371187 if (time) {
Jack Franklin28577db2021-10-14 08:12:531188 this.mainRequestLoadTime = time;
1189 this.columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371190 }
1191 }
1192
Jan Scheffler17b8fb42021-08-12 12:28:381193 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531194 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371195 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341196 }
Simon Zünd1a930492021-07-30 08:22:271197 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371198 if (data) {
Jack Franklin28577db2021-10-14 08:12:531199 this.mainRequestDOMContentLoadedTime = data;
1200 this.columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371201 }
1202 }
1203
Jan Schefflerd6c1d402021-02-26 16:56:381204 wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381205 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301206 this.registerCSSFiles([networkLogViewStyles]);
Jack Franklin28577db2021-10-14 08:12:531207 this.columns.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371208 }
1209
Jan Schefflerd6c1d402021-02-26 16:56:381210 willHide(): void {
Jack Franklin28577db2021-10-14 08:12:531211 this.columns.willHide();
Blink Reformat4c46d092018-04-07 15:32:371212 }
1213
Jan Schefflerd6c1d402021-02-26 16:56:381214 onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531215 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371216 }
1217
Jan Schefflerd6c1d402021-02-26 16:56:381218 flatNodesList(): NetworkNode[] {
1219 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531220 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381221 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1222 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371223 }
1224
Jan Scheffler17b8fb42021-08-12 12:28:381225 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531226 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351227 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381228 }
Brandon Goddard44934902020-03-25 16:03:181229 this.updateNodeBackground();
1230 }
1231
Jan Scheffler17b8fb42021-08-12 12:28:381232 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181233 this.element.classList.remove('grid-focused');
1234 this.updateNodeBackground();
1235 }
1236
Jan Schefflerd6c1d402021-02-26 16:56:381237 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531238 if (this.dataGrid.selectedNode) {
1239 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051240 }
1241 }
1242
Jan Schefflerd6c1d402021-02-26 16:56:381243 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051244 if (isSelected) {
1245 this.element.classList.remove('no-node-selected');
1246 } else {
1247 this.element.classList.add('no-node-selected');
1248 }
1249 }
1250
Jan Schefflerd6c1d402021-02-26 16:56:381251 stylesChanged(): void {
Jack Franklin28577db2021-10-14 08:12:531252 this.columns.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371253 }
1254
Jan Scheffler17b8fb42021-08-12 12:28:381255 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531256 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371257
Jack Franklin28577db2021-10-14 08:12:531258 if (this.refreshRequestId) {
1259 this.element.window().cancelAnimationFrame(this.refreshRequestId);
1260 this.refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:371261 }
1262
1263 this.removeAllNodeHighlights();
1264
Jack Franklin28577db2021-10-14 08:12:531265 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1266 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1267 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1268 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371269
Jan Schefflerd6c1d402021-02-26 16:56:381270 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1271 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371272
Jan Schefflerd6c1d402021-02-26 16:56:381273 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371274
Jack Franklin28577db2021-10-14 08:12:531275 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371276 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531277 while (this.staleRequests.size) {
1278 const request = this.staleRequests.values().next().value;
1279 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371280 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341281 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381282 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341283 }
Blink Reformat4c46d092018-04-07 15:32:371284 staleNodes.add(node);
1285 }
1286
1287 for (const node of staleNodes) {
Jan Scheffler17b8fb42021-08-12 12:28:381288 const isFilteredOut = !this.applyFilter(node);
Jack Franklin28577db2021-10-14 08:12:531289 if (isFilteredOut && node === this.hoveredNodeInternal) {
Jan Scheffler17b8fb42021-08-12 12:28:381290 this.setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341291 }
Blink Reformat4c46d092018-04-07 15:32:371292
Tim van der Lippe1d6e57a2019-09-30 11:55:341293 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371294 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341295 }
Blink Reformat4c46d092018-04-07 15:32:371296 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531297 this.timeCalculatorInternal.updateBoundaries(request);
1298 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381299 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371300 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1301 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371302 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341303 }
Tim van der Lippe224a8622020-09-23 12:14:371304 if (isFilteredOut) {
1305 filteredNetworkRequests.add(node);
1306 } else {
1307 filteredNetworkRequests.delete(node);
1308 }
Blink Reformat4c46d092018-04-07 15:32:371309 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1310 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381311 let parent: NetworkNode|
1312 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1313 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1314 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111315 if (!parent) {
1316 continue;
1317 }
Blink Reformat4c46d092018-04-07 15:32:371318 parent.removeChild(node);
1319 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381320 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371321 grandparent.removeChild(parent);
1322 parent = grandparent;
1323 }
1324 }
1325
Tim van der Lippe1d6e57a2019-09-30 11:55:341326 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371327 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341328 }
Blink Reformat4c46d092018-04-07 15:32:371329
1330 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531331 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371332 nodesToRefresh.push(newParent);
1333 }
1334 nodesToInsert.set(node, newParent);
1335 }
1336
Tim van der Lippe1d6e57a2019-09-30 11:55:341337 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381338 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341339 }
Blink Reformat4c46d092018-04-07 15:32:371340
Tim van der Lippe1d6e57a2019-09-30 11:55:341341 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371342 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341343 }
Blink Reformat4c46d092018-04-07 15:32:371344
Jan Scheffler17b8fb42021-08-12 12:28:381345 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371346
Tim van der Lippe1d6e57a2019-09-30 11:55:341347 if (nodesToInsert.size) {
Jack Franklin28577db2021-10-14 08:12:531348 this.columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341349 }
Blink Reformat4c46d092018-04-07 15:32:371350
Jack Franklin28577db2021-10-14 08:12:531351 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381352 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371353 }
1354
Jan Scheffler17b8fb42021-08-12 12:28:381355 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371356 }
1357
Jan Scheffler17b8fb42021-08-12 12:28:381358 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531359 if (!this.activeGroupLookup) {
1360 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341361 }
Blink Reformat4c46d092018-04-07 15:32:371362
Jack Franklin28577db2021-10-14 08:12:531363 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341364 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531365 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341366 }
Blink Reformat4c46d092018-04-07 15:32:371367 return groupNode;
1368 }
1369
Jan Scheffler17b8fb42021-08-12 12:28:381370 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151371 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371372
Jan Scheffler17b8fb42021-08-12 12:28:381373 this.setHoveredNode(null);
Jack Franklin28577db2021-10-14 08:12:531374 this.columns.reset();
Blink Reformat4c46d092018-04-07 15:32:371375
Jack Franklin28577db2021-10-14 08:12:531376 this.timeFilter = null;
1377 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371378
Jack Franklin28577db2021-10-14 08:12:531379 this.timeCalculatorInternal.setWindow(null);
1380 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371381
Jack Franklin28577db2021-10-14 08:12:531382 if (this.activeGroupLookup) {
1383 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341384 }
Jack Franklin28577db2021-10-14 08:12:531385 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381386 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371387
Jack Franklin28577db2021-10-14 08:12:531388 this.mainRequestLoadTime = -1;
1389 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371390
Jack Franklin28577db2021-10-14 08:12:531391 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381392 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531393 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371394 this.scheduleRefresh();
1395 }
1396
Jan Schefflerd6c1d402021-02-26 16:56:381397 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531398 this.textFilterUI.setValue(filterString);
1399 this.dataURLFilterUI.setChecked(false);
1400 this.onlyIssuesFilterUI.setChecked(false);
1401 this.onlyBlockedRequestsUI.setChecked(false);
1402 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371403 }
1404
Jan Scheffler17b8fb42021-08-12 12:28:381405 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301406 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371407 networkRequestToNode.set(request, node);
1408 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371409
Tim van der Lippe1d6e57a2019-09-30 11:55:341410 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381411 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341412 }
Blink Reformat4c46d092018-04-07 15:32:371413 return node;
1414 }
1415
Kateryna Prokopenko460f5492021-08-27 08:20:281416 private onRequestUpdated(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1417 const request = event.data;
Jan Scheffler17b8fb42021-08-12 12:28:381418 this.refreshRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371419 }
1420
Jan Scheffler17b8fb42021-08-12 12:28:381421 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1422 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161423 .forEach(
Jack Franklin28577db2021-10-14 08:12:531424 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1425 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1426 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1427 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1428 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1429 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1430 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371431
1432 const priority = request.priority();
1433 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531434 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161435 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371436 }
1437
1438 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531439 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161440 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371441 }
1442
1443 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531444 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161445 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371446 }
1447
1448 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161449 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1450 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531451 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371452 }
1453
1454 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511455 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531456 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511457 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531458 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511459 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341460 }
Jan Scheffler341eea52019-12-12 09:08:411461
1462 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531463 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1464 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1465 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371466 }
1467
Jan Scheffler341eea52019-12-12 09:08:411468 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531469 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1470 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1471 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1472 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411473 }
1474
Jack Franklin28577db2021-10-14 08:12:531475 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371476 this.scheduleRefresh();
1477 }
1478
Jan Schefflerd6c1d402021-02-26 16:56:381479 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531480 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371481 }
1482
Jan Schefflerd6c1d402021-02-26 16:56:381483 switchViewMode(gridMode: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531484 this.columns.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371485 }
1486
Jan Schefflerd6c1d402021-02-26 16:56:381487 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1488 void {
Blink Reformat4c46d092018-04-07 15:32:371489 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551490 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371491 const footerSection = copyMenu.footerSection();
1492 if (request) {
1493 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 UI.UIUtils.copyLinkAddressLabel(),
1495 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1496 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371497 if (request.requestHeadersText()) {
1498 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381499 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371500 }
1501
1502 if (request.responseHeadersText) {
1503 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381504 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371505 }
1506
1507 if (request.finished) {
1508 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381509 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371510 }
1511
Tim van der Lippeb4faf5a2020-11-06 15:02:021512 const initiator = request.initiator();
1513
1514 if (initiator) {
1515 const stack = initiator.stack;
1516 if (stack) {
1517 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531518 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021519 // any callFrames, but its parent frames do.
1520 const stackTraceText = computeStackTraceText(stack);
1521 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551522 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021523 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1524 });
1525 }
1526 }
1527 }
1528
Harley Libcf41f92018-09-10 18:01:131529 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131530 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371531 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381532 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371533 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461534 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1535 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291536 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461537 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1538 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371539 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381540 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131541 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381542 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1543 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461544 footerSection.appendItem(
1545 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1546 footerSection.appendItem(
1547 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381548 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this.copyAllCurlCommand.bind(this, 'win'));
1549 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371550 } else {
Harley Libcf41f92018-09-10 18:01:131551 footerSection.appendItem(
Danil Somsikova4b089c2021-11-09 14:32:091552 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
1553 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461554 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1555 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291556 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461557 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1558 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131559 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381560 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Danil Somsikova4b089c2021-11-09 14:32:091561 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461562 footerSection.appendItem(
1563 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1564 footerSection.appendItem(
1565 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381566 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371567 }
1568 } else {
Christy Chencac3f102021-02-03 10:07:551569 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371570 }
Jan Scheffler17b8fb42021-08-12 12:28:381571 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this.copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371572
Christy Chencac3f102021-02-03 10:07:551573 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371574
Jan Scheffler17b8fb42021-08-12 12:28:381575 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371576 contextMenu.editSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381577 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371578
1579 if (request) {
1580 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211581 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371582 let patterns = manager.blockedPatterns();
1583
Jan Schefflerd6c1d402021-02-26 16:56:381584 function addBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121585 patterns.push({enabled: true, url: url});
1586 manager.setBlockedPatterns(patterns);
1587 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031588 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121589 }
1590
Jan Schefflerd6c1d402021-02-26 16:56:381591 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121592 patterns = patterns.filter(pattern => pattern.url !== url);
1593 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031594 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121595 }
1596
Blink Reformat4c46d092018-04-07 15:32:371597 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1598 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1599 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551600 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371601 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311602 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371603 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551604 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371605 }
1606
1607 const domain = request.parsedURL.domain();
1608 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1609 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551610 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371611 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311612 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371613 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551614 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371615 }
1616
Tim van der Lippe0ed1d2b2020-02-04 13:45:131617 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371618 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551619 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371620 }
Blink Reformat4c46d092018-04-07 15:32:371621 }
1622 }
1623
Jan Scheffler17b8fb42021-08-12 12:28:381624 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271625 return Logs.NetworkLog.NetworkLog.instance()
1626 .requests()
Sigurd Schneider576ca9a2021-07-16 05:58:041627 .filter(NetworkLogView.getHTTPRequestsFilter)
Sigurd Schneidercf5b8302021-04-23 07:52:271628 .filter(request => {
1629 return request.finished ||
1630 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1631 });
Blink Reformat4c46d092018-04-07 15:32:371632 }
1633
Jan Scheffler17b8fb42021-08-12 12:28:381634 private async copyAll(): Promise<void> {
1635 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131636 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371637 }
1638
Jan Scheffler17b8fb42021-08-12 12:28:381639 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
1640 const command = await this.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131641 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371642 }
1643
Jan Scheffler17b8fb42021-08-12 12:28:381644 private async copyAllCurlCommand(platform: string): Promise<void> {
1645 const commands = await this.generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131646 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371647 }
1648
Danil Somsikov59f4c612021-09-08 10:58:461649 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1650 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131651 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371652 }
1653
Danil Somsikov59f4c612021-09-08 10:58:461654 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
1655 const commands = await this.generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131656 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371657 }
1658
Jan Scheffler17b8fb42021-08-12 12:28:381659 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1660 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131661 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371662 }
1663
Jan Scheffler17b8fb42021-08-12 12:28:381664 private async copyAllPowerShellCommand(): Promise<void> {
1665 const commands = await this.generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131666 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371667 }
1668
Jan Schefflerd6c1d402021-02-26 16:56:381669 async exportAll(): Promise<void> {
Sigurd Schneiderb9f6c792021-05-31 10:57:241670 const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget();
Tim van der Lippe224a8622020-09-23 12:14:371671 if (!mainTarget) {
1672 return;
1673 }
1674 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131675 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371676 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131677 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371678
Tim van der Lippe1d6e57a2019-09-30 11:55:341679 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371680 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341681 }
Blink Reformat4c46d092018-04-07 15:32:371682
Tim van der Lippe0ed1d2b2020-02-04 13:45:131683 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531684 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381685 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371686 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031687 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371688 }
1689
Jan Scheffler17b8fb42021-08-12 12:28:381690 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551691 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211692 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341693 }
Blink Reformat4c46d092018-04-07 15:32:371694 }
1695
Jan Scheffler17b8fb42021-08-12 12:28:381696 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551697 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211698 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341699 }
Blink Reformat4c46d092018-04-07 15:32:371700 }
1701
Jan Scheffler17b8fb42021-08-12 12:28:381702 private removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371703 this.removeAllNodeHighlights();
Blink Reformat4c46d092018-04-07 15:32:371704 }
1705
Jan Scheffler17b8fb42021-08-12 12:28:381706 private applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371707 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531708 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371709 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341710 }
Christy Chen1825c612021-02-25 10:28:441711 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531712 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371713 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341714 }
Jack Franklin28577db2021-10-14 08:12:531715 if (this.dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371716 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341717 }
Jack Franklin28577db2021-10-14 08:12:531718 if (this.onlyIssuesFilterUI.checked() &&
Juba Borgohain2af14942022-03-02 12:46:151719 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.Cookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371720 return false;
1721 }
Jack Franklin28577db2021-10-14 08:12:531722 if (this.onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131723 return false;
1724 }
Jack Franklin28577db2021-10-14 08:12:531725 if (this.onlyThirdPartyFilterUI.checked() && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271726 return false;
1727 }
Jack Franklin28577db2021-10-14 08:12:531728 for (let i = 0; i < this.filters.length; ++i) {
1729 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371730 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 }
Blink Reformat4c46d092018-04-07 15:32:371732 }
1733 return true;
1734 }
1735
Danil Somsikov7a392fb2021-09-13 11:09:461736 private isValidUrl(url: string): boolean {
1737 try {
1738 new URL(url);
1739 return true;
1740 } catch (e) {
1741 return false;
1742 }
1743 }
1744
Jan Scheffler17b8fb42021-08-12 12:28:381745 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531746 // A query string can have multiple filters, some of them regular
1747 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371748 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:531749 // checkbox therefore inverts each one of those individual filters.
1750 const descriptors = this.filterParser.parse(query);
1751 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:371752 const key = descriptor.key;
1753 const text = descriptor.text || '';
1754 const regex = descriptor.regex;
1755 let filter;
1756 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171757 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:381758 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
1759 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371760 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:381761 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:461762 } else if (this.isValidUrl(text)) {
1763 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:371764 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381765 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:171766 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371767 }
Victor Porof66878d62021-07-16 13:12:371768 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:381769 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:371770 }
1771 return filter;
Blink Reformat4c46d092018-04-07 15:32:371772 });
1773 }
1774
Jan Scheffler17b8fb42021-08-12 12:28:381775 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371776 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:161777 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:381778 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371779
Sigurd Schneider30722582021-06-16 06:54:161780 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:381781 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371782
Simon Zünd6dedde52021-08-03 09:04:511783 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:381784 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:511785
Sigurd Schneider30722582021-06-16 06:54:161786 case NetworkForward.UIFilter.FilterType.Is:
1787 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:381788 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341789 }
Sigurd Schneider30722582021-06-16 06:54:161790 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:381791 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341792 }
Sigurd Schneider30722582021-06-16 06:54:161793 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:381794 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341795 }
Sigurd Schneider30722582021-06-16 06:54:161796 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:381797 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341798 }
Blink Reformat4c46d092018-04-07 15:32:371799 break;
1800
Sigurd Schneider30722582021-06-16 06:54:161801 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:381802 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:371803
Sigurd Schneider30722582021-06-16 06:54:161804 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:381805 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371806
Sigurd Schneider30722582021-06-16 06:54:161807 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:381808 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371809
Sigurd Schneider30722582021-06-16 06:54:161810 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:381811 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:161812 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371813
Sigurd Schneider30722582021-06-16 06:54:161814 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:381815 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371816
Sigurd Schneider30722582021-06-16 06:54:161817 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381818 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371819
Sigurd Schneider30722582021-06-16 06:54:161820 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381821 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371822
Sigurd Schneider30722582021-06-16 06:54:161823 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381824 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371825
Sigurd Schneider30722582021-06-16 06:54:161826 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381827 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411828
Sigurd Schneider30722582021-06-16 06:54:161829 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381830 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411831
Sigurd Schneider30722582021-06-16 06:54:161832 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:381833 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:541834
Sigurd Schneider30722582021-06-16 06:54:161835 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381836 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411837
Sigurd Schneider30722582021-06-16 06:54:161838 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:381839 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:501840 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371841
Sigurd Schneider30722582021-06-16 06:54:161842 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:381843 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031844
Sigurd Schneider30722582021-06-16 06:54:161845 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:381846 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031847
Sigurd Schneider30722582021-06-16 06:54:161848 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:381849 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371850 }
1851 return null;
1852 }
1853
Jan Scheffler17b8fb42021-08-12 12:28:381854 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371855 let multiplier = 1;
1856 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541857 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371858 value = value.substring(0, value.length - 1);
1859 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541860 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371861 value = value.substring(0, value.length - 1);
1862 }
1863 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341864 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371865 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341866 }
Jan Scheffler17b8fb42021-08-12 12:28:381867 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371868 }
1869
Jan Scheffler17b8fb42021-08-12 12:28:381870 private filterRequests(): void {
1871 this.removeAllHighlights();
1872 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371873 }
1874
Jan Scheffler17b8fb42021-08-12 12:28:381875 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371876 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371877 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341878 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371879 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341880 }
Brandon Goddard5e4244d2020-04-08 22:08:471881 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:531882 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:471883 // reveal and expand parent to ensure child is revealable.
1884 if (node.parent && node.parent instanceof NetworkGroupNode) {
1885 node.parent.reveal();
1886 node.parent.expand();
1887 }
Blink Reformat4c46d092018-04-07 15:32:371888 node.reveal();
1889 return node;
1890 }
1891
Jan Schefflerd6c1d402021-02-26 16:56:381892 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:381893 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341894 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:381895 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341896 }
Blink Reformat4c46d092018-04-07 15:32:371897 }
1898
Sigurd Schneider722301e2021-06-15 13:41:201899 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:071900 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
1901 if (request) {
1902 this.revealAndHighlightRequest(request);
1903 }
1904 }
1905
Sigurd Schneider14d3e9f2021-06-14 08:29:011906 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
1907 void {
chait pinnamaneni6bc1c122020-10-30 17:30:521908 const defaultOptions = {clearFilter: true};
1909 const {clearFilter} = options || defaultOptions;
1910 if (clearFilter) {
1911 this.setTextFilterValue('');
1912 }
Jan Scheffler17b8fb42021-08-12 12:28:381913 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341914 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371915 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341916 }
Blink Reformat4c46d092018-04-07 15:32:371917 }
1918
Jan Schefflerd6c1d402021-02-26 16:56:381919 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:531920 if (this.highlightedNode) {
1921 this.highlightedNode.element().classList.remove('highlighted-row');
1922 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:371923 }
1924 }
1925
Jan Scheffler17b8fb42021-08-12 12:28:381926 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131927 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:531928 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:371929 }
1930
Jan Scheffler17b8fb42021-08-12 12:28:381931 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131932 return requests.filter(request => !request.isBlobRequest());
1933 }
1934
Danil Somsikov59f4c612021-09-08 10:58:461935 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:381936 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371937 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371938 'method',
1939 'path',
1940 'scheme',
1941 'version',
Blink Reformat4c46d092018-04-07 15:32:371942
1943 // Unsafe headers
1944 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371945 'accept-charset',
1946 'accept-encoding',
1947 'access-control-request-headers',
1948 'access-control-request-method',
1949 'connection',
1950 'content-length',
1951 'cookie',
1952 'cookie2',
1953 'date',
1954 'dnt',
1955 'expect',
1956 'host',
1957 'keep-alive',
1958 'origin',
1959 'referer',
1960 'te',
1961 'trailer',
1962 'transfer-encoding',
1963 'upgrade',
1964 'via',
Blink Reformat4c46d092018-04-07 15:32:371965 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371966 'user-agent',
1967 ]);
Blink Reformat4c46d092018-04-07 15:32:371968
Jan Schefflerd6c1d402021-02-26 16:56:381969 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371970
1971 const url = JSON.stringify(request.url());
1972
1973 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:381974 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:371975 const name = header.name;
1976
Tim van der Lippe224a8622020-09-23 12:14:371977 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371978 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341979 }
Blink Reformat4c46d092018-04-07 15:32:371980
1981 return result;
1982 }, new Headers());
1983
Jan Schefflerd6c1d402021-02-26 16:56:381984 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341985 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411986 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341987 }
Blink Reformat4c46d092018-04-07 15:32:371988
Sigurd Schneider0e88b912020-05-08 08:28:231989 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371990 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411991 'include' :
1992 'omit';
Blink Reformat4c46d092018-04-07 15:32:371993
1994 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1995
1996 const referrer = referrerHeader ? referrerHeader.value : void 0;
1997
1998 const referrerPolicy = request.referrerPolicy() || void 0;
1999
2000 const requestBody = await request.requestFormData();
2001
Jan Schefflerd6c1d402021-02-26 16:56:382002 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412003 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372004 referrer,
2005 referrerPolicy,
2006 body: requestBody,
2007 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372008 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372009 };
2010
Danil Somsikov59f4c612021-09-08 10:58:462011 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292012 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462013 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532014 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462015 // following properties are not implemented in Node.js.
2016 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292017 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462018 extraHeaders['cookie'] = cookieHeader.value;
2019 }
2020 if (referrer) {
2021 delete fetchOptions.referrer;
2022 extraHeaders['Referer'] = referrer;
2023 }
2024 if (referrer) {
2025 delete fetchOptions.referrerPolicy;
2026 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2027 }
2028 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292029 fetchOptions.headers = {
2030 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462031 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292032 };
2033 }
2034 } else {
2035 fetchOptions.credentials = credentials;
2036 }
2037
Jan Scheffler172d5212020-01-02 14:42:562038 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372039 return `fetch(${url}, ${options});`;
2040 }
2041
Danil Somsikov59f4c612021-09-08 10:58:462042 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382043 Promise<string> {
2044 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462045 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132046 return commands.join(' ;\n');
2047 }
2048
Jan Scheffler17b8fb42021-08-12 12:28:382049 private async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382050 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362051 // Most of these headers are derived from the URL and are automatically added by cURL.
2052 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:382053 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372054
Jan Schefflerd6c1d402021-02-26 16:56:382055 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372056 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:382057 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:372058
Jan Schefflerd6c1d402021-02-26 16:56:382059 Because cmd.exe parser and MS Crt arguments parsers use some of the
2060 same escape characters, they can interact with each other in
2061 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372062
Jan Schefflerd6c1d402021-02-26 16:56:382063 Replace \ with \\ first because it is an escape character for certain
2064 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372065
Jan Schefflerd6c1d402021-02-26 16:56:382066 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372067
Jan Schefflerd6c1d402021-02-26 16:56:382068 Then escape all characters we are not sure about with ^ to ensure it
2069 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372070
Jan Schefflerd6c1d402021-02-26 16:56:382071 The % character is special because MS Crt parser will try and look for
2072 ENV variables and fill them in it's place. We cannot escape them with %
2073 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2074 parser); So we can get cmd.exe parser to escape the character after it,
2075 if it is followed by a valid beginning character of an ENV variable.
2076 This ensures we do not try and double escape another ^ if it was placed
2077 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372078
Jan Schefflerd6c1d402021-02-26 16:56:382079 Lastly we replace new lines with ^ and TWO new lines because the first
2080 new line is there to enact the escape command the second is the character
2081 to escape (in this case new line).
2082 */
Blink Reformat4c46d092018-04-07 15:32:372083 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2084 return encapsChars +
2085 str.replace(/\\/g, '\\\\')
2086 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542087 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372088 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542089 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372090 encapsChars;
2091 }
2092
Jan Schefflerd6c1d402021-02-26 16:56:382093 function escapeStringPosix(str: string): string {
2094 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222095 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122096 let hexString = code.toString(16);
2097 // Zero pad to four digits to comply with ANSI-C Quoting:
2098 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342099 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122100 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342101 }
Joey Arhar2d21f712019-05-20 21:07:122102
2103 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372104 }
2105
Mathias Bynensf06e8c02020-02-28 13:58:282106 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372107 // Use ANSI-C quoting syntax.
2108 return '$\'' +
2109 str.replace(/\\/g, '\\\\')
2110 .replace(/\'/g, '\\\'')
2111 .replace(/\n/g, '\\n')
2112 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282113 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372114 '\'';
Blink Reformat4c46d092018-04-07 15:32:372115 }
Mathias Bynensf06e8c02020-02-28 13:58:282116 // Use single quote syntax.
2117 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372118 }
2119
2120 // cURL command expected to run on the same platform that DevTools run
2121 // (it may be different from the inspected page platform).
2122 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2123
2124 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2125
2126 let inferredMethod = 'GET';
2127 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372128 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082129 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272130 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532131 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272132 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372133 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372134 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372135 }
2136
2137 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292138 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372139 }
2140
2141 const requestHeaders = request.requestHeaders();
2142 for (let i = 0; i < requestHeaders.length; i++) {
2143 const header = requestHeaders[i];
2144 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372145 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372146 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342147 }
Jan Scheffler172d5212020-01-02 14:42:562148 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372149 }
2150 command = command.concat(data);
2151 command.push('--compressed');
2152
Tim van der Lippe1d6e57a2019-09-30 11:55:342153 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372154 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342155 }
Jan Scheffler172d5212020-01-02 14:42:562156 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372157 }
2158
Jan Scheffler17b8fb42021-08-12 12:28:382159 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string):
2160 Promise<string> {
2161 const nonBlobRequests = this.filterOutBlobRequests(requests);
2162 const commands = await Promise.all(nonBlobRequests.map(request => this.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342163 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132164 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342165 }
Mathias Bynensf06e8c02020-02-28 13:58:282166 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132167 }
2168
Jan Scheffler17b8fb42021-08-12 12:28:382169 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562170 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242171 const ignoredHeaders = new Set<string>([
2172 'host',
2173 'connection',
2174 'proxy-connection',
2175 'content-length',
2176 'expect',
2177 'range',
2178 'content-type',
2179 'user-agent',
2180 'cookie',
2181 ]);
Blink Reformat4c46d092018-04-07 15:32:372182
Jan Schefflerd6c1d402021-02-26 16:56:382183 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372184 return '"' +
2185 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2186 }
2187
Brandon Walderman153b8d72021-06-28 18:45:242188 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2189 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2190 // command does not allow setting these headers through the -Headers parameter. See docs at:
2191 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2192 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2193 const requestHeaders = request.requestHeaders();
2194 const props = [];
2195
2196 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2197 if (userAgentHeader) {
2198 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2199 }
2200
2201 for (const cookie of request.includedRequestCookies()) {
2202 const name = escapeString(cookie.name());
2203 const value = escapeString(cookie.value());
2204 const domain = escapeString(cookie.domain());
2205 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2206 }
2207
2208 if (props.length) {
2209 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2210 }
2211
2212 return null;
2213 }
2214
Jan Scheffler172d5212020-01-02 14:42:562215 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372216
2217 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562218 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372219 }
2220
Brandon Walderman153b8d72021-06-28 18:45:242221 const session = generatePowerShellSession(request);
2222 if (session) {
2223 command.push('-WebSession $session');
2224 }
2225
Blink Reformat4c46d092018-04-07 15:32:372226 const requestHeaders = request.requestHeaders();
2227 const headerNameValuePairs = [];
2228 for (const header of requestHeaders) {
2229 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342230 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372231 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342232 }
Blink Reformat4c46d092018-04-07 15:32:372233 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2234 }
2235 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562236 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372237 }
2238
2239 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2240 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562241 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372242 }
2243
2244 const formData = await request.requestFormData();
2245 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372246 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342247 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562248 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342249 } else {
Jan Scheffler172d5212020-01-02 14:42:562250 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342251 }
Blink Reformat4c46d092018-04-07 15:32:372252 }
2253
Brandon Walderman153b8d72021-06-28 18:45:242254 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2255 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2256 // compatibility only.
2257 const prelude = session || '';
2258 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372259 }
Harley Libcf41f92018-09-10 18:01:132260
Jan Scheffler17b8fb42021-08-12 12:28:382261 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2262 const nonBlobRequests = this.filterOutBlobRequests(requests);
2263 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132264 return commands.join(';\r\n');
2265 }
Joey Arhara86c14e2019-03-12 03:20:502266
Jan Schefflerd6c1d402021-02-26 16:56:382267 static getDCLEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052268 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-3');
Joey Arhara86c14e2019-03-12 03:20:502269 }
2270
Jan Schefflerd6c1d402021-02-26 16:56:382271 static getLoadEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052272 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-1');
Joey Arhara86c14e2019-03-12 03:20:502273 }
Paul Lewis56509652019-12-06 12:51:582274}
Blink Reformat4c46d092018-04-07 15:32:372275
Jan Schefflerd6c1d402021-02-26 16:56:382276export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022277 let stackTraceText = '';
2278 for (const frame of stackTrace.callFrames) {
2279 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2280 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2281 }
2282 if (stackTrace.parent) {
2283 stackTraceText += computeStackTraceText(stackTrace.parent);
2284 }
2285 return stackTraceText;
2286}
2287
Jan Schefflerd6c1d402021-02-26 16:56:382288const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2289const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372290
Jan Schefflerd6c1d402021-02-26 16:56:382291export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372292 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222293}
2294
Paul Lewis56509652019-12-06 12:51:582295export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372296 'http': true,
2297 'https': true,
2298 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382299 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372300};
2301
Sigurd Schneider576ca9a2021-07-16 05:58:042302const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382303
2304export interface GroupLookupInterface {
2305 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2306 reset(): void;
2307}
2308
2309export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;