blob: 08bedb8a11ea639022863b081e772a6d1a720785 [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
Jan Schefflerd6c1d402021-02-26 16:56:3835/* eslint-disable rulesdir/no_underscored_properties */
36
Tim van der Lippe76961572021-04-06 10:48:0737import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3038import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2839import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2740import * as Platform from '../../core/platform/platform.js';
Tim van der Lippee00b92f2021-03-31 16:52:1741import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0542import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5943import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5644import * as HAR from '../../models/har/har.js';
Sigurd Schneider055e2e32021-04-12 11:10:4245import * as IssuesManager from '../../models/issues_manager/issues_manager.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2746import * as Logs from '../../models/logs/logs.js';
Tim van der Lippefca98ed2021-04-08 14:10:1447import * as TextUtils from '../../models/text_utils/text_utils.js';
Tim van der Lippe8499fe22021-04-12 16:42:4748import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1449import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3650import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0751import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippefddcf402021-04-19 13:00:2952import * as ThemeSupport from '../../ui/legacy/theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1353
Jack Franklina75ae7c2021-05-11 13:22:5454import type {NetworkLogViewInterface, NetworkNode} from './NetworkDataGridNode.js';
55import {Events, NetworkGroupNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe119690c2020-01-13 12:31:3056import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
57import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Franklina75ae7c2021-05-11 13:22:5458import type {FilterOptions} from './NetworkPanel.js'; // eslint-disable-line no-unused-vars
59import type {NetworkTimeCalculator} from './NetworkTimeCalculator.js';
60import {NetworkTimeBoundary, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
Danil Somsikov0c13d2d2021-06-10 15:02:0761import type {NetworkRequestId} from './NetworkRequestId.js';
Tim van der Lippe119690c2020-01-13 12:31:3062
Simon Zünd34490692021-03-01 08:25:1863const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5564 /**
65 *@description Text in Network Log View of the Network panel
66 */
67 hideDataUrls: 'Hide data URLs',
68 /**
69 *@description Data urlfilter ui element title in Network Log View of the Network panel
70 */
71 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
72 /**
73 *@description Aria accessible name in Network Log View of the Network panel
74 */
75 resourceTypesToInclude: 'Resource types to include',
76 /**
77 *@description Label for a filter in the Network panel
78 */
79 hasBlockedCookies: 'Has blocked cookies',
80 /**
Simon Zünd562d32c2021-02-17 09:22:5481 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
82 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
83 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:5584 */
85 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
86 /**
87 *@description Label for a filter in the Network panel
88 */
89 blockedRequests: 'Blocked Requests',
90 /**
91 *@description Tooltip for a filter in the Network panel
92 */
93 onlyShowBlockedRequests: 'Only show blocked requests',
94 /**
95 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
96 */
97 dropHarFilesHere: 'Drop HAR files here',
98 /**
99 *@description Recording text text content in Network Log View of the Network panel
100 */
101 recordingNetworkActivity: 'Recording network activity…',
102 /**
103 *@description Text in Network Log View of the Network panel
104 *@example {Ctrl + R} PH1
105 */
106 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
107 /**
Peter Marshall266ab2e2021-02-16 17:30:49108 *@description Shown in the Network Log View of the Network panel when the user has not yet
109 * recorded any network activity. This is an instruction to the user to start recording in order to
110 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55111 *@example {Ctrl + E} PH1
112 */
113 recordSToDisplayNetworkActivity: 'Record ({PH1}) to display network activity.',
114 /**
115 *@description Text that is usually a hyperlink to more documentation
116 */
117 learnMore: 'Learn more',
118 /**
119 *@description Text to announce to screen readers that network data is available.
120 */
121 networkDataAvailable: 'Network Data Available',
122 /**
123 *@description Text in Network Log View of the Network panel
124 *@example {3} PH1
125 *@example {5} PH2
126 */
127 sSRequests: '{PH1} / {PH2} requests',
128 /**
Andres Olivares7fbed142021-03-01 16:22:23129 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
130 * resources transferred during a selected time frame over the compressed size of all resources transferred during
131 * the whole network log.
132 *@example {5 B} PH1
133 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55134 */
135 sSTransferred: '{PH1} / {PH2} transferred',
136 /**
Andres Olivares7fbed142021-03-01 16:22:23137 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
138 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55139 *@example {10} PH1
140 *@example {15} PH2
141 */
142 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
143 /**
Peter Marshall2c3fb302021-02-19 12:47:04144 * @description Text in Network Log View of the Network panel. Appears when a particular network
145 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
146 * total size (PH2).
147 * @example {40MB} PH1
148 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55149 */
150 sSResources: '{PH1} / {PH2} resources',
151 /**
152 *@description Text in Network Log View of the Network panel
153 *@example {40} PH1
154 *@example {50} PH2
155 */
156 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
157 /**
158 *@description Text in Network Log View of the Network panel
159 *@example {6} PH1
160 */
161 sRequests: '{PH1} requests',
162 /**
Andres Olivares0a863ab2021-02-19 15:21:23163 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
164 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55165 *@example {4 B} PH1
166 */
167 sTransferred: '{PH1} transferred',
168 /**
Andres Olivares0a863ab2021-02-19 15:21:23169 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
170 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55171 *@example {4} PH1
172 */
173 sBTransferredOverNetwork: '{PH1} B transferred over network',
174 /**
175 *@description Text in Network Log View of the Network panel
176 *@example {4} PH1
177 */
178 sResources: '{PH1} resources',
179 /**
180 *@description Text in Network Log View of the Network panel
181 *@example {10} PH1
182 */
183 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
184 /**
185 *@description Text in Network Log View of the Network panel
186 *@example {120ms} PH1
187 */
188 finishS: 'Finish: {PH1}',
189 /**
190 *@description Text in Network Log View of the Network panel
191 *@example {3000ms} PH1
192 */
193 domcontentloadedS: 'DOMContentLoaded: {PH1}',
194 /**
195 *@description Text in Network Log View of the Network panel
196 *@example {40ms} PH1
197 */
198 loadS: 'Load: {PH1}',
199 /**
200 *@description Text for copying
201 */
202 copy: 'Copy',
203 /**
204 *@description Text in Network Log View of the Network panel
205 */
206 copyRequestHeaders: 'Copy request headers',
207 /**
208 *@description Text in Network Log View of the Network panel
209 */
210 copyResponseHeaders: 'Copy response headers',
211 /**
212 *@description Text in Network Log View of the Network panel
213 */
214 copyResponse: 'Copy response',
215 /**
216 *@description Text in Network Log View of the Network panel
217 */
Peter Marshallf625dc82021-03-02 08:10:57218 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55219 /**
Peter Marshall3ec813d2021-03-01 19:40:25220 * @description A context menu command in the Network panel, for copying to the clipboard.
221 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55222 */
Peter Marshallb8bd00f2021-02-24 08:25:18223 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55224 /**
Peter Marshall3ec813d2021-03-01 19:40:25225 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
226 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55227 */
Peter Marshallb8bd00f2021-02-24 08:25:18228 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55229 /**
Peter Marshall3ec813d2021-03-01 19:40:25230 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21231 * the developer's clipboard. The command allows the developer to replay this specific network
232 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
233 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55234 */
Peter Marshallb8bd00f2021-02-24 08:25:18235 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55236 /**
Peter Marshallec861882021-02-16 11:14:21237 *@description Text in Network Log View of the Network panel. An action that copies a command to
238 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
239 *translatable).
Christy Chencac3f102021-02-03 10:07:55240 */
Peter Marshallb8bd00f2021-02-24 08:25:18241 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55242 /**
Peter Marshallec861882021-02-16 11:14:21243 *@description Text in Network Log View of the Network panel. An action that copies a command to
244 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55245 */
Peter Marshallb8bd00f2021-02-24 08:25:18246 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55247 /**
Peter Marshallec861882021-02-16 11:14:21248 *@description Text in Network Log View of the Network panel. An action that copies a command to
249 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55250 */
Peter Marshallb8bd00f2021-02-24 08:25:18251 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55252 /**
Peter Marshallec861882021-02-16 11:14:21253 *@description Text in Network Log View of the Network panel. An action that copies a command to
254 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
255 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55256 */
Peter Marshallb8bd00f2021-02-24 08:25:18257 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55258 /**
Peter Marshallec861882021-02-16 11:14:21259 *@description Text in Network Log View of the Network panel. An action that copies a command to
260 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
261 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55262 */
Peter Marshallb8bd00f2021-02-24 08:25:18263 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55264 /**
Peter Marshallec861882021-02-16 11:14:21265 *@description Text in Network Log View of the Network panel. An action that copies a command to
266 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
267 *translatable).
Christy Chencac3f102021-02-03 10:07:55268 */
Peter Marshallb8bd00f2021-02-24 08:25:18269 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55270 /**
Peter Marshallec861882021-02-16 11:14:21271 *@description Text in Network Log View of the Network panel. An action that copies a command to
272 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55273 */
Peter Marshallb8bd00f2021-02-24 08:25:18274 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55275 /**
Peter Marshallec861882021-02-16 11:14:21276 *@description Text in Network Log View of the Network panel. An action that copies a command to
277 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
278 *translatable).
Christy Chencac3f102021-02-03 10:07:55279 */
Peter Marshallb8bd00f2021-02-24 08:25:18280 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55281 /**
Peter Marshallec861882021-02-16 11:14:21282 *@description Text in Network Log View of the Network panel. An action that copies a command to
283 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
284 *translatable).
Christy Chencac3f102021-02-03 10:07:55285 */
Peter Marshallb8bd00f2021-02-24 08:25:18286 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55287 /**
Peter Marshallb8bd00f2021-02-24 08:25:18288 * @description Text in Network Log View of the Network panel. An action that copies data to the
289 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
290 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55291 */
Peter Marshallb8bd00f2021-02-24 08:25:18292 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55293 /**
294 *@description A context menu item in the Network Log View of the Network panel
295 */
Peter Marshallb8bd00f2021-02-24 08:25:18296 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55297 /**
298 *@description A context menu item in the Network Log View of the Network panel
299 */
300 clearBrowserCache: 'Clear browser cache',
301 /**
302 *@description A context menu item in the Network Log View of the Network panel
303 */
304 clearBrowserCookies: 'Clear browser cookies',
305 /**
306 *@description A context menu item in the Network Log View of the Network panel
307 */
308 blockRequestUrl: 'Block request URL',
309 /**
310 *@description A context menu item in the Network Log View of the Network panel
311 *@example {example.com} PH1
312 */
313 unblockS: 'Unblock {PH1}',
314 /**
315 *@description A context menu item in the Network Log View of the Network panel
316 */
317 blockRequestDomain: 'Block request domain',
318 /**
319 *@description Text to replay an XHR request
320 */
321 replayXhr: 'Replay XHR',
322 /**
323 *@description Text in Network Log View of the Network panel
324 */
325 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
326 /**
327 *@description Text in Network Log View of the Network panel
328 */
329 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
330};
Tim van der Lippef596ca02021-03-31 10:02:47331const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55332const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Jan Schefflerd6c1d402021-02-26 16:56:38333export class NetworkLogView extends UI.Widget.VBox implements
Sigurd Schneiderb9f6c792021-05-31 10:57:24334 SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jan Schefflerd6c1d402021-02-26 16:56:38335 _networkHideDataURLSetting: Common.Settings.Setting<boolean>;
336 _networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
337 _networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
338 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
339 // eslint-disable-next-line @typescript-eslint/no-explicit-any
340 _networkResourceTypeFiltersSetting: Common.Settings.Setting<any>;
341 _rawRowHeight: number;
342 _progressBarContainer: Element;
343 _networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
344 _rowHeight: number;
345 _timeCalculator: NetworkTransferTimeCalculator;
346 _durationCalculator: NetworkTransferDurationCalculator;
347 _calculator: NetworkTransferTimeCalculator;
348 _columns: NetworkLogViewColumns;
349 _staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
350 _mainRequestLoadTime: number;
351 _mainRequestDOMContentLoadedTime: number;
352 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
353 // eslint-disable-next-line @typescript-eslint/no-explicit-any
354 _highlightedSubstringChanges: any;
355 _filters: Filter[];
356 _timeFilter: Filter|null;
357 _hoveredNode: NetworkNode|null;
358 _recordingHint: Element|null;
359 _refreshRequestId: number|null;
360 _highlightedNode: NetworkRequestNode|null;
361 _linkifier: Components.Linkifier.Linkifier;
362 _recording: boolean;
363 _needsRefresh: boolean;
364 _headerHeight: number;
365 _groupLookups: Map<string, GroupLookupInterface>;
366 _activeGroupLookup: GroupLookupInterface|null;
367 _textFilterUI: UI.FilterBar.TextFilterUI;
368 _dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
369 _resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
370 _onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
371 _onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
372 _filterParser: TextUtils.TextUtils.FilterParser;
373 _suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
374 _dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
375 _summaryToolbar: UI.Toolbar.Toolbar;
376 _filterBar: UI.FilterBar.FilterBar;
377 _textFilterSetting: Common.Settings.Setting<string>;
378
379 constructor(
380 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
381 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37382 super();
383 this.setMinimumSize(50, 64);
Jack Franklina0685ef2021-05-17 11:14:10384 this.registerRequiredCSS('panels/network/networkLogView.css', {enableLegacyPatching: false});
Blink Reformat4c46d092018-04-07 15:32:37385
386 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05387 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37388
Paul Lewis2d7d65c2020-03-16 17:26:30389 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
390 this._networkShowIssuesOnlySetting =
391 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
392 this._networkOnlyBlockedRequestsSetting =
393 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
394 this._networkResourceTypeFiltersSetting =
395 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37396
397 this._rawRowHeight = 0;
398 this._progressBarContainer = progressBarContainer;
399 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
400 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
401
Jan Schefflerd6c1d402021-02-26 16:56:38402 function updateRowHeight(this: NetworkLogView): void {
Tim van der Lipped7cfd142021-01-07 12:17:24403 this._rawRowHeight = Boolean(this._networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:37404 this._rowHeight = this._computeRowHeight();
405 }
406 this._rawRowHeight = 0;
407 this._rowHeight = 0;
408 updateRowHeight.call(this);
409
Tim van der Lippe119690c2020-01-13 12:31:30410 this._timeCalculator = new NetworkTransferTimeCalculator();
Tim van der Lippe119690c2020-01-13 12:31:30411 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:37412 this._calculator = this._timeCalculator;
413
Tim van der Lippe119690c2020-01-13 12:31:30414 this._columns =
Jan Schefflerd6c1d402021-02-26 16:56:38415 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
416 // @ts-expect-error
Tim van der Lippe119690c2020-01-13 12:31:30417 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37418 this._columns.show(this.element);
419
Blink Reformat4c46d092018-04-07 15:32:37420 this._staleRequests = new Set();
Blink Reformat4c46d092018-04-07 15:32:37421 this._mainRequestLoadTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37422 this._mainRequestDOMContentLoadedTime = -1;
423 this._highlightedSubstringChanges = [];
424
Blink Reformat4c46d092018-04-07 15:32:37425 this._filters = [];
Blink Reformat4c46d092018-04-07 15:32:37426 this._timeFilter = null;
Blink Reformat4c46d092018-04-07 15:32:37427 this._hoveredNode = null;
Blink Reformat4c46d092018-04-07 15:32:37428 this._recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37429 this._refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:37430 this._highlightedNode = null;
431
Simon Zündcdd72c92020-10-07 11:48:13432 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37433
434 this._recording = false;
435 this._needsRefresh = false;
436
437 this._headerHeight = 0;
438
Blink Reformat4c46d092018-04-07 15:32:37439 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30440 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37441
Blink Reformat4c46d092018-04-07 15:32:37442 this._activeGroupLookup = null;
443
Tim van der Lippe0ed1d2b2020-02-04 13:45:13444 this._textFilterUI = new UI.FilterBar.TextFilterUI();
445 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37446 filterBar.addFilter(this._textFilterUI);
447
Tim van der Lippe0ed1d2b2020-02-04 13:45:13448 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55449 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this._networkHideDataURLSetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13450 this._dataURLFilterUI.addEventListener(
451 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55452 UI.Tooltip.Tooltip.install(this._dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
Blink Reformat4c46d092018-04-07 15:32:37453 filterBar.addFilter(this._dataURLFilterUI);
454
455 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13456 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38457 .map(
458 category =>
459 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13460 this._resourceCategoryFilterUI =
461 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55462 UI.ARIAUtils.setAccessibleName(
463 this._resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
Blink Reformat4c46d092018-04-07 15:32:37464 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13465 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37466 filterBar.addFilter(this._resourceCategoryFilterUI);
467
Tim van der Lippe0ed1d2b2020-02-04 13:45:13468 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55469 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this._networkShowIssuesOnlySetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13470 this._onlyIssuesFilterUI.addEventListener(
471 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55472 UI.Tooltip.Tooltip.install(this._onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
Jan Scheffler1ae7c9e2019-12-03 15:48:37473 filterBar.addFilter(this._onlyIssuesFilterUI);
474
Sigurd Schneidera2afe0b2020-03-03 15:27:13475 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55476 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
477 this._networkOnlyBlockedRequestsSetting);
Sigurd Schneidera2afe0b2020-03-03 15:27:13478 this._onlyBlockedRequestsUI.addEventListener(
479 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55480 UI.Tooltip.Tooltip.install(this._onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
Sigurd Schneidera2afe0b2020-03-03 15:27:13481 filterBar.addFilter(this._onlyBlockedRequestsUI);
482
Tim van der Lippe0ed1d2b2020-02-04 13:45:13483 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
484 this._suggestionBuilder =
485 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37486 this._resetSuggestionBuilder();
487
488 this._dataGrid = this._columns.dataGrid();
489 this._setupDataGrid();
490 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49491 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13492 UI.Toolbar.ToolbarButton.Events.Click,
493 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37494
Tim van der Lippe0ed1d2b2020-02-04 13:45:13495 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
chait pinnamaneni83f4b6b2021-04-08 16:27:05496 this._summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37497
Tim van der Lippe0ed1d2b2020-02-04 13:45:13498 new UI.DropTarget.DropTarget(
Christy Chencac3f102021-02-03 10:07:55499 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37500
Paul Lewis2d7d65c2020-03-16 17:26:30501 Common.Settings.Settings.instance()
502 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37503 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
504
Sigurd Schneiderb9f6c792021-05-31 10:57:24505 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27506 Logs.NetworkLog.NetworkLog.instance().addEventListener(
507 Logs.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
508 Logs.NetworkLog.NetworkLog.instance().addEventListener(
509 Logs.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
510 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37511
512 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30513 Common.Settings.Settings.instance()
514 .moduleSetting('network.group-by-frame')
515 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37516
517 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03518
519 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
520 if (this._textFilterSetting.get()) {
Jack Franklinec064412020-12-08 13:02:24521 this._textFilterUI.setValue(this._textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03522 }
Blink Reformat4c46d092018-04-07 15:32:37523 }
524
Jan Schefflerd6c1d402021-02-26 16:56:38525 _updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30526 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37527 this._setGrouping(value ? 'Frame' : null);
528 }
529
Jan Schefflerd6c1d402021-02-26 16:56:38530 static _sortSearchValues(key: string, values: string[]): void {
Paul Lewis56509652019-12-06 12:51:58531 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37532 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38533 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
534 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50535 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
536 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37537 });
538 } else {
539 values.sort();
540 }
541 }
542
Jan Schefflerd6c1d402021-02-26 16:56:38543 static _negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37544 return !filter(request);
545 }
546
Jan Schefflerd6c1d402021-02-26 16:56:38547 static _requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34548 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37549 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34550 }
Blink Reformat4c46d092018-04-07 15:32:37551
552 return regex.test(request.path() + '/' + request.name());
553 }
554
Jan Schefflerd6c1d402021-02-26 16:56:38555 static _subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37556 const result = [domain];
557 let indexOfPeriod = domain.indexOf('.');
558 while (indexOfPeriod !== -1) {
559 result.push('*' + domain.substring(indexOfPeriod));
560 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
561 }
562 return result;
563 }
564
Jan Schefflerd6c1d402021-02-26 16:56:38565 static _createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17566 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58567 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37568 }
569
Jan Schefflerd6c1d402021-02-26 16:56:38570 static _requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37571 return regex.test(request.domain);
572 }
573
Jan Schefflerd6c1d402021-02-26 16:56:38574 static _runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37575 return !request.finished;
576 }
577
Jan Schefflerd6c1d402021-02-26 16:56:38578 static _fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37579 return request.cached();
580 }
581
Jan Schefflerd6c1d402021-02-26 16:56:38582 static _interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05583 return request.fetchedViaServiceWorker;
584 }
585
Jan Schefflerd6c1d402021-02-26 16:56:38586 static _initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05587 return request.initiatedByServiceWorker();
588 }
589
Jan Schefflerd6c1d402021-02-26 16:56:38590 static _requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37591 return request.responseHeaderValue(value) !== undefined;
592 }
593
Jan Schefflerd6c1d402021-02-26 16:56:38594 static _requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37595 return request.requestMethod === value;
596 }
597
Jan Schefflerd6c1d402021-02-26 16:56:38598 static _requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37599 return request.priority() === value;
600 }
601
Jan Schefflerd6c1d402021-02-26 16:56:38602 static _requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37603 return request.mimeType === value;
604 }
605
Jan Schefflerd6c1d402021-02-26 16:56:38606 static _requestMixedContentFilter(value: MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest):
607 boolean {
Paul Lewis56509652019-12-06 12:51:58608 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37609 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28610 }
611 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37612 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28613 }
614 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37615 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28616 }
617 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37618 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34619 }
Blink Reformat4c46d092018-04-07 15:32:37620
621 return false;
622 }
623
Jan Schefflerd6c1d402021-02-26 16:56:38624 static _requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37625 return request.scheme === value;
626 }
627
Jan Schefflerd6c1d402021-02-26 16:56:38628 static _requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41629 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
630 }
631
Jan Schefflerd6c1d402021-02-26 16:56:38632 static _requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41633 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
634 }
635
Jan Schefflerd6c1d402021-02-26 16:56:38636 static _requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54637 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
638 }
639
Jan Schefflerd6c1d402021-02-26 16:56:38640 static _requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41641 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
642 }
643
Jan Schefflerd6c1d402021-02-26 16:56:38644 static _requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41645 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37646 }
647
Jan Schefflerd6c1d402021-02-26 16:56:38648 static _requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41649 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37650 }
651
Jan Schefflerd6c1d402021-02-26 16:56:38652 static _requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41653 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37654 }
655
Jan Schefflerd6c1d402021-02-26 16:56:38656 static _requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37657 return request.transferSize >= value;
658 }
659
Jan Schefflerd6c1d402021-02-26 16:56:38660 static _statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24661 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37662 }
663
Jan Schefflerd6c1d402021-02-26 16:56:38664 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
665 // eslint-disable-next-line @typescript-eslint/naming-convention
666 static HTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58667 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37668 }
669
Jan Schefflerd6c1d402021-02-26 16:56:38670 static _resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03671 return request.resourceType().name() === value;
672 }
673
Jan Schefflerd6c1d402021-02-26 16:56:38674 static _requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17675 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03676 return regex.test(request.url());
677 }
678
Jan Schefflerd6c1d402021-02-26 16:56:38679 static _requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
680 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34681 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37682 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34683 }
684 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37685 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34686 }
Blink Reformat4c46d092018-04-07 15:32:37687 return true;
688 }
689
Jan Schefflerd6c1d402021-02-26 16:56:38690 static _copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13691 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37692 }
693
Jan Schefflerd6c1d402021-02-26 16:56:38694 static _copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13695 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37696 }
697
Jan Schefflerd6c1d402021-02-26 16:56:38698 static async _copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37699 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38700 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40702 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37703 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08704 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34705 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13706 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37707 }
708
Jan Schefflerd6c1d402021-02-26 16:56:38709 _handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37710 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34711 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37712 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34713 }
Blink Reformat4c46d092018-04-07 15:32:37714 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34715 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37716 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34717 }
Blink Reformat4c46d092018-04-07 15:32:37718
Joey Arhar0e1093c2019-05-21 00:34:22719 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37720 }
721
Jan Schefflerd6c1d402021-02-26 16:56:38722 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13723 const outputStream = new Common.StringOutputStream.StringOutputStream();
724 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37725 const success = await reader.read(outputStream);
726 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37727 const error = reader.error();
728 if (error) {
Jan Schefflerd6c1d402021-02-26 16:56:38729 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
730 // eslint-disable-next-line @typescript-eslint/no-explicit-any
731 this._harLoadFailed((error as any).message);
Tim van der Lippe224a8622020-09-23 12:14:37732 }
Blink Reformat4c46d092018-04-07 15:32:37733 return;
734 }
735 let harRoot;
736 try {
737 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56738 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37739 } catch (e) {
740 this._harLoadFailed(e);
741 return;
742 }
Tim van der Lippe09cf5032021-04-29 15:08:09743 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37744 }
745
Jan Schefflerd6c1d402021-02-26 16:56:38746 _harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36747 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37748 }
749
Jan Schefflerd6c1d402021-02-26 16:56:38750 _setGrouping(groupKey: string|null): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34751 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37752 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34753 }
Blink Reformat4c46d092018-04-07 15:32:37754 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
755 this._activeGroupLookup = groupLookup;
756 this._invalidateAllItems();
757 }
758
Jan Schefflerd6c1d402021-02-26 16:56:38759 _computeRowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37760 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
761 }
762
Jan Schefflerd6c1d402021-02-26 16:56:38763 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37764 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37765 }
766
Jan Schefflerd6c1d402021-02-26 16:56:38767 headerHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37768 return this._headerHeight;
769 }
770
Jan Schefflerd6c1d402021-02-26 16:56:38771 setRecording(recording: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:37772 this._recording = recording;
773 this._updateSummaryBar();
774 }
775
Jan Schefflerd6c1d402021-02-26 16:56:38776 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37777 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34778 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37779 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34780 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13781 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37782 if (resourceTreeModel) {
783 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
784 resourceTreeModel.addEventListener(
785 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
786 }
787 }
788
Jan Schefflerd6c1d402021-02-26 16:56:38789 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37790 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13791 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37792 if (resourceTreeModel) {
793 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
794 resourceTreeModel.removeEventListener(
795 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
796 }
797 }
798 }
799
Jan Schefflerd6c1d402021-02-26 16:56:38800 linkifier(): Components.Linkifier.Linkifier {
Simon Zündcdd72c92020-10-07 11:48:13801 return this._linkifier;
802 }
803
Jan Schefflerd6c1d402021-02-26 16:56:38804 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37805 if (!start && !end) {
806 this._timeFilter = null;
807 this._timeCalculator.setWindow(null);
808 } else {
Paul Lewis56509652019-12-06 12:51:58809 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30810 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37811 }
812 this._filterRequests();
813 }
814
Jan Schefflerd6c1d402021-02-26 16:56:38815 resetFocus(): void {
Brandon Goddard88d885a2019-10-31 16:11:05816 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37817 }
818
Jan Schefflerd6c1d402021-02-26 16:56:38819 _resetSuggestionBuilder(): void {
Blink Reformat4c46d092018-04-07 15:32:37820 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58821 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
822 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
823 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
824 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
825 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
826 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
827 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37828 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
829 }
830
Jan Schefflerd6c1d402021-02-26 16:56:38831 _filterChanged(_event: Common.EventTarget.EventTargetEvent): void {
Blink Reformat4c46d092018-04-07 15:32:37832 this.removeAllNodeHighlights();
833 this._parseFilterQuery(this._textFilterUI.value());
834 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03835 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37836 }
837
Jan Schefflerd6c1d402021-02-26 16:56:38838 async resetFilter(): Promise<void> {
Rajasekar Murugan3ad369e2020-02-19 18:20:12839 this._textFilterUI.clear();
840 }
841
Jan Schefflerd6c1d402021-02-26 16:56:38842 _showRecordingHint(): void {
Blink Reformat4c46d092018-04-07 15:32:37843 this._hideRecordingHint();
844 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
845 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18846
Blink Reformat4c46d092018-04-07 15:32:37847 if (this._recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38848 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04849 const reloadShortcut =
850 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
851 if (reloadShortcut) {
852 reloadShortcutNode = this._recordingHint.createChild('b');
853 reloadShortcutNode.textContent = reloadShortcut.title();
854 }
855
Blink Reformat4c46d092018-04-07 15:32:37856 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55857 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18858 if (reloadShortcutNode) {
859 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55860 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
861 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18862 }
Blink Reformat4c46d092018-04-07 15:32:37863 } else {
864 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17865 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37866 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55867 hintText.appendChild(
868 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordSToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37869 }
Kayce Basques5444c1b2019-02-15 20:32:53870 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13871 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35872 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55873 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11874
875 this._setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37876 }
877
Jan Schefflerd6c1d402021-02-26 16:56:38878 _hideRecordingHint(): void {
Amanda Baker6761aae2019-11-05 18:59:11879 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34880 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37881 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34882 }
Michael Liao7322dee2021-04-07 18:33:30883 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Blink Reformat4c46d092018-04-07 15:32:37884 this._recordingHint = null;
885 }
886
Jan Schefflerd6c1d402021-02-26 16:56:38887 _setHidden(value: boolean): void {
Amanda Baker6761aae2019-11-05 18:59:11888 this._columns.setHidden(value);
889 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
890 }
891
Jan Schefflerd6c1d402021-02-26 16:56:38892 elementsToRestoreScrollPositionsFor(): Element[] {
Blink Reformat4c46d092018-04-07 15:32:37893 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34894 {
Blink Reformat4c46d092018-04-07 15:32:37895 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34896 }
Blink Reformat4c46d092018-04-07 15:32:37897 return [this._dataGrid.scrollContainer];
898 }
899
Jan Schefflerd6c1d402021-02-26 16:56:38900 columnExtensionResolved(): void {
Blink Reformat4c46d092018-04-07 15:32:37901 this._invalidateAllItems(true);
902 }
903
Jan Schefflerd6c1d402021-02-26 16:56:38904 _setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Blink Reformat4c46d092018-04-07 15:32:37905 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38906 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34907 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37908 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34909 }
Blink Reformat4c46d092018-04-07 15:32:37910 });
911 this._dataGrid.setStickToBottom(true);
912 this._dataGrid.setName('networkLog');
913 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
914 this._dataGrid.element.classList.add('network-log-grid');
915 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
916 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
917 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05918 this._dataGrid.element.addEventListener('keydown', event => {
Olivia Flynn54728dd2021-05-21 20:15:43919 if (event.key === 'ArrowRight' && this._dataGrid.selectedNode) {
920 const initiatorLink = this._dataGrid.selectedNode.element().querySelector('span.devtools-link');
921 if (initiatorLink) {
922 (initiatorLink as HTMLElement).focus();
923 }
924 }
Brandon Goddard88d885a2019-10-31 16:11:05925 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05926 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05927 event.consume(true);
928 }
929 });
Brandon Goddard44934902020-03-25 16:03:18930 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
931 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37932 return this._dataGrid;
933 }
934
Jan Schefflerd6c1d402021-02-26 16:56:38935 _dataGridMouseMove(event: Event): void {
936 const mouseEvent = (event as MouseEvent);
937 const node = (this._dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:37938 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Schefflerd6c1d402021-02-26 16:56:38939 this._setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:37940 }
941
Jan Schefflerd6c1d402021-02-26 16:56:38942 hoveredNode(): NetworkNode|null {
Blink Reformat4c46d092018-04-07 15:32:37943 return this._hoveredNode;
944 }
945
Jan Schefflerd6c1d402021-02-26 16:56:38946 _setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34947 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37948 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34949 }
Blink Reformat4c46d092018-04-07 15:32:37950 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34951 if (this._hoveredNode) {
Tim van der Lipped7cfd142021-01-07 12:17:24952 this._hoveredNode.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:34953 }
Blink Reformat4c46d092018-04-07 15:32:37954 }
955
Jan Schefflerd6c1d402021-02-26 16:56:38956 _dataGridMouseDown(event: Event): void {
957 const mouseEvent = (event as MouseEvent);
Tim van der Lippe224a8622020-09-23 12:14:37958 if (!this._dataGrid.selectedNode && mouseEvent.button) {
959 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34960 }
Blink Reformat4c46d092018-04-07 15:32:37961 }
962
Jan Schefflerd6c1d402021-02-26 16:56:38963 _updateSummaryBar(): void {
Blink Reformat4c46d092018-04-07 15:32:37964 this._hideRecordingHint();
965
966 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20967 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37968 let selectedNodeNumber = 0;
969 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20970 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37971 let baseTime = -1;
972 let maxTime = -1;
973
974 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:27975 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37976 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34977 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37978 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34979 }
Blink Reformat4c46d092018-04-07 15:32:37980 nodeCount++;
981 const requestTransferSize = request.transferSize;
982 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20983 const requestResourceSize = request.resourceSize;
984 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37985 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37986 selectedNodeNumber++;
987 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20988 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37989 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13990 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37991 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
992 // inspected url.
993 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13994 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
995 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37996 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34997 }
998 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37999 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341000 }
Blink Reformat4c46d092018-04-07 15:32:371001 }
1002
1003 if (!nodeCount) {
1004 this._showRecordingHint();
1005 return;
1006 }
1007
Joey Arhara86c14e2019-03-12 03:20:501008 this._summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381009 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131010 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501011 toolbarText.setTitle(title ? title : chunk);
1012 this._summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381013 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501014 };
Blink Reformat4c46d092018-04-07 15:32:371015
1016 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551017 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501018 this._summaryToolbar.appendSeparator();
1019 appendChunk(
Christy Chencac3f102021-02-03 10:07:551020 i18nString(UIStrings.sSTransferred, {
1021 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381022 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551023 }),
1024 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501025 this._summaryToolbar.appendSeparator();
1026 appendChunk(
Christy Chencac3f102021-02-03 10:07:551027 i18nString(UIStrings.sSResources, {
1028 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381029 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551030 }),
1031 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371032 } else {
Christy Chencac3f102021-02-03 10:07:551033 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501034 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251035 appendChunk(
Christy Chencac3f102021-02-03 10:07:551036 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1037 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501038 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251039 appendChunk(
Christy Chencac3f102021-02-03 10:07:551040 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1041 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371042 }
Dan Beam87466b52018-12-01 18:41:201043
Blink Reformat4c46d092018-04-07 15:32:371044 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501045 this._summaryToolbar.appendSeparator();
Kriti Sapra915aed72021-06-04 11:29:581046 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.i18n.secondsToString(maxTime - baseTime)}));
Blink Reformat4c46d092018-04-07 15:32:371047 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:501048 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551049 const domContentLoadedText = i18nString(
1050 UIStrings.domcontentloadedS,
Kriti Sapra915aed72021-06-04 11:29:581051 {PH1: i18n.i18n.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581052 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371053 }
1054 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501055 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551056 const loadText =
Kriti Sapra915aed72021-06-04 11:29:581057 i18nString(UIStrings.loadS, {PH1: i18n.i18n.secondsToString(this._mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581058 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371059 }
1060 }
Blink Reformat4c46d092018-04-07 15:32:371061 }
1062
Jan Schefflerd6c1d402021-02-26 16:56:381063 scheduleRefresh(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341064 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371065 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341066 }
Blink Reformat4c46d092018-04-07 15:32:371067
1068 this._needsRefresh = true;
1069
Tim van der Lippe1d6e57a2019-09-30 11:55:341070 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:371071 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341072 }
Blink Reformat4c46d092018-04-07 15:32:371073 }
1074
Jan Schefflerd6c1d402021-02-26 16:56:381075 addFilmStripFrames(times: number[]): void {
Blink Reformat4c46d092018-04-07 15:32:371076 this._columns.addEventDividers(times, 'network-frame-divider');
1077 }
1078
Jan Schefflerd6c1d402021-02-26 16:56:381079 selectFilmStripFrame(time: number): void {
Blink Reformat4c46d092018-04-07 15:32:371080 this._columns.selectFilmStripFrame(time);
1081 }
1082
Jan Schefflerd6c1d402021-02-26 16:56:381083 clearFilmStripFrame(): void {
Blink Reformat4c46d092018-04-07 15:32:371084 this._columns.clearFilmStripFrame();
1085 }
1086
Jan Schefflerd6c1d402021-02-26 16:56:381087 _refreshIfNeeded(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341088 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371089 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341090 }
Blink Reformat4c46d092018-04-07 15:32:371091 }
1092
Jan Schefflerd6c1d402021-02-26 16:56:381093 _invalidateAllItems(deferUpdate?: boolean): void {
Sigurd Schneidercf5b8302021-04-23 07:52:271094 this._staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341095 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371096 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341097 } else {
Blink Reformat4c46d092018-04-07 15:32:371098 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341099 }
Blink Reformat4c46d092018-04-07 15:32:371100 }
1101
Jan Schefflerd6c1d402021-02-26 16:56:381102 timeCalculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371103 return this._timeCalculator;
1104 }
1105
Jan Schefflerd6c1d402021-02-26 16:56:381106 calculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371107 return this._calculator;
1108 }
1109
Jan Schefflerd6c1d402021-02-26 16:56:381110 setCalculator(x: NetworkTimeCalculator): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341111 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371112 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341113 }
Blink Reformat4c46d092018-04-07 15:32:371114
1115 if (this._calculator !== x) {
1116 this._calculator = x;
1117 this._columns.setCalculator(this._calculator);
1118 }
1119 this._calculator.reset();
1120
Tim van der Lippe1d6e57a2019-09-30 11:55:341121 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371122 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341123 } else {
Blink Reformat4c46d092018-04-07 15:32:371124 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341125 }
Blink Reformat4c46d092018-04-07 15:32:371126
1127 this._invalidateAllItems();
1128 }
1129
Jan Schefflerd6c1d402021-02-26 16:56:381130 _loadEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341131 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371132 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341133 }
Blink Reformat4c46d092018-04-07 15:32:371134
Jan Schefflerd6c1d402021-02-26 16:56:381135 const time = (event.data.loadTime as number);
Blink Reformat4c46d092018-04-07 15:32:371136 if (time) {
1137 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301138 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371139 }
1140 }
1141
Jan Schefflerd6c1d402021-02-26 16:56:381142 _domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341143 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371144 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341145 }
Jan Schefflerd6c1d402021-02-26 16:56:381146 const data = (event.data as number);
Blink Reformat4c46d092018-04-07 15:32:371147 if (data) {
1148 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301149 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371150 }
1151 }
1152
Jan Schefflerd6c1d402021-02-26 16:56:381153 wasShown(): void {
Blink Reformat4c46d092018-04-07 15:32:371154 this._refreshIfNeeded();
1155 this._columns.wasShown();
1156 }
1157
Jan Schefflerd6c1d402021-02-26 16:56:381158 willHide(): void {
Blink Reformat4c46d092018-04-07 15:32:371159 this._columns.willHide();
1160 }
1161
Jan Schefflerd6c1d402021-02-26 16:56:381162 onResize(): void {
Blink Reformat4c46d092018-04-07 15:32:371163 this._rowHeight = this._computeRowHeight();
1164 }
1165
Jan Schefflerd6c1d402021-02-26 16:56:381166 flatNodesList(): NetworkNode[] {
1167 const rootNode =
1168 (this._dataGrid.rootNode() as
1169 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1170 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371171 }
1172
Jan Schefflerd6c1d402021-02-26 16:56:381173 _onDataGridFocus(): void {
Peter Marshallde3fee72020-08-24 14:12:491174 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351175 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381176 }
Brandon Goddard44934902020-03-25 16:03:181177 this.updateNodeBackground();
1178 }
1179
Jan Schefflerd6c1d402021-02-26 16:56:381180 _onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181181 this.element.classList.remove('grid-focused');
1182 this.updateNodeBackground();
1183 }
1184
Jan Schefflerd6c1d402021-02-26 16:56:381185 updateNodeBackground(): void {
Brandon Goddard88d885a2019-10-31 16:11:051186 if (this._dataGrid.selectedNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381187 (this._dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051188 }
1189 }
1190
Jan Schefflerd6c1d402021-02-26 16:56:381191 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051192 if (isSelected) {
1193 this.element.classList.remove('no-node-selected');
1194 } else {
1195 this.element.classList.add('no-node-selected');
1196 }
1197 }
1198
Jan Schefflerd6c1d402021-02-26 16:56:381199 stylesChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371200 this._columns.scheduleRefresh();
1201 }
1202
Jan Schefflerd6c1d402021-02-26 16:56:381203 _refresh(): void {
Blink Reformat4c46d092018-04-07 15:32:371204 this._needsRefresh = false;
1205
1206 if (this._refreshRequestId) {
1207 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1208 this._refreshRequestId = null;
1209 }
1210
1211 this.removeAllNodeHighlights();
1212
1213 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1214 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1215 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1216 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1217
Jan Schefflerd6c1d402021-02-26 16:56:381218 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1219 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371220
Jan Schefflerd6c1d402021-02-26 16:56:381221 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371222
1223 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1224 // node so we loop until we have no more stale requests.
1225 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371226 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371227 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371228 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341229 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371230 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341231 }
Blink Reformat4c46d092018-04-07 15:32:371232 staleNodes.add(node);
1233 }
1234
1235 for (const node of staleNodes) {
1236 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341237 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371238 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341239 }
Blink Reformat4c46d092018-04-07 15:32:371240
Tim van der Lippe1d6e57a2019-09-30 11:55:341241 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371242 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341243 }
Blink Reformat4c46d092018-04-07 15:32:371244 const request = node.request();
1245 this._timeCalculator.updateBoundaries(request);
1246 this._durationCalculator.updateBoundaries(request);
1247 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371248 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1249 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371250 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341251 }
Tim van der Lippe224a8622020-09-23 12:14:371252 if (isFilteredOut) {
1253 filteredNetworkRequests.add(node);
1254 } else {
1255 filteredNetworkRequests.delete(node);
1256 }
Blink Reformat4c46d092018-04-07 15:32:371257 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1258 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381259 let parent: NetworkNode|
1260 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1261 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1262 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111263 if (!parent) {
1264 continue;
1265 }
Blink Reformat4c46d092018-04-07 15:32:371266 parent.removeChild(node);
1267 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381268 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371269 grandparent.removeChild(parent);
1270 parent = grandparent;
1271 }
1272 }
1273
Tim van der Lippe1d6e57a2019-09-30 11:55:341274 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371275 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 }
Blink Reformat4c46d092018-04-07 15:32:371277
1278 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jan Schefflerd6c1d402021-02-26 16:56:381279 nodesToInsert.set(newParent, (this._dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371280 nodesToRefresh.push(newParent);
1281 }
1282 nodesToInsert.set(node, newParent);
1283 }
1284
Tim van der Lippe1d6e57a2019-09-30 11:55:341285 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381286 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341287 }
Blink Reformat4c46d092018-04-07 15:32:371288
Tim van der Lippe1d6e57a2019-09-30 11:55:341289 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371290 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341291 }
Blink Reformat4c46d092018-04-07 15:32:371292
1293 this._updateSummaryBar();
1294
Tim van der Lippe1d6e57a2019-09-30 11:55:341295 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371296 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341297 }
Blink Reformat4c46d092018-04-07 15:32:371298
1299 this._dataGrid.updateInstantly();
1300 this._didRefreshForTest();
1301 }
1302
Jan Schefflerd6c1d402021-02-26 16:56:381303 _didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371304 }
1305
Jan Schefflerd6c1d402021-02-26 16:56:381306 _parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Tim van der Lippe1d6e57a2019-09-30 11:55:341307 if (!this._activeGroupLookup) {
Jan Schefflerd6c1d402021-02-26 16:56:381308 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341309 }
Blink Reformat4c46d092018-04-07 15:32:371310
1311 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341312 if (!groupNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381313 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341314 }
Blink Reformat4c46d092018-04-07 15:32:371315 return groupNode;
1316 }
1317
Jan Schefflerd6c1d402021-02-26 16:56:381318 _reset(): void {
Simon Zünd98419832020-03-12 06:18:151319 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371320
1321 this._setHoveredNode(null);
1322 this._columns.reset();
1323
1324 this._timeFilter = null;
1325 this._calculator.reset();
1326
1327 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131328 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371329
Tim van der Lippe1d6e57a2019-09-30 11:55:341330 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371331 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341332 }
Blink Reformat4c46d092018-04-07 15:32:371333 this._staleRequests.clear();
1334 this._resetSuggestionBuilder();
1335
1336 this._mainRequestLoadTime = -1;
1337 this._mainRequestDOMContentLoadedTime = -1;
1338
1339 this._dataGrid.rootNode().removeChildren();
1340 this._updateSummaryBar();
1341 this._dataGrid.setStickToBottom(true);
1342 this.scheduleRefresh();
1343 }
1344
Jan Schefflerd6c1d402021-02-26 16:56:381345 setTextFilterValue(filterString: string): void {
Blink Reformat4c46d092018-04-07 15:32:371346 this._textFilterUI.setValue(filterString);
1347 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371348 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131349 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371350 this._resourceCategoryFilterUI.reset();
1351 }
1352
Jan Schefflerd6c1d402021-02-26 16:56:381353 _createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301354 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371355 networkRequestToNode.set(request, node);
1356 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371357
Tim van der Lippe1d6e57a2019-09-30 11:55:341358 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371359 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341360 }
Blink Reformat4c46d092018-04-07 15:32:371361 return node;
1362 }
1363
Jan Schefflerd6c1d402021-02-26 16:56:381364 _onRequestUpdated(event: Common.EventTarget.EventTargetEvent): void {
1365 const request = (event.data as SDK.NetworkRequest.NetworkRequest);
Blink Reformat4c46d092018-04-07 15:32:371366 this._refreshRequest(request);
1367 }
1368
Jan Schefflerd6c1d402021-02-26 16:56:381369 _refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Paul Lewis56509652019-12-06 12:51:581370 NetworkLogView._subdomains(request.domain)
1371 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1372 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1373 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
Tim van der Lipped7cfd142021-01-07 12:17:241374 this._suggestionBuilder.addItem(FilterType.Scheme, String(request.scheme));
1375 this._suggestionBuilder.addItem(FilterType.StatusCode, String(request.statusCode));
Sigurd Schneider464838b2020-08-24 13:53:031376 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031377 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371378
1379 const priority = request.priority();
1380 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501381 this._suggestionBuilder.addItem(
1382 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371383 }
1384
1385 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581386 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371387 }
1388
1389 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581390 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371391 }
1392
1393 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581394 const suggestion =
1395 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1396 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371397 }
1398
1399 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341400 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581401 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341402 }
Jan Scheffler341eea52019-12-12 09:08:411403
1404 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581405 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1406 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1407 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371408 }
1409
Jan Scheffler341eea52019-12-12 09:08:411410 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1411 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1412 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541413 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411414 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1415 }
1416
Blink Reformat4c46d092018-04-07 15:32:371417 this._staleRequests.add(request);
1418 this.scheduleRefresh();
1419 }
1420
Jan Schefflerd6c1d402021-02-26 16:56:381421 rowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:371422 return this._rowHeight;
1423 }
1424
Jan Schefflerd6c1d402021-02-26 16:56:381425 switchViewMode(gridMode: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:371426 this._columns.switchViewMode(gridMode);
1427 }
1428
Jan Schefflerd6c1d402021-02-26 16:56:381429 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1430 void {
Blink Reformat4c46d092018-04-07 15:32:371431 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551432 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371433 const footerSection = copyMenu.footerSection();
1434 if (request) {
1435 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131436 UI.UIUtils.copyLinkAddressLabel(),
1437 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1438 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371439 if (request.requestHeadersText()) {
1440 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551441 i18nString(UIStrings.copyRequestHeaders), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371442 }
1443
1444 if (request.responseHeadersText) {
1445 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551446 i18nString(UIStrings.copyResponseHeaders), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371447 }
1448
1449 if (request.finished) {
1450 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551451 i18nString(UIStrings.copyResponse), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371452 }
1453
Tim van der Lippeb4faf5a2020-11-06 15:02:021454 const initiator = request.initiator();
1455
1456 if (initiator) {
1457 const stack = initiator.stack;
1458 if (stack) {
1459 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1460 // has any context solely based on the top frame. Sometimes, the top frame does not have
1461 // any callFrames, but its parent frames do.
1462 const stackTraceText = computeStackTraceText(stack);
1463 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551464 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021465 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1466 });
1467 }
1468 }
1469 }
1470
Harley Libcf41f92018-09-10 18:01:131471 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131472 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371473 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551474 i18nString(UIStrings.copyAsPowershell), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371475 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551476 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291477 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551478 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371479 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551480 i18nString(UIStrings.copyAsCurlCmd), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131481 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551482 i18nString(UIStrings.copyAsCurlBash), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1483 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this._copyAllPowerShellCommand.bind(this));
1484 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1485 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1486 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this._copyAllCurlCommand.bind(this, 'win'));
1487 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371488 } else {
Harley Libcf41f92018-09-10 18:01:131489 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551490 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291491 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551492 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131493 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551494 i18nString(UIStrings.copyAsCurl), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1495 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1496 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1497 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371498 }
1499 } else {
Christy Chencac3f102021-02-03 10:07:551500 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371501 }
Christy Chencac3f102021-02-03 10:07:551502 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371503
Christy Chencac3f102021-02-03 10:07:551504 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371505
Christy Chencac3f102021-02-03 10:07:551506 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this._clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371507 contextMenu.editSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551508 i18nString(UIStrings.clearBrowserCookies), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371509
1510 if (request) {
1511 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211512 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371513 let patterns = manager.blockedPatterns();
1514
Jan Schefflerd6c1d402021-02-26 16:56:381515 function addBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121516 patterns.push({enabled: true, url: url});
1517 manager.setBlockedPatterns(patterns);
1518 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261519 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121520 }
1521
Jan Schefflerd6c1d402021-02-26 16:56:381522 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121523 patterns = patterns.filter(pattern => pattern.url !== url);
1524 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261525 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121526 }
1527
Blink Reformat4c46d092018-04-07 15:32:371528 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1529 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1530 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551531 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371532 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311533 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371534 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551535 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371536 }
1537
1538 const domain = request.parsedURL.domain();
1539 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1540 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551541 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371542 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311543 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371544 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551545 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371546 }
1547
Tim van der Lippe0ed1d2b2020-02-04 13:45:131548 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371549 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551550 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371551 }
Blink Reformat4c46d092018-04-07 15:32:371552 }
1553 }
1554
Jan Schefflerd6c1d402021-02-26 16:56:381555 _harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271556 return Logs.NetworkLog.NetworkLog.instance()
1557 .requests()
1558 .filter(NetworkLogView.HTTPRequestsFilter)
1559 .filter(request => {
1560 return request.finished ||
1561 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1562 });
Blink Reformat4c46d092018-04-07 15:32:371563 }
1564
Jan Schefflerd6c1d402021-02-26 16:56:381565 async _copyAll(): Promise<void> {
Tim van der Lippe09cf5032021-04-29 15:08:091566 const harArchive = {log: await HAR.Log.Log.build(this._harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131567 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371568 }
1569
Jan Schefflerd6c1d402021-02-26 16:56:381570 async _copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371571 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371573 }
1574
Jan Schefflerd6c1d402021-02-26 16:56:381575 async _copyAllCurlCommand(platform: string): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271576 const commands = await this._generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131577 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371578 }
1579
Jan Schefflerd6c1d402021-02-26 16:56:381580 async _copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<void> {
Jan Scheffler7c50d1f2019-12-17 13:33:291581 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131582 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371583 }
1584
Jan Schefflerd6c1d402021-02-26 16:56:381585 async _copyAllFetchCall(includeCookies: boolean): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271586 const commands = await this._generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131587 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371588 }
1589
Jan Schefflerd6c1d402021-02-26 16:56:381590 async _copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371591 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131592 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371593 }
1594
Jan Schefflerd6c1d402021-02-26 16:56:381595 async _copyAllPowerShellCommand(): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271596 const commands = await this._generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131597 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371598 }
1599
Jan Schefflerd6c1d402021-02-26 16:56:381600 async exportAll(): Promise<void> {
Sigurd Schneiderb9f6c792021-05-31 10:57:241601 const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget();
Tim van der Lippe224a8622020-09-23 12:14:371602 if (!mainTarget) {
1603 return;
1604 }
1605 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131606 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371607 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131608 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371609
Tim van der Lippe1d6e57a2019-09-30 11:55:341610 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371611 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341612 }
Blink Reformat4c46d092018-04-07 15:32:371613
Tim van der Lippe0ed1d2b2020-02-04 13:45:131614 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371615 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe09cf5032021-04-29 15:08:091616 await HAR.Writer.Writer.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371617 progressIndicator.done();
1618 stream.close();
1619 }
1620
Jan Schefflerd6c1d402021-02-26 16:56:381621 _clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551622 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211623 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341624 }
Blink Reformat4c46d092018-04-07 15:32:371625 }
1626
Jan Schefflerd6c1d402021-02-26 16:56:381627 _clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551628 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211629 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341630 }
Blink Reformat4c46d092018-04-07 15:32:371631 }
1632
Jan Schefflerd6c1d402021-02-26 16:56:381633 _removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371634 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341635 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131636 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341637 }
Blink Reformat4c46d092018-04-07 15:32:371638 this._highlightedSubstringChanges = [];
1639 }
1640
Jan Schefflerd6c1d402021-02-26 16:56:381641 _applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371642 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341643 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371644 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341645 }
Christy Chen1825c612021-02-25 10:28:441646 const categoryName = request.resourceType().category().title();
Tim van der Lippe1d6e57a2019-09-30 11:55:341647 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371648 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341649 }
1650 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371651 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341652 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221653 if (this._onlyIssuesFilterUI.checked() &&
Sigurd Schneider84b6cf72021-04-13 06:40:541654 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371655 return false;
1656 }
Sigurd Schneider20088de2020-10-30 08:08:331657 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131658 return false;
1659 }
Blink Reformat4c46d092018-04-07 15:32:371660 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341661 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371662 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 }
Blink Reformat4c46d092018-04-07 15:32:371664 }
1665 return true;
1666 }
1667
Jan Schefflerd6c1d402021-02-26 16:56:381668 _parseFilterQuery(query: string): void {
Blink Reformat4c46d092018-04-07 15:32:371669 const descriptors = this._filterParser.parse(query);
1670 this._filters = descriptors.map(descriptor => {
1671 const key = descriptor.key;
1672 const text = descriptor.text || '';
1673 const regex = descriptor.regex;
1674 let filter;
1675 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171676 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Schefflerd6c1d402021-02-26 16:56:381677 filter = this._createSpecialFilter((key as FilterType), text) ||
Paul Lewis56509652019-12-06 12:51:581678 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371679 } else if (descriptor.regex) {
Jan Schefflerd6c1d402021-02-26 16:56:381680 filter = NetworkLogView._requestPathFilter.bind(null, (regex as RegExp));
Blink Reformat4c46d092018-04-07 15:32:371681 } else {
Tim van der Lippebafa3bd2021-01-20 12:19:171682 filter = NetworkLogView._requestPathFilter.bind(
1683 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371684 }
Paul Lewis56509652019-12-06 12:51:581685 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371686 });
1687 }
1688
Jan Schefflerd6c1d402021-02-26 16:56:381689 _createSpecialFilter(type: FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371690 switch (type) {
Paul Lewis56509652019-12-06 12:51:581691 case FilterType.Domain:
1692 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371693
Paul Lewis56509652019-12-06 12:51:581694 case FilterType.HasResponseHeader:
1695 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371696
Paul Lewis56509652019-12-06 12:51:581697 case FilterType.Is:
1698 if (value.toLowerCase() === IsFilterType.Running) {
1699 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341700 }
Paul Lewis56509652019-12-06 12:51:581701 if (value.toLowerCase() === IsFilterType.FromCache) {
1702 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341703 }
Paul Lewis56509652019-12-06 12:51:581704 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1705 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341706 }
Paul Lewis56509652019-12-06 12:51:581707 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1708 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341709 }
Blink Reformat4c46d092018-04-07 15:32:371710 break;
1711
Paul Lewis56509652019-12-06 12:51:581712 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371713 return this._createSizeFilter(value.toLowerCase());
1714
Paul Lewis56509652019-12-06 12:51:581715 case FilterType.Method:
1716 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371717
Paul Lewis56509652019-12-06 12:51:581718 case FilterType.MimeType:
1719 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371720
Paul Lewis56509652019-12-06 12:51:581721 case FilterType.MixedContent:
Jan Schefflerd6c1d402021-02-26 16:56:381722 return NetworkLogView._requestMixedContentFilter.bind(null, (value as MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371723
Paul Lewis56509652019-12-06 12:51:581724 case FilterType.Scheme:
1725 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371726
Paul Lewis56509652019-12-06 12:51:581727 case FilterType.SetCookieDomain:
1728 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371729
Paul Lewis56509652019-12-06 12:51:581730 case FilterType.SetCookieName:
1731 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371732
Paul Lewis56509652019-12-06 12:51:581733 case FilterType.SetCookieValue:
1734 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371735
Jan Scheffler341eea52019-12-12 09:08:411736 case FilterType.CookieDomain:
1737 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1738
1739 case FilterType.CookieName:
1740 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1741
Simon Zündc9759102020-03-25 11:24:541742 case FilterType.CookiePath:
1743 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1744
Jan Scheffler341eea52019-12-12 09:08:411745 case FilterType.CookieValue:
1746 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1747
Paul Lewis56509652019-12-06 12:51:581748 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501749 return NetworkLogView._requestPriorityFilter.bind(
1750 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371751
Paul Lewis56509652019-12-06 12:51:581752 case FilterType.StatusCode:
1753 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031754
1755 case FilterType.ResourceType:
1756 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031757
1758 case FilterType.Url:
1759 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371760 }
1761 return null;
1762 }
1763
Jan Schefflerd6c1d402021-02-26 16:56:381764 _createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371765 let multiplier = 1;
1766 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541767 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371768 value = value.substring(0, value.length - 1);
1769 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541770 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371771 value = value.substring(0, value.length - 1);
1772 }
1773 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341774 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371775 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341776 }
Paul Lewis56509652019-12-06 12:51:581777 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371778 }
1779
Jan Schefflerd6c1d402021-02-26 16:56:381780 _filterRequests(): void {
Blink Reformat4c46d092018-04-07 15:32:371781 this._removeAllHighlights();
1782 this._invalidateAllItems();
1783 }
1784
Jan Schefflerd6c1d402021-02-26 16:56:381785 _reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371786 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371787 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341788 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371789 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341790 }
Brandon Goddard5e4244d2020-04-08 22:08:471791 // Viewport datagrid nodes do not reveal if not in the root node
1792 // list of flatChildren. For children of grouped frame nodes:
1793 // reveal and expand parent to ensure child is revealable.
1794 if (node.parent && node.parent instanceof NetworkGroupNode) {
1795 node.parent.reveal();
1796 node.parent.expand();
1797 }
Blink Reformat4c46d092018-04-07 15:32:371798 node.reveal();
1799 return node;
1800 }
1801
Jan Schefflerd6c1d402021-02-26 16:56:381802 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Blink Reformat4c46d092018-04-07 15:32:371803 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341804 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371805 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341806 }
Blink Reformat4c46d092018-04-07 15:32:371807 }
1808
Danil Somsikov0c13d2d2021-06-10 15:02:071809 revealAndHighlightRequestWithId(requestId: NetworkRequestId): void {
1810 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
1811 if (request) {
1812 this.revealAndHighlightRequest(request);
1813 }
1814 }
1815
Jan Schefflerd6c1d402021-02-26 16:56:381816 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: FilterOptions): void {
chait pinnamaneni6bc1c122020-10-30 17:30:521817 const defaultOptions = {clearFilter: true};
1818 const {clearFilter} = options || defaultOptions;
1819 if (clearFilter) {
1820 this.setTextFilterValue('');
1821 }
Blink Reformat4c46d092018-04-07 15:32:371822 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341823 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371824 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341825 }
Blink Reformat4c46d092018-04-07 15:32:371826 }
1827
Jan Schefflerd6c1d402021-02-26 16:56:381828 removeAllNodeHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371829 if (this._highlightedNode) {
1830 this._highlightedNode.element().classList.remove('highlighted-row');
1831 this._highlightedNode = null;
1832 }
1833 }
1834
Jan Schefflerd6c1d402021-02-26 16:56:381835 _highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131836 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371837 this._highlightedNode = node;
1838 }
1839
Jan Schefflerd6c1d402021-02-26 16:56:381840 _filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131841 return requests.filter(request => !request.isBlobRequest());
1842 }
1843
Jan Schefflerd6c1d402021-02-26 16:56:381844 async _generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<string> {
1845 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371846 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371847 'method',
1848 'path',
1849 'scheme',
1850 'version',
Blink Reformat4c46d092018-04-07 15:32:371851
1852 // Unsafe headers
1853 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371854 'accept-charset',
1855 'accept-encoding',
1856 'access-control-request-headers',
1857 'access-control-request-method',
1858 'connection',
1859 'content-length',
1860 'cookie',
1861 'cookie2',
1862 'date',
1863 'dnt',
1864 'expect',
1865 'host',
1866 'keep-alive',
1867 'origin',
1868 'referer',
1869 'te',
1870 'trailer',
1871 'transfer-encoding',
1872 'upgrade',
1873 'via',
Blink Reformat4c46d092018-04-07 15:32:371874 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371875 'user-agent',
1876 ]);
Blink Reformat4c46d092018-04-07 15:32:371877
Jan Schefflerd6c1d402021-02-26 16:56:381878 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371879
1880 const url = JSON.stringify(request.url());
1881
1882 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:381883 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:371884 const name = header.name;
1885
Tim van der Lippe224a8622020-09-23 12:14:371886 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371887 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341888 }
Blink Reformat4c46d092018-04-07 15:32:371889
1890 return result;
1891 }, new Headers());
1892
Jan Schefflerd6c1d402021-02-26 16:56:381893 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341894 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411895 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341896 }
Blink Reformat4c46d092018-04-07 15:32:371897
Sigurd Schneider0e88b912020-05-08 08:28:231898 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371899 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411900 'include' :
1901 'omit';
Blink Reformat4c46d092018-04-07 15:32:371902
1903 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1904
1905 const referrer = referrerHeader ? referrerHeader.value : void 0;
1906
1907 const referrerPolicy = request.referrerPolicy() || void 0;
1908
1909 const requestBody = await request.requestFormData();
1910
Jan Schefflerd6c1d402021-02-26 16:56:381911 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:411912 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371913 referrer,
1914 referrerPolicy,
1915 body: requestBody,
1916 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371917 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371918 };
1919
Jan Scheffler7c50d1f2019-12-17 13:33:291920 if (includeCookies) {
1921 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1922 if (cookieHeader) {
1923 fetchOptions.headers = {
1924 ...headers,
1925 'cookie': cookieHeader.value,
1926 };
1927 }
1928 } else {
1929 fetchOptions.credentials = credentials;
1930 }
1931
Jan Scheffler172d5212020-01-02 14:42:561932 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371933 return `fetch(${url}, ${options});`;
1934 }
1935
Jan Schefflerd6c1d402021-02-26 16:56:381936 async _generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], includeCookies: boolean): Promise<string> {
Harley Libcf41f92018-09-10 18:01:131937 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291938 const commands =
1939 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131940 return commands.join(' ;\n');
1941 }
1942
Jan Schefflerd6c1d402021-02-26 16:56:381943 async _generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
1944 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:361945 // Most of these headers are derived from the URL and are automatically added by cURL.
1946 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:381947 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:371948
Jan Schefflerd6c1d402021-02-26 16:56:381949 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:371950 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:381951 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:371952
Jan Schefflerd6c1d402021-02-26 16:56:381953 Because cmd.exe parser and MS Crt arguments parsers use some of the
1954 same escape characters, they can interact with each other in
1955 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:371956
Jan Schefflerd6c1d402021-02-26 16:56:381957 Replace \ with \\ first because it is an escape character for certain
1958 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:371959
Jan Schefflerd6c1d402021-02-26 16:56:381960 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:371961
Jan Schefflerd6c1d402021-02-26 16:56:381962 Then escape all characters we are not sure about with ^ to ensure it
1963 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:371964
Jan Schefflerd6c1d402021-02-26 16:56:381965 The % character is special because MS Crt parser will try and look for
1966 ENV variables and fill them in it's place. We cannot escape them with %
1967 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1968 parser); So we can get cmd.exe parser to escape the character after it,
1969 if it is followed by a valid beginning character of an ENV variable.
1970 This ensures we do not try and double escape another ^ if it was placed
1971 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:371972
Jan Schefflerd6c1d402021-02-26 16:56:381973 Lastly we replace new lines with ^ and TWO new lines because the first
1974 new line is there to enact the escape command the second is the character
1975 to escape (in this case new line).
1976 */
Blink Reformat4c46d092018-04-07 15:32:371977 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1978 return encapsChars +
1979 str.replace(/\\/g, '\\\\')
1980 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:541981 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:371982 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:541983 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:371984 encapsChars;
1985 }
1986
Jan Schefflerd6c1d402021-02-26 16:56:381987 function escapeStringPosix(str: string): string {
1988 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:221989 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121990 let hexString = code.toString(16);
1991 // Zero pad to four digits to comply with ANSI-C Quoting:
1992 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121994 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341995 }
Joey Arhar2d21f712019-05-20 21:07:121996
1997 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371998 }
1999
Mathias Bynensf06e8c02020-02-28 13:58:282000 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372001 // Use ANSI-C quoting syntax.
2002 return '$\'' +
2003 str.replace(/\\/g, '\\\\')
2004 .replace(/\'/g, '\\\'')
2005 .replace(/\n/g, '\\n')
2006 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282007 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372008 '\'';
Blink Reformat4c46d092018-04-07 15:32:372009 }
Mathias Bynensf06e8c02020-02-28 13:58:282010 // Use single quote syntax.
2011 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372012 }
2013
2014 // cURL command expected to run on the same platform that DevTools run
2015 // (it may be different from the inspected page platform).
2016 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2017
2018 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2019
2020 let inferredMethod = 'GET';
2021 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372022 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082023 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272024 // Note that formData is not necessarily urlencoded because it might for example
2025 // come from a fetch request made with an explicitly unencoded body.
2026 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372027 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372028 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372029 }
2030
2031 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292032 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372033 }
2034
2035 const requestHeaders = request.requestHeaders();
2036 for (let i = 0; i < requestHeaders.length; i++) {
2037 const header = requestHeaders[i];
2038 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372039 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372040 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342041 }
Jan Scheffler172d5212020-01-02 14:42:562042 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372043 }
2044 command = command.concat(data);
2045 command.push('--compressed');
2046
Tim van der Lippe1d6e57a2019-09-30 11:55:342047 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372048 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342049 }
Jan Scheffler172d5212020-01-02 14:42:562050 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372051 }
2052
Jan Schefflerd6c1d402021-02-26 16:56:382053 async _generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132054 const nonBlobRequests = this._filterOutBlobRequests(requests);
2055 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342056 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132057 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342058 }
Mathias Bynensf06e8c02020-02-28 13:58:282059 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132060 }
2061
Jan Schefflerd6c1d402021-02-26 16:56:382062 async _generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562063 const command = [];
Jan Schefflerd6c1d402021-02-26 16:56:382064 const ignoredHeaders = new Set<string>(
2065 ['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
Blink Reformat4c46d092018-04-07 15:32:372066
Jan Schefflerd6c1d402021-02-26 16:56:382067 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372068 return '"' +
2069 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2070 }
2071
Jan Scheffler172d5212020-01-02 14:42:562072 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372073
2074 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562075 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372076 }
2077
2078 const requestHeaders = request.requestHeaders();
2079 const headerNameValuePairs = [];
2080 for (const header of requestHeaders) {
2081 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342082 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372083 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342084 }
Blink Reformat4c46d092018-04-07 15:32:372085 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2086 }
2087 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562088 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372089 }
2090
2091 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2092 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562093 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372094 }
2095
2096 const formData = await request.requestFormData();
2097 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372098 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342099 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562100 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342101 } else {
Jan Scheffler172d5212020-01-02 14:42:562102 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342103 }
Blink Reformat4c46d092018-04-07 15:32:372104 }
2105
Jan Scheffler172d5212020-01-02 14:42:562106 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372107 }
Harley Libcf41f92018-09-10 18:01:132108
Jan Schefflerd6c1d402021-02-26 16:56:382109 async _generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132110 const nonBlobRequests = this._filterOutBlobRequests(requests);
2111 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2112 return commands.join(';\r\n');
2113 }
Joey Arhara86c14e2019-03-12 03:20:502114
Jan Schefflerd6c1d402021-02-26 16:56:382115 static getDCLEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512116 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502117 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342118 }
Joey Arhara86c14e2019-03-12 03:20:502119 return '#0867CB';
2120 }
2121
Jan Schefflerd6c1d402021-02-26 16:56:382122 static getLoadEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512123 return ThemeSupport.ThemeSupport.instance().patchColorText(
2124 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502125 }
Paul Lewis56509652019-12-06 12:51:582126}
Blink Reformat4c46d092018-04-07 15:32:372127
Jan Schefflerd6c1d402021-02-26 16:56:382128export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022129 let stackTraceText = '';
2130 for (const frame of stackTrace.callFrames) {
2131 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2132 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2133 }
2134 if (stackTrace.parent) {
2135 stackTraceText += computeStackTraceText(stackTrace.parent);
2136 }
2137 return stackTraceText;
2138}
2139
Jan Schefflerd6c1d402021-02-26 16:56:382140const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2141const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372142
Jan Schefflerd6c1d402021-02-26 16:56:382143export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372144 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222145}
2146
Paul Lewis56509652019-12-06 12:51:582147export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372148 'http': true,
2149 'https': true,
2150 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382151 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372152};
2153
Jan Schefflerd6c1d402021-02-26 16:56:382154// TODO(crbug.com/1167717): Make this a const enum again
2155// eslint-disable-next-line rulesdir/const_enum
2156export enum FilterType {
2157 Domain = 'domain',
2158 HasResponseHeader = 'has-response-header',
2159 Is = 'is',
2160 LargerThan = 'larger-than',
2161 Method = 'method',
2162 MimeType = 'mime-type',
2163 MixedContent = 'mixed-content',
2164 Priority = 'priority',
2165 Scheme = 'scheme',
2166 SetCookieDomain = 'set-cookie-domain',
2167 SetCookieName = 'set-cookie-name',
2168 SetCookieValue = 'set-cookie-value',
2169 ResourceType = 'resource-type',
2170 CookieDomain = 'cookie-domain',
2171 CookieName = 'cookie-name',
2172 CookiePath = 'cookie-path',
2173 CookieValue = 'cookie-value',
2174 StatusCode = 'status-code',
2175 Url = 'url',
Paul Lewis56509652019-12-06 12:51:582176}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162177
Jan Schefflerd6c1d402021-02-26 16:56:382178// TODO(crbug.com/1167717): Make this a const enum again
2179// eslint-disable-next-line rulesdir/const_enum
2180export enum MixedContentFilterValues {
2181 All = 'all',
2182 Displayed = 'displayed',
2183 Blocked = 'blocked',
2184 BlockOverridden = 'block-overridden',
2185}
2186
2187// TODO(crbug.com/1167717): Make this a const enum again
2188// eslint-disable-next-line rulesdir/const_enum
2189export enum IsFilterType {
2190 Running = 'running',
2191 FromCache = 'from-cache',
2192 ServiceWorkerIntercepted = 'service-worker-intercepted',
2193 ServiceWorkerInitiated = 'service-worker-initiated',
2194}
2195
2196// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
2197// eslint-disable-next-line @typescript-eslint/naming-convention
2198export const _searchKeys: string[] = Object.values(FilterType);
2199
2200export interface GroupLookupInterface {
2201 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2202 reset(): void;
2203}
2204
2205export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;