blob: cdedfdd53cdc20b91e01c74108052b0d8da67d69 [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';
Jack Frankline839c0c2022-05-03 08:47:4460import {
61 NetworkTimeBoundary,
62 NetworkTransferDurationCalculator,
63 NetworkTransferTimeCalculator,
64} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3065
Simon Zünd34490692021-03-01 08:25:1866const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5567 /**
68 *@description Text in Network Log View of the Network panel
69 */
Victor Porof66878d62021-07-16 13:12:3770 invertFilter: 'Invert',
71 /**
72 *@description Tooltip for the 'invert' checkbox in the Network panel.
73 */
74 invertsFilter: 'Inverts the search filter',
75 /**
76 *@description Text in Network Log View of the Network panel
77 */
Christy Chencac3f102021-02-03 10:07:5578 hideDataUrls: 'Hide data URLs',
79 /**
80 *@description Data urlfilter ui element title in Network Log View of the Network panel
81 */
82 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
83 /**
84 *@description Aria accessible name in Network Log View of the Network panel
85 */
86 resourceTypesToInclude: 'Resource types to include',
87 /**
88 *@description Label for a filter in the Network panel
89 */
90 hasBlockedCookies: 'Has blocked cookies',
91 /**
Jack Franklin28577db2021-10-14 08:12:5392 *@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:5493 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
94 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:5595 */
96 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
97 /**
98 *@description Label for a filter in the Network panel
99 */
100 blockedRequests: 'Blocked Requests',
101 /**
102 *@description Tooltip for a filter in the Network panel
103 */
104 onlyShowBlockedRequests: 'Only show blocked requests',
105 /**
Danil Somsikov721956a2021-07-07 08:17:27106 *@description Label for a filter in the Network panel
107 */
108 thirdParty: '3rd-party requests',
109 /**
110 *@description Tooltip for a filter in the Network panel
111 */
112 onlyShowThirdPartyRequests: 'Shows only requests with origin different from page origin',
113 /**
Christy Chencac3f102021-02-03 10:07:55114 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
115 */
116 dropHarFilesHere: 'Drop HAR files here',
117 /**
118 *@description Recording text text content in Network Log View of the Network panel
119 */
120 recordingNetworkActivity: 'Recording network activity…',
121 /**
122 *@description Text in Network Log View of the Network panel
123 *@example {Ctrl + R} PH1
124 */
125 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
126 /**
Peter Marshall266ab2e2021-02-16 17:30:49127 *@description Shown in the Network Log View of the Network panel when the user has not yet
Jack Franklin28577db2021-10-14 08:12:53128 * recorded any network activity. This is an instruction to the user to start recording in order to
Peter Marshall266ab2e2021-02-16 17:30:49129 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55130 *@example {Ctrl + E} PH1
131 */
Wolfgang Beyerf4237472021-08-18 14:55:41132 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55133 /**
134 *@description Text that is usually a hyperlink to more documentation
135 */
136 learnMore: 'Learn more',
137 /**
138 *@description Text to announce to screen readers that network data is available.
139 */
140 networkDataAvailable: 'Network Data Available',
141 /**
142 *@description Text in Network Log View of the Network panel
143 *@example {3} PH1
144 *@example {5} PH2
145 */
146 sSRequests: '{PH1} / {PH2} requests',
147 /**
Andres Olivares7fbed142021-03-01 16:22:23148 *@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:53149 * resources transferred during a selected time frame over the compressed size of all resources transferred during
Andres Olivares7fbed142021-03-01 16:22:23150 * the whole network log.
151 *@example {5 B} PH1
152 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55153 */
154 sSTransferred: '{PH1} / {PH2} transferred',
155 /**
Andres Olivares7fbed142021-03-01 16:22:23156 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
Jack Franklin28577db2021-10-14 08:12:53157 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55158 *@example {10} PH1
159 *@example {15} PH2
160 */
161 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
162 /**
Peter Marshall2c3fb302021-02-19 12:47:04163 * @description Text in Network Log View of the Network panel. Appears when a particular network
164 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
165 * total size (PH2).
166 * @example {40MB} PH1
167 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55168 */
169 sSResources: '{PH1} / {PH2} resources',
170 /**
171 *@description Text in Network Log View of the Network panel
172 *@example {40} PH1
173 *@example {50} PH2
174 */
175 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
176 /**
177 *@description Text in Network Log View of the Network panel
178 *@example {6} PH1
179 */
180 sRequests: '{PH1} requests',
181 /**
Andres Olivares0a863ab2021-02-19 15:21:23182 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
183 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55184 *@example {4 B} PH1
185 */
186 sTransferred: '{PH1} transferred',
187 /**
Andres Olivares0a863ab2021-02-19 15:21:23188 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
189 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55190 *@example {4} PH1
191 */
192 sBTransferredOverNetwork: '{PH1} B transferred over network',
193 /**
194 *@description Text in Network Log View of the Network panel
195 *@example {4} PH1
196 */
197 sResources: '{PH1} resources',
198 /**
199 *@description Text in Network Log View of the Network panel
200 *@example {10} PH1
201 */
202 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
203 /**
204 *@description Text in Network Log View of the Network panel
205 *@example {120ms} PH1
206 */
207 finishS: 'Finish: {PH1}',
208 /**
209 *@description Text in Network Log View of the Network panel
210 *@example {3000ms} PH1
211 */
212 domcontentloadedS: 'DOMContentLoaded: {PH1}',
213 /**
214 *@description Text in Network Log View of the Network panel
215 *@example {40ms} PH1
216 */
217 loadS: 'Load: {PH1}',
218 /**
219 *@description Text for copying
220 */
221 copy: 'Copy',
222 /**
223 *@description Text in Network Log View of the Network panel
224 */
225 copyRequestHeaders: 'Copy request headers',
226 /**
227 *@description Text in Network Log View of the Network panel
228 */
229 copyResponseHeaders: 'Copy response headers',
230 /**
231 *@description Text in Network Log View of the Network panel
232 */
233 copyResponse: 'Copy response',
234 /**
235 *@description Text in Network Log View of the Network panel
236 */
Peter Marshallf625dc82021-03-02 08:10:57237 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55238 /**
Peter Marshall3ec813d2021-03-01 19:40:25239 * @description A context menu command in the Network panel, for copying to the clipboard.
240 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55241 */
Peter Marshallb8bd00f2021-02-24 08:25:18242 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55243 /**
Peter Marshall3ec813d2021-03-01 19:40:25244 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
245 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55246 */
Peter Marshallb8bd00f2021-02-24 08:25:18247 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55248 /**
Peter Marshall3ec813d2021-03-01 19:40:25249 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21250 * the developer's clipboard. The command allows the developer to replay this specific network
Jack Franklin28577db2021-10-14 08:12:53251 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
252 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55253 */
Peter Marshallb8bd00f2021-02-24 08:25:18254 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55255 /**
Peter Marshallec861882021-02-16 11:14:21256 *@description Text in Network Log View of the Network panel. An action that copies a command to
257 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
258 *translatable).
Christy Chencac3f102021-02-03 10:07:55259 */
Peter Marshallb8bd00f2021-02-24 08:25:18260 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55261 /**
Peter Marshallec861882021-02-16 11:14:21262 *@description Text in Network Log View of the Network panel. An action that copies a command to
263 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55264 */
Peter Marshallb8bd00f2021-02-24 08:25:18265 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55266 /**
Peter Marshallec861882021-02-16 11:14:21267 *@description Text in Network Log View of the Network panel. An action that copies a command to
268 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55269 */
Peter Marshallb8bd00f2021-02-24 08:25:18270 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55271 /**
Peter Marshallec861882021-02-16 11:14:21272 *@description Text in Network Log View of the Network panel. An action that copies a command to
273 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
274 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55275 */
Peter Marshallb8bd00f2021-02-24 08:25:18276 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55277 /**
Peter Marshallec861882021-02-16 11:14:21278 *@description Text in Network Log View of the Network panel. An action that copies a command to
279 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
280 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55281 */
Peter Marshallb8bd00f2021-02-24 08:25:18282 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55283 /**
Peter Marshallec861882021-02-16 11:14:21284 *@description Text in Network Log View of the Network panel. An action that copies a command to
285 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
286 *translatable).
Christy Chencac3f102021-02-03 10:07:55287 */
Peter Marshallb8bd00f2021-02-24 08:25:18288 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55289 /**
Peter Marshallec861882021-02-16 11:14:21290 *@description Text in Network Log View of the Network panel. An action that copies a command to
291 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55292 */
Peter Marshallb8bd00f2021-02-24 08:25:18293 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55294 /**
Peter Marshallec861882021-02-16 11:14:21295 *@description Text in Network Log View of the Network panel. An action that copies a command to
296 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
297 *translatable).
Christy Chencac3f102021-02-03 10:07:55298 */
Peter Marshallb8bd00f2021-02-24 08:25:18299 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55300 /**
Peter Marshallec861882021-02-16 11:14:21301 *@description Text in Network Log View of the Network panel. An action that copies a command to
302 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
303 *translatable).
Christy Chencac3f102021-02-03 10:07:55304 */
Peter Marshallb8bd00f2021-02-24 08:25:18305 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55306 /**
Peter Marshallb8bd00f2021-02-24 08:25:18307 * @description Text in Network Log View of the Network panel. An action that copies data to the
308 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
Jack Franklin28577db2021-10-14 08:12:53309 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55310 */
Peter Marshallb8bd00f2021-02-24 08:25:18311 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55312 /**
313 *@description A context menu item in the Network Log View of the Network panel
314 */
Peter Marshallb8bd00f2021-02-24 08:25:18315 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55316 /**
317 *@description A context menu item in the Network Log View of the Network panel
318 */
319 clearBrowserCache: 'Clear browser cache',
320 /**
321 *@description A context menu item in the Network Log View of the Network panel
322 */
323 clearBrowserCookies: 'Clear browser cookies',
324 /**
325 *@description A context menu item in the Network Log View of the Network panel
326 */
327 blockRequestUrl: 'Block request URL',
328 /**
329 *@description A context menu item in the Network Log View of the Network panel
330 *@example {example.com} PH1
331 */
332 unblockS: 'Unblock {PH1}',
333 /**
334 *@description A context menu item in the Network Log View of the Network panel
335 */
336 blockRequestDomain: 'Block request domain',
337 /**
Jack Franklin28577db2021-10-14 08:12:53338 *@description Text to replay an XHR request
Christy Chencac3f102021-02-03 10:07:55339 */
340 replayXhr: 'Replay XHR',
341 /**
342 *@description Text in Network Log View of the Network panel
343 */
344 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
345 /**
346 *@description Text in Network Log View of the Network panel
347 */
348 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
349};
Tim van der Lippef596ca02021-03-31 10:02:47350const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55351const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46352
353const enum FetchStyle {
354 Browser = 0,
355 NodeJs = 1,
356}
357
Simon Zünd940cb1f2021-09-16 11:46:09358export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
359 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53360 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
361 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
362 private readonly networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
363 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
364 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
365 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
366 private rawRowHeight: number;
367 private readonly progressBarContainer: Element;
368 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
369 private rowHeightInternal: number;
370 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
371 private readonly durationCalculator: NetworkTransferDurationCalculator;
372 private calculatorInternal: NetworkTransferTimeCalculator;
373 private readonly columns: NetworkLogViewColumns;
374 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
375 private mainRequestLoadTime: number;
376 private mainRequestDOMContentLoadedTime: number;
377 private filters: Filter[];
378 private timeFilter: Filter|null;
379 private hoveredNodeInternal: NetworkNode|null;
380 private recordingHint: Element|null;
381 private refreshRequestId: number|null;
382 private highlightedNode: NetworkRequestNode|null;
383 private readonly linkifierInternal: Components.Linkifier.Linkifier;
384 private recording: boolean;
385 private needsRefresh: boolean;
386 private readonly headerHeightInternal: number;
387 private readonly groupLookups: Map<string, GroupLookupInterface>;
388 private activeGroupLookup: GroupLookupInterface|null;
389 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
390 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
391 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
392 private resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
393 private readonly onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
394 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
395 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI;
396 private readonly filterParser: TextUtils.TextUtils.FilterParser;
397 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
398 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
399 private readonly summaryToolbar: UI.Toolbar.Toolbar;
400 private readonly filterBar: UI.FilterBar.FilterBar;
401 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38402
403 constructor(
404 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
405 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37406 super();
407 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37408
409 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05410 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37411
Jack Franklin28577db2021-10-14 08:12:53412 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('networkInvertFilter', false);
413 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
414 this.networkShowIssuesOnlySetting =
Paul Lewis2d7d65c2020-03-16 17:26:30415 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
Jack Franklin28577db2021-10-14 08:12:53416 this.networkOnlyBlockedRequestsSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30417 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
Jack Franklin28577db2021-10-14 08:12:53418 this.networkOnlyThirdPartySetting =
Danil Somsikov721956a2021-07-07 08:17:27419 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
Jack Franklin28577db2021-10-14 08:12:53420 this.networkResourceTypeFiltersSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30421 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37422
Jack Franklin28577db2021-10-14 08:12:53423 this.rawRowHeight = 0;
424 this.progressBarContainer = progressBarContainer;
425 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
426 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37427
Jan Schefflerd6c1d402021-02-26 16:56:38428 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53429 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
430 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37431 }
Jack Franklin28577db2021-10-14 08:12:53432 this.rawRowHeight = 0;
433 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37434 updateRowHeight.call(this);
435
Jack Franklin28577db2021-10-14 08:12:53436 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
437 this.durationCalculator = new NetworkTransferDurationCalculator();
438 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37439
Jack Franklin28577db2021-10-14 08:12:53440 this.columns = new NetworkLogViewColumns(
441 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
442 this.columns.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37443
Jack Franklin28577db2021-10-14 08:12:53444 this.staleRequests = new Set();
445 this.mainRequestLoadTime = -1;
446 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37447
Jack Franklin28577db2021-10-14 08:12:53448 this.filters = [];
449 this.timeFilter = null;
450 this.hoveredNodeInternal = null;
451 this.recordingHint = null;
452 this.refreshRequestId = null;
453 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37454
Jack Franklin28577db2021-10-14 08:12:53455 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37456
Jack Franklin28577db2021-10-14 08:12:53457 this.recording = false;
458 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37459
Jack Franklin28577db2021-10-14 08:12:53460 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37461
Jack Franklin28577db2021-10-14 08:12:53462 this.groupLookups = new Map();
463 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37464
Jack Franklin28577db2021-10-14 08:12:53465 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37466
Jack Franklin28577db2021-10-14 08:12:53467 this.textFilterUI = new UI.FilterBar.TextFilterUI();
468 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
469 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37470
Jack Franklin28577db2021-10-14 08:12:53471 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
472 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting);
473 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38474 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53475 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
476 filterBar.addFilter(this.invertFilterUI);
Victor Porof66878d62021-07-16 13:12:37477
Jack Franklin28577db2021-10-14 08:12:53478 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
479 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting);
480 this.dataURLFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38481 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53482 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
483 filterBar.addFilter(this.dataURLFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37484
485 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13486 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38487 .map(
488 category =>
489 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Jack Franklin28577db2021-10-14 08:12:53490 this.resourceCategoryFilterUI =
491 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55492 UI.ARIAUtils.setAccessibleName(
Jack Franklin28577db2021-10-14 08:12:53493 this.resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
494 this.resourceCategoryFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38495 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53496 filterBar.addFilter(this.resourceCategoryFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37497
Jack Franklin28577db2021-10-14 08:12:53498 this.onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
499 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this.networkShowIssuesOnlySetting);
500 this.onlyIssuesFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38501 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53502 UI.Tooltip.Tooltip.install(this.onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
503 filterBar.addFilter(this.onlyIssuesFilterUI);
Jan Scheffler1ae7c9e2019-12-03 15:48:37504
Jack Franklin28577db2021-10-14 08:12:53505 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55506 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Jack Franklin28577db2021-10-14 08:12:53507 this.networkOnlyBlockedRequestsSetting);
508 this.onlyBlockedRequestsUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38509 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53510 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
511 filterBar.addFilter(this.onlyBlockedRequestsUI);
Sigurd Schneidera2afe0b2020-03-03 15:27:13512
Jack Franklin28577db2021-10-14 08:12:53513 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
514 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting);
515 this.onlyThirdPartyFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38516 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53517 UI.Tooltip.Tooltip.install(this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
518 filterBar.addFilter(this.onlyThirdPartyFilterUI);
Danil Somsikov721956a2021-07-07 08:17:27519
Jack Franklin28577db2021-10-14 08:12:53520 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
521 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38522 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
523 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37524
Jack Franklin28577db2021-10-14 08:12:53525 this.dataGrid = this.columns.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38526 this.setupDataGrid();
Jack Franklin28577db2021-10-14 08:12:53527 this.columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49528 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53529 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37530
Jack Franklin28577db2021-10-14 08:12:53531 this.summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
532 this.summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37533
Tim van der Lippe0ed1d2b2020-02-04 13:45:13534 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38535 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37536
Paul Lewis2d7d65c2020-03-16 17:26:30537 Common.Settings.Settings.instance()
538 .moduleSetting('networkColorCodeResourceTypes')
Jan Scheffler17b8fb42021-08-12 12:28:38539 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37540
Sigurd Schneiderb9f6c792021-05-31 10:57:24541 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27542 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38543 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27544 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38545 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
546 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37547
Jan Scheffler17b8fb42021-08-12 12:28:38548 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30549 Common.Settings.Settings.instance()
550 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38551 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37552
Jack Franklin28577db2021-10-14 08:12:53553 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03554
Jack Franklin28577db2021-10-14 08:12:53555 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
556 if (this.textFilterSetting.get()) {
557 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03558 }
Blink Reformat4c46d092018-04-07 15:32:37559 }
560
Jan Scheffler17b8fb42021-08-12 12:28:38561 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30562 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38563 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37564 }
565
Jan Scheffler17b8fb42021-08-12 12:28:38566 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16567 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37568 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38569 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
570 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50571 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
572 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37573 });
574 } else {
575 values.sort();
576 }
577 }
578
Jan Scheffler17b8fb42021-08-12 12:28:38579 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37580 return !filter(request);
581 }
582
Jan Scheffler17b8fb42021-08-12 12:28:38583 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34584 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37585 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34586 }
Blink Reformat4c46d092018-04-07 15:32:37587
588 return regex.test(request.path() + '/' + request.name());
589 }
590
Jan Scheffler17b8fb42021-08-12 12:28:38591 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37592 const result = [domain];
593 let indexOfPeriod = domain.indexOf('.');
594 while (indexOfPeriod !== -1) {
595 result.push('*' + domain.substring(indexOfPeriod));
596 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
597 }
598 return result;
599 }
600
Jan Scheffler17b8fb42021-08-12 12:28:38601 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17602 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38603 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37604 }
605
Jan Scheffler17b8fb42021-08-12 12:28:38606 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37607 return regex.test(request.domain);
608 }
609
Jan Scheffler17b8fb42021-08-12 12:28:38610 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37611 return !request.finished;
612 }
613
Jan Scheffler17b8fb42021-08-12 12:28:38614 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37615 return request.cached();
616 }
617
Jan Scheffler17b8fb42021-08-12 12:28:38618 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05619 return request.fetchedViaServiceWorker;
620 }
621
Jan Scheffler17b8fb42021-08-12 12:28:38622 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05623 return request.initiatedByServiceWorker();
624 }
625
Jan Scheffler17b8fb42021-08-12 12:28:38626 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37627 return request.responseHeaderValue(value) !== undefined;
628 }
629
Jan Scheffler17b8fb42021-08-12 12:28:38630 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
631 boolean {
Jack Franklin28577db2021-10-14 08:12:53632 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51633 // filter via `includes` instead of strict equality.
634 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
635 }
636
Jan Scheffler17b8fb42021-08-12 12:28:38637 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37638 return request.requestMethod === value;
639 }
640
Jan Scheffler17b8fb42021-08-12 12:28:38641 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37642 return request.priority() === value;
643 }
644
Jan Scheffler17b8fb42021-08-12 12:28:38645 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37646 return request.mimeType === value;
647 }
648
Jan Scheffler17b8fb42021-08-12 12:28:38649 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16650 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
651 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37652 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28653 }
Sigurd Schneider30722582021-06-16 06:54:16654 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37655 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28656 }
Sigurd Schneider30722582021-06-16 06:54:16657 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37658 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28659 }
Sigurd Schneider30722582021-06-16 06:54:16660 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37661 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34662 }
Blink Reformat4c46d092018-04-07 15:32:37663
664 return false;
665 }
666
Jan Scheffler17b8fb42021-08-12 12:28:38667 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37668 return request.scheme === value;
669 }
670
Jan Scheffler17b8fb42021-08-12 12:28:38671 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41672 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
673 }
674
Jan Scheffler17b8fb42021-08-12 12:28:38675 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41676 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
677 }
678
Jan Scheffler17b8fb42021-08-12 12:28:38679 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54680 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
681 }
682
Jan Scheffler17b8fb42021-08-12 12:28:38683 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41684 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
685 }
686
Jan Scheffler17b8fb42021-08-12 12:28:38687 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41688 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37689 }
690
Jan Scheffler17b8fb42021-08-12 12:28:38691 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41692 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37693 }
694
Jan Scheffler17b8fb42021-08-12 12:28:38695 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41696 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37697 }
698
Jan Scheffler17b8fb42021-08-12 12:28:38699 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37700 return request.transferSize >= value;
701 }
702
Jan Scheffler17b8fb42021-08-12 12:28:38703 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24704 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37705 }
706
Sigurd Schneider576ca9a2021-07-16 05:58:04707 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58708 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37709 }
710
Jan Scheffler17b8fb42021-08-12 12:28:38711 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03712 return request.resourceType().name() === value;
713 }
714
Jan Scheffler17b8fb42021-08-12 12:28:38715 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17716 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03717 return regex.test(request.url());
718 }
719
Jan Scheffler17b8fb42021-08-12 12:28:38720 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38721 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34722 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37723 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34724 }
725 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37726 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34727 }
Blink Reformat4c46d092018-04-07 15:32:37728 return true;
729 }
730
Jan Scheffler17b8fb42021-08-12 12:28:38731 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13732 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37733 }
734
Jan Scheffler17b8fb42021-08-12 12:28:38735 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13736 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37737 }
738
Jan Scheffler17b8fb42021-08-12 12:28:38739 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37740 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38741 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34742 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40743 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37744 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08745 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34746 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13747 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37748 }
749
Jan Scheffler17b8fb42021-08-12 12:28:38750 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37751 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34752 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37753 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34754 }
Simon Zünd99961242021-09-08 11:02:12755 const file = items[0].getAsFile();
756 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03757 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34758 }
Blink Reformat4c46d092018-04-07 15:32:37759 }
760
Jan Schefflerd6c1d402021-02-26 16:56:38761 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13762 const outputStream = new Common.StringOutputStream.StringOutputStream();
763 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37764 const success = await reader.read(outputStream);
765 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37766 const error = reader.error();
767 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38768 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37769 }
Blink Reformat4c46d092018-04-07 15:32:37770 return;
771 }
772 let harRoot;
773 try {
774 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56775 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37776 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38777 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37778 return;
779 }
Tim van der Lippe09cf5032021-04-29 15:08:09780 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37781 }
782
Jan Scheffler17b8fb42021-08-12 12:28:38783 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36784 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37785 }
786
Jan Scheffler17b8fb42021-08-12 12:28:38787 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53788 if (this.activeGroupLookup) {
789 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34790 }
Jack Franklin28577db2021-10-14 08:12:53791 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
792 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38793 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37794 }
795
Jan Scheffler17b8fb42021-08-12 12:28:38796 private computeRowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53797 return Math.round(this.rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
Blink Reformat4c46d092018-04-07 15:32:37798 }
799
Jan Schefflerd6c1d402021-02-26 16:56:38800 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37801 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37802 }
803
Jan Schefflerd6c1d402021-02-26 16:56:38804 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53805 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37806 }
807
Jan Schefflerd6c1d402021-02-26 16:56:38808 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53809 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38810 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37811 }
812
Jan Schefflerd6c1d402021-02-26 16:56:38813 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37814 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34815 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37816 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34817 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13818 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37819 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38820 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37821 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38822 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37823 }
824 }
825
Jan Schefflerd6c1d402021-02-26 16:56:38826 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37827 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13828 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37829 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38830 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37831 resourceTreeModel.removeEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38832 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37833 }
834 }
835 }
836
Jan Schefflerd6c1d402021-02-26 16:56:38837 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53838 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13839 }
840
Jan Schefflerd6c1d402021-02-26 16:56:38841 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37842 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53843 this.timeFilter = null;
844 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37845 } else {
Jack Franklin28577db2021-10-14 08:12:53846 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
847 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37848 }
Jan Scheffler17b8fb42021-08-12 12:28:38849 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37850 }
851
Jan Schefflerd6c1d402021-02-26 16:56:38852 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53853 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37854 }
855
Jan Scheffler17b8fb42021-08-12 12:28:38856 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:53857 this.suggestionBuilder.clear();
858 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
859 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16860 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:53861 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16862 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:53863 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16864 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:53865 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
866 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
867 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
868 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Blink Reformat4c46d092018-04-07 15:32:37869 }
870
Simon Zünda2bae2e2021-09-16 07:57:13871 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:37872 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:53873 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:38874 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:53875 this.textFilterSetting.set(this.textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37876 }
877
Jan Schefflerd6c1d402021-02-26 16:56:38878 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:53879 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:12880 }
881
Jan Scheffler17b8fb42021-08-12 12:28:38882 private showRecordingHint(): void {
883 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:53884 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
885 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18886
Jack Franklin28577db2021-10-14 08:12:53887 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38888 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04889 const reloadShortcut =
890 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
891 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:53892 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:04893 reloadShortcutNode.textContent = reloadShortcut.title();
894 }
895
Blink Reformat4c46d092018-04-07 15:32:37896 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55897 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18898 if (reloadShortcutNode) {
899 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55900 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
901 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18902 }
Blink Reformat4c46d092018-04-07 15:32:37903 } else {
904 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17905 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37906 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55907 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:41908 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37909 }
Kayce Basques5444c1b2019-02-15 20:32:53910 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13911 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35912 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55913 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11914
Jan Scheffler17b8fb42021-08-12 12:28:38915 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37916 }
917
Jan Scheffler17b8fb42021-08-12 12:28:38918 private hideRecordingHint(): void {
919 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:53920 if (this.recordingHint) {
921 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34922 }
Michael Liao7322dee2021-04-07 18:33:30923 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:53924 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37925 }
926
Jan Scheffler17b8fb42021-08-12 12:28:38927 private setHidden(value: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53928 this.columns.setHidden(value);
929 UI.ARIAUtils.setHidden(this.summaryToolbar.element, value);
Amanda Baker6761aae2019-11-05 18:59:11930 }
931
Jan Schefflerd6c1d402021-02-26 16:56:38932 elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:53933 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34934 {
Blink Reformat4c46d092018-04-07 15:32:37935 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34936 }
Jack Franklin28577db2021-10-14 08:12:53937 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:37938 }
939
Jan Schefflerd6c1d402021-02-26 16:56:38940 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:38941 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:37942 }
943
Jan Scheffler17b8fb42021-08-12 12:28:38944 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:53945 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38946 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34947 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37948 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34949 }
Blink Reformat4c46d092018-04-07 15:32:37950 });
Jack Franklin28577db2021-10-14 08:12:53951 this.dataGrid.setStickToBottom(true);
952 this.dataGrid.setName('networkLog');
953 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
954 this.dataGrid.element.classList.add('network-log-grid');
955 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
956 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
957 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
958 this.dataGrid.element.addEventListener('keydown', event => {
959 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
960 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('span.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:43961 if (initiatorLink) {
962 (initiatorLink as HTMLElement).focus();
963 }
964 }
ergunshee4a6132021-11-05 16:21:25965
Brandon Goddard88d885a2019-10-31 16:11:05966 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05967 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05968 event.consume(true);
969 }
970 });
ergunshee4a6132021-11-05 16:21:25971 this.dataGrid.element.addEventListener('keyup', event => {
972 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
973 const request = (this.dataGrid.selectedNode as NetworkNode).request();
974 if (!request) {
975 return;
976 }
977
978 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
979 SDK.NetworkManager.NetworkManager.replayRequest(request);
980 }
981 }
982 });
Jack Franklin28577db2021-10-14 08:12:53983 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
984 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
985 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:37986 }
987
Jan Scheffler17b8fb42021-08-12 12:28:38988 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:38989 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:53990 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:37991 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:38992 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:37993 }
994
Jan Schefflerd6c1d402021-02-26 16:56:38995 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:53996 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:37997 }
998
Jan Scheffler17b8fb42021-08-12 12:28:38999 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531000 if (this.hoveredNodeInternal) {
1001 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341002 }
Jack Franklin28577db2021-10-14 08:12:531003 this.hoveredNodeInternal = node;
1004 if (this.hoveredNodeInternal) {
1005 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 }
Blink Reformat4c46d092018-04-07 15:32:371007 }
1008
Jan Scheffler17b8fb42021-08-12 12:28:381009 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381010 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531011 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371012 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341013 }
Blink Reformat4c46d092018-04-07 15:32:371014 }
1015
Jan Scheffler17b8fb42021-08-12 12:28:381016 private updateSummaryBar(): void {
1017 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371018
1019 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201020 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371021 let selectedNodeNumber = 0;
1022 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201023 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371024 let baseTime = -1;
1025 let maxTime = -1;
1026
1027 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271028 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371029 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341030 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371031 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341032 }
Blink Reformat4c46d092018-04-07 15:32:371033 nodeCount++;
1034 const requestTransferSize = request.transferSize;
1035 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201036 const requestResourceSize = request.resourceSize;
1037 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371038 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371039 selectedNodeNumber++;
1040 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201041 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371042 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131043 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371044 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1045 // inspected url.
1046 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131047 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
1048 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:371049 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341050 }
1051 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371052 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341053 }
Blink Reformat4c46d092018-04-07 15:32:371054 }
1055
1056 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381057 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371058 return;
1059 }
1060
Jack Franklin28577db2021-10-14 08:12:531061 this.summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381062 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131063 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501064 toolbarText.setTitle(title ? title : chunk);
Jack Franklin28577db2021-10-14 08:12:531065 this.summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381066 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501067 };
Blink Reformat4c46d092018-04-07 15:32:371068
1069 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551070 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Jack Franklin28577db2021-10-14 08:12:531071 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501072 appendChunk(
Christy Chencac3f102021-02-03 10:07:551073 i18nString(UIStrings.sSTransferred, {
1074 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381075 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551076 }),
1077 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531078 this.summaryToolbar.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501079 appendChunk(
Christy Chencac3f102021-02-03 10:07:551080 i18nString(UIStrings.sSResources, {
1081 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381082 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551083 }),
1084 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371085 } else {
Christy Chencac3f102021-02-03 10:07:551086 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
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.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1090 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Jack Franklin28577db2021-10-14 08:12:531091 this.summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251092 appendChunk(
Christy Chencac3f102021-02-03 10:07:551093 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1094 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371095 }
Dan Beam87466b52018-12-01 18:41:201096
Blink Reformat4c46d092018-04-07 15:32:371097 if (baseTime !== -1 && maxTime !== -1) {
Jack Franklin28577db2021-10-14 08:12:531098 this.summaryToolbar.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581099 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531100 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
1101 this.summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551102 const domContentLoadedText = i18nString(
1103 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531104 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581105 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371106 }
Jack Franklin28577db2021-10-14 08:12:531107 if (this.mainRequestLoadTime !== -1) {
1108 this.summaryToolbar.appendSeparator();
1109 const loadText =
1110 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581111 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371112 }
1113 }
Blink Reformat4c46d092018-04-07 15:32:371114 }
1115
Jan Schefflerd6c1d402021-02-26 16:56:381116 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531117 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371118 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341119 }
Blink Reformat4c46d092018-04-07 15:32:371120
Jack Franklin28577db2021-10-14 08:12:531121 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371122
Jack Franklin28577db2021-10-14 08:12:531123 if (this.isShowing() && !this.refreshRequestId) {
1124 this.refreshRequestId = this.element.window().requestAnimationFrame(this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341125 }
Blink Reformat4c46d092018-04-07 15:32:371126 }
1127
Jan Schefflerd6c1d402021-02-26 16:56:381128 addFilmStripFrames(times: number[]): void {
Jack Franklin28577db2021-10-14 08:12:531129 this.columns.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371130 }
1131
Jan Schefflerd6c1d402021-02-26 16:56:381132 selectFilmStripFrame(time: number): void {
Jack Franklin28577db2021-10-14 08:12:531133 this.columns.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371134 }
1135
Jan Schefflerd6c1d402021-02-26 16:56:381136 clearFilmStripFrame(): void {
Jack Franklin28577db2021-10-14 08:12:531137 this.columns.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371138 }
1139
Jan Scheffler17b8fb42021-08-12 12:28:381140 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531141 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381142 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341143 }
Blink Reformat4c46d092018-04-07 15:32:371144 }
1145
Jan Scheffler17b8fb42021-08-12 12:28:381146 private invalidateAllItems(deferUpdate?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531147 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341148 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371149 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381151 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341152 }
Blink Reformat4c46d092018-04-07 15:32:371153 }
1154
Jan Schefflerd6c1d402021-02-26 16:56:381155 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531156 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371157 }
1158
Jan Schefflerd6c1d402021-02-26 16:56:381159 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531160 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371161 }
1162
Jan Schefflerd6c1d402021-02-26 16:56:381163 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531164 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371165 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341166 }
Blink Reformat4c46d092018-04-07 15:32:371167
Jack Franklin28577db2021-10-14 08:12:531168 if (this.calculatorInternal !== x) {
1169 this.calculatorInternal = x;
1170 this.columns.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371171 }
Jack Franklin28577db2021-10-14 08:12:531172 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371173
Jack Franklin28577db2021-10-14 08:12:531174 if (this.calculatorInternal.startAtZero) {
1175 this.columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341176 } else {
Jack Franklin28577db2021-10-14 08:12:531177 this.columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341178 }
Blink Reformat4c46d092018-04-07 15:32:371179
Jan Scheffler17b8fb42021-08-12 12:28:381180 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371181 }
1182
Jan Scheffler17b8fb42021-08-12 12:28:381183 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271184 event: Common.EventTarget
1185 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531186 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371187 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341188 }
Blink Reformat4c46d092018-04-07 15:32:371189
Simon Zünd1a930492021-07-30 08:22:271190 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371191 if (time) {
Jack Franklin28577db2021-10-14 08:12:531192 this.mainRequestLoadTime = time;
1193 this.columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371194 }
1195 }
1196
Jan Scheffler17b8fb42021-08-12 12:28:381197 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531198 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371199 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341200 }
Simon Zünd1a930492021-07-30 08:22:271201 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371202 if (data) {
Jack Franklin28577db2021-10-14 08:12:531203 this.mainRequestDOMContentLoadedTime = data;
1204 this.columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371205 }
1206 }
1207
Jan Schefflerd6c1d402021-02-26 16:56:381208 wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381209 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301210 this.registerCSSFiles([networkLogViewStyles]);
Jack Franklin28577db2021-10-14 08:12:531211 this.columns.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371212 }
1213
Jan Schefflerd6c1d402021-02-26 16:56:381214 willHide(): void {
Jack Franklin28577db2021-10-14 08:12:531215 this.columns.willHide();
Blink Reformat4c46d092018-04-07 15:32:371216 }
1217
Jan Schefflerd6c1d402021-02-26 16:56:381218 onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531219 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371220 }
1221
Jan Schefflerd6c1d402021-02-26 16:56:381222 flatNodesList(): NetworkNode[] {
1223 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531224 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381225 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1226 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371227 }
1228
Jan Scheffler17b8fb42021-08-12 12:28:381229 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531230 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351231 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381232 }
Brandon Goddard44934902020-03-25 16:03:181233 this.updateNodeBackground();
1234 }
1235
Jan Scheffler17b8fb42021-08-12 12:28:381236 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181237 this.element.classList.remove('grid-focused');
1238 this.updateNodeBackground();
1239 }
1240
Jan Schefflerd6c1d402021-02-26 16:56:381241 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531242 if (this.dataGrid.selectedNode) {
1243 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051244 }
1245 }
1246
Jan Schefflerd6c1d402021-02-26 16:56:381247 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051248 if (isSelected) {
1249 this.element.classList.remove('no-node-selected');
1250 } else {
1251 this.element.classList.add('no-node-selected');
1252 }
1253 }
1254
Jan Schefflerd6c1d402021-02-26 16:56:381255 stylesChanged(): void {
Jack Franklin28577db2021-10-14 08:12:531256 this.columns.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371257 }
1258
Jan Scheffler17b8fb42021-08-12 12:28:381259 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531260 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371261
Jack Franklin28577db2021-10-14 08:12:531262 if (this.refreshRequestId) {
1263 this.element.window().cancelAnimationFrame(this.refreshRequestId);
1264 this.refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:371265 }
1266
1267 this.removeAllNodeHighlights();
1268
Jack Franklin28577db2021-10-14 08:12:531269 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1270 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1271 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1272 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371273
Jan Schefflerd6c1d402021-02-26 16:56:381274 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1275 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371276
Jan Schefflerd6c1d402021-02-26 16:56:381277 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371278
Jack Franklin28577db2021-10-14 08:12:531279 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371280 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531281 while (this.staleRequests.size) {
1282 const request = this.staleRequests.values().next().value;
1283 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371284 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341285 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381286 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341287 }
Blink Reformat4c46d092018-04-07 15:32:371288 staleNodes.add(node);
1289 }
1290
1291 for (const node of staleNodes) {
Jan Scheffler17b8fb42021-08-12 12:28:381292 const isFilteredOut = !this.applyFilter(node);
Jack Franklin28577db2021-10-14 08:12:531293 if (isFilteredOut && node === this.hoveredNodeInternal) {
Jan Scheffler17b8fb42021-08-12 12:28:381294 this.setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341295 }
Blink Reformat4c46d092018-04-07 15:32:371296
Tim van der Lippe1d6e57a2019-09-30 11:55:341297 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371298 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341299 }
Blink Reformat4c46d092018-04-07 15:32:371300 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531301 this.timeCalculatorInternal.updateBoundaries(request);
1302 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381303 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371304 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1305 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371306 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341307 }
Tim van der Lippe224a8622020-09-23 12:14:371308 if (isFilteredOut) {
1309 filteredNetworkRequests.add(node);
1310 } else {
1311 filteredNetworkRequests.delete(node);
1312 }
Blink Reformat4c46d092018-04-07 15:32:371313 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1314 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381315 let parent: NetworkNode|
1316 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1317 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1318 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111319 if (!parent) {
1320 continue;
1321 }
Blink Reformat4c46d092018-04-07 15:32:371322 parent.removeChild(node);
1323 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381324 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371325 grandparent.removeChild(parent);
1326 parent = grandparent;
1327 }
1328 }
1329
Tim van der Lippe1d6e57a2019-09-30 11:55:341330 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371331 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341332 }
Blink Reformat4c46d092018-04-07 15:32:371333
1334 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531335 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371336 nodesToRefresh.push(newParent);
1337 }
1338 nodesToInsert.set(node, newParent);
1339 }
1340
Tim van der Lippe1d6e57a2019-09-30 11:55:341341 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381342 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341343 }
Blink Reformat4c46d092018-04-07 15:32:371344
Tim van der Lippe1d6e57a2019-09-30 11:55:341345 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371346 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341347 }
Blink Reformat4c46d092018-04-07 15:32:371348
Jan Scheffler17b8fb42021-08-12 12:28:381349 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371350
Tim van der Lippe1d6e57a2019-09-30 11:55:341351 if (nodesToInsert.size) {
Jack Franklin28577db2021-10-14 08:12:531352 this.columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341353 }
Blink Reformat4c46d092018-04-07 15:32:371354
Jack Franklin28577db2021-10-14 08:12:531355 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381356 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371357 }
1358
Jan Scheffler17b8fb42021-08-12 12:28:381359 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371360 }
1361
Jan Scheffler17b8fb42021-08-12 12:28:381362 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531363 if (!this.activeGroupLookup) {
1364 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341365 }
Blink Reformat4c46d092018-04-07 15:32:371366
Jack Franklin28577db2021-10-14 08:12:531367 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341368 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531369 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341370 }
Blink Reformat4c46d092018-04-07 15:32:371371 return groupNode;
1372 }
1373
Jan Scheffler17b8fb42021-08-12 12:28:381374 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151375 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371376
Jan Scheffler17b8fb42021-08-12 12:28:381377 this.setHoveredNode(null);
Jack Franklin28577db2021-10-14 08:12:531378 this.columns.reset();
Blink Reformat4c46d092018-04-07 15:32:371379
Jack Franklin28577db2021-10-14 08:12:531380 this.timeFilter = null;
1381 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371382
Jack Franklin28577db2021-10-14 08:12:531383 this.timeCalculatorInternal.setWindow(null);
1384 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371385
Jack Franklin28577db2021-10-14 08:12:531386 if (this.activeGroupLookup) {
1387 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341388 }
Jack Franklin28577db2021-10-14 08:12:531389 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381390 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371391
Jack Franklin28577db2021-10-14 08:12:531392 this.mainRequestLoadTime = -1;
1393 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371394
Jack Franklin28577db2021-10-14 08:12:531395 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381396 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531397 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371398 this.scheduleRefresh();
1399 }
1400
Jan Schefflerd6c1d402021-02-26 16:56:381401 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531402 this.textFilterUI.setValue(filterString);
1403 this.dataURLFilterUI.setChecked(false);
1404 this.onlyIssuesFilterUI.setChecked(false);
1405 this.onlyBlockedRequestsUI.setChecked(false);
1406 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371407 }
1408
Jan Scheffler17b8fb42021-08-12 12:28:381409 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301410 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371411 networkRequestToNode.set(request, node);
1412 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371413
Tim van der Lippe1d6e57a2019-09-30 11:55:341414 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381415 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341416 }
Blink Reformat4c46d092018-04-07 15:32:371417 return node;
1418 }
1419
Kateryna Prokopenko460f5492021-08-27 08:20:281420 private onRequestUpdated(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1421 const request = event.data;
Jan Scheffler17b8fb42021-08-12 12:28:381422 this.refreshRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371423 }
1424
Jan Scheffler17b8fb42021-08-12 12:28:381425 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1426 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161427 .forEach(
Jack Franklin28577db2021-10-14 08:12:531428 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1429 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1430 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1431 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1432 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1433 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1434 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371435
1436 const priority = request.priority();
1437 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531438 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161439 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371440 }
1441
1442 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531443 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161444 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371445 }
1446
1447 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531448 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161449 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371450 }
1451
1452 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161453 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1454 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531455 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371456 }
1457
1458 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511459 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531460 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511461 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531462 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511463 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341464 }
Jan Scheffler341eea52019-12-12 09:08:411465
1466 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531467 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1468 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1469 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371470 }
1471
Jan Scheffler341eea52019-12-12 09:08:411472 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531473 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1474 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1475 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1476 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411477 }
1478
Jack Franklin28577db2021-10-14 08:12:531479 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371480 this.scheduleRefresh();
1481 }
1482
Jan Schefflerd6c1d402021-02-26 16:56:381483 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531484 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371485 }
1486
Jan Schefflerd6c1d402021-02-26 16:56:381487 switchViewMode(gridMode: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531488 this.columns.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371489 }
1490
Jan Schefflerd6c1d402021-02-26 16:56:381491 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1492 void {
Blink Reformat4c46d092018-04-07 15:32:371493 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551494 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371495 const footerSection = copyMenu.footerSection();
1496 if (request) {
1497 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131498 UI.UIUtils.copyLinkAddressLabel(),
1499 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1500 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371501 if (request.requestHeadersText()) {
1502 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381503 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371504 }
1505
1506 if (request.responseHeadersText) {
1507 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381508 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371509 }
1510
1511 if (request.finished) {
1512 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381513 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371514 }
1515
Tim van der Lippeb4faf5a2020-11-06 15:02:021516 const initiator = request.initiator();
1517
1518 if (initiator) {
1519 const stack = initiator.stack;
1520 if (stack) {
1521 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531522 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021523 // any callFrames, but its parent frames do.
1524 const stackTraceText = computeStackTraceText(stack);
1525 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551526 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021527 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1528 });
1529 }
1530 }
1531 }
1532
Harley Libcf41f92018-09-10 18:01:131533 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131534 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371535 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381536 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371537 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461538 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1539 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291540 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461541 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1542 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371543 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381544 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131545 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381546 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1547 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461548 footerSection.appendItem(
1549 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1550 footerSection.appendItem(
1551 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381552 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this.copyAllCurlCommand.bind(this, 'win'));
1553 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371554 } else {
Harley Libcf41f92018-09-10 18:01:131555 footerSection.appendItem(
Danil Somsikova4b089c2021-11-09 14:32:091556 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
1557 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461558 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1559 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291560 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461561 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1562 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131563 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381564 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Danil Somsikova4b089c2021-11-09 14:32:091565 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461566 footerSection.appendItem(
1567 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1568 footerSection.appendItem(
1569 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381570 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371571 }
1572 } else {
Christy Chencac3f102021-02-03 10:07:551573 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371574 }
Jan Scheffler17b8fb42021-08-12 12:28:381575 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this.copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371576
Christy Chencac3f102021-02-03 10:07:551577 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371578
Jan Scheffler17b8fb42021-08-12 12:28:381579 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371580 contextMenu.editSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381581 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371582
1583 if (request) {
1584 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211585 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371586 let patterns = manager.blockedPatterns();
1587
Jan Schefflerd6c1d402021-02-26 16:56:381588 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201589 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121590 manager.setBlockedPatterns(patterns);
1591 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031592 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121593 }
1594
Jan Schefflerd6c1d402021-02-26 16:56:381595 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121596 patterns = patterns.filter(pattern => pattern.url !== url);
1597 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031598 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121599 }
1600
Blink Reformat4c46d092018-04-07 15:32:371601 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1602 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1603 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551604 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371605 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311606 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371607 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551608 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371609 }
1610
1611 const domain = request.parsedURL.domain();
1612 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1613 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551614 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371615 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311616 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371617 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551618 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371619 }
1620
Tim van der Lippe0ed1d2b2020-02-04 13:45:131621 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371622 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551623 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371624 }
Blink Reformat4c46d092018-04-07 15:32:371625 }
1626 }
1627
Jan Scheffler17b8fb42021-08-12 12:28:381628 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271629 return Logs.NetworkLog.NetworkLog.instance()
1630 .requests()
Sigurd Schneider576ca9a2021-07-16 05:58:041631 .filter(NetworkLogView.getHTTPRequestsFilter)
Sigurd Schneidercf5b8302021-04-23 07:52:271632 .filter(request => {
1633 return request.finished ||
1634 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1635 });
Blink Reformat4c46d092018-04-07 15:32:371636 }
1637
Jan Scheffler17b8fb42021-08-12 12:28:381638 private async copyAll(): Promise<void> {
1639 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131640 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371641 }
1642
Jan Scheffler17b8fb42021-08-12 12:28:381643 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
1644 const command = await this.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131645 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371646 }
1647
Jan Scheffler17b8fb42021-08-12 12:28:381648 private async copyAllCurlCommand(platform: string): Promise<void> {
1649 const commands = await this.generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131650 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371651 }
1652
Danil Somsikov59f4c612021-09-08 10:58:461653 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1654 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131655 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371656 }
1657
Danil Somsikov59f4c612021-09-08 10:58:461658 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
1659 const commands = await this.generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131660 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371661 }
1662
Jan Scheffler17b8fb42021-08-12 12:28:381663 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1664 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131665 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371666 }
1667
Jan Scheffler17b8fb42021-08-12 12:28:381668 private async copyAllPowerShellCommand(): Promise<void> {
1669 const commands = await this.generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131670 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371671 }
1672
Jan Schefflerd6c1d402021-02-26 16:56:381673 async exportAll(): Promise<void> {
Sigurd Schneiderb9f6c792021-05-31 10:57:241674 const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget();
Tim van der Lippe224a8622020-09-23 12:14:371675 if (!mainTarget) {
1676 return;
1677 }
1678 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131679 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321680 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131681 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371682
Kateryna Prokopenko380fdfa2022-03-16 16:39:321683 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371684 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341685 }
Blink Reformat4c46d092018-04-07 15:32:371686
Tim van der Lippe0ed1d2b2020-02-04 13:45:131687 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531688 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381689 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371690 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031691 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371692 }
1693
Jan Scheffler17b8fb42021-08-12 12:28:381694 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551695 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211696 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341697 }
Blink Reformat4c46d092018-04-07 15:32:371698 }
1699
Jan Scheffler17b8fb42021-08-12 12:28:381700 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551701 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211702 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341703 }
Blink Reformat4c46d092018-04-07 15:32:371704 }
1705
Jan Scheffler17b8fb42021-08-12 12:28:381706 private removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371707 this.removeAllNodeHighlights();
Blink Reformat4c46d092018-04-07 15:32:371708 }
1709
Jan Scheffler17b8fb42021-08-12 12:28:381710 private applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371711 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531712 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371713 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341714 }
Christy Chen1825c612021-02-25 10:28:441715 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531716 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371717 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341718 }
Jack Franklin28577db2021-10-14 08:12:531719 if (this.dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371720 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341721 }
Jack Franklin28577db2021-10-14 08:12:531722 if (this.onlyIssuesFilterUI.checked() &&
Juba Borgohain2af14942022-03-02 12:46:151723 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.Cookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371724 return false;
1725 }
Jack Franklin28577db2021-10-14 08:12:531726 if (this.onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131727 return false;
1728 }
Jack Franklin28577db2021-10-14 08:12:531729 if (this.onlyThirdPartyFilterUI.checked() && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271730 return false;
1731 }
Jack Franklin28577db2021-10-14 08:12:531732 for (let i = 0; i < this.filters.length; ++i) {
1733 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371734 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341735 }
Blink Reformat4c46d092018-04-07 15:32:371736 }
1737 return true;
1738 }
1739
Danil Somsikov7a392fb2021-09-13 11:09:461740 private isValidUrl(url: string): boolean {
1741 try {
1742 new URL(url);
1743 return true;
1744 } catch (e) {
1745 return false;
1746 }
1747 }
1748
Jan Scheffler17b8fb42021-08-12 12:28:381749 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531750 // A query string can have multiple filters, some of them regular
1751 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371752 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:531753 // checkbox therefore inverts each one of those individual filters.
1754 const descriptors = this.filterParser.parse(query);
1755 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:371756 const key = descriptor.key;
1757 const text = descriptor.text || '';
1758 const regex = descriptor.regex;
1759 let filter;
1760 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171761 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:381762 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
1763 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371764 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:381765 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:461766 } else if (this.isValidUrl(text)) {
1767 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:371768 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381769 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:171770 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371771 }
Victor Porof66878d62021-07-16 13:12:371772 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:381773 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:371774 }
1775 return filter;
Blink Reformat4c46d092018-04-07 15:32:371776 });
1777 }
1778
Jan Scheffler17b8fb42021-08-12 12:28:381779 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371780 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:161781 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:381782 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371783
Sigurd Schneider30722582021-06-16 06:54:161784 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:381785 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371786
Simon Zünd6dedde52021-08-03 09:04:511787 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:381788 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:511789
Sigurd Schneider30722582021-06-16 06:54:161790 case NetworkForward.UIFilter.FilterType.Is:
1791 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:381792 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341793 }
Sigurd Schneider30722582021-06-16 06:54:161794 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:381795 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341796 }
Sigurd Schneider30722582021-06-16 06:54:161797 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:381798 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341799 }
Sigurd Schneider30722582021-06-16 06:54:161800 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:381801 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341802 }
Blink Reformat4c46d092018-04-07 15:32:371803 break;
1804
Sigurd Schneider30722582021-06-16 06:54:161805 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:381806 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:371807
Sigurd Schneider30722582021-06-16 06:54:161808 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:381809 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371810
Sigurd Schneider30722582021-06-16 06:54:161811 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:381812 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371813
Sigurd Schneider30722582021-06-16 06:54:161814 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:381815 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:161816 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371817
Sigurd Schneider30722582021-06-16 06:54:161818 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:381819 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371820
Sigurd Schneider30722582021-06-16 06:54:161821 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381822 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371823
Sigurd Schneider30722582021-06-16 06:54:161824 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381825 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371826
Sigurd Schneider30722582021-06-16 06:54:161827 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381828 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371829
Sigurd Schneider30722582021-06-16 06:54:161830 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381831 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411832
Sigurd Schneider30722582021-06-16 06:54:161833 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381834 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411835
Sigurd Schneider30722582021-06-16 06:54:161836 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:381837 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:541838
Sigurd Schneider30722582021-06-16 06:54:161839 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381840 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411841
Sigurd Schneider30722582021-06-16 06:54:161842 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:381843 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:501844 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371845
Sigurd Schneider30722582021-06-16 06:54:161846 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:381847 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031848
Sigurd Schneider30722582021-06-16 06:54:161849 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:381850 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031851
Sigurd Schneider30722582021-06-16 06:54:161852 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:381853 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371854 }
1855 return null;
1856 }
1857
Jan Scheffler17b8fb42021-08-12 12:28:381858 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371859 let multiplier = 1;
1860 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541861 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371862 value = value.substring(0, value.length - 1);
1863 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541864 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371865 value = value.substring(0, value.length - 1);
1866 }
1867 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341868 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371869 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341870 }
Jan Scheffler17b8fb42021-08-12 12:28:381871 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371872 }
1873
Jan Scheffler17b8fb42021-08-12 12:28:381874 private filterRequests(): void {
1875 this.removeAllHighlights();
1876 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371877 }
1878
Jan Scheffler17b8fb42021-08-12 12:28:381879 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371880 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371881 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341882 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371883 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341884 }
Brandon Goddard5e4244d2020-04-08 22:08:471885 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:531886 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:471887 // reveal and expand parent to ensure child is revealable.
1888 if (node.parent && node.parent instanceof NetworkGroupNode) {
1889 node.parent.reveal();
1890 node.parent.expand();
1891 }
Blink Reformat4c46d092018-04-07 15:32:371892 node.reveal();
1893 return node;
1894 }
1895
Jan Schefflerd6c1d402021-02-26 16:56:381896 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:381897 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341898 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:381899 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341900 }
Blink Reformat4c46d092018-04-07 15:32:371901 }
1902
Sigurd Schneider722301e2021-06-15 13:41:201903 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:071904 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
1905 if (request) {
1906 this.revealAndHighlightRequest(request);
1907 }
1908 }
1909
Sigurd Schneider14d3e9f2021-06-14 08:29:011910 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
1911 void {
chait pinnamaneni6bc1c122020-10-30 17:30:521912 const defaultOptions = {clearFilter: true};
1913 const {clearFilter} = options || defaultOptions;
1914 if (clearFilter) {
1915 this.setTextFilterValue('');
1916 }
Jan Scheffler17b8fb42021-08-12 12:28:381917 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341918 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371919 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341920 }
Blink Reformat4c46d092018-04-07 15:32:371921 }
1922
Jan Schefflerd6c1d402021-02-26 16:56:381923 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:531924 if (this.highlightedNode) {
1925 this.highlightedNode.element().classList.remove('highlighted-row');
1926 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:371927 }
1928 }
1929
Jan Scheffler17b8fb42021-08-12 12:28:381930 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131931 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:531932 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:371933 }
1934
Jan Scheffler17b8fb42021-08-12 12:28:381935 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131936 return requests.filter(request => !request.isBlobRequest());
1937 }
1938
Danil Somsikov59f4c612021-09-08 10:58:461939 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:381940 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371941 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371942 'method',
1943 'path',
1944 'scheme',
1945 'version',
Blink Reformat4c46d092018-04-07 15:32:371946
1947 // Unsafe headers
1948 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371949 'accept-charset',
1950 'accept-encoding',
1951 'access-control-request-headers',
1952 'access-control-request-method',
1953 'connection',
1954 'content-length',
1955 'cookie',
1956 'cookie2',
1957 'date',
1958 'dnt',
1959 'expect',
1960 'host',
1961 'keep-alive',
1962 'origin',
1963 'referer',
1964 'te',
1965 'trailer',
1966 'transfer-encoding',
1967 'upgrade',
1968 'via',
Blink Reformat4c46d092018-04-07 15:32:371969 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371970 'user-agent',
1971 ]);
Blink Reformat4c46d092018-04-07 15:32:371972
Jan Schefflerd6c1d402021-02-26 16:56:381973 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371974
1975 const url = JSON.stringify(request.url());
1976
1977 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:381978 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:371979 const name = header.name;
1980
Tim van der Lippe224a8622020-09-23 12:14:371981 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371982 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341983 }
Blink Reformat4c46d092018-04-07 15:32:371984
1985 return result;
1986 }, new Headers());
1987
Jan Schefflerd6c1d402021-02-26 16:56:381988 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341989 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411990 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341991 }
Blink Reformat4c46d092018-04-07 15:32:371992
Sigurd Schneider0e88b912020-05-08 08:28:231993 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371994 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411995 'include' :
1996 'omit';
Blink Reformat4c46d092018-04-07 15:32:371997
1998 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1999
2000 const referrer = referrerHeader ? referrerHeader.value : void 0;
2001
2002 const referrerPolicy = request.referrerPolicy() || void 0;
2003
2004 const requestBody = await request.requestFormData();
2005
Jan Schefflerd6c1d402021-02-26 16:56:382006 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412007 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372008 referrer,
2009 referrerPolicy,
2010 body: requestBody,
2011 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372012 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372013 };
2014
Danil Somsikov59f4c612021-09-08 10:58:462015 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292016 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462017 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532018 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462019 // following properties are not implemented in Node.js.
2020 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292021 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462022 extraHeaders['cookie'] = cookieHeader.value;
2023 }
2024 if (referrer) {
2025 delete fetchOptions.referrer;
2026 extraHeaders['Referer'] = referrer;
2027 }
2028 if (referrer) {
2029 delete fetchOptions.referrerPolicy;
2030 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2031 }
2032 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292033 fetchOptions.headers = {
2034 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462035 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292036 };
2037 }
2038 } else {
2039 fetchOptions.credentials = credentials;
2040 }
2041
Jan Scheffler172d5212020-01-02 14:42:562042 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372043 return `fetch(${url}, ${options});`;
2044 }
2045
Danil Somsikov59f4c612021-09-08 10:58:462046 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382047 Promise<string> {
2048 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462049 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132050 return commands.join(' ;\n');
2051 }
2052
Jan Scheffler17b8fb42021-08-12 12:28:382053 private async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382054 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362055 // Most of these headers are derived from the URL and are automatically added by cURL.
2056 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:382057 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372058
Jan Schefflerd6c1d402021-02-26 16:56:382059 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372060 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:382061 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:372062
Jan Schefflerd6c1d402021-02-26 16:56:382063 Because cmd.exe parser and MS Crt arguments parsers use some of the
2064 same escape characters, they can interact with each other in
2065 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372066
Jan Schefflerd6c1d402021-02-26 16:56:382067 Replace \ with \\ first because it is an escape character for certain
2068 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372069
Jan Schefflerd6c1d402021-02-26 16:56:382070 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372071
Jan Schefflerd6c1d402021-02-26 16:56:382072 Then escape all characters we are not sure about with ^ to ensure it
2073 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372074
Jan Schefflerd6c1d402021-02-26 16:56:382075 The % character is special because MS Crt parser will try and look for
2076 ENV variables and fill them in it's place. We cannot escape them with %
2077 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2078 parser); So we can get cmd.exe parser to escape the character after it,
2079 if it is followed by a valid beginning character of an ENV variable.
2080 This ensures we do not try and double escape another ^ if it was placed
2081 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372082
Jan Schefflerd6c1d402021-02-26 16:56:382083 Lastly we replace new lines with ^ and TWO new lines because the first
2084 new line is there to enact the escape command the second is the character
2085 to escape (in this case new line).
2086 */
Blink Reformat4c46d092018-04-07 15:32:372087 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2088 return encapsChars +
2089 str.replace(/\\/g, '\\\\')
2090 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542091 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372092 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542093 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372094 encapsChars;
2095 }
2096
Jan Schefflerd6c1d402021-02-26 16:56:382097 function escapeStringPosix(str: string): string {
2098 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222099 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122100 let hexString = code.toString(16);
2101 // Zero pad to four digits to comply with ANSI-C Quoting:
2102 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342103 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122104 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342105 }
Joey Arhar2d21f712019-05-20 21:07:122106
2107 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372108 }
2109
Mathias Bynensf06e8c02020-02-28 13:58:282110 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372111 // Use ANSI-C quoting syntax.
2112 return '$\'' +
2113 str.replace(/\\/g, '\\\\')
2114 .replace(/\'/g, '\\\'')
2115 .replace(/\n/g, '\\n')
2116 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282117 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372118 '\'';
Blink Reformat4c46d092018-04-07 15:32:372119 }
Mathias Bynensf06e8c02020-02-28 13:58:282120 // Use single quote syntax.
2121 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372122 }
2123
2124 // cURL command expected to run on the same platform that DevTools run
2125 // (it may be different from the inspected page platform).
2126 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2127
2128 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2129
2130 let inferredMethod = 'GET';
2131 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372132 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082133 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272134 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532135 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272136 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372137 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372138 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372139 }
2140
2141 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292142 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372143 }
2144
2145 const requestHeaders = request.requestHeaders();
2146 for (let i = 0; i < requestHeaders.length; i++) {
2147 const header = requestHeaders[i];
2148 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372149 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372150 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342151 }
Jan Scheffler172d5212020-01-02 14:42:562152 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372153 }
2154 command = command.concat(data);
2155 command.push('--compressed');
2156
Tim van der Lippe1d6e57a2019-09-30 11:55:342157 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372158 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342159 }
Jan Scheffler172d5212020-01-02 14:42:562160 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372161 }
2162
Jan Scheffler17b8fb42021-08-12 12:28:382163 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string):
2164 Promise<string> {
2165 const nonBlobRequests = this.filterOutBlobRequests(requests);
2166 const commands = await Promise.all(nonBlobRequests.map(request => this.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342167 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132168 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342169 }
Mathias Bynensf06e8c02020-02-28 13:58:282170 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132171 }
2172
Jan Scheffler17b8fb42021-08-12 12:28:382173 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562174 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242175 const ignoredHeaders = new Set<string>([
2176 'host',
2177 'connection',
2178 'proxy-connection',
2179 'content-length',
2180 'expect',
2181 'range',
2182 'content-type',
2183 'user-agent',
2184 'cookie',
2185 ]);
Blink Reformat4c46d092018-04-07 15:32:372186
Jan Schefflerd6c1d402021-02-26 16:56:382187 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372188 return '"' +
2189 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2190 }
2191
Brandon Walderman153b8d72021-06-28 18:45:242192 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2193 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2194 // command does not allow setting these headers through the -Headers parameter. See docs at:
2195 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2196 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2197 const requestHeaders = request.requestHeaders();
2198 const props = [];
2199
2200 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2201 if (userAgentHeader) {
2202 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2203 }
2204
2205 for (const cookie of request.includedRequestCookies()) {
2206 const name = escapeString(cookie.name());
2207 const value = escapeString(cookie.value());
2208 const domain = escapeString(cookie.domain());
2209 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2210 }
2211
2212 if (props.length) {
2213 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2214 }
2215
2216 return null;
2217 }
2218
Jan Scheffler172d5212020-01-02 14:42:562219 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372220
2221 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562222 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372223 }
2224
Brandon Walderman153b8d72021-06-28 18:45:242225 const session = generatePowerShellSession(request);
2226 if (session) {
2227 command.push('-WebSession $session');
2228 }
2229
Blink Reformat4c46d092018-04-07 15:32:372230 const requestHeaders = request.requestHeaders();
2231 const headerNameValuePairs = [];
2232 for (const header of requestHeaders) {
2233 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342234 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372235 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342236 }
Blink Reformat4c46d092018-04-07 15:32:372237 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2238 }
2239 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562240 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372241 }
2242
2243 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2244 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562245 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372246 }
2247
2248 const formData = await request.requestFormData();
2249 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372250 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342251 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562252 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342253 } else {
Jan Scheffler172d5212020-01-02 14:42:562254 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342255 }
Blink Reformat4c46d092018-04-07 15:32:372256 }
2257
Brandon Walderman153b8d72021-06-28 18:45:242258 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2259 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2260 // compatibility only.
2261 const prelude = session || '';
2262 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372263 }
Harley Libcf41f92018-09-10 18:01:132264
Jan Scheffler17b8fb42021-08-12 12:28:382265 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2266 const nonBlobRequests = this.filterOutBlobRequests(requests);
2267 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132268 return commands.join(';\r\n');
2269 }
Joey Arhara86c14e2019-03-12 03:20:502270
Jan Schefflerd6c1d402021-02-26 16:56:382271 static getDCLEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052272 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-3');
Joey Arhara86c14e2019-03-12 03:20:502273 }
2274
Jan Schefflerd6c1d402021-02-26 16:56:382275 static getLoadEventColor(): string {
Paul Lewisc929b612021-12-15 11:31:052276 return ThemeSupport.ThemeSupport.instance().getComputedValue('--color-syntax-1');
Joey Arhara86c14e2019-03-12 03:20:502277 }
Paul Lewis56509652019-12-06 12:51:582278}
Blink Reformat4c46d092018-04-07 15:32:372279
Jan Schefflerd6c1d402021-02-26 16:56:382280export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022281 let stackTraceText = '';
2282 for (const frame of stackTrace.callFrames) {
2283 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2284 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2285 }
2286 if (stackTrace.parent) {
2287 stackTraceText += computeStackTraceText(stackTrace.parent);
2288 }
2289 return stackTraceText;
2290}
2291
Jan Schefflerd6c1d402021-02-26 16:56:382292const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2293const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372294
Jan Schefflerd6c1d402021-02-26 16:56:382295export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372296 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222297}
2298
Paul Lewis56509652019-12-06 12:51:582299export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372300 'http': true,
2301 'https': true,
2302 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382303 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372304};
2305
Sigurd Schneider576ca9a2021-07-16 05:58:042306const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382307
2308export interface GroupLookupInterface {
2309 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2310 reset(): void;
2311}
2312
2313export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;