blob: cbbb99841213983f52b49d92a2d3dccc626ac0ef [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 Lippef596ca02021-03-31 10:02:4737import * as Components from '../../components/components.js';
Tim van der Lippe76961572021-04-06 10:48:0738import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3039import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2840import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2741import * as Platform from '../../core/platform/platform.js';
Tim van der Lippee00b92f2021-03-31 16:52:1742import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippef596ca02021-03-31 10:02:4743import * as HARImporter from '../../har_importer/har_importer.js';
Tim van der Lippe959b6f02021-04-07 09:07:5944import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneider055e2e32021-04-12 11:10:4245import * as IssuesManager from '../../models/issues_manager/issues_manager.js';
Tim van der Lippefca98ed2021-04-08 14:10:1446import * as TextUtils from '../../models/text_utils/text_utils.js';
Tim van der Lippef596ca02021-03-31 10:02:4747import * as ThemeSupport from '../../theme_support/theme_support.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 Lippeaa61faf2021-04-07 15:32:0750import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1351
Tim van der Lippe119690c2020-01-13 12:31:3052import {HARWriter} from './HARWriter.js';
53import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
54import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
55import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
chait pinnamaneni6bc1c122020-10-30 17:30:5256import {FilterOptions} from './NetworkPanel.js'; // eslint-disable-line no-unused-vars
Jan Schefflerd6c1d402021-02-26 16:56:3857import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe119690c2020-01-13 12:31:3058
Simon Zünd34490692021-03-01 08:25:1859const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5560 /**
61 *@description Text in Network Log View of the Network panel
62 */
63 hideDataUrls: 'Hide data URLs',
64 /**
65 *@description Data urlfilter ui element title in Network Log View of the Network panel
66 */
67 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
68 /**
69 *@description Aria accessible name in Network Log View of the Network panel
70 */
71 resourceTypesToInclude: 'Resource types to include',
72 /**
73 *@description Label for a filter in the Network panel
74 */
75 hasBlockedCookies: 'Has blocked cookies',
76 /**
Simon Zünd562d32c2021-02-17 09:22:5477 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
78 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
79 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
Christy Chencac3f102021-02-03 10:07:5580 */
81 onlyShowRequestsWithBlocked: 'Only show requests with blocked response cookies',
82 /**
83 *@description Label for a filter in the Network panel
84 */
85 blockedRequests: 'Blocked Requests',
86 /**
87 *@description Tooltip for a filter in the Network panel
88 */
89 onlyShowBlockedRequests: 'Only show blocked requests',
90 /**
91 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
92 */
93 dropHarFilesHere: 'Drop HAR files here',
94 /**
95 *@description Recording text text content in Network Log View of the Network panel
96 */
97 recordingNetworkActivity: 'Recording network activity…',
98 /**
99 *@description Text in Network Log View of the Network panel
100 *@example {Ctrl + R} PH1
101 */
102 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
103 /**
Peter Marshall266ab2e2021-02-16 17:30:49104 *@description Shown in the Network Log View of the Network panel when the user has not yet
105 * recorded any network activity. This is an instruction to the user to start recording in order to
106 * show network activity in the current UI.
Christy Chencac3f102021-02-03 10:07:55107 *@example {Ctrl + E} PH1
108 */
109 recordSToDisplayNetworkActivity: 'Record ({PH1}) to display network activity.',
110 /**
111 *@description Text that is usually a hyperlink to more documentation
112 */
113 learnMore: 'Learn more',
114 /**
115 *@description Text to announce to screen readers that network data is available.
116 */
117 networkDataAvailable: 'Network Data Available',
118 /**
119 *@description Text in Network Log View of the Network panel
120 *@example {3} PH1
121 *@example {5} PH2
122 */
123 sSRequests: '{PH1} / {PH2} requests',
124 /**
Andres Olivares7fbed142021-03-01 16:22:23125 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
126 * resources transferred during a selected time frame over the compressed size of all resources transferred during
127 * the whole network log.
128 *@example {5 B} PH1
129 *@example {10 B} PH2
Christy Chencac3f102021-02-03 10:07:55130 */
131 sSTransferred: '{PH1} / {PH2} transferred',
132 /**
Andres Olivares7fbed142021-03-01 16:22:23133 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
134 * time frame over the compressed size of all resources transferred during the whole network log.
Christy Chencac3f102021-02-03 10:07:55135 *@example {10} PH1
136 *@example {15} PH2
137 */
138 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
139 /**
Peter Marshall2c3fb302021-02-19 12:47:04140 * @description Text in Network Log View of the Network panel. Appears when a particular network
141 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
142 * total size (PH2).
143 * @example {40MB} PH1
144 * @example {50MB} PH2
Christy Chencac3f102021-02-03 10:07:55145 */
146 sSResources: '{PH1} / {PH2} resources',
147 /**
148 *@description Text in Network Log View of the Network panel
149 *@example {40} PH1
150 *@example {50} PH2
151 */
152 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
153 /**
154 *@description Text in Network Log View of the Network panel
155 *@example {6} PH1
156 */
157 sRequests: '{PH1} requests',
158 /**
Andres Olivares0a863ab2021-02-19 15:21:23159 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
160 * all resources transferred over network during a network activity log.
Christy Chencac3f102021-02-03 10:07:55161 *@example {4 B} PH1
162 */
163 sTransferred: '{PH1} transferred',
164 /**
Andres Olivares0a863ab2021-02-19 15:21:23165 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
166 * a network activity log.
Christy Chencac3f102021-02-03 10:07:55167 *@example {4} PH1
168 */
169 sBTransferredOverNetwork: '{PH1} B transferred over network',
170 /**
171 *@description Text in Network Log View of the Network panel
172 *@example {4} PH1
173 */
174 sResources: '{PH1} resources',
175 /**
176 *@description Text in Network Log View of the Network panel
177 *@example {10} PH1
178 */
179 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
180 /**
181 *@description Text in Network Log View of the Network panel
182 *@example {120ms} PH1
183 */
184 finishS: 'Finish: {PH1}',
185 /**
186 *@description Text in Network Log View of the Network panel
187 *@example {3000ms} PH1
188 */
189 domcontentloadedS: 'DOMContentLoaded: {PH1}',
190 /**
191 *@description Text in Network Log View of the Network panel
192 *@example {40ms} PH1
193 */
194 loadS: 'Load: {PH1}',
195 /**
196 *@description Text for copying
197 */
198 copy: 'Copy',
199 /**
200 *@description Text in Network Log View of the Network panel
201 */
202 copyRequestHeaders: 'Copy request headers',
203 /**
204 *@description Text in Network Log View of the Network panel
205 */
206 copyResponseHeaders: 'Copy response headers',
207 /**
208 *@description Text in Network Log View of the Network panel
209 */
210 copyResponse: 'Copy response',
211 /**
212 *@description Text in Network Log View of the Network panel
213 */
Peter Marshallf625dc82021-03-02 08:10:57214 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55215 /**
Peter Marshall3ec813d2021-03-01 19:40:25216 * @description A context menu command in the Network panel, for copying to the clipboard.
217 * PowerShell refers to the format the data will be copied as.
Christy Chencac3f102021-02-03 10:07:55218 */
Peter Marshallb8bd00f2021-02-24 08:25:18219 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55220 /**
Peter Marshall3ec813d2021-03-01 19:40:25221 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
222 * refers to the format the data will be copied as, which is compatible with the fetch web API.
Christy Chencac3f102021-02-03 10:07:55223 */
Peter Marshallb8bd00f2021-02-24 08:25:18224 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55225 /**
Peter Marshall3ec813d2021-03-01 19:40:25226 * @description Text in Network Log View of the Network panel. An action that copies a command to
Peter Marshallec861882021-02-16 11:14:21227 * the developer's clipboard. The command allows the developer to replay this specific network
228 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
229 * type of request that will be copied.
Christy Chencac3f102021-02-03 10:07:55230 */
Peter Marshallb8bd00f2021-02-24 08:25:18231 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55232 /**
Peter Marshallec861882021-02-16 11:14:21233 *@description Text in Network Log View of the Network panel. An action that copies a command to
234 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
235 *translatable).
Christy Chencac3f102021-02-03 10:07:55236 */
Peter Marshallb8bd00f2021-02-24 08:25:18237 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55238 /**
Peter Marshallec861882021-02-16 11:14:21239 *@description Text in Network Log View of the Network panel. An action that copies a command to
240 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55241 */
Peter Marshallb8bd00f2021-02-24 08:25:18242 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55243 /**
Peter Marshallec861882021-02-16 11:14:21244 *@description Text in Network Log View of the Network panel. An action that copies a command to
245 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
Christy Chencac3f102021-02-03 10:07:55246 */
Peter Marshallb8bd00f2021-02-24 08:25:18247 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55248 /**
Peter Marshallec861882021-02-16 11:14:21249 *@description Text in Network Log View of the Network panel. An action that copies a command to
250 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
251 *should not be translated).
Christy Chencac3f102021-02-03 10:07:55252 */
Peter Marshallb8bd00f2021-02-24 08:25:18253 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55254 /**
Peter Marshallec861882021-02-16 11:14:21255 *@description Text in Network Log View of the Network panel. An action that copies a command to
256 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
257 *(fetch and Node.js should not be translated).
Christy Chencac3f102021-02-03 10:07:55258 */
Peter Marshallb8bd00f2021-02-24 08:25:18259 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55260 /**
Peter Marshallec861882021-02-16 11:14:21261 *@description Text in Network Log View of the Network panel. An action that copies a command to
262 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
263 *translatable).
Christy Chencac3f102021-02-03 10:07:55264 */
Peter Marshallb8bd00f2021-02-24 08:25:18265 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55266 /**
Peter Marshallec861882021-02-16 11:14:21267 *@description Text in Network Log View of the Network panel. An action that copies a command to
268 *the clipboard. It will copy the command in the format compatible with a Bash script.
Christy Chencac3f102021-02-03 10:07:55269 */
Peter Marshallb8bd00f2021-02-24 08:25:18270 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55271 /**
Peter Marshallec861882021-02-16 11:14:21272 *@description Text in Network Log View of the Network panel. An action that copies a command to
273 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
274 *translatable).
Christy Chencac3f102021-02-03 10:07:55275 */
Peter Marshallb8bd00f2021-02-24 08:25:18276 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55277 /**
Peter Marshallec861882021-02-16 11:14:21278 *@description Text in Network Log View of the Network panel. An action that copies a command to
279 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
280 *translatable).
Christy Chencac3f102021-02-03 10:07:55281 */
Peter Marshallb8bd00f2021-02-24 08:25:18282 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55283 /**
Peter Marshallb8bd00f2021-02-24 08:25:18284 * @description Text in Network Log View of the Network panel. An action that copies data to the
285 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
286 * network request that is currently shown.
Christy Chencac3f102021-02-03 10:07:55287 */
Peter Marshallb8bd00f2021-02-24 08:25:18288 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55289 /**
290 *@description A context menu item in the Network Log View of the Network panel
291 */
Peter Marshallb8bd00f2021-02-24 08:25:18292 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55293 /**
294 *@description A context menu item in the Network Log View of the Network panel
295 */
296 clearBrowserCache: 'Clear browser cache',
297 /**
298 *@description A context menu item in the Network Log View of the Network panel
299 */
300 clearBrowserCookies: 'Clear browser cookies',
301 /**
302 *@description A context menu item in the Network Log View of the Network panel
303 */
304 blockRequestUrl: 'Block request URL',
305 /**
306 *@description A context menu item in the Network Log View of the Network panel
307 *@example {example.com} PH1
308 */
309 unblockS: 'Unblock {PH1}',
310 /**
311 *@description A context menu item in the Network Log View of the Network panel
312 */
313 blockRequestDomain: 'Block request domain',
314 /**
315 *@description Text to replay an XHR request
316 */
317 replayXhr: 'Replay XHR',
318 /**
319 *@description Text in Network Log View of the Network panel
320 */
321 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
322 /**
323 *@description Text in Network Log View of the Network panel
324 */
325 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
326};
Tim van der Lippef596ca02021-03-31 10:02:47327const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55328const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Jan Schefflerd6c1d402021-02-26 16:56:38329export class NetworkLogView extends UI.Widget.VBox implements
330 SDK.SDKModel.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
331 _networkHideDataURLSetting: Common.Settings.Setting<boolean>;
332 _networkShowIssuesOnlySetting: Common.Settings.Setting<boolean>;
333 _networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
334 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
335 // eslint-disable-next-line @typescript-eslint/no-explicit-any
336 _networkResourceTypeFiltersSetting: Common.Settings.Setting<any>;
337 _rawRowHeight: number;
338 _progressBarContainer: Element;
339 _networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
340 _rowHeight: number;
341 _timeCalculator: NetworkTransferTimeCalculator;
342 _durationCalculator: NetworkTransferDurationCalculator;
343 _calculator: NetworkTransferTimeCalculator;
344 _columns: NetworkLogViewColumns;
345 _staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
346 _mainRequestLoadTime: number;
347 _mainRequestDOMContentLoadedTime: number;
348 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
349 // eslint-disable-next-line @typescript-eslint/no-explicit-any
350 _highlightedSubstringChanges: any;
351 _filters: Filter[];
352 _timeFilter: Filter|null;
353 _hoveredNode: NetworkNode|null;
354 _recordingHint: Element|null;
355 _refreshRequestId: number|null;
356 _highlightedNode: NetworkRequestNode|null;
357 _linkifier: Components.Linkifier.Linkifier;
358 _recording: boolean;
359 _needsRefresh: boolean;
360 _headerHeight: number;
361 _groupLookups: Map<string, GroupLookupInterface>;
362 _activeGroupLookup: GroupLookupInterface|null;
363 _textFilterUI: UI.FilterBar.TextFilterUI;
364 _dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
365 _resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
366 _onlyIssuesFilterUI: UI.FilterBar.CheckboxFilterUI;
367 _onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
368 _filterParser: TextUtils.TextUtils.FilterParser;
369 _suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
370 _dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
371 _summaryToolbar: UI.Toolbar.Toolbar;
372 _filterBar: UI.FilterBar.FilterBar;
373 _textFilterSetting: Common.Settings.Setting<string>;
374
375 constructor(
376 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
377 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37378 super();
379 this.setMinimumSize(50, 64);
Tim van der Lippef596ca02021-03-31 10:02:47380 this.registerRequiredCSS('panels/network/networkLogView.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:37381
382 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05383 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37384
Paul Lewis2d7d65c2020-03-16 17:26:30385 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
386 this._networkShowIssuesOnlySetting =
387 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
388 this._networkOnlyBlockedRequestsSetting =
389 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
390 this._networkResourceTypeFiltersSetting =
391 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37392
393 this._rawRowHeight = 0;
394 this._progressBarContainer = progressBarContainer;
395 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
396 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
397
Jan Schefflerd6c1d402021-02-26 16:56:38398 function updateRowHeight(this: NetworkLogView): void {
Tim van der Lipped7cfd142021-01-07 12:17:24399 this._rawRowHeight = Boolean(this._networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:37400 this._rowHeight = this._computeRowHeight();
401 }
402 this._rawRowHeight = 0;
403 this._rowHeight = 0;
404 updateRowHeight.call(this);
405
Tim van der Lippe119690c2020-01-13 12:31:30406 this._timeCalculator = new NetworkTransferTimeCalculator();
Tim van der Lippe119690c2020-01-13 12:31:30407 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:37408 this._calculator = this._timeCalculator;
409
Tim van der Lippe119690c2020-01-13 12:31:30410 this._columns =
Jan Schefflerd6c1d402021-02-26 16:56:38411 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration
412 // @ts-expect-error
Tim van der Lippe119690c2020-01-13 12:31:30413 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37414 this._columns.show(this.element);
415
Blink Reformat4c46d092018-04-07 15:32:37416 this._staleRequests = new Set();
Blink Reformat4c46d092018-04-07 15:32:37417 this._mainRequestLoadTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37418 this._mainRequestDOMContentLoadedTime = -1;
419 this._highlightedSubstringChanges = [];
420
Blink Reformat4c46d092018-04-07 15:32:37421 this._filters = [];
Blink Reformat4c46d092018-04-07 15:32:37422 this._timeFilter = null;
Blink Reformat4c46d092018-04-07 15:32:37423 this._hoveredNode = null;
Blink Reformat4c46d092018-04-07 15:32:37424 this._recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37425 this._refreshRequestId = null;
Blink Reformat4c46d092018-04-07 15:32:37426 this._highlightedNode = null;
427
Simon Zündcdd72c92020-10-07 11:48:13428 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37429
430 this._recording = false;
431 this._needsRefresh = false;
432
433 this._headerHeight = 0;
434
Blink Reformat4c46d092018-04-07 15:32:37435 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30436 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37437
Blink Reformat4c46d092018-04-07 15:32:37438 this._activeGroupLookup = null;
439
Tim van der Lippe0ed1d2b2020-02-04 13:45:13440 this._textFilterUI = new UI.FilterBar.TextFilterUI();
441 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37442 filterBar.addFilter(this._textFilterUI);
443
Tim van der Lippe0ed1d2b2020-02-04 13:45:13444 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55445 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this._networkHideDataURLSetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13446 this._dataURLFilterUI.addEventListener(
447 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55448 UI.Tooltip.Tooltip.install(this._dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
Blink Reformat4c46d092018-04-07 15:32:37449 filterBar.addFilter(this._dataURLFilterUI);
450
451 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13452 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38453 .map(
454 category =>
455 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13456 this._resourceCategoryFilterUI =
457 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Christy Chencac3f102021-02-03 10:07:55458 UI.ARIAUtils.setAccessibleName(
459 this._resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
Blink Reformat4c46d092018-04-07 15:32:37460 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13461 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37462 filterBar.addFilter(this._resourceCategoryFilterUI);
463
Tim van der Lippe0ed1d2b2020-02-04 13:45:13464 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55465 'only-show-issues', i18nString(UIStrings.hasBlockedCookies), true, this._networkShowIssuesOnlySetting);
Tim van der Lippe0ed1d2b2020-02-04 13:45:13466 this._onlyIssuesFilterUI.addEventListener(
467 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55468 UI.Tooltip.Tooltip.install(this._onlyIssuesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlocked));
Jan Scheffler1ae7c9e2019-12-03 15:48:37469 filterBar.addFilter(this._onlyIssuesFilterUI);
470
Sigurd Schneidera2afe0b2020-03-03 15:27:13471 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55472 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
473 this._networkOnlyBlockedRequestsSetting);
Sigurd Schneidera2afe0b2020-03-03 15:27:13474 this._onlyBlockedRequestsUI.addEventListener(
475 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Christy Chencac3f102021-02-03 10:07:55476 UI.Tooltip.Tooltip.install(this._onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
Sigurd Schneidera2afe0b2020-03-03 15:27:13477 filterBar.addFilter(this._onlyBlockedRequestsUI);
478
Tim van der Lippe0ed1d2b2020-02-04 13:45:13479 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
480 this._suggestionBuilder =
481 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37482 this._resetSuggestionBuilder();
483
484 this._dataGrid = this._columns.dataGrid();
485 this._setupDataGrid();
486 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49487 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13488 UI.Toolbar.ToolbarButton.Events.Click,
489 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37490
Tim van der Lippe0ed1d2b2020-02-04 13:45:13491 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
chait pinnamaneni83f4b6b2021-04-08 16:27:05492 this._summaryToolbar.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37493
Tim van der Lippe0ed1d2b2020-02-04 13:45:13494 new UI.DropTarget.DropTarget(
Christy Chencac3f102021-02-03 10:07:55495 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37496
Paul Lewis2d7d65c2020-03-16 17:26:30497 Common.Settings.Settings.instance()
498 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37499 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
500
Paul Lewisdaac1062020-03-05 14:37:10501 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27502 SDK.NetworkLog.NetworkLog.instance().addEventListener(
503 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
504 SDK.NetworkLog.NetworkLog.instance().addEventListener(
505 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
506 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37507
508 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30509 Common.Settings.Settings.instance()
510 .moduleSetting('network.group-by-frame')
511 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37512
513 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03514
515 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
516 if (this._textFilterSetting.get()) {
Jack Franklinec064412020-12-08 13:02:24517 this._textFilterUI.setValue(this._textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03518 }
Blink Reformat4c46d092018-04-07 15:32:37519 }
520
Jan Schefflerd6c1d402021-02-26 16:56:38521 _updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30522 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37523 this._setGrouping(value ? 'Frame' : null);
524 }
525
Jan Schefflerd6c1d402021-02-26 16:56:38526 static _sortSearchValues(key: string, values: string[]): void {
Paul Lewis56509652019-12-06 12:51:58527 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37528 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38529 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
530 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50531 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
532 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37533 });
534 } else {
535 values.sort();
536 }
537 }
538
Jan Schefflerd6c1d402021-02-26 16:56:38539 static _negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37540 return !filter(request);
541 }
542
Jan Schefflerd6c1d402021-02-26 16:56:38543 static _requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34544 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37545 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34546 }
Blink Reformat4c46d092018-04-07 15:32:37547
548 return regex.test(request.path() + '/' + request.name());
549 }
550
Jan Schefflerd6c1d402021-02-26 16:56:38551 static _subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37552 const result = [domain];
553 let indexOfPeriod = domain.indexOf('.');
554 while (indexOfPeriod !== -1) {
555 result.push('*' + domain.substring(indexOfPeriod));
556 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
557 }
558 return result;
559 }
560
Jan Schefflerd6c1d402021-02-26 16:56:38561 static _createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17562 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58563 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37564 }
565
Jan Schefflerd6c1d402021-02-26 16:56:38566 static _requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37567 return regex.test(request.domain);
568 }
569
Jan Schefflerd6c1d402021-02-26 16:56:38570 static _runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37571 return !request.finished;
572 }
573
Jan Schefflerd6c1d402021-02-26 16:56:38574 static _fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37575 return request.cached();
576 }
577
Jan Schefflerd6c1d402021-02-26 16:56:38578 static _interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05579 return request.fetchedViaServiceWorker;
580 }
581
Jan Schefflerd6c1d402021-02-26 16:56:38582 static _initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05583 return request.initiatedByServiceWorker();
584 }
585
Jan Schefflerd6c1d402021-02-26 16:56:38586 static _requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37587 return request.responseHeaderValue(value) !== undefined;
588 }
589
Jan Schefflerd6c1d402021-02-26 16:56:38590 static _requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37591 return request.requestMethod === value;
592 }
593
Jan Schefflerd6c1d402021-02-26 16:56:38594 static _requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37595 return request.priority() === value;
596 }
597
Jan Schefflerd6c1d402021-02-26 16:56:38598 static _requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37599 return request.mimeType === value;
600 }
601
Jan Schefflerd6c1d402021-02-26 16:56:38602 static _requestMixedContentFilter(value: MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest):
603 boolean {
Paul Lewis56509652019-12-06 12:51:58604 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37605 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28606 }
607 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37608 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28609 }
610 if (value === MixedContentFilterValues.BlockOverridden) {
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.All) {
Blink Reformat4c46d092018-04-07 15:32:37614 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34615 }
Blink Reformat4c46d092018-04-07 15:32:37616
617 return false;
618 }
619
Jan Schefflerd6c1d402021-02-26 16:56:38620 static _requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37621 return request.scheme === value;
622 }
623
Jan Schefflerd6c1d402021-02-26 16:56:38624 static _requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41625 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
626 }
627
Jan Schefflerd6c1d402021-02-26 16:56:38628 static _requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41629 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
630 }
631
Jan Schefflerd6c1d402021-02-26 16:56:38632 static _requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54633 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
634 }
635
Jan Schefflerd6c1d402021-02-26 16:56:38636 static _requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41637 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
638 }
639
Jan Schefflerd6c1d402021-02-26 16:56:38640 static _requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41641 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37642 }
643
Jan Schefflerd6c1d402021-02-26 16:56:38644 static _requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41645 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37646 }
647
Jan Schefflerd6c1d402021-02-26 16:56:38648 static _requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41649 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37650 }
651
Jan Schefflerd6c1d402021-02-26 16:56:38652 static _requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37653 return request.transferSize >= value;
654 }
655
Jan Schefflerd6c1d402021-02-26 16:56:38656 static _statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24657 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37658 }
659
Jan Schefflerd6c1d402021-02-26 16:56:38660 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
661 // eslint-disable-next-line @typescript-eslint/naming-convention
662 static HTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58663 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37664 }
665
Jan Schefflerd6c1d402021-02-26 16:56:38666 static _resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03667 return request.resourceType().name() === value;
668 }
669
Jan Schefflerd6c1d402021-02-26 16:56:38670 static _requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17671 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03672 return regex.test(request.url());
673 }
674
Jan Schefflerd6c1d402021-02-26 16:56:38675 static _requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
676 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34677 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37678 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34679 }
680 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37681 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34682 }
Blink Reformat4c46d092018-04-07 15:32:37683 return true;
684 }
685
Jan Schefflerd6c1d402021-02-26 16:56:38686 static _copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13687 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37688 }
689
Jan Schefflerd6c1d402021-02-26 16:56:38690 static _copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13691 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37692 }
693
Jan Schefflerd6c1d402021-02-26 16:56:38694 static async _copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37695 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38696 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34697 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40698 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37699 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08700 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13702 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37703 }
704
Jan Schefflerd6c1d402021-02-26 16:56:38705 _handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37706 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34707 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37708 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34709 }
Blink Reformat4c46d092018-04-07 15:32:37710 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34711 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37712 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34713 }
Blink Reformat4c46d092018-04-07 15:32:37714
Joey Arhar0e1093c2019-05-21 00:34:22715 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37716 }
717
Jan Schefflerd6c1d402021-02-26 16:56:38718 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13719 const outputStream = new Common.StringOutputStream.StringOutputStream();
720 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37721 const success = await reader.read(outputStream);
722 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37723 const error = reader.error();
724 if (error) {
Jan Schefflerd6c1d402021-02-26 16:56:38725 // TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
726 // eslint-disable-next-line @typescript-eslint/no-explicit-any
727 this._harLoadFailed((error as any).message);
Tim van der Lippe224a8622020-09-23 12:14:37728 }
Blink Reformat4c46d092018-04-07 15:32:37729 return;
730 }
731 let harRoot;
732 try {
733 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13734 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37735 } catch (e) {
736 this._harLoadFailed(e);
737 return;
738 }
Wolfgang Beyerd81fad62020-05-27 12:30:27739 SDK.NetworkLog.NetworkLog.instance().importRequests(
740 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37741 }
742
Jan Schefflerd6c1d402021-02-26 16:56:38743 _harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36744 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37745 }
746
Jan Schefflerd6c1d402021-02-26 16:56:38747 _setGrouping(groupKey: string|null): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34748 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37749 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34750 }
Blink Reformat4c46d092018-04-07 15:32:37751 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
752 this._activeGroupLookup = groupLookup;
753 this._invalidateAllItems();
754 }
755
Jan Schefflerd6c1d402021-02-26 16:56:38756 _computeRowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37757 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
758 }
759
Jan Schefflerd6c1d402021-02-26 16:56:38760 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37761 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37762 }
763
Jan Schefflerd6c1d402021-02-26 16:56:38764 headerHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:37765 return this._headerHeight;
766 }
767
Jan Schefflerd6c1d402021-02-26 16:56:38768 setRecording(recording: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:37769 this._recording = recording;
770 this._updateSummaryBar();
771 }
772
Jan Schefflerd6c1d402021-02-26 16:56:38773 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37774 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34775 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37776 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34777 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13778 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37779 if (resourceTreeModel) {
780 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
781 resourceTreeModel.addEventListener(
782 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
783 }
784 }
785
Jan Schefflerd6c1d402021-02-26 16:56:38786 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37787 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13788 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37789 if (resourceTreeModel) {
790 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
791 resourceTreeModel.removeEventListener(
792 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
793 }
794 }
795 }
796
Jan Schefflerd6c1d402021-02-26 16:56:38797 linkifier(): Components.Linkifier.Linkifier {
Simon Zündcdd72c92020-10-07 11:48:13798 return this._linkifier;
799 }
800
Jan Schefflerd6c1d402021-02-26 16:56:38801 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37802 if (!start && !end) {
803 this._timeFilter = null;
804 this._timeCalculator.setWindow(null);
805 } else {
Paul Lewis56509652019-12-06 12:51:58806 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30807 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37808 }
809 this._filterRequests();
810 }
811
Jan Schefflerd6c1d402021-02-26 16:56:38812 resetFocus(): void {
Brandon Goddard88d885a2019-10-31 16:11:05813 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37814 }
815
Jan Schefflerd6c1d402021-02-26 16:56:38816 _resetSuggestionBuilder(): void {
Blink Reformat4c46d092018-04-07 15:32:37817 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58818 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
819 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
820 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
821 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
822 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
823 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
824 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37825 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
826 }
827
Jan Schefflerd6c1d402021-02-26 16:56:38828 _filterChanged(_event: Common.EventTarget.EventTargetEvent): void {
Blink Reformat4c46d092018-04-07 15:32:37829 this.removeAllNodeHighlights();
830 this._parseFilterQuery(this._textFilterUI.value());
831 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03832 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37833 }
834
Jan Schefflerd6c1d402021-02-26 16:56:38835 async resetFilter(): Promise<void> {
Rajasekar Murugan3ad369e2020-02-19 18:20:12836 this._textFilterUI.clear();
837 }
838
Jan Schefflerd6c1d402021-02-26 16:56:38839 _showRecordingHint(): void {
Blink Reformat4c46d092018-04-07 15:32:37840 this._hideRecordingHint();
841 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
842 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18843
Blink Reformat4c46d092018-04-07 15:32:37844 if (this._recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38845 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04846 const reloadShortcut =
847 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
848 if (reloadShortcut) {
849 reloadShortcutNode = this._recordingHint.createChild('b');
850 reloadShortcutNode.textContent = reloadShortcut.title();
851 }
852
Blink Reformat4c46d092018-04-07 15:32:37853 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55854 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18855 if (reloadShortcutNode) {
856 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55857 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
858 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18859 }
Blink Reformat4c46d092018-04-07 15:32:37860 } else {
861 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17862 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37863 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55864 hintText.appendChild(
865 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordSToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37866 }
Kayce Basques5444c1b2019-02-15 20:32:53867 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13868 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35869 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55870 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11871
872 this._setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37873 }
874
Jan Schefflerd6c1d402021-02-26 16:56:38875 _hideRecordingHint(): void {
Amanda Baker6761aae2019-11-05 18:59:11876 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34877 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37878 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34879 }
Michael Liao7322dee2021-04-07 18:33:30880 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Blink Reformat4c46d092018-04-07 15:32:37881 this._recordingHint = null;
882 }
883
Jan Schefflerd6c1d402021-02-26 16:56:38884 _setHidden(value: boolean): void {
Amanda Baker6761aae2019-11-05 18:59:11885 this._columns.setHidden(value);
886 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
887 }
888
Jan Schefflerd6c1d402021-02-26 16:56:38889 elementsToRestoreScrollPositionsFor(): Element[] {
Blink Reformat4c46d092018-04-07 15:32:37890 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34891 {
Blink Reformat4c46d092018-04-07 15:32:37892 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34893 }
Blink Reformat4c46d092018-04-07 15:32:37894 return [this._dataGrid.scrollContainer];
895 }
896
Jan Schefflerd6c1d402021-02-26 16:56:38897 columnExtensionResolved(): void {
Blink Reformat4c46d092018-04-07 15:32:37898 this._invalidateAllItems(true);
899 }
900
Jan Schefflerd6c1d402021-02-26 16:56:38901 _setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Blink Reformat4c46d092018-04-07 15:32:37902 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38903 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34904 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37905 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34906 }
Blink Reformat4c46d092018-04-07 15:32:37907 });
908 this._dataGrid.setStickToBottom(true);
909 this._dataGrid.setName('networkLog');
910 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
911 this._dataGrid.element.classList.add('network-log-grid');
912 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
913 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
914 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05915 this._dataGrid.element.addEventListener('keydown', event => {
916 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05917 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05918 event.consume(true);
919 }
920 });
Brandon Goddard44934902020-03-25 16:03:18921 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
922 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37923 return this._dataGrid;
924 }
925
Jan Schefflerd6c1d402021-02-26 16:56:38926 _dataGridMouseMove(event: Event): void {
927 const mouseEvent = (event as MouseEvent);
928 const node = (this._dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:37929 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Schefflerd6c1d402021-02-26 16:56:38930 this._setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:37931 }
932
Jan Schefflerd6c1d402021-02-26 16:56:38933 hoveredNode(): NetworkNode|null {
Blink Reformat4c46d092018-04-07 15:32:37934 return this._hoveredNode;
935 }
936
Jan Schefflerd6c1d402021-02-26 16:56:38937 _setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:34938 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37939 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34940 }
Blink Reformat4c46d092018-04-07 15:32:37941 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34942 if (this._hoveredNode) {
Tim van der Lipped7cfd142021-01-07 12:17:24943 this._hoveredNode.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:34944 }
Blink Reformat4c46d092018-04-07 15:32:37945 }
946
Jan Schefflerd6c1d402021-02-26 16:56:38947 _dataGridMouseDown(event: Event): void {
948 const mouseEvent = (event as MouseEvent);
Tim van der Lippe224a8622020-09-23 12:14:37949 if (!this._dataGrid.selectedNode && mouseEvent.button) {
950 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34951 }
Blink Reformat4c46d092018-04-07 15:32:37952 }
953
Jan Schefflerd6c1d402021-02-26 16:56:38954 _updateSummaryBar(): void {
Blink Reformat4c46d092018-04-07 15:32:37955 this._hideRecordingHint();
956
957 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20958 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37959 let selectedNodeNumber = 0;
960 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20961 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37962 let baseTime = -1;
963 let maxTime = -1;
964
965 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27966 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37967 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34968 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37969 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34970 }
Blink Reformat4c46d092018-04-07 15:32:37971 nodeCount++;
972 const requestTransferSize = request.transferSize;
973 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20974 const requestResourceSize = request.resourceSize;
975 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37976 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37977 selectedNodeNumber++;
978 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20979 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37980 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13981 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37982 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
983 // inspected url.
984 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13985 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
986 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37987 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34988 }
989 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37990 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34991 }
Blink Reformat4c46d092018-04-07 15:32:37992 }
993
994 if (!nodeCount) {
995 this._showRecordingHint();
996 return;
997 }
998
Joey Arhara86c14e2019-03-12 03:20:50999 this._summaryToolbar.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381000 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131001 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501002 toolbarText.setTitle(title ? title : chunk);
1003 this._summaryToolbar.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381004 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501005 };
Blink Reformat4c46d092018-04-07 15:32:371006
1007 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551008 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501009 this._summaryToolbar.appendSeparator();
1010 appendChunk(
Christy Chencac3f102021-02-03 10:07:551011 i18nString(UIStrings.sSTransferred, {
1012 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381013 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551014 }),
1015 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501016 this._summaryToolbar.appendSeparator();
1017 appendChunk(
Christy Chencac3f102021-02-03 10:07:551018 i18nString(UIStrings.sSResources, {
1019 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381020 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551021 }),
1022 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371023 } else {
Christy Chencac3f102021-02-03 10:07:551024 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Joey Arhara86c14e2019-03-12 03:20:501025 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251026 appendChunk(
Christy Chencac3f102021-02-03 10:07:551027 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1028 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Joey Arhara86c14e2019-03-12 03:20:501029 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251030 appendChunk(
Christy Chencac3f102021-02-03 10:07:551031 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1032 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371033 }
Dan Beam87466b52018-12-01 18:41:201034
Blink Reformat4c46d092018-04-07 15:32:371035 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501036 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551037 appendChunk(i18nString(UIStrings.finishS, {PH1: Number.secondsToString(maxTime - baseTime)}));
Blink Reformat4c46d092018-04-07 15:32:371038 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:501039 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551040 const domContentLoadedText = i18nString(
1041 UIStrings.domcontentloadedS,
1042 {PH1: Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581043 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:371044 }
1045 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:501046 this._summaryToolbar.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551047 const loadText =
1048 i18nString(UIStrings.loadS, {PH1: Number.secondsToString(this._mainRequestLoadTime - baseTime)});
Paul Lewis56509652019-12-06 12:51:581049 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:371050 }
1051 }
Blink Reformat4c46d092018-04-07 15:32:371052 }
1053
Jan Schefflerd6c1d402021-02-26 16:56:381054 scheduleRefresh(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341055 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371056 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341057 }
Blink Reformat4c46d092018-04-07 15:32:371058
1059 this._needsRefresh = true;
1060
Tim van der Lippe1d6e57a2019-09-30 11:55:341061 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:371062 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341063 }
Blink Reformat4c46d092018-04-07 15:32:371064 }
1065
Jan Schefflerd6c1d402021-02-26 16:56:381066 addFilmStripFrames(times: number[]): void {
Blink Reformat4c46d092018-04-07 15:32:371067 this._columns.addEventDividers(times, 'network-frame-divider');
1068 }
1069
Jan Schefflerd6c1d402021-02-26 16:56:381070 selectFilmStripFrame(time: number): void {
Blink Reformat4c46d092018-04-07 15:32:371071 this._columns.selectFilmStripFrame(time);
1072 }
1073
Jan Schefflerd6c1d402021-02-26 16:56:381074 clearFilmStripFrame(): void {
Blink Reformat4c46d092018-04-07 15:32:371075 this._columns.clearFilmStripFrame();
1076 }
1077
Jan Schefflerd6c1d402021-02-26 16:56:381078 _refreshIfNeeded(): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341079 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371080 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341081 }
Blink Reformat4c46d092018-04-07 15:32:371082 }
1083
Jan Schefflerd6c1d402021-02-26 16:56:381084 _invalidateAllItems(deferUpdate?: boolean): void {
Wolfgang Beyerd81fad62020-05-27 12:30:271085 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371087 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341088 } else {
Blink Reformat4c46d092018-04-07 15:32:371089 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341090 }
Blink Reformat4c46d092018-04-07 15:32:371091 }
1092
Jan Schefflerd6c1d402021-02-26 16:56:381093 timeCalculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371094 return this._timeCalculator;
1095 }
1096
Jan Schefflerd6c1d402021-02-26 16:56:381097 calculator(): NetworkTimeCalculator {
Blink Reformat4c46d092018-04-07 15:32:371098 return this._calculator;
1099 }
1100
Jan Schefflerd6c1d402021-02-26 16:56:381101 setCalculator(x: NetworkTimeCalculator): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341102 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371103 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341104 }
Blink Reformat4c46d092018-04-07 15:32:371105
1106 if (this._calculator !== x) {
1107 this._calculator = x;
1108 this._columns.setCalculator(this._calculator);
1109 }
1110 this._calculator.reset();
1111
Tim van der Lippe1d6e57a2019-09-30 11:55:341112 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371113 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341114 } else {
Blink Reformat4c46d092018-04-07 15:32:371115 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341116 }
Blink Reformat4c46d092018-04-07 15:32:371117
1118 this._invalidateAllItems();
1119 }
1120
Jan Schefflerd6c1d402021-02-26 16:56:381121 _loadEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341122 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371123 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341124 }
Blink Reformat4c46d092018-04-07 15:32:371125
Jan Schefflerd6c1d402021-02-26 16:56:381126 const time = (event.data.loadTime as number);
Blink Reformat4c46d092018-04-07 15:32:371127 if (time) {
1128 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301129 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371130 }
1131 }
1132
Jan Schefflerd6c1d402021-02-26 16:56:381133 _domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent): void {
Tim van der Lippe1d6e57a2019-09-30 11:55:341134 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371135 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341136 }
Jan Schefflerd6c1d402021-02-26 16:56:381137 const data = (event.data as number);
Blink Reformat4c46d092018-04-07 15:32:371138 if (data) {
1139 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301140 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371141 }
1142 }
1143
Jan Schefflerd6c1d402021-02-26 16:56:381144 wasShown(): void {
Blink Reformat4c46d092018-04-07 15:32:371145 this._refreshIfNeeded();
1146 this._columns.wasShown();
1147 }
1148
Jan Schefflerd6c1d402021-02-26 16:56:381149 willHide(): void {
Blink Reformat4c46d092018-04-07 15:32:371150 this._columns.willHide();
1151 }
1152
Jan Schefflerd6c1d402021-02-26 16:56:381153 onResize(): void {
Blink Reformat4c46d092018-04-07 15:32:371154 this._rowHeight = this._computeRowHeight();
1155 }
1156
Jan Schefflerd6c1d402021-02-26 16:56:381157 flatNodesList(): NetworkNode[] {
1158 const rootNode =
1159 (this._dataGrid.rootNode() as
1160 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1161 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371162 }
1163
Jan Schefflerd6c1d402021-02-26 16:56:381164 _onDataGridFocus(): void {
Peter Marshallde3fee72020-08-24 14:12:491165 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351166 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381167 }
Brandon Goddard44934902020-03-25 16:03:181168 this.updateNodeBackground();
1169 }
1170
Jan Schefflerd6c1d402021-02-26 16:56:381171 _onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181172 this.element.classList.remove('grid-focused');
1173 this.updateNodeBackground();
1174 }
1175
Jan Schefflerd6c1d402021-02-26 16:56:381176 updateNodeBackground(): void {
Brandon Goddard88d885a2019-10-31 16:11:051177 if (this._dataGrid.selectedNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381178 (this._dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051179 }
1180 }
1181
Jan Schefflerd6c1d402021-02-26 16:56:381182 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051183 if (isSelected) {
1184 this.element.classList.remove('no-node-selected');
1185 } else {
1186 this.element.classList.add('no-node-selected');
1187 }
1188 }
1189
Jan Schefflerd6c1d402021-02-26 16:56:381190 stylesChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371191 this._columns.scheduleRefresh();
1192 }
1193
Jan Schefflerd6c1d402021-02-26 16:56:381194 _refresh(): void {
Blink Reformat4c46d092018-04-07 15:32:371195 this._needsRefresh = false;
1196
1197 if (this._refreshRequestId) {
1198 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1199 this._refreshRequestId = null;
1200 }
1201
1202 this.removeAllNodeHighlights();
1203
1204 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1205 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1206 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1207 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1208
Jan Schefflerd6c1d402021-02-26 16:56:381209 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1210 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371211
Jan Schefflerd6c1d402021-02-26 16:56:381212 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371213
1214 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1215 // node so we loop until we have no more stale requests.
1216 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371217 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371218 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371219 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341220 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371221 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341222 }
Blink Reformat4c46d092018-04-07 15:32:371223 staleNodes.add(node);
1224 }
1225
1226 for (const node of staleNodes) {
1227 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341228 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371229 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341230 }
Blink Reformat4c46d092018-04-07 15:32:371231
Tim van der Lippe1d6e57a2019-09-30 11:55:341232 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371233 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341234 }
Blink Reformat4c46d092018-04-07 15:32:371235 const request = node.request();
1236 this._timeCalculator.updateBoundaries(request);
1237 this._durationCalculator.updateBoundaries(request);
1238 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371239 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1240 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371241 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341242 }
Tim van der Lippe224a8622020-09-23 12:14:371243 if (isFilteredOut) {
1244 filteredNetworkRequests.add(node);
1245 } else {
1246 filteredNetworkRequests.delete(node);
1247 }
Blink Reformat4c46d092018-04-07 15:32:371248 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1249 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381250 let parent: NetworkNode|
1251 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1252 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1253 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111254 if (!parent) {
1255 continue;
1256 }
Blink Reformat4c46d092018-04-07 15:32:371257 parent.removeChild(node);
1258 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381259 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371260 grandparent.removeChild(parent);
1261 parent = grandparent;
1262 }
1263 }
1264
Tim van der Lippe1d6e57a2019-09-30 11:55:341265 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371266 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341267 }
Blink Reformat4c46d092018-04-07 15:32:371268
1269 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jan Schefflerd6c1d402021-02-26 16:56:381270 nodesToInsert.set(newParent, (this._dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371271 nodesToRefresh.push(newParent);
1272 }
1273 nodesToInsert.set(node, newParent);
1274 }
1275
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381277 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341278 }
Blink Reformat4c46d092018-04-07 15:32:371279
Tim van der Lippe1d6e57a2019-09-30 11:55:341280 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371281 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341282 }
Blink Reformat4c46d092018-04-07 15:32:371283
1284 this._updateSummaryBar();
1285
Tim van der Lippe1d6e57a2019-09-30 11:55:341286 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371287 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341288 }
Blink Reformat4c46d092018-04-07 15:32:371289
1290 this._dataGrid.updateInstantly();
1291 this._didRefreshForTest();
1292 }
1293
Jan Schefflerd6c1d402021-02-26 16:56:381294 _didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371295 }
1296
Jan Schefflerd6c1d402021-02-26 16:56:381297 _parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Tim van der Lippe1d6e57a2019-09-30 11:55:341298 if (!this._activeGroupLookup) {
Jan Schefflerd6c1d402021-02-26 16:56:381299 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341300 }
Blink Reformat4c46d092018-04-07 15:32:371301
1302 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341303 if (!groupNode) {
Jan Schefflerd6c1d402021-02-26 16:56:381304 return this._dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341305 }
Blink Reformat4c46d092018-04-07 15:32:371306 return groupNode;
1307 }
1308
Jan Schefflerd6c1d402021-02-26 16:56:381309 _reset(): void {
Simon Zünd98419832020-03-12 06:18:151310 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371311
1312 this._setHoveredNode(null);
1313 this._columns.reset();
1314
1315 this._timeFilter = null;
1316 this._calculator.reset();
1317
1318 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131319 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371320
Tim van der Lippe1d6e57a2019-09-30 11:55:341321 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371322 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341323 }
Blink Reformat4c46d092018-04-07 15:32:371324 this._staleRequests.clear();
1325 this._resetSuggestionBuilder();
1326
1327 this._mainRequestLoadTime = -1;
1328 this._mainRequestDOMContentLoadedTime = -1;
1329
1330 this._dataGrid.rootNode().removeChildren();
1331 this._updateSummaryBar();
1332 this._dataGrid.setStickToBottom(true);
1333 this.scheduleRefresh();
1334 }
1335
Jan Schefflerd6c1d402021-02-26 16:56:381336 setTextFilterValue(filterString: string): void {
Blink Reformat4c46d092018-04-07 15:32:371337 this._textFilterUI.setValue(filterString);
1338 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371339 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131340 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371341 this._resourceCategoryFilterUI.reset();
1342 }
1343
Jan Schefflerd6c1d402021-02-26 16:56:381344 _createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301345 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371346 networkRequestToNode.set(request, node);
1347 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371348
Tim van der Lippe1d6e57a2019-09-30 11:55:341349 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371350 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341351 }
Blink Reformat4c46d092018-04-07 15:32:371352 return node;
1353 }
1354
Jan Schefflerd6c1d402021-02-26 16:56:381355 _onRequestUpdated(event: Common.EventTarget.EventTargetEvent): void {
1356 const request = (event.data as SDK.NetworkRequest.NetworkRequest);
Blink Reformat4c46d092018-04-07 15:32:371357 this._refreshRequest(request);
1358 }
1359
Jan Schefflerd6c1d402021-02-26 16:56:381360 _refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Paul Lewis56509652019-12-06 12:51:581361 NetworkLogView._subdomains(request.domain)
1362 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1363 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1364 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
Tim van der Lipped7cfd142021-01-07 12:17:241365 this._suggestionBuilder.addItem(FilterType.Scheme, String(request.scheme));
1366 this._suggestionBuilder.addItem(FilterType.StatusCode, String(request.statusCode));
Sigurd Schneider464838b2020-08-24 13:53:031367 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031368 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371369
1370 const priority = request.priority();
1371 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501372 this._suggestionBuilder.addItem(
1373 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371374 }
1375
1376 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581377 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371378 }
1379
1380 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581381 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371382 }
1383
1384 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581385 const suggestion =
1386 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1387 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371388 }
1389
1390 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341391 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581392 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341393 }
Jan Scheffler341eea52019-12-12 09:08:411394
1395 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581396 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1397 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1398 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371399 }
1400
Jan Scheffler341eea52019-12-12 09:08:411401 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1402 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1403 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541404 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411405 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1406 }
1407
Blink Reformat4c46d092018-04-07 15:32:371408 this._staleRequests.add(request);
1409 this.scheduleRefresh();
1410 }
1411
Jan Schefflerd6c1d402021-02-26 16:56:381412 rowHeight(): number {
Blink Reformat4c46d092018-04-07 15:32:371413 return this._rowHeight;
1414 }
1415
Jan Schefflerd6c1d402021-02-26 16:56:381416 switchViewMode(gridMode: boolean): void {
Blink Reformat4c46d092018-04-07 15:32:371417 this._columns.switchViewMode(gridMode);
1418 }
1419
Jan Schefflerd6c1d402021-02-26 16:56:381420 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1421 void {
Blink Reformat4c46d092018-04-07 15:32:371422 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551423 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371424 const footerSection = copyMenu.footerSection();
1425 if (request) {
1426 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131427 UI.UIUtils.copyLinkAddressLabel(),
1428 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1429 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371430 if (request.requestHeadersText()) {
1431 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551432 i18nString(UIStrings.copyRequestHeaders), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371433 }
1434
1435 if (request.responseHeadersText) {
1436 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551437 i18nString(UIStrings.copyResponseHeaders), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371438 }
1439
1440 if (request.finished) {
1441 copyMenu.defaultSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551442 i18nString(UIStrings.copyResponse), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371443 }
1444
Tim van der Lippeb4faf5a2020-11-06 15:02:021445 const initiator = request.initiator();
1446
1447 if (initiator) {
1448 const stack = initiator.stack;
1449 if (stack) {
1450 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1451 // has any context solely based on the top frame. Sometimes, the top frame does not have
1452 // any callFrames, but its parent frames do.
1453 const stackTraceText = computeStackTraceText(stack);
1454 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551455 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021456 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1457 });
1458 }
1459 }
1460 }
1461
Harley Libcf41f92018-09-10 18:01:131462 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371464 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551465 i18nString(UIStrings.copyAsPowershell), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371466 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551467 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291468 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551469 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371470 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551471 i18nString(UIStrings.copyAsCurlCmd), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131472 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551473 i18nString(UIStrings.copyAsCurlBash), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1474 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this._copyAllPowerShellCommand.bind(this));
1475 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1476 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1477 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this._copyAllCurlCommand.bind(this, 'win'));
1478 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371479 } else {
Harley Libcf41f92018-09-10 18:01:131480 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551481 i18nString(UIStrings.copyAsFetch), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291482 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551483 i18nString(UIStrings.copyAsNodejsFetch), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131484 footerSection.appendItem(
Christy Chencac3f102021-02-03 10:07:551485 i18nString(UIStrings.copyAsCurl), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1486 footerSection.appendItem(i18nString(UIStrings.copyAllAsFetch), this._copyAllFetchCall.bind(this, false));
1487 footerSection.appendItem(i18nString(UIStrings.copyAllAsNodejsFetch), this._copyAllFetchCall.bind(this, true));
1488 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371489 }
1490 } else {
Christy Chencac3f102021-02-03 10:07:551491 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371492 }
Christy Chencac3f102021-02-03 10:07:551493 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371494
Christy Chencac3f102021-02-03 10:07:551495 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371496
Christy Chencac3f102021-02-03 10:07:551497 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this._clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371498 contextMenu.editSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551499 i18nString(UIStrings.clearBrowserCookies), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371500
1501 if (request) {
1502 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211503 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371504 let patterns = manager.blockedPatterns();
1505
Jan Schefflerd6c1d402021-02-26 16:56:381506 function addBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121507 patterns.push({enabled: true, url: url});
1508 manager.setBlockedPatterns(patterns);
1509 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261510 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121511 }
1512
Jan Schefflerd6c1d402021-02-26 16:56:381513 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121514 patterns = patterns.filter(pattern => pattern.url !== url);
1515 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261516 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121517 }
1518
Blink Reformat4c46d092018-04-07 15:32:371519 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1520 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1521 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551522 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371523 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311524 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371525 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551526 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371527 }
1528
1529 const domain = request.parsedURL.domain();
1530 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1531 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551532 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371533 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311534 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371535 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551536 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371537 }
1538
Tim van der Lippe0ed1d2b2020-02-04 13:45:131539 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371540 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551541 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371542 }
Blink Reformat4c46d092018-04-07 15:32:371543 }
1544 }
1545
Jan Schefflerd6c1d402021-02-26 16:56:381546 _harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Wolfgang Beyerd81fad62020-05-27 12:30:271547 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171548 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131549 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171550 });
Blink Reformat4c46d092018-04-07 15:32:371551 }
1552
Jan Schefflerd6c1d402021-02-26 16:56:381553 async _copyAll(): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131554 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1555 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371556 }
1557
Jan Schefflerd6c1d402021-02-26 16:56:381558 async _copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371559 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131560 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371561 }
1562
Jan Schefflerd6c1d402021-02-26 16:56:381563 async _copyAllCurlCommand(platform: string): Promise<void> {
Wolfgang Beyerd81fad62020-05-27 12:30:271564 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131565 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371566 }
1567
Jan Schefflerd6c1d402021-02-26 16:56:381568 async _copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<void> {
Jan Scheffler7c50d1f2019-12-17 13:33:291569 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131570 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371571 }
1572
Jan Schefflerd6c1d402021-02-26 16:56:381573 async _copyAllFetchCall(includeCookies: boolean): Promise<void> {
Wolfgang Beyerd81fad62020-05-27 12:30:271574 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131575 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371576 }
1577
Jan Schefflerd6c1d402021-02-26 16:56:381578 async _copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:371579 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131580 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371581 }
1582
Jan Schefflerd6c1d402021-02-26 16:56:381583 async _copyAllPowerShellCommand(): Promise<void> {
Wolfgang Beyerd81fad62020-05-27 12:30:271584 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131585 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371586 }
1587
Jan Schefflerd6c1d402021-02-26 16:56:381588 async exportAll(): Promise<void> {
Tim van der Lippe224a8622020-09-23 12:14:371589 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1590 if (!mainTarget) {
1591 return;
1592 }
1593 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131594 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371595 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131596 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371597
Tim van der Lippe1d6e57a2019-09-30 11:55:341598 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371599 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341600 }
Blink Reformat4c46d092018-04-07 15:32:371601
Tim van der Lippe0ed1d2b2020-02-04 13:45:131602 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371603 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301604 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371605 progressIndicator.done();
1606 stream.close();
1607 }
1608
Jan Schefflerd6c1d402021-02-26 16:56:381609 _clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551610 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211611 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341612 }
Blink Reformat4c46d092018-04-07 15:32:371613 }
1614
Jan Schefflerd6c1d402021-02-26 16:56:381615 _clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551616 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211617 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341618 }
Blink Reformat4c46d092018-04-07 15:32:371619 }
1620
Jan Schefflerd6c1d402021-02-26 16:56:381621 _removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371622 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341623 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131624 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341625 }
Blink Reformat4c46d092018-04-07 15:32:371626 this._highlightedSubstringChanges = [];
1627 }
1628
Jan Schefflerd6c1d402021-02-26 16:56:381629 _applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371630 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341631 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371632 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341633 }
Christy Chen1825c612021-02-25 10:28:441634 const categoryName = request.resourceType().category().title();
Tim van der Lippe1d6e57a2019-09-30 11:55:341635 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371636 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341637 }
1638 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371639 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341640 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221641 if (this._onlyIssuesFilterUI.checked() &&
Sigurd Schneider84b6cf72021-04-13 06:40:541642 !IssuesManager.RelatedIssue.hasIssueOfCategory(request, IssuesManager.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371643 return false;
1644 }
Sigurd Schneider20088de2020-10-30 08:08:331645 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131646 return false;
1647 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341648 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371649 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341650 }
Blink Reformat4c46d092018-04-07 15:32:371651 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341652 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371653 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341654 }
Blink Reformat4c46d092018-04-07 15:32:371655 }
1656 return true;
1657 }
1658
Jan Schefflerd6c1d402021-02-26 16:56:381659 _parseFilterQuery(query: string): void {
Blink Reformat4c46d092018-04-07 15:32:371660 const descriptors = this._filterParser.parse(query);
1661 this._filters = descriptors.map(descriptor => {
1662 const key = descriptor.key;
1663 const text = descriptor.text || '';
1664 const regex = descriptor.regex;
1665 let filter;
1666 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171667 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Schefflerd6c1d402021-02-26 16:56:381668 filter = this._createSpecialFilter((key as FilterType), text) ||
Paul Lewis56509652019-12-06 12:51:581669 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371670 } else if (descriptor.regex) {
Jan Schefflerd6c1d402021-02-26 16:56:381671 filter = NetworkLogView._requestPathFilter.bind(null, (regex as RegExp));
Blink Reformat4c46d092018-04-07 15:32:371672 } else {
Tim van der Lippebafa3bd2021-01-20 12:19:171673 filter = NetworkLogView._requestPathFilter.bind(
1674 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371675 }
Paul Lewis56509652019-12-06 12:51:581676 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371677 });
1678 }
1679
Jan Schefflerd6c1d402021-02-26 16:56:381680 _createSpecialFilter(type: FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371681 switch (type) {
Paul Lewis56509652019-12-06 12:51:581682 case FilterType.Domain:
1683 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371684
Paul Lewis56509652019-12-06 12:51:581685 case FilterType.HasResponseHeader:
1686 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371687
Paul Lewis56509652019-12-06 12:51:581688 case FilterType.Is:
1689 if (value.toLowerCase() === IsFilterType.Running) {
1690 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341691 }
Paul Lewis56509652019-12-06 12:51:581692 if (value.toLowerCase() === IsFilterType.FromCache) {
1693 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341694 }
Paul Lewis56509652019-12-06 12:51:581695 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1696 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341697 }
Paul Lewis56509652019-12-06 12:51:581698 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1699 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341700 }
Blink Reformat4c46d092018-04-07 15:32:371701 break;
1702
Paul Lewis56509652019-12-06 12:51:581703 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371704 return this._createSizeFilter(value.toLowerCase());
1705
Paul Lewis56509652019-12-06 12:51:581706 case FilterType.Method:
1707 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371708
Paul Lewis56509652019-12-06 12:51:581709 case FilterType.MimeType:
1710 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371711
Paul Lewis56509652019-12-06 12:51:581712 case FilterType.MixedContent:
Jan Schefflerd6c1d402021-02-26 16:56:381713 return NetworkLogView._requestMixedContentFilter.bind(null, (value as MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371714
Paul Lewis56509652019-12-06 12:51:581715 case FilterType.Scheme:
1716 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371717
Paul Lewis56509652019-12-06 12:51:581718 case FilterType.SetCookieDomain:
1719 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371720
Paul Lewis56509652019-12-06 12:51:581721 case FilterType.SetCookieName:
1722 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371723
Paul Lewis56509652019-12-06 12:51:581724 case FilterType.SetCookieValue:
1725 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371726
Jan Scheffler341eea52019-12-12 09:08:411727 case FilterType.CookieDomain:
1728 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1729
1730 case FilterType.CookieName:
1731 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1732
Simon Zündc9759102020-03-25 11:24:541733 case FilterType.CookiePath:
1734 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1735
Jan Scheffler341eea52019-12-12 09:08:411736 case FilterType.CookieValue:
1737 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1738
Paul Lewis56509652019-12-06 12:51:581739 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501740 return NetworkLogView._requestPriorityFilter.bind(
1741 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371742
Paul Lewis56509652019-12-06 12:51:581743 case FilterType.StatusCode:
1744 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031745
1746 case FilterType.ResourceType:
1747 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031748
1749 case FilterType.Url:
1750 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371751 }
1752 return null;
1753 }
1754
Jan Schefflerd6c1d402021-02-26 16:56:381755 _createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371756 let multiplier = 1;
1757 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541758 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371759 value = value.substring(0, value.length - 1);
1760 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541761 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371762 value = value.substring(0, value.length - 1);
1763 }
1764 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341765 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371766 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341767 }
Paul Lewis56509652019-12-06 12:51:581768 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371769 }
1770
Jan Schefflerd6c1d402021-02-26 16:56:381771 _filterRequests(): void {
Blink Reformat4c46d092018-04-07 15:32:371772 this._removeAllHighlights();
1773 this._invalidateAllItems();
1774 }
1775
Jan Schefflerd6c1d402021-02-26 16:56:381776 _reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371777 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371778 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341779 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371780 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341781 }
Brandon Goddard5e4244d2020-04-08 22:08:471782 // Viewport datagrid nodes do not reveal if not in the root node
1783 // list of flatChildren. For children of grouped frame nodes:
1784 // reveal and expand parent to ensure child is revealable.
1785 if (node.parent && node.parent instanceof NetworkGroupNode) {
1786 node.parent.reveal();
1787 node.parent.expand();
1788 }
Blink Reformat4c46d092018-04-07 15:32:371789 node.reveal();
1790 return node;
1791 }
1792
Jan Schefflerd6c1d402021-02-26 16:56:381793 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Blink Reformat4c46d092018-04-07 15:32:371794 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341795 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371796 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341797 }
Blink Reformat4c46d092018-04-07 15:32:371798 }
1799
Jan Schefflerd6c1d402021-02-26 16:56:381800 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: FilterOptions): void {
chait pinnamaneni6bc1c122020-10-30 17:30:521801 const defaultOptions = {clearFilter: true};
1802 const {clearFilter} = options || defaultOptions;
1803 if (clearFilter) {
1804 this.setTextFilterValue('');
1805 }
Blink Reformat4c46d092018-04-07 15:32:371806 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341807 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371808 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341809 }
Blink Reformat4c46d092018-04-07 15:32:371810 }
1811
Jan Schefflerd6c1d402021-02-26 16:56:381812 removeAllNodeHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371813 if (this._highlightedNode) {
1814 this._highlightedNode.element().classList.remove('highlighted-row');
1815 this._highlightedNode = null;
1816 }
1817 }
1818
Jan Schefflerd6c1d402021-02-26 16:56:381819 _highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131820 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371821 this._highlightedNode = node;
1822 }
1823
Jan Schefflerd6c1d402021-02-26 16:56:381824 _filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131825 return requests.filter(request => !request.isBlobRequest());
1826 }
1827
Jan Schefflerd6c1d402021-02-26 16:56:381828 async _generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, includeCookies: boolean): Promise<string> {
1829 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371830 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371831 'method',
1832 'path',
1833 'scheme',
1834 'version',
Blink Reformat4c46d092018-04-07 15:32:371835
1836 // Unsafe headers
1837 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371838 'accept-charset',
1839 'accept-encoding',
1840 'access-control-request-headers',
1841 'access-control-request-method',
1842 'connection',
1843 'content-length',
1844 'cookie',
1845 'cookie2',
1846 'date',
1847 'dnt',
1848 'expect',
1849 'host',
1850 'keep-alive',
1851 'origin',
1852 'referer',
1853 'te',
1854 'trailer',
1855 'transfer-encoding',
1856 'upgrade',
1857 'via',
Blink Reformat4c46d092018-04-07 15:32:371858 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371859 'user-agent',
1860 ]);
Blink Reformat4c46d092018-04-07 15:32:371861
Jan Schefflerd6c1d402021-02-26 16:56:381862 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371863
1864 const url = JSON.stringify(request.url());
1865
1866 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:381867 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:371868 const name = header.name;
1869
Tim van der Lippe224a8622020-09-23 12:14:371870 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371871 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341872 }
Blink Reformat4c46d092018-04-07 15:32:371873
1874 return result;
1875 }, new Headers());
1876
Jan Schefflerd6c1d402021-02-26 16:56:381877 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341878 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411879 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341880 }
Blink Reformat4c46d092018-04-07 15:32:371881
Sigurd Schneider0e88b912020-05-08 08:28:231882 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371883 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411884 'include' :
1885 'omit';
Blink Reformat4c46d092018-04-07 15:32:371886
1887 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1888
1889 const referrer = referrerHeader ? referrerHeader.value : void 0;
1890
1891 const referrerPolicy = request.referrerPolicy() || void 0;
1892
1893 const requestBody = await request.requestFormData();
1894
Jan Schefflerd6c1d402021-02-26 16:56:381895 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:411896 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371897 referrer,
1898 referrerPolicy,
1899 body: requestBody,
1900 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371901 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371902 };
1903
Jan Scheffler7c50d1f2019-12-17 13:33:291904 if (includeCookies) {
1905 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1906 if (cookieHeader) {
1907 fetchOptions.headers = {
1908 ...headers,
1909 'cookie': cookieHeader.value,
1910 };
1911 }
1912 } else {
1913 fetchOptions.credentials = credentials;
1914 }
1915
Jan Scheffler172d5212020-01-02 14:42:561916 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371917 return `fetch(${url}, ${options});`;
1918 }
1919
Jan Schefflerd6c1d402021-02-26 16:56:381920 async _generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], includeCookies: boolean): Promise<string> {
Harley Libcf41f92018-09-10 18:01:131921 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291922 const commands =
1923 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131924 return commands.join(' ;\n');
1925 }
1926
Jan Schefflerd6c1d402021-02-26 16:56:381927 async _generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
1928 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:361929 // Most of these headers are derived from the URL and are automatically added by cURL.
1930 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:381931 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:371932
Jan Schefflerd6c1d402021-02-26 16:56:381933 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:371934 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:381935 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:371936
Jan Schefflerd6c1d402021-02-26 16:56:381937 Because cmd.exe parser and MS Crt arguments parsers use some of the
1938 same escape characters, they can interact with each other in
1939 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:371940
Jan Schefflerd6c1d402021-02-26 16:56:381941 Replace \ with \\ first because it is an escape character for certain
1942 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:371943
Jan Schefflerd6c1d402021-02-26 16:56:381944 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:371945
Jan Schefflerd6c1d402021-02-26 16:56:381946 Then escape all characters we are not sure about with ^ to ensure it
1947 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:371948
Jan Schefflerd6c1d402021-02-26 16:56:381949 The % character is special because MS Crt parser will try and look for
1950 ENV variables and fill them in it's place. We cannot escape them with %
1951 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1952 parser); So we can get cmd.exe parser to escape the character after it,
1953 if it is followed by a valid beginning character of an ENV variable.
1954 This ensures we do not try and double escape another ^ if it was placed
1955 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:371956
Jan Schefflerd6c1d402021-02-26 16:56:381957 Lastly we replace new lines with ^ and TWO new lines because the first
1958 new line is there to enact the escape command the second is the character
1959 to escape (in this case new line).
1960 */
Blink Reformat4c46d092018-04-07 15:32:371961 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1962 return encapsChars +
1963 str.replace(/\\/g, '\\\\')
1964 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:541965 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:371966 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:541967 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:371968 encapsChars;
1969 }
1970
Jan Schefflerd6c1d402021-02-26 16:56:381971 function escapeStringPosix(str: string): string {
1972 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:221973 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121974 let hexString = code.toString(16);
1975 // Zero pad to four digits to comply with ANSI-C Quoting:
1976 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341977 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121978 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341979 }
Joey Arhar2d21f712019-05-20 21:07:121980
1981 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371982 }
1983
Mathias Bynensf06e8c02020-02-28 13:58:281984 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371985 // Use ANSI-C quoting syntax.
1986 return '$\'' +
1987 str.replace(/\\/g, '\\\\')
1988 .replace(/\'/g, '\\\'')
1989 .replace(/\n/g, '\\n')
1990 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:281991 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371992 '\'';
Blink Reformat4c46d092018-04-07 15:32:371993 }
Mathias Bynensf06e8c02020-02-28 13:58:281994 // Use single quote syntax.
1995 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:371996 }
1997
1998 // cURL command expected to run on the same platform that DevTools run
1999 // (it may be different from the inspected page platform).
2000 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2001
2002 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2003
2004 let inferredMethod = 'GET';
2005 const data = [];
2006 const requestContentType = request.requestContentType();
2007 const formData = await request.requestFormData();
2008 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272009 // Note that formData is not necessarily urlencoded because it might for example
2010 // come from a fetch request made with an explicitly unencoded body.
2011 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372012 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372013 inferredMethod = 'POST';
2014 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112015 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372016 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372017 inferredMethod = 'POST';
2018 }
2019
2020 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292021 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372022 }
2023
2024 const requestHeaders = request.requestHeaders();
2025 for (let i = 0; i < requestHeaders.length; i++) {
2026 const header = requestHeaders[i];
2027 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372028 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372029 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342030 }
Jan Scheffler172d5212020-01-02 14:42:562031 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372032 }
2033 command = command.concat(data);
2034 command.push('--compressed');
2035
Tim van der Lippe1d6e57a2019-09-30 11:55:342036 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372037 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342038 }
Jan Scheffler172d5212020-01-02 14:42:562039 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372040 }
2041
Jan Schefflerd6c1d402021-02-26 16:56:382042 async _generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132043 const nonBlobRequests = this._filterOutBlobRequests(requests);
2044 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342045 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132046 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342047 }
Mathias Bynensf06e8c02020-02-28 13:58:282048 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132049 }
2050
Jan Schefflerd6c1d402021-02-26 16:56:382051 async _generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562052 const command = [];
Jan Schefflerd6c1d402021-02-26 16:56:382053 const ignoredHeaders = new Set<string>(
2054 ['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
Blink Reformat4c46d092018-04-07 15:32:372055
Jan Schefflerd6c1d402021-02-26 16:56:382056 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372057 return '"' +
2058 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2059 }
2060
Jan Scheffler172d5212020-01-02 14:42:562061 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372062
2063 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562064 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372065 }
2066
2067 const requestHeaders = request.requestHeaders();
2068 const headerNameValuePairs = [];
2069 for (const header of requestHeaders) {
2070 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342071 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372072 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342073 }
Blink Reformat4c46d092018-04-07 15:32:372074 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2075 }
2076 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562077 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372078 }
2079
2080 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2081 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562082 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372083 }
2084
2085 const formData = await request.requestFormData();
2086 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372087 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342088 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562089 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342090 } else {
Jan Scheffler172d5212020-01-02 14:42:562091 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342092 }
Blink Reformat4c46d092018-04-07 15:32:372093 }
2094
Jan Scheffler172d5212020-01-02 14:42:562095 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372096 }
Harley Libcf41f92018-09-10 18:01:132097
Jan Schefflerd6c1d402021-02-26 16:56:382098 async _generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
Harley Libcf41f92018-09-10 18:01:132099 const nonBlobRequests = this._filterOutBlobRequests(requests);
2100 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2101 return commands.join(';\r\n');
2102 }
Joey Arhara86c14e2019-03-12 03:20:502103
Jan Schefflerd6c1d402021-02-26 16:56:382104 static getDCLEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512105 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502106 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342107 }
Joey Arhara86c14e2019-03-12 03:20:502108 return '#0867CB';
2109 }
2110
Jan Schefflerd6c1d402021-02-26 16:56:382111 static getLoadEventColor(): string {
Paul Lewisca569a52020-09-09 16:11:512112 return ThemeSupport.ThemeSupport.instance().patchColorText(
2113 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502114 }
Paul Lewis56509652019-12-06 12:51:582115}
Blink Reformat4c46d092018-04-07 15:32:372116
Jan Schefflerd6c1d402021-02-26 16:56:382117export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022118 let stackTraceText = '';
2119 for (const frame of stackTrace.callFrames) {
2120 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2121 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2122 }
2123 if (stackTrace.parent) {
2124 stackTraceText += computeStackTraceText(stackTrace.parent);
2125 }
2126 return stackTraceText;
2127}
2128
Jan Schefflerd6c1d402021-02-26 16:56:382129const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2130const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372131
Jan Schefflerd6c1d402021-02-26 16:56:382132export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372133 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222134}
2135
Paul Lewis56509652019-12-06 12:51:582136export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372137 'http': true,
2138 'https': true,
2139 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382140 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372141};
2142
Jan Schefflerd6c1d402021-02-26 16:56:382143// TODO(crbug.com/1167717): Make this a const enum again
2144// eslint-disable-next-line rulesdir/const_enum
2145export enum FilterType {
2146 Domain = 'domain',
2147 HasResponseHeader = 'has-response-header',
2148 Is = 'is',
2149 LargerThan = 'larger-than',
2150 Method = 'method',
2151 MimeType = 'mime-type',
2152 MixedContent = 'mixed-content',
2153 Priority = 'priority',
2154 Scheme = 'scheme',
2155 SetCookieDomain = 'set-cookie-domain',
2156 SetCookieName = 'set-cookie-name',
2157 SetCookieValue = 'set-cookie-value',
2158 ResourceType = 'resource-type',
2159 CookieDomain = 'cookie-domain',
2160 CookieName = 'cookie-name',
2161 CookiePath = 'cookie-path',
2162 CookieValue = 'cookie-value',
2163 StatusCode = 'status-code',
2164 Url = 'url',
Paul Lewis56509652019-12-06 12:51:582165}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162166
Jan Schefflerd6c1d402021-02-26 16:56:382167// TODO(crbug.com/1167717): Make this a const enum again
2168// eslint-disable-next-line rulesdir/const_enum
2169export enum MixedContentFilterValues {
2170 All = 'all',
2171 Displayed = 'displayed',
2172 Blocked = 'blocked',
2173 BlockOverridden = 'block-overridden',
2174}
2175
2176// TODO(crbug.com/1167717): Make this a const enum again
2177// eslint-disable-next-line rulesdir/const_enum
2178export enum IsFilterType {
2179 Running = 'running',
2180 FromCache = 'from-cache',
2181 ServiceWorkerIntercepted = 'service-worker-intercepted',
2182 ServiceWorkerInitiated = 'service-worker-initiated',
2183}
2184
2185// TODO(crbug.com/1172300) Ignored during the jsdoc to ts migration)
2186// eslint-disable-next-line @typescript-eslint/naming-convention
2187export const _searchKeys: string[] = Object.values(FilterType);
2188
2189export interface GroupLookupInterface {
2190 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2191 reset(): void;
2192}
2193
2194export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;