blob: 0f8045eedfe00c0a68cabd660c44ede6f99bf325 [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
Tim van der Lippe119690c2020-01-13 12:31:3061
Simon Zünd34490692021-03-01 08:25:1862const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5563 /**
64 *@description Text in Network Log View of the Network panel
65 */
66 hideDataUrls: 'Hide data URLs',
67 /**
68 *@description Data urlfilter ui element title in Network Log View of the Network panel
69 */
70 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
71 /**
72 *@description Aria accessible name in Network Log View of the Network panel
73 */
74 resourceTypesToInclude: 'Resource types to include',
75 /**
76 *@description Label for a filter in the Network panel
77 */
78 hasBlockedCookies: 'Has blocked cookies',
79 /**
Simon Zünd562d32c2021-02-17 09:22:5480 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
81 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
82 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:5583 */
84 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
85 /**
86 *@description Label for a filter in the Network panel
87 */
88 blockedRequests: 'Blocked Requests',
89 /**
90 *@description Tooltip for a filter in the Network panel
91 */
92 onlyShowBlockedRequests: 'Only show blocked requests',
93 /**
94 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
95 */
96 dropHarFilesHere: 'Drop HAR files here',
97 /**
98 *@description Recording text text content in Network Log View of the Network panel
99 */
100 recordingNetworkActivity: 'Recording network activity…',
101 /**
102 *@description Text in Network Log View of the Network panel
103 *@example {Ctrl + R} PH1
104 */
105 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
106 /**
Peter Marshall266ab2e2021-02-16 17:30:49107 *@description Shown in the Network Log View of the Network panel when the user has not yet
108 * recorded any network activity. This is an instruction to the user to start recording in order to
109 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55110 *@example {Ctrl + E} PH1
111 */
112 recordSToDisplayNetworkActivity: 'Record ({PH1}) to display network activity.',
113 /**
114 *@description Text that is usually a hyperlink to more documentation
115 */
116 learnMore: 'Learn more',
117 /**
118 *@description Text to announce to screen readers that network data is available.
119 */
120 networkDataAvailable: 'Network Data Available',
121 /**
122 *@description Text in Network Log View of the Network panel
123 *@example {3} PH1
124 *@example {5} PH2
125 */
126 sSRequests: '{PH1} / {PH2} requests',
127 /**
Andres Olivares7fbed142021-03-01 16:22:23128 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
129 * resources transferred during a selected time frame over the compressed size of all resources transferred during
130 * the whole network log.
131 *@example {5 B} PH1
132 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55133 */
134 sSTransferred: '{PH1} / {PH2} transferred',
135 /**
Andres Olivares7fbed142021-03-01 16:22:23136 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
137 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55138 *@example {10} PH1
139 *@example {15} PH2
140 */
141 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
142 /**
Peter Marshall2c3fb302021-02-19 12:47:04143 * @description Text in Network Log View of the Network panel. Appears when a particular network
144 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
145 * total size (PH2).
146 * @example {40MB} PH1
147 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55148 */
149 sSResources: '{PH1} / {PH2} resources',
150 /**
151 *@description Text in Network Log View of the Network panel
152 *@example {40} PH1
153 *@example {50} PH2
154 */
155 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
156 /**
157 *@description Text in Network Log View of the Network panel
158 *@example {6} PH1
159 */
160 sRequests: '{PH1} requests',
161 /**
Andres Olivares0a863ab2021-02-19 15:21:23162 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
163 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55164 *@example {4 B} PH1
165 */
166 sTransferred: '{PH1} transferred',
167 /**
Andres Olivares0a863ab2021-02-19 15:21:23168 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
169 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55170 *@example {4} PH1
171 */
172 sBTransferredOverNetwork: '{PH1} B transferred over network',
173 /**
174 *@description Text in Network Log View of the Network panel
175 *@example {4} PH1
176 */
177 sResources: '{PH1} resources',
178 /**
179 *@description Text in Network Log View of the Network panel
180 *@example {10} PH1
181 */
182 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
183 /**
184 *@description Text in Network Log View of the Network panel
185 *@example {120ms} PH1
186 */
187 finishS: 'Finish: {PH1}',
188 /**
189 *@description Text in Network Log View of the Network panel
190 *@example {3000ms} PH1
191 */
192 domcontentloadedS: 'DOMContentLoaded: {PH1}',
193 /**
194 *@description Text in Network Log View of the Network panel
195 *@example {40ms} PH1
196 */
197 loadS: 'Load: {PH1}',
198 /**
199 *@description Text for copying
200 */
201 copy: 'Copy',
202 /**
203 *@description Text in Network Log View of the Network panel
204 */
205 copyRequestHeaders: 'Copy request headers',
206 /**
207 *@description Text in Network Log View of the Network panel
208 */
209 copyResponseHeaders: 'Copy response headers',
210 /**
211 *@description Text in Network Log View of the Network panel
212 */
213 copyResponse: 'Copy response',
214 /**
215 *@description Text in Network Log View of the Network panel
216 */
Peter Marshallf625dc82021-03-02 08:10:57217 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55218 /**
Peter Marshall3ec813d2021-03-01 19:40:25219 * @description A context menu command in the Network panel, for copying to the clipboard.
220 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55221 */
Peter Marshallb8bd00f2021-02-24 08:25:18222 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55223 /**
Peter Marshall3ec813d2021-03-01 19:40:25224 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
225 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55226 */
Peter Marshallb8bd00f2021-02-24 08:25:18227 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55228 /**
Peter Marshall3ec813d2021-03-01 19:40:25229 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21230 * the developer's clipboard. The command allows the developer to replay this specific network
231 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
232 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55233 */
Peter Marshallb8bd00f2021-02-24 08:25:18234 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55235 /**
Peter Marshallec861882021-02-16 11:14:21236 *@description Text in Network Log View of the Network panel. An action that copies a command to
237 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
238 *translatable).
Christy Chencac3f102021-02-03 10:07:55239 */
Peter Marshallb8bd00f2021-02-24 08:25:18240 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55241 /**
Peter Marshallec861882021-02-16 11:14:21242 *@description Text in Network Log View of the Network panel. An action that copies a command to
243 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55244 */
Peter Marshallb8bd00f2021-02-24 08:25:18245 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55246 /**
Peter Marshallec861882021-02-16 11:14:21247 *@description Text in Network Log View of the Network panel. An action that copies a command to
248 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55249 */
Peter Marshallb8bd00f2021-02-24 08:25:18250 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55251 /**
Peter Marshallec861882021-02-16 11:14:21252 *@description Text in Network Log View of the Network panel. An action that copies a command to
253 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
254 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55255 */
Peter Marshallb8bd00f2021-02-24 08:25:18256 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55257 /**
Peter Marshallec861882021-02-16 11:14:21258 *@description Text in Network Log View of the Network panel. An action that copies a command to
259 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
260 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55261 */
Peter Marshallb8bd00f2021-02-24 08:25:18262 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55263 /**
Peter Marshallec861882021-02-16 11:14:21264 *@description Text in Network Log View of the Network panel. An action that copies a command to
265 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
266 *translatable).
Christy Chencac3f102021-02-03 10:07:55267 */
Peter Marshallb8bd00f2021-02-24 08:25:18268 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55269 /**
Peter Marshallec861882021-02-16 11:14:21270 *@description Text in Network Log View of the Network panel. An action that copies a command to
271 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55272 */
Peter Marshallb8bd00f2021-02-24 08:25:18273 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55274 /**
Peter Marshallec861882021-02-16 11:14:21275 *@description Text in Network Log View of the Network panel. An action that copies a command to
276 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
277 *translatable).
Christy Chencac3f102021-02-03 10:07:55278 */
Peter Marshallb8bd00f2021-02-24 08:25:18279 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55280 /**
Peter Marshallec861882021-02-16 11:14:21281 *@description Text in Network Log View of the Network panel. An action that copies a command to
282 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
283 *translatable).
Christy Chencac3f102021-02-03 10:07:55284 */
Peter Marshallb8bd00f2021-02-24 08:25:18285 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55286 /**
Peter Marshallb8bd00f2021-02-24 08:25:18287 * @description Text in Network Log View of the Network panel. An action that copies data to the
288 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
289 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55290 */
Peter Marshallb8bd00f2021-02-24 08:25:18291 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55292 /**
293 *@description A context menu item in the Network Log View of the Network panel
294 */
Peter Marshallb8bd00f2021-02-24 08:25:18295 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55296 /**
297 *@description A context menu item in the Network Log View of the Network panel
298 */
299 clearBrowserCache: 'Clear browser cache',
300 /**
301 *@description A context menu item in the Network Log View of the Network panel
302 */
303 clearBrowserCookies: 'Clear browser cookies',
304 /**
305 *@description A context menu item in the Network Log View of the Network panel
306 */
307 blockRequestUrl: 'Block request URL',
308 /**
309 *@description A context menu item in the Network Log View of the Network panel
310 *@example {example.com} PH1
311 */
312 unblockS: 'Unblock {PH1}',
313 /**
314 *@description A context menu item in the Network Log View of the Network panel
315 */
316 blockRequestDomain: 'Block request domain',
317 /**
318 *@description Text to replay an XHR request
319 */
320 replayXhr: 'Replay XHR',
321 /**
322 *@description Text in Network Log View of the Network panel
323 */
324 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
325 /**
326 *@description Text in Network Log View of the Network panel
327 */
328 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
329};
Tim van der Lippef596ca02021-03-31 10:02:47330const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55331const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Jan Schefflerd6c1d402021-02-26 16:56:38332export class NetworkLogView extends UI.Widget.VBox implements
Sigurd Schneiderb9f6c792021-05-31 10:57:24333 SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jan Schefflerd6c1d402021-02-26 16:56:38334 _networkHideDataURLSetting: Common.Settings.Setting<boolean>;
335 _networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
336 _networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
337 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
338 // eslint-disable-next-line @typescript-eslint/no-explicit-any
339 _networkResourceTypeFiltersSetting: Common.Settings.Setting<any>;
340 _rawRowHeight: number;
341 _progressBarContainer: Element;
342 _networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
343 _rowHeight: number;
344 _timeCalculator: NetworkTransferTimeCalculator;
345 _durationCalculator: NetworkTransferDurationCalculator;
346 _calculator: NetworkTransferTimeCalculator;
347 _columns: NetworkLogViewColumns;
348 _staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
349 _mainRequestLoadTime: number;
350 _mainRequestDOMContentLoadedTime: number;
351 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
352 // eslint-disable-next-line @typescript-eslint/no-explicit-any
353 _highlightedSubstringChanges: any;
354 _filters: Filter[];
355 _timeFilter: Filter|null;
356 _hoveredNode: NetworkNode|null;
357 _recordingHint: Element|null;
358 _refreshRequestId: number|null;
359 _highlightedNode: NetworkRequestNode|null;
360 _linkifier: Components.Linkifier.Linkifier;
361 _recording: boolean;
362 _needsRefresh: boolean;
363 _headerHeight: number;
364 _groupLookups: Map<string, GroupLookupInterface>;
365 _activeGroupLookup: GroupLookupInterface|null;
366 _textFilterUI: UI.FilterBar.TextFilterUI;
367 _dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
368 _resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
369 _onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
370 _onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
371 _filterParser: TextUtils.TextUtils.FilterParser;
372 _suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
373 _dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
374 _summaryToolbar: UI.Toolbar.Toolbar;
375 _filterBar: UI.FilterBar.FilterBar;
376 _textFilterSetting: Common.Settings.Setting<string>;
377
378 constructor(
379 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
380 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37381 super();
382 this.setMinimumSize(50, 64);
Jack Franklina0685ef2021-05-17 11:14:10383 this.registerRequiredCSS('panels/network/networkLogView.css', {enableLegacyPatching: false});
Blink Reformat4c46d092018-04-07 15:32:37384
385 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05386 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37387
Paul Lewis2d7d65c2020-03-16 17:26:30388 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
389 this._networkShowIssuesOnlySetting =
390 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
391 this._networkOnlyBlockedRequestsSetting =
392 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
393 this._networkResourceTypeFiltersSetting =
394 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37395
396 this._rawRowHeight = 0;
397 this._progressBarContainer = progressBarContainer;
398 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
399 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
400
Jan Schefflerd6c1d402021-02-26 16:56:38401 function updateRowHeight(this: NetworkLogView): void {
Tim van der Lipped7cfd142021-01-07 12:17:24402 this._rawRowHeight = Boolean(this._networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:37403 this._rowHeight = this._computeRowHeight();
404 }
405 this._rawRowHeight = 0;
406 this._rowHeight = 0;
407 updateRowHeight.call(this);
408
Tim van der Lippe119690c2020-01-13 12:31:30409 this._timeCalculator = new NetworkTransferTimeCalculator();
Tim van der Lippe119690c2020-01-13 12:31:30410 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:37411 this._calculator = this._timeCalculator;
412
Tim van der Lippe119690c2020-01-13 12:31:30413 this._columns =
Jan Schefflerd6c1d402021-02-26 16:56:38414 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
415 // @ts-expect-error
Tim van der Lippe119690c2020-01-13 12:31:30416 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37417 this._columns.show(this.element);
418
Blink Reformat4c46d092018-04-07 15:32:37419 this._staleRequests = new Set();
Blink Reformat4c46d092018-04-07 15:32:37420 this._mainRequestLoadTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37421 this._mainRequestDOMContentLoadedTime = -1;
422 this._highlightedSubstringChanges = [];
423
Blink Reformat4c46d092018-04-07 15:32:37424 this._filters = [];
Blink Reformat4c46d092018-04-07 15:32:37425 this._timeFilter = null;
Blink Reformat4c46d092018-04-07 15:32:37426 this._hoveredNode = null;
Blink Reformat4c46d092018-04-07 15:32:37427 this._recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37428 this._refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:37429 this._highlightedNode = null;
430
Simon Zündcdd72c92020-10-07 11:48:13431 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37432
433 this._recording = false;
434 this._needsRefresh = false;
435
436 this._headerHeight = 0;
437
Blink Reformat4c46d092018-04-07 15:32:37438 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30439 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37440
Blink Reformat4c46d092018-04-07 15:32:37441 this._activeGroupLookup = null;
442
Tim van der Lippe0ed1d2b2020-02-04 13:45:13443 this._textFilterUI = new UI.FilterBar.TextFilterUI();
444 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37445 filterBar.addFilter(this._textFilterUI);
446
Tim van der Lippe0ed1d2b2020-02-04 13:45:13447 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55448 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this._networkHideDataURLSetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13449 this._dataURLFilterUI.addEventListener(
450 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55451 UI.Tooltip.Tooltip.install(this._dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
Blink Reformat4c46d092018-04-07 15:32:37452 filterBar.addFilter(this._dataURLFilterUI);
453
454 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13455 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38456 .map(
457 category =>
458 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13459 this._resourceCategoryFilterUI =
460 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55461 UI.ARIAUtils.setAccessibleName(
462 this._resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
Blink Reformat4c46d092018-04-07 15:32:37463 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13464 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37465 filterBar.addFilter(this._resourceCategoryFilterUI);
466
Tim van der Lippe0ed1d2b2020-02-04 13:45:13467 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55468 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this._networkShowIssuesOnlySetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13469 this._onlyIssuesFilterUI.addEventListener(
470 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55471 UI.Tooltip.Tooltip.install(this._onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
Jan Scheffler1ae7c9e2019-12-03 15:48:37472 filterBar.addFilter(this._onlyIssuesFilterUI);
473
Sigurd Schneidera2afe0b2020-03-03 15:27:13474 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55475 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
476 this._networkOnlyBlockedRequestsSetting);
Sigurd Schneidera2afe0b2020-03-03 15:27:13477 this._onlyBlockedRequestsUI.addEventListener(
478 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55479 UI.Tooltip.Tooltip.install(this._onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
Sigurd Schneidera2afe0b2020-03-03 15:27:13480 filterBar.addFilter(this._onlyBlockedRequestsUI);
481
Tim van der Lippe0ed1d2b2020-02-04 13:45:13482 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
483 this._suggestionBuilder =
484 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37485 this._resetSuggestionBuilder();
486
487 this._dataGrid = this._columns.dataGrid();
488 this._setupDataGrid();
489 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49490 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13491 UI.Toolbar.ToolbarButton.Events.Click,
492 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37493
Tim van der Lippe0ed1d2b2020-02-04 13:45:13494 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
chait pinnamaneni83f4b6b2021-04-08 16:27:05495 this._summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37496
Tim van der Lippe0ed1d2b2020-02-04 13:45:13497 new UI.DropTarget.DropTarget(
Christy Chencac3f102021-02-03 10:07:55498 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37499
Paul Lewis2d7d65c2020-03-16 17:26:30500 Common.Settings.Settings.instance()
501 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37502 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
503
Sigurd Schneiderb9f6c792021-05-31 10:57:24504 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27505 Logs.NetworkLog.NetworkLog.instance().addEventListener(
506 Logs.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
507 Logs.NetworkLog.NetworkLog.instance().addEventListener(
508 Logs.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
509 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37510
511 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30512 Common.Settings.Settings.instance()
513 .moduleSetting('network.group-by-frame')
514 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37515
516 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03517
518 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
519 if (this._textFilterSetting.get()) {
Jack Franklinec064412020-12-08 13:02:24520 this._textFilterUI.setValue(this._textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03521 }
Blink Reformat4c46d092018-04-07 15:32:37522 }
523
Jan Schefflerd6c1d402021-02-26 16:56:38524 _updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30525 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37526 this._setGrouping(value ? 'Frame' : null);
527 }
528
Jan Schefflerd6c1d402021-02-26 16:56:38529 static _sortSearchValues(key: string, values: string[]): void {
Paul Lewis56509652019-12-06 12:51:58530 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37531 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38532 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
533 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50534 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
535 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37536 });
537 } else {
538 values.sort();
539 }
540 }
541
Jan Schefflerd6c1d402021-02-26 16:56:38542 static _negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37543 return !filter(request);
544 }
545
Jan Schefflerd6c1d402021-02-26 16:56:38546 static _requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34547 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37548 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34549 }
Blink Reformat4c46d092018-04-07 15:32:37550
551 return regex.test(request.path() + '/' + request.name());
552 }
553
Jan Schefflerd6c1d402021-02-26 16:56:38554 static _subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37555 const result = [domain];
556 let indexOfPeriod = domain.indexOf('.');
557 while (indexOfPeriod !== -1) {
558 result.push('*' + domain.substring(indexOfPeriod));
559 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
560 }
561 return result;
562 }
563
Jan Schefflerd6c1d402021-02-26 16:56:38564 static _createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17565 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58566 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37567 }
568
Jan Schefflerd6c1d402021-02-26 16:56:38569 static _requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37570 return regex.test(request.domain);
571 }
572
Jan Schefflerd6c1d402021-02-26 16:56:38573 static _runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37574 return !request.finished;
575 }
576
Jan Schefflerd6c1d402021-02-26 16:56:38577 static _fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37578 return request.cached();
579 }
580
Jan Schefflerd6c1d402021-02-26 16:56:38581 static _interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05582 return request.fetchedViaServiceWorker;
583 }
584
Jan Schefflerd6c1d402021-02-26 16:56:38585 static _initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05586 return request.initiatedByServiceWorker();
587 }
588
Jan Schefflerd6c1d402021-02-26 16:56:38589 static _requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37590 return request.responseHeaderValue(value) !== undefined;
591 }
592
Jan Schefflerd6c1d402021-02-26 16:56:38593 static _requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37594 return request.requestMethod === value;
595 }
596
Jan Schefflerd6c1d402021-02-26 16:56:38597 static _requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37598 return request.priority() === value;
599 }
600
Jan Schefflerd6c1d402021-02-26 16:56:38601 static _requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37602 return request.mimeType === value;
603 }
604
Jan Schefflerd6c1d402021-02-26 16:56:38605 static _requestMixedContentFilter(value: MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest):
606 boolean {
Paul Lewis56509652019-12-06 12:51:58607 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37608 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28609 }
610 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37611 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28612 }
613 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37614 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28615 }
616 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37617 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34618 }
Blink Reformat4c46d092018-04-07 15:32:37619
620 return false;
621 }
622
Jan Schefflerd6c1d402021-02-26 16:56:38623 static _requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37624 return request.scheme === value;
625 }
626
Jan Schefflerd6c1d402021-02-26 16:56:38627 static _requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41628 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
629 }
630
Jan Schefflerd6c1d402021-02-26 16:56:38631 static _requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41632 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
633 }
634
Jan Schefflerd6c1d402021-02-26 16:56:38635 static _requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54636 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
637 }
638
Jan Schefflerd6c1d402021-02-26 16:56:38639 static _requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41640 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
641 }
642
Jan Schefflerd6c1d402021-02-26 16:56:38643 static _requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41644 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37645 }
646
Jan Schefflerd6c1d402021-02-26 16:56:38647 static _requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41648 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37649 }
650
Jan Schefflerd6c1d402021-02-26 16:56:38651 static _requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41652 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37653 }
654
Jan Schefflerd6c1d402021-02-26 16:56:38655 static _requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37656 return request.transferSize >= value;
657 }
658
Jan Schefflerd6c1d402021-02-26 16:56:38659 static _statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24660 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37661 }
662
Jan Schefflerd6c1d402021-02-26 16:56:38663 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
664 // eslint-disable-next-line @typescript-eslint/naming-convention
665 static HTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58666 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37667 }
668
Jan Schefflerd6c1d402021-02-26 16:56:38669 static _resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03670 return request.resourceType().name() === value;
671 }
672
Jan Schefflerd6c1d402021-02-26 16:56:38673 static _requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17674 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03675 return regex.test(request.url());
676 }
677
Jan Schefflerd6c1d402021-02-26 16:56:38678 static _requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
679 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34680 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37681 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34682 }
683 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37684 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34685 }
Blink Reformat4c46d092018-04-07 15:32:37686 return true;
687 }
688
Jan Schefflerd6c1d402021-02-26 16:56:38689 static _copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13690 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37691 }
692
Jan Schefflerd6c1d402021-02-26 16:56:38693 static _copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13694 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37695 }
696
Jan Schefflerd6c1d402021-02-26 16:56:38697 static async _copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37698 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38699 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34700 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40701 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37702 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08703 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34704 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13705 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37706 }
707
Jan Schefflerd6c1d402021-02-26 16:56:38708 _handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37709 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34710 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37711 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34712 }
Blink Reformat4c46d092018-04-07 15:32:37713 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34714 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37715 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34716 }
Blink Reformat4c46d092018-04-07 15:32:37717
Joey Arhar0e1093c2019-05-21 00:34:22718 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37719 }
720
Jan Schefflerd6c1d402021-02-26 16:56:38721 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13722 const outputStream = new Common.StringOutputStream.StringOutputStream();
723 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37724 const success = await reader.read(outputStream);
725 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37726 const error = reader.error();
727 if (error) {
Jan Schefflerd6c1d402021-02-26 16:56:38728 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
729 // eslint-disable-next-line @typescript-eslint/no-explicit-any
730 this._harLoadFailed((error as any).message);
Tim van der Lippe224a8622020-09-23 12:14:37731 }
Blink Reformat4c46d092018-04-07 15:32:37732 return;
733 }
734 let harRoot;
735 try {
736 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56737 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37738 } catch (e) {
739 this._harLoadFailed(e);
740 return;
741 }
Tim van der Lippe09cf5032021-04-29 15:08:09742 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37743 }
744
Jan Schefflerd6c1d402021-02-26 16:56:38745 _harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36746 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37747 }
748
Jan Schefflerd6c1d402021-02-26 16:56:38749 _setGrouping(groupKey: string|null): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34750 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37751 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34752 }
Blink Reformat4c46d092018-04-07 15:32:37753 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
754 this._activeGroupLookup = groupLookup;
755 this._invalidateAllItems();
756 }
757
Jan Schefflerd6c1d402021-02-26 16:56:38758 _computeRowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37759 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
760 }
761
Jan Schefflerd6c1d402021-02-26 16:56:38762 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37763 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37764 }
765
Jan Schefflerd6c1d402021-02-26 16:56:38766 headerHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37767 return this._headerHeight;
768 }
769
Jan Schefflerd6c1d402021-02-26 16:56:38770 setRecording(recording: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:37771 this._recording = recording;
772 this._updateSummaryBar();
773 }
774
Jan Schefflerd6c1d402021-02-26 16:56:38775 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37776 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34777 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37778 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34779 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13780 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37781 if (resourceTreeModel) {
782 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
783 resourceTreeModel.addEventListener(
784 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
785 }
786 }
787
Jan Schefflerd6c1d402021-02-26 16:56:38788 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37789 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13790 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37791 if (resourceTreeModel) {
792 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
793 resourceTreeModel.removeEventListener(
794 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
795 }
796 }
797 }
798
Jan Schefflerd6c1d402021-02-26 16:56:38799 linkifier(): Components.Linkifier.Linkifier {
Simon Zündcdd72c92020-10-07 11:48:13800 return this._linkifier;
801 }
802
Jan Schefflerd6c1d402021-02-26 16:56:38803 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37804 if (!start && !end) {
805 this._timeFilter = null;
806 this._timeCalculator.setWindow(null);
807 } else {
Paul Lewis56509652019-12-06 12:51:58808 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30809 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37810 }
811 this._filterRequests();
812 }
813
Jan Schefflerd6c1d402021-02-26 16:56:38814 resetFocus(): void {
Brandon Goddard88d885a2019-10-31 16:11:05815 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37816 }
817
Jan Schefflerd6c1d402021-02-26 16:56:38818 _resetSuggestionBuilder(): void {
Blink Reformat4c46d092018-04-07 15:32:37819 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58820 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
821 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
822 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
823 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
824 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
825 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
826 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37827 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
828 }
829
Jan Schefflerd6c1d402021-02-26 16:56:38830 _filterChanged(_event: Common.EventTarget.EventTargetEvent): void {
Blink Reformat4c46d092018-04-07 15:32:37831 this.removeAllNodeHighlights();
832 this._parseFilterQuery(this._textFilterUI.value());
833 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03834 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37835 }
836
Jan Schefflerd6c1d402021-02-26 16:56:38837 async resetFilter(): Promise<void> {
Rajasekar Murugan3ad369e2020-02-19 18:20:12838 this._textFilterUI.clear();
839 }
840
Jan Schefflerd6c1d402021-02-26 16:56:38841 _showRecordingHint(): void {
Blink Reformat4c46d092018-04-07 15:32:37842 this._hideRecordingHint();
843 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
844 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18845
Blink Reformat4c46d092018-04-07 15:32:37846 if (this._recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38847 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04848 const reloadShortcut =
849 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
850 if (reloadShortcut) {
851 reloadShortcutNode = this._recordingHint.createChild('b');
852 reloadShortcutNode.textContent = reloadShortcut.title();
853 }
854
Blink Reformat4c46d092018-04-07 15:32:37855 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55856 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18857 if (reloadShortcutNode) {
858 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55859 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
860 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18861 }
Blink Reformat4c46d092018-04-07 15:32:37862 } else {
863 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17864 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37865 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55866 hintText.appendChild(
867 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordSToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37868 }
Kayce Basques5444c1b2019-02-15 20:32:53869 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13870 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35871 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55872 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11873
874 this._setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37875 }
876
Jan Schefflerd6c1d402021-02-26 16:56:38877 _hideRecordingHint(): void {
Amanda Baker6761aae2019-11-05 18:59:11878 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34879 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37880 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34881 }
Michael Liao7322dee2021-04-07 18:33:30882 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Blink Reformat4c46d092018-04-07 15:32:37883 this._recordingHint = null;
884 }
885
Jan Schefflerd6c1d402021-02-26 16:56:38886 _setHidden(value: boolean): void {
Amanda Baker6761aae2019-11-05 18:59:11887 this._columns.setHidden(value);
888 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
889 }
890
Jan Schefflerd6c1d402021-02-26 16:56:38891 elementsToRestoreScrollPositionsFor(): Element[] {
Blink Reformat4c46d092018-04-07 15:32:37892 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34893 {
Blink Reformat4c46d092018-04-07 15:32:37894 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34895 }
Blink Reformat4c46d092018-04-07 15:32:37896 return [this._dataGrid.scrollContainer];
897 }
898
Jan Schefflerd6c1d402021-02-26 16:56:38899 columnExtensionResolved(): void {
Blink Reformat4c46d092018-04-07 15:32:37900 this._invalidateAllItems(true);
901 }
902
Jan Schefflerd6c1d402021-02-26 16:56:38903 _setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Blink Reformat4c46d092018-04-07 15:32:37904 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38905 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34906 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37907 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34908 }
Blink Reformat4c46d092018-04-07 15:32:37909 });
910 this._dataGrid.setStickToBottom(true);
911 this._dataGrid.setName('networkLog');
912 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
913 this._dataGrid.element.classList.add('network-log-grid');
914 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
915 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
916 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05917 this._dataGrid.element.addEventListener('keydown', event => {
Olivia Flynn54728dd2021-05-21 20:15:43918 if (event.key === 'ArrowRight' && this._dataGrid.selectedNode) {
919 const initiatorLink = this._dataGrid.selectedNode.element().querySelector('span.devtools-link');
920 if (initiatorLink) {
921 (initiatorLink as HTMLElement).focus();
922 }
923 }
Brandon Goddard88d885a2019-10-31 16:11:05924 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05925 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05926 event.consume(true);
927 }
928 });
Brandon Goddard44934902020-03-25 16:03:18929 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
930 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37931 return this._dataGrid;
932 }
933
Jan Schefflerd6c1d402021-02-26 16:56:38934 _dataGridMouseMove(event: Event): void {
935 const mouseEvent = (event as MouseEvent);
936 const node = (this._dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:37937 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Schefflerd6c1d402021-02-26 16:56:38938 this._setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:37939 }
940
Jan Schefflerd6c1d402021-02-26 16:56:38941 hoveredNode(): NetworkNode|null {
Blink Reformat4c46d092018-04-07 15:32:37942 return this._hoveredNode;
943 }
944
Jan Schefflerd6c1d402021-02-26 16:56:38945 _setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34946 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37947 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34948 }
Blink Reformat4c46d092018-04-07 15:32:37949 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34950 if (this._hoveredNode) {
Tim van der Lipped7cfd142021-01-07 12:17:24951 this._hoveredNode.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:34952 }
Blink Reformat4c46d092018-04-07 15:32:37953 }
954
Jan Schefflerd6c1d402021-02-26 16:56:38955 _dataGridMouseDown(event: Event): void {
956 const mouseEvent = (event as MouseEvent);
Tim van der Lippe224a8622020-09-23 12:14:37957 if (!this._dataGrid.selectedNode && mouseEvent.button) {
958 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 }
Blink Reformat4c46d092018-04-07 15:32:37960 }
961
Jan Schefflerd6c1d402021-02-26 16:56:38962 _updateSummaryBar(): void {
Blink Reformat4c46d092018-04-07 15:32:37963 this._hideRecordingHint();
964
965 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20966 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37967 let selectedNodeNumber = 0;
968 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20969 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37970 let baseTime = -1;
971 let maxTime = -1;
972
973 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:27974 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37975 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34976 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37977 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34978 }
Blink Reformat4c46d092018-04-07 15:32:37979 nodeCount++;
980 const requestTransferSize = request.transferSize;
981 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20982 const requestResourceSize = request.resourceSize;
983 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37984 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37985 selectedNodeNumber++;
986 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20987 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37988 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13989 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37990 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
991 // inspected url.
992 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13993 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
994 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37995 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34996 }
997 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37998 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34999 }
Blink Reformat4c46d092018-04-07 15:32:371000 }
1001
1002 if (!nodeCount) {
1003 this._showRecordingHint();
1004 return;
1005 }
1006
Joey Arhara86c14e2019-03-12 03:20:501007 this._summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381008 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131009 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501010 toolbarText.setTitle(title ? title : chunk);
1011 this._summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381012 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501013 };
Blink Reformat4c46d092018-04-07 15:32:371014
1015 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551016 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501017 this._summaryToolbar.appendSeparator();
1018 appendChunk(
Christy Chencac3f102021-02-03 10:07:551019 i18nString(UIStrings.sSTransferred, {
1020 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381021 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551022 }),
1023 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501024 this._summaryToolbar.appendSeparator();
1025 appendChunk(
Christy Chencac3f102021-02-03 10:07:551026 i18nString(UIStrings.sSResources, {
1027 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381028 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551029 }),
1030 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371031 } else {
Christy Chencac3f102021-02-03 10:07:551032 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501033 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251034 appendChunk(
Christy Chencac3f102021-02-03 10:07:551035 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1036 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501037 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251038 appendChunk(
Christy Chencac3f102021-02-03 10:07:551039 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1040 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371041 }
Dan Beam87466b52018-12-01 18:41:201042
Blink Reformat4c46d092018-04-07 15:32:371043 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501044 this._summaryToolbar.appendSeparator();
Kriti Sapra915aed72021-06-04 11:29:581045 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.i18n.secondsToString(maxTime - baseTime)}));
Blink Reformat4c46d092018-04-07 15:32:371046 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:501047 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551048 const domContentLoadedText = i18nString(
1049 UIStrings.domcontentloadedS,
Kriti Sapra915aed72021-06-04 11:29:581050 {PH1: i18n.i18n.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581051 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371052 }
1053 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501054 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551055 const loadText =
Kriti Sapra915aed72021-06-04 11:29:581056 i18nString(UIStrings.loadS, {PH1: i18n.i18n.secondsToString(this._mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581057 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371058 }
1059 }
Blink Reformat4c46d092018-04-07 15:32:371060 }
1061
Jan Schefflerd6c1d402021-02-26 16:56:381062 scheduleRefresh(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341063 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371064 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341065 }
Blink Reformat4c46d092018-04-07 15:32:371066
1067 this._needsRefresh = true;
1068
Tim van der Lippe1d6e57a2019-09-30 11:55:341069 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:371070 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341071 }
Blink Reformat4c46d092018-04-07 15:32:371072 }
1073
Jan Schefflerd6c1d402021-02-26 16:56:381074 addFilmStripFrames(times: number[]): void {
Blink Reformat4c46d092018-04-07 15:32:371075 this._columns.addEventDividers(times, 'network-frame-divider');
1076 }
1077
Jan Schefflerd6c1d402021-02-26 16:56:381078 selectFilmStripFrame(time: number): void {
Blink Reformat4c46d092018-04-07 15:32:371079 this._columns.selectFilmStripFrame(time);
1080 }
1081
Jan Schefflerd6c1d402021-02-26 16:56:381082 clearFilmStripFrame(): void {
Blink Reformat4c46d092018-04-07 15:32:371083 this._columns.clearFilmStripFrame();
1084 }
1085
Jan Schefflerd6c1d402021-02-26 16:56:381086 _refreshIfNeeded(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341087 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371088 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341089 }
Blink Reformat4c46d092018-04-07 15:32:371090 }
1091
Jan Schefflerd6c1d402021-02-26 16:56:381092 _invalidateAllItems(deferUpdate?: boolean): void {
Sigurd Schneidercf5b8302021-04-23 07:52:271093 this._staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341094 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371095 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341096 } else {
Blink Reformat4c46d092018-04-07 15:32:371097 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341098 }
Blink Reformat4c46d092018-04-07 15:32:371099 }
1100
Jan Schefflerd6c1d402021-02-26 16:56:381101 timeCalculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371102 return this._timeCalculator;
1103 }
1104
Jan Schefflerd6c1d402021-02-26 16:56:381105 calculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371106 return this._calculator;
1107 }
1108
Jan Schefflerd6c1d402021-02-26 16:56:381109 setCalculator(x: NetworkTimeCalculator): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341110 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371111 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341112 }
Blink Reformat4c46d092018-04-07 15:32:371113
1114 if (this._calculator !== x) {
1115 this._calculator = x;
1116 this._columns.setCalculator(this._calculator);
1117 }
1118 this._calculator.reset();
1119
Tim van der Lippe1d6e57a2019-09-30 11:55:341120 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371121 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341122 } else {
Blink Reformat4c46d092018-04-07 15:32:371123 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341124 }
Blink Reformat4c46d092018-04-07 15:32:371125
1126 this._invalidateAllItems();
1127 }
1128
Jan Schefflerd6c1d402021-02-26 16:56:381129 _loadEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341130 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371131 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341132 }
Blink Reformat4c46d092018-04-07 15:32:371133
Jan Schefflerd6c1d402021-02-26 16:56:381134 const time = (event.data.loadTime as number);
Blink Reformat4c46d092018-04-07 15:32:371135 if (time) {
1136 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301137 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371138 }
1139 }
1140
Jan Schefflerd6c1d402021-02-26 16:56:381141 _domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341142 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371143 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 }
Jan Schefflerd6c1d402021-02-26 16:56:381145 const data = (event.data as number);
Blink Reformat4c46d092018-04-07 15:32:371146 if (data) {
1147 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301148 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371149 }
1150 }
1151
Jan Schefflerd6c1d402021-02-26 16:56:381152 wasShown(): void {
Blink Reformat4c46d092018-04-07 15:32:371153 this._refreshIfNeeded();
1154 this._columns.wasShown();
1155 }
1156
Jan Schefflerd6c1d402021-02-26 16:56:381157 willHide(): void {
Blink Reformat4c46d092018-04-07 15:32:371158 this._columns.willHide();
1159 }
1160
Jan Schefflerd6c1d402021-02-26 16:56:381161 onResize(): void {
Blink Reformat4c46d092018-04-07 15:32:371162 this._rowHeight = this._computeRowHeight();
1163 }
1164
Jan Schefflerd6c1d402021-02-26 16:56:381165 flatNodesList(): NetworkNode[] {
1166 const rootNode =
1167 (this._dataGrid.rootNode() as
1168 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1169 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371170 }
1171
Jan Schefflerd6c1d402021-02-26 16:56:381172 _onDataGridFocus(): void {
Peter Marshallde3fee72020-08-24 14:12:491173 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351174 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381175 }
Brandon Goddard44934902020-03-25 16:03:181176 this.updateNodeBackground();
1177 }
1178
Jan Schefflerd6c1d402021-02-26 16:56:381179 _onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181180 this.element.classList.remove('grid-focused');
1181 this.updateNodeBackground();
1182 }
1183
Jan Schefflerd6c1d402021-02-26 16:56:381184 updateNodeBackground(): void {
Brandon Goddard88d885a2019-10-31 16:11:051185 if (this._dataGrid.selectedNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381186 (this._dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051187 }
1188 }
1189
Jan Schefflerd6c1d402021-02-26 16:56:381190 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051191 if (isSelected) {
1192 this.element.classList.remove('no-node-selected');
1193 } else {
1194 this.element.classList.add('no-node-selected');
1195 }
1196 }
1197
Jan Schefflerd6c1d402021-02-26 16:56:381198 stylesChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371199 this._columns.scheduleRefresh();
1200 }
1201
Jan Schefflerd6c1d402021-02-26 16:56:381202 _refresh(): void {
Blink Reformat4c46d092018-04-07 15:32:371203 this._needsRefresh = false;
1204
1205 if (this._refreshRequestId) {
1206 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1207 this._refreshRequestId = null;
1208 }
1209
1210 this.removeAllNodeHighlights();
1211
1212 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1213 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1214 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1215 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1216
Jan Schefflerd6c1d402021-02-26 16:56:381217 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1218 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371219
Jan Schefflerd6c1d402021-02-26 16:56:381220 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371221
1222 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1223 // node so we loop until we have no more stale requests.
1224 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371225 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371226 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371227 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341228 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371229 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341230 }
Blink Reformat4c46d092018-04-07 15:32:371231 staleNodes.add(node);
1232 }
1233
1234 for (const node of staleNodes) {
1235 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341236 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371237 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341238 }
Blink Reformat4c46d092018-04-07 15:32:371239
Tim van der Lippe1d6e57a2019-09-30 11:55:341240 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371241 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341242 }
Blink Reformat4c46d092018-04-07 15:32:371243 const request = node.request();
1244 this._timeCalculator.updateBoundaries(request);
1245 this._durationCalculator.updateBoundaries(request);
1246 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371247 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1248 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371249 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341250 }
Tim van der Lippe224a8622020-09-23 12:14:371251 if (isFilteredOut) {
1252 filteredNetworkRequests.add(node);
1253 } else {
1254 filteredNetworkRequests.delete(node);
1255 }
Blink Reformat4c46d092018-04-07 15:32:371256 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1257 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381258 let parent: NetworkNode|
1259 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1260 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1261 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111262 if (!parent) {
1263 continue;
1264 }
Blink Reformat4c46d092018-04-07 15:32:371265 parent.removeChild(node);
1266 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381267 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371268 grandparent.removeChild(parent);
1269 parent = grandparent;
1270 }
1271 }
1272
Tim van der Lippe1d6e57a2019-09-30 11:55:341273 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371274 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341275 }
Blink Reformat4c46d092018-04-07 15:32:371276
1277 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jan Schefflerd6c1d402021-02-26 16:56:381278 nodesToInsert.set(newParent, (this._dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371279 nodesToRefresh.push(newParent);
1280 }
1281 nodesToInsert.set(node, newParent);
1282 }
1283
Tim van der Lippe1d6e57a2019-09-30 11:55:341284 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381285 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341286 }
Blink Reformat4c46d092018-04-07 15:32:371287
Tim van der Lippe1d6e57a2019-09-30 11:55:341288 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371289 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341290 }
Blink Reformat4c46d092018-04-07 15:32:371291
1292 this._updateSummaryBar();
1293
Tim van der Lippe1d6e57a2019-09-30 11:55:341294 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371295 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341296 }
Blink Reformat4c46d092018-04-07 15:32:371297
1298 this._dataGrid.updateInstantly();
1299 this._didRefreshForTest();
1300 }
1301
Jan Schefflerd6c1d402021-02-26 16:56:381302 _didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371303 }
1304
Jan Schefflerd6c1d402021-02-26 16:56:381305 _parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Tim van der Lippe1d6e57a2019-09-30 11:55:341306 if (!this._activeGroupLookup) {
Jan Schefflerd6c1d402021-02-26 16:56:381307 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341308 }
Blink Reformat4c46d092018-04-07 15:32:371309
1310 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341311 if (!groupNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381312 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341313 }
Blink Reformat4c46d092018-04-07 15:32:371314 return groupNode;
1315 }
1316
Jan Schefflerd6c1d402021-02-26 16:56:381317 _reset(): void {
Simon Zünd98419832020-03-12 06:18:151318 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371319
1320 this._setHoveredNode(null);
1321 this._columns.reset();
1322
1323 this._timeFilter = null;
1324 this._calculator.reset();
1325
1326 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131327 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371328
Tim van der Lippe1d6e57a2019-09-30 11:55:341329 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371330 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341331 }
Blink Reformat4c46d092018-04-07 15:32:371332 this._staleRequests.clear();
1333 this._resetSuggestionBuilder();
1334
1335 this._mainRequestLoadTime = -1;
1336 this._mainRequestDOMContentLoadedTime = -1;
1337
1338 this._dataGrid.rootNode().removeChildren();
1339 this._updateSummaryBar();
1340 this._dataGrid.setStickToBottom(true);
1341 this.scheduleRefresh();
1342 }
1343
Jan Schefflerd6c1d402021-02-26 16:56:381344 setTextFilterValue(filterString: string): void {
Blink Reformat4c46d092018-04-07 15:32:371345 this._textFilterUI.setValue(filterString);
1346 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371347 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131348 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371349 this._resourceCategoryFilterUI.reset();
1350 }
1351
Jan Schefflerd6c1d402021-02-26 16:56:381352 _createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301353 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371354 networkRequestToNode.set(request, node);
1355 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371356
Tim van der Lippe1d6e57a2019-09-30 11:55:341357 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371358 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341359 }
Blink Reformat4c46d092018-04-07 15:32:371360 return node;
1361 }
1362
Jan Schefflerd6c1d402021-02-26 16:56:381363 _onRequestUpdated(event: Common.EventTarget.EventTargetEvent): void {
1364 const request = (event.data as SDK.NetworkRequest.NetworkRequest);
Blink Reformat4c46d092018-04-07 15:32:371365 this._refreshRequest(request);
1366 }
1367
Jan Schefflerd6c1d402021-02-26 16:56:381368 _refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Paul Lewis56509652019-12-06 12:51:581369 NetworkLogView._subdomains(request.domain)
1370 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1371 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1372 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
Tim van der Lipped7cfd142021-01-07 12:17:241373 this._suggestionBuilder.addItem(FilterType.Scheme, String(request.scheme));
1374 this._suggestionBuilder.addItem(FilterType.StatusCode, String(request.statusCode));
Sigurd Schneider464838b2020-08-24 13:53:031375 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031376 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371377
1378 const priority = request.priority();
1379 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501380 this._suggestionBuilder.addItem(
1381 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371382 }
1383
1384 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581385 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371386 }
1387
1388 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581389 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371390 }
1391
1392 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581393 const suggestion =
1394 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1395 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371396 }
1397
1398 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341399 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581400 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341401 }
Jan Scheffler341eea52019-12-12 09:08:411402
1403 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581404 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1405 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1406 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371407 }
1408
Jan Scheffler341eea52019-12-12 09:08:411409 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1410 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1411 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541412 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411413 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1414 }
1415
Blink Reformat4c46d092018-04-07 15:32:371416 this._staleRequests.add(request);
1417 this.scheduleRefresh();
1418 }
1419
Jan Schefflerd6c1d402021-02-26 16:56:381420 rowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:371421 return this._rowHeight;
1422 }
1423
Jan Schefflerd6c1d402021-02-26 16:56:381424 switchViewMode(gridMode: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:371425 this._columns.switchViewMode(gridMode);
1426 }
1427
Jan Schefflerd6c1d402021-02-26 16:56:381428 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1429 void {
Blink Reformat4c46d092018-04-07 15:32:371430 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551431 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371432 const footerSection = copyMenu.footerSection();
1433 if (request) {
1434 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 UI.UIUtils.copyLinkAddressLabel(),
1436 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1437 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371438 if (request.requestHeadersText()) {
1439 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551440 i18nString(UIStrings.copyRequestHeaders), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371441 }
1442
1443 if (request.responseHeadersText) {
1444 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551445 i18nString(UIStrings.copyResponseHeaders), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371446 }
1447
1448 if (request.finished) {
1449 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551450 i18nString(UIStrings.copyResponse), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371451 }
1452
Tim van der Lippeb4faf5a2020-11-06 15:02:021453 const initiator = request.initiator();
1454
1455 if (initiator) {
1456 const stack = initiator.stack;
1457 if (stack) {
1458 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1459 // has any context solely based on the top frame. Sometimes, the top frame does not have
1460 // any callFrames, but its parent frames do.
1461 const stackTraceText = computeStackTraceText(stack);
1462 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551463 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021464 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1465 });
1466 }
1467 }
1468 }
1469
Harley Libcf41f92018-09-10 18:01:131470 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131471 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371472 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551473 i18nString(UIStrings.copyAsPowershell), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371474 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551475 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291476 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551477 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371478 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551479 i18nString(UIStrings.copyAsCurlCmd), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131480 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551481 i18nString(UIStrings.copyAsCurlBash), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1482 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this._copyAllPowerShellCommand.bind(this));
1483 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1484 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1485 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this._copyAllCurlCommand.bind(this, 'win'));
1486 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371487 } else {
Harley Libcf41f92018-09-10 18:01:131488 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551489 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291490 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551491 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131492 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551493 i18nString(UIStrings.copyAsCurl), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1494 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1495 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1496 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371497 }
1498 } else {
Christy Chencac3f102021-02-03 10:07:551499 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371500 }
Christy Chencac3f102021-02-03 10:07:551501 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371502
Christy Chencac3f102021-02-03 10:07:551503 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371504
Christy Chencac3f102021-02-03 10:07:551505 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this._clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371506 contextMenu.editSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551507 i18nString(UIStrings.clearBrowserCookies), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371508
1509 if (request) {
1510 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211511 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371512 let patterns = manager.blockedPatterns();
1513
Jan Schefflerd6c1d402021-02-26 16:56:381514 function addBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121515 patterns.push({enabled: true, url: url});
1516 manager.setBlockedPatterns(patterns);
1517 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261518 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121519 }
1520
Jan Schefflerd6c1d402021-02-26 16:56:381521 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121522 patterns = patterns.filter(pattern => pattern.url !== url);
1523 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261524 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121525 }
1526
Blink Reformat4c46d092018-04-07 15:32:371527 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1528 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1529 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551530 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371531 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311532 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371533 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551534 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371535 }
1536
1537 const domain = request.parsedURL.domain();
1538 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1539 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551540 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371541 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311542 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371543 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551544 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371545 }
1546
Tim van der Lippe0ed1d2b2020-02-04 13:45:131547 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371548 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551549 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371550 }
Blink Reformat4c46d092018-04-07 15:32:371551 }
1552 }
1553
Jan Schefflerd6c1d402021-02-26 16:56:381554 _harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271555 return Logs.NetworkLog.NetworkLog.instance()
1556 .requests()
1557 .filter(NetworkLogView.HTTPRequestsFilter)
1558 .filter(request => {
1559 return request.finished ||
1560 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1561 });
Blink Reformat4c46d092018-04-07 15:32:371562 }
1563
Jan Schefflerd6c1d402021-02-26 16:56:381564 async _copyAll(): Promise<void> {
Tim van der Lippe09cf5032021-04-29 15:08:091565 const harArchive = {log: await HAR.Log.Log.build(this._harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131566 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371567 }
1568
Jan Schefflerd6c1d402021-02-26 16:56:381569 async _copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371570 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131571 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371572 }
1573
Jan Schefflerd6c1d402021-02-26 16:56:381574 async _copyAllCurlCommand(platform: string): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271575 const commands = await this._generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131576 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371577 }
1578
Jan Schefflerd6c1d402021-02-26 16:56:381579 async _copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<void> {
Jan Scheffler7c50d1f2019-12-17 13:33:291580 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131581 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371582 }
1583
Jan Schefflerd6c1d402021-02-26 16:56:381584 async _copyAllFetchCall(includeCookies: boolean): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271585 const commands = await this._generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131586 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371587 }
1588
Jan Schefflerd6c1d402021-02-26 16:56:381589 async _copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371590 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131591 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371592 }
1593
Jan Schefflerd6c1d402021-02-26 16:56:381594 async _copyAllPowerShellCommand(): Promise<void> {
Sigurd Schneidercf5b8302021-04-23 07:52:271595 const commands = await this._generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131596 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371597 }
1598
Jan Schefflerd6c1d402021-02-26 16:56:381599 async exportAll(): Promise<void> {
Sigurd Schneiderb9f6c792021-05-31 10:57:241600 const mainTarget = SDK.TargetManager.TargetManager.instance().mainTarget();
Tim van der Lippe224a8622020-09-23 12:14:371601 if (!mainTarget) {
1602 return;
1603 }
1604 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131605 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371606 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131607 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371608
Tim van der Lippe1d6e57a2019-09-30 11:55:341609 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371610 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341611 }
Blink Reformat4c46d092018-04-07 15:32:371612
Tim van der Lippe0ed1d2b2020-02-04 13:45:131613 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371614 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe09cf5032021-04-29 15:08:091615 await HAR.Writer.Writer.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371616 progressIndicator.done();
1617 stream.close();
1618 }
1619
Jan Schefflerd6c1d402021-02-26 16:56:381620 _clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551621 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211622 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341623 }
Blink Reformat4c46d092018-04-07 15:32:371624 }
1625
Jan Schefflerd6c1d402021-02-26 16:56:381626 _clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551627 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211628 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341629 }
Blink Reformat4c46d092018-04-07 15:32:371630 }
1631
Jan Schefflerd6c1d402021-02-26 16:56:381632 _removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371633 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341634 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131635 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341636 }
Blink Reformat4c46d092018-04-07 15:32:371637 this._highlightedSubstringChanges = [];
1638 }
1639
Jan Schefflerd6c1d402021-02-26 16:56:381640 _applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371641 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341642 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371643 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341644 }
Christy Chen1825c612021-02-25 10:28:441645 const categoryName = request.resourceType().category().title();
Tim van der Lippe1d6e57a2019-09-30 11:55:341646 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371647 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341648 }
1649 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371650 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341651 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221652 if (this._onlyIssuesFilterUI.checked() &&
Sigurd Schneider84b6cf72021-04-13 06:40:541653 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371654 return false;
1655 }
Sigurd Schneider20088de2020-10-30 08:08:331656 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131657 return false;
1658 }
Blink Reformat4c46d092018-04-07 15:32:371659 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341660 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371661 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341662 }
Blink Reformat4c46d092018-04-07 15:32:371663 }
1664 return true;
1665 }
1666
Jan Schefflerd6c1d402021-02-26 16:56:381667 _parseFilterQuery(query: string): void {
Blink Reformat4c46d092018-04-07 15:32:371668 const descriptors = this._filterParser.parse(query);
1669 this._filters = descriptors.map(descriptor => {
1670 const key = descriptor.key;
1671 const text = descriptor.text || '';
1672 const regex = descriptor.regex;
1673 let filter;
1674 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171675 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Schefflerd6c1d402021-02-26 16:56:381676 filter = this._createSpecialFilter((key as FilterType), text) ||
Paul Lewis56509652019-12-06 12:51:581677 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371678 } else if (descriptor.regex) {
Jan Schefflerd6c1d402021-02-26 16:56:381679 filter = NetworkLogView._requestPathFilter.bind(null, (regex as RegExp));
Blink Reformat4c46d092018-04-07 15:32:371680 } else {
Tim van der Lippebafa3bd2021-01-20 12:19:171681 filter = NetworkLogView._requestPathFilter.bind(
1682 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371683 }
Paul Lewis56509652019-12-06 12:51:581684 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371685 });
1686 }
1687
Jan Schefflerd6c1d402021-02-26 16:56:381688 _createSpecialFilter(type: FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371689 switch (type) {
Paul Lewis56509652019-12-06 12:51:581690 case FilterType.Domain:
1691 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371692
Paul Lewis56509652019-12-06 12:51:581693 case FilterType.HasResponseHeader:
1694 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371695
Paul Lewis56509652019-12-06 12:51:581696 case FilterType.Is:
1697 if (value.toLowerCase() === IsFilterType.Running) {
1698 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341699 }
Paul Lewis56509652019-12-06 12:51:581700 if (value.toLowerCase() === IsFilterType.FromCache) {
1701 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341702 }
Paul Lewis56509652019-12-06 12:51:581703 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1704 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341705 }
Paul Lewis56509652019-12-06 12:51:581706 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1707 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341708 }
Blink Reformat4c46d092018-04-07 15:32:371709 break;
1710
Paul Lewis56509652019-12-06 12:51:581711 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371712 return this._createSizeFilter(value.toLowerCase());
1713
Paul Lewis56509652019-12-06 12:51:581714 case FilterType.Method:
1715 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371716
Paul Lewis56509652019-12-06 12:51:581717 case FilterType.MimeType:
1718 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371719
Paul Lewis56509652019-12-06 12:51:581720 case FilterType.MixedContent:
Jan Schefflerd6c1d402021-02-26 16:56:381721 return NetworkLogView._requestMixedContentFilter.bind(null, (value as MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371722
Paul Lewis56509652019-12-06 12:51:581723 case FilterType.Scheme:
1724 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371725
Paul Lewis56509652019-12-06 12:51:581726 case FilterType.SetCookieDomain:
1727 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371728
Paul Lewis56509652019-12-06 12:51:581729 case FilterType.SetCookieName:
1730 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371731
Paul Lewis56509652019-12-06 12:51:581732 case FilterType.SetCookieValue:
1733 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371734
Jan Scheffler341eea52019-12-12 09:08:411735 case FilterType.CookieDomain:
1736 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1737
1738 case FilterType.CookieName:
1739 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1740
Simon Zündc9759102020-03-25 11:24:541741 case FilterType.CookiePath:
1742 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1743
Jan Scheffler341eea52019-12-12 09:08:411744 case FilterType.CookieValue:
1745 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1746
Paul Lewis56509652019-12-06 12:51:581747 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501748 return NetworkLogView._requestPriorityFilter.bind(
1749 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371750
Paul Lewis56509652019-12-06 12:51:581751 case FilterType.StatusCode:
1752 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031753
1754 case FilterType.ResourceType:
1755 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031756
1757 case FilterType.Url:
1758 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371759 }
1760 return null;
1761 }
1762
Jan Schefflerd6c1d402021-02-26 16:56:381763 _createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371764 let multiplier = 1;
1765 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541766 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371767 value = value.substring(0, value.length - 1);
1768 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541769 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371770 value = value.substring(0, value.length - 1);
1771 }
1772 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341773 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371774 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341775 }
Paul Lewis56509652019-12-06 12:51:581776 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371777 }
1778
Jan Schefflerd6c1d402021-02-26 16:56:381779 _filterRequests(): void {
Blink Reformat4c46d092018-04-07 15:32:371780 this._removeAllHighlights();
1781 this._invalidateAllItems();
1782 }
1783
Jan Schefflerd6c1d402021-02-26 16:56:381784 _reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371785 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371786 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341787 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371788 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341789 }
Brandon Goddard5e4244d2020-04-08 22:08:471790 // Viewport datagrid nodes do not reveal if not in the root node
1791 // list of flatChildren. For children of grouped frame nodes:
1792 // reveal and expand parent to ensure child is revealable.
1793 if (node.parent && node.parent instanceof NetworkGroupNode) {
1794 node.parent.reveal();
1795 node.parent.expand();
1796 }
Blink Reformat4c46d092018-04-07 15:32:371797 node.reveal();
1798 return node;
1799 }
1800
Jan Schefflerd6c1d402021-02-26 16:56:381801 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Blink Reformat4c46d092018-04-07 15:32:371802 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341803 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371804 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341805 }
Blink Reformat4c46d092018-04-07 15:32:371806 }
1807
Jan Schefflerd6c1d402021-02-26 16:56:381808 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: FilterOptions): void {
chait pinnamaneni6bc1c122020-10-30 17:30:521809 const defaultOptions = {clearFilter: true};
1810 const {clearFilter} = options || defaultOptions;
1811 if (clearFilter) {
1812 this.setTextFilterValue('');
1813 }
Blink Reformat4c46d092018-04-07 15:32:371814 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341815 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371816 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341817 }
Blink Reformat4c46d092018-04-07 15:32:371818 }
1819
Jan Schefflerd6c1d402021-02-26 16:56:381820 removeAllNodeHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371821 if (this._highlightedNode) {
1822 this._highlightedNode.element().classList.remove('highlighted-row');
1823 this._highlightedNode = null;
1824 }
1825 }
1826
Jan Schefflerd6c1d402021-02-26 16:56:381827 _highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131828 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371829 this._highlightedNode = node;
1830 }
1831
Jan Schefflerd6c1d402021-02-26 16:56:381832 _filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131833 return requests.filter(request => !request.isBlobRequest());
1834 }
1835
Jan Schefflerd6c1d402021-02-26 16:56:381836 async _generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<string> {
1837 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371838 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371839 'method',
1840 'path',
1841 'scheme',
1842 'version',
Blink Reformat4c46d092018-04-07 15:32:371843
1844 // Unsafe headers
1845 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371846 'accept-charset',
1847 'accept-encoding',
1848 'access-control-request-headers',
1849 'access-control-request-method',
1850 'connection',
1851 'content-length',
1852 'cookie',
1853 'cookie2',
1854 'date',
1855 'dnt',
1856 'expect',
1857 'host',
1858 'keep-alive',
1859 'origin',
1860 'referer',
1861 'te',
1862 'trailer',
1863 'transfer-encoding',
1864 'upgrade',
1865 'via',
Blink Reformat4c46d092018-04-07 15:32:371866 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371867 'user-agent',
1868 ]);
Blink Reformat4c46d092018-04-07 15:32:371869
Jan Schefflerd6c1d402021-02-26 16:56:381870 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371871
1872 const url = JSON.stringify(request.url());
1873
1874 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:381875 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:371876 const name = header.name;
1877
Tim van der Lippe224a8622020-09-23 12:14:371878 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371879 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341880 }
Blink Reformat4c46d092018-04-07 15:32:371881
1882 return result;
1883 }, new Headers());
1884
Jan Schefflerd6c1d402021-02-26 16:56:381885 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341886 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411887 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341888 }
Blink Reformat4c46d092018-04-07 15:32:371889
Sigurd Schneider0e88b912020-05-08 08:28:231890 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371891 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411892 'include' :
1893 'omit';
Blink Reformat4c46d092018-04-07 15:32:371894
1895 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1896
1897 const referrer = referrerHeader ? referrerHeader.value : void 0;
1898
1899 const referrerPolicy = request.referrerPolicy() || void 0;
1900
1901 const requestBody = await request.requestFormData();
1902
Jan Schefflerd6c1d402021-02-26 16:56:381903 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:411904 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371905 referrer,
1906 referrerPolicy,
1907 body: requestBody,
1908 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371909 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371910 };
1911
Jan Scheffler7c50d1f2019-12-17 13:33:291912 if (includeCookies) {
1913 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1914 if (cookieHeader) {
1915 fetchOptions.headers = {
1916 ...headers,
1917 'cookie': cookieHeader.value,
1918 };
1919 }
1920 } else {
1921 fetchOptions.credentials = credentials;
1922 }
1923
Jan Scheffler172d5212020-01-02 14:42:561924 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371925 return `fetch(${url}, ${options});`;
1926 }
1927
Jan Schefflerd6c1d402021-02-26 16:56:381928 async _generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], includeCookies: boolean): Promise<string> {
Harley Libcf41f92018-09-10 18:01:131929 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291930 const commands =
1931 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131932 return commands.join(' ;\n');
1933 }
1934
Jan Schefflerd6c1d402021-02-26 16:56:381935 async _generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
1936 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:361937 // Most of these headers are derived from the URL and are automatically added by cURL.
1938 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:381939 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:371940
Jan Schefflerd6c1d402021-02-26 16:56:381941 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:371942 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:381943 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:371944
Jan Schefflerd6c1d402021-02-26 16:56:381945 Because cmd.exe parser and MS Crt arguments parsers use some of the
1946 same escape characters, they can interact with each other in
1947 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:371948
Jan Schefflerd6c1d402021-02-26 16:56:381949 Replace \ with \\ first because it is an escape character for certain
1950 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:371951
Jan Schefflerd6c1d402021-02-26 16:56:381952 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:371953
Jan Schefflerd6c1d402021-02-26 16:56:381954 Then escape all characters we are not sure about with ^ to ensure it
1955 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:371956
Jan Schefflerd6c1d402021-02-26 16:56:381957 The % character is special because MS Crt parser will try and look for
1958 ENV variables and fill them in it's place. We cannot escape them with %
1959 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1960 parser); So we can get cmd.exe parser to escape the character after it,
1961 if it is followed by a valid beginning character of an ENV variable.
1962 This ensures we do not try and double escape another ^ if it was placed
1963 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:371964
Jan Schefflerd6c1d402021-02-26 16:56:381965 Lastly we replace new lines with ^ and TWO new lines because the first
1966 new line is there to enact the escape command the second is the character
1967 to escape (in this case new line).
1968 */
Blink Reformat4c46d092018-04-07 15:32:371969 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1970 return encapsChars +
1971 str.replace(/\\/g, '\\\\')
1972 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:541973 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:371974 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:541975 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:371976 encapsChars;
1977 }
1978
Jan Schefflerd6c1d402021-02-26 16:56:381979 function escapeStringPosix(str: string): string {
1980 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:221981 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121982 let hexString = code.toString(16);
1983 // Zero pad to four digits to comply with ANSI-C Quoting:
1984 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341985 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121986 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341987 }
Joey Arhar2d21f712019-05-20 21:07:121988
1989 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371990 }
1991
Mathias Bynensf06e8c02020-02-28 13:58:281992 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371993 // Use ANSI-C quoting syntax.
1994 return '$\'' +
1995 str.replace(/\\/g, '\\\\')
1996 .replace(/\'/g, '\\\'')
1997 .replace(/\n/g, '\\n')
1998 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:281999 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372000 '\'';
Blink Reformat4c46d092018-04-07 15:32:372001 }
Mathias Bynensf06e8c02020-02-28 13:58:282002 // Use single quote syntax.
2003 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372004 }
2005
2006 // cURL command expected to run on the same platform that DevTools run
2007 // (it may be different from the inspected page platform).
2008 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2009
2010 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2011
2012 let inferredMethod = 'GET';
2013 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372014 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082015 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272016 // Note that formData is not necessarily urlencoded because it might for example
2017 // come from a fetch request made with an explicitly unencoded body.
2018 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372019 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372020 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372021 }
2022
2023 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292024 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372025 }
2026
2027 const requestHeaders = request.requestHeaders();
2028 for (let i = 0; i < requestHeaders.length; i++) {
2029 const header = requestHeaders[i];
2030 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372031 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372032 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342033 }
Jan Scheffler172d5212020-01-02 14:42:562034 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372035 }
2036 command = command.concat(data);
2037 command.push('--compressed');
2038
Tim van der Lippe1d6e57a2019-09-30 11:55:342039 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372040 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342041 }
Jan Scheffler172d5212020-01-02 14:42:562042 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372043 }
2044
Jan Schefflerd6c1d402021-02-26 16:56:382045 async _generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132046 const nonBlobRequests = this._filterOutBlobRequests(requests);
2047 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342048 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132049 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342050 }
Mathias Bynensf06e8c02020-02-28 13:58:282051 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132052 }
2053
Jan Schefflerd6c1d402021-02-26 16:56:382054 async _generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562055 const command = [];
Jan Schefflerd6c1d402021-02-26 16:56:382056 const ignoredHeaders = new Set<string>(
2057 ['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
Blink Reformat4c46d092018-04-07 15:32:372058
Jan Schefflerd6c1d402021-02-26 16:56:382059 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372060 return '"' +
2061 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2062 }
2063
Jan Scheffler172d5212020-01-02 14:42:562064 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372065
2066 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562067 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372068 }
2069
2070 const requestHeaders = request.requestHeaders();
2071 const headerNameValuePairs = [];
2072 for (const header of requestHeaders) {
2073 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342074 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372075 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342076 }
Blink Reformat4c46d092018-04-07 15:32:372077 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2078 }
2079 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562080 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372081 }
2082
2083 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2084 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562085 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372086 }
2087
2088 const formData = await request.requestFormData();
2089 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372090 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342091 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562092 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342093 } else {
Jan Scheffler172d5212020-01-02 14:42:562094 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342095 }
Blink Reformat4c46d092018-04-07 15:32:372096 }
2097
Jan Scheffler172d5212020-01-02 14:42:562098 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372099 }
Harley Libcf41f92018-09-10 18:01:132100
Jan Schefflerd6c1d402021-02-26 16:56:382101 async _generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132102 const nonBlobRequests = this._filterOutBlobRequests(requests);
2103 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2104 return commands.join(';\r\n');
2105 }
Joey Arhara86c14e2019-03-12 03:20:502106
Jan Schefflerd6c1d402021-02-26 16:56:382107 static getDCLEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512108 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502109 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342110 }
Joey Arhara86c14e2019-03-12 03:20:502111 return '#0867CB';
2112 }
2113
Jan Schefflerd6c1d402021-02-26 16:56:382114 static getLoadEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512115 return ThemeSupport.ThemeSupport.instance().patchColorText(
2116 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502117 }
Paul Lewis56509652019-12-06 12:51:582118}
Blink Reformat4c46d092018-04-07 15:32:372119
Jan Schefflerd6c1d402021-02-26 16:56:382120export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022121 let stackTraceText = '';
2122 for (const frame of stackTrace.callFrames) {
2123 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2124 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2125 }
2126 if (stackTrace.parent) {
2127 stackTraceText += computeStackTraceText(stackTrace.parent);
2128 }
2129 return stackTraceText;
2130}
2131
Jan Schefflerd6c1d402021-02-26 16:56:382132const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2133const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372134
Jan Schefflerd6c1d402021-02-26 16:56:382135export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372136 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222137}
2138
Paul Lewis56509652019-12-06 12:51:582139export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372140 'http': true,
2141 'https': true,
2142 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382143 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372144};
2145
Jan Schefflerd6c1d402021-02-26 16:56:382146// TODO(crbug.com/1167717): Make this a const enum again
2147// eslint-disable-next-line rulesdir/const_enum
2148export enum FilterType {
2149 Domain = 'domain',
2150 HasResponseHeader = 'has-response-header',
2151 Is = 'is',
2152 LargerThan = 'larger-than',
2153 Method = 'method',
2154 MimeType = 'mime-type',
2155 MixedContent = 'mixed-content',
2156 Priority = 'priority',
2157 Scheme = 'scheme',
2158 SetCookieDomain = 'set-cookie-domain',
2159 SetCookieName = 'set-cookie-name',
2160 SetCookieValue = 'set-cookie-value',
2161 ResourceType = 'resource-type',
2162 CookieDomain = 'cookie-domain',
2163 CookieName = 'cookie-name',
2164 CookiePath = 'cookie-path',
2165 CookieValue = 'cookie-value',
2166 StatusCode = 'status-code',
2167 Url = 'url',
Paul Lewis56509652019-12-06 12:51:582168}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162169
Jan Schefflerd6c1d402021-02-26 16:56:382170// TODO(crbug.com/1167717): Make this a const enum again
2171// eslint-disable-next-line rulesdir/const_enum
2172export enum MixedContentFilterValues {
2173 All = 'all',
2174 Displayed = 'displayed',
2175 Blocked = 'blocked',
2176 BlockOverridden = 'block-overridden',
2177}
2178
2179// TODO(crbug.com/1167717): Make this a const enum again
2180// eslint-disable-next-line rulesdir/const_enum
2181export enum IsFilterType {
2182 Running = 'running',
2183 FromCache = 'from-cache',
2184 ServiceWorkerIntercepted = 'service-worker-intercepted',
2185 ServiceWorkerInitiated = 'service-worker-initiated',
2186}
2187
2188// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
2189// eslint-disable-next-line @typescript-eslint/naming-convention
2190export const _searchKeys: string[] = Object.values(FilterType);
2191
2192export interface GroupLookupInterface {
2193 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2194 reset(): void;
2195}
2196
2197export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;