blob: 5d0f3e1abc155527a3453ddb7541d2a08ea84f77 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lippe0ed1d2b2020-02-04 13:45:1331import * as Bindings from '../bindings/bindings.js';
Sigurd Schneiderba818512020-04-29 10:54:3732import * as BrowserSDK from '../browser_sdk/browser_sdk.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1333import * as Common from '../common/common.js';
34import * as Components from '../components/components.js';
35import * as DataGrid from '../data_grid/data_grid.js';
36import * as HARImporter from '../har_importer/har_importer.js';
37import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5038import * as PerfUI from '../perf_ui/perf_ui.js';
Jack Franklin9c225ca2020-04-29 09:55:1739import * as Platform from '../platform/platform.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1340import * as SDK from '../sdk/sdk.js';
41import * as TextUtils from '../text_utils/text_utils.js';
Paul Lewisca569a52020-09-09 16:11:5142import * as ThemeSupport from '../theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1343import * as UI from '../ui/ui.js';
44
Tim van der Lippe119690c2020-01-13 12:31:3045import {HARWriter} from './HARWriter.js';
46import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
47import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
48import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
chait pinnamaneni6bc1c122020-10-30 17:30:5249import {FilterOptions} from './NetworkPanel.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe119690c2020-01-13 12:31:3050import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
51
Blink Reformat4c46d092018-04-07 15:32:3752/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1353 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3054 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3755 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3757 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1358 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3759 * @param {!Element} progressBarContainer
Tim van der Lippe224a8622020-09-23 12:14:3760 * @param {!Common.Settings.Setting<number>} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3761 */
62 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
63 super();
64 this.setMinimumSize(50, 64);
65 this.registerRequiredCSS('network/networkLogView.css');
66
67 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0568 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3769
Paul Lewis2d7d65c2020-03-16 17:26:3070 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
71 this._networkShowIssuesOnlySetting =
72 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
73 this._networkOnlyBlockedRequestsSetting =
74 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
75 this._networkResourceTypeFiltersSetting =
76 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3777
78 this._rawRowHeight = 0;
79 this._progressBarContainer = progressBarContainer;
80 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
81 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
82
83 /**
Paul Lewis56509652019-12-06 12:51:5884 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3785 */
86 function updateRowHeight() {
87 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
88 this._rowHeight = this._computeRowHeight();
89 }
90 this._rawRowHeight = 0;
91 this._rowHeight = 0;
92 updateRowHeight.call(this);
93
Tim van der Lippe119690c2020-01-13 12:31:3094 /** @type {!NetworkTransferTimeCalculator} */
95 this._timeCalculator = new NetworkTransferTimeCalculator();
96 /** @type {!NetworkTransferDurationCalculator} */
97 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3798 this._calculator = this._timeCalculator;
99
Tim van der Lippe119690c2020-01-13 12:31:30100 this._columns =
101 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37102 this._columns.show(this.element);
103
Tim van der Lippe0ed1d2b2020-02-04 13:45:13104 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37105 this._staleRequests = new Set();
106 /** @type {number} */
107 this._mainRequestLoadTime = -1;
108 /** @type {number} */
109 this._mainRequestDOMContentLoadedTime = -1;
Tim van der Lippe224a8622020-09-23 12:14:37110 /** @type {*} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._highlightedSubstringChanges = [];
112
Tim van der Lippeb1f2b6c2020-02-17 13:00:16113 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16115 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37116 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30117 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37118 this._hoveredNode = null;
119 /** @type {?Element} */
120 this._recordingHint = null;
121 /** @type {?number} */
122 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30123 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37124 this._highlightedNode = null;
125
Simon Zündcdd72c92020-10-07 11:48:13126 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37127
128 this._recording = false;
129 this._needsRefresh = false;
130
131 this._headerHeight = 0;
132
Paul Lewis56509652019-12-06 12:51:58133 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37134 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30135 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37136
Paul Lewis56509652019-12-06 12:51:58137 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37138 this._activeGroupLookup = null;
139
Tim van der Lippe0ed1d2b2020-02-04 13:45:13140 this._textFilterUI = new UI.FilterBar.TextFilterUI();
141 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37142 filterBar.addFilter(this._textFilterUI);
143
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
145 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
146 this._dataURLFilterUI.addEventListener(
147 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48148 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37149 filterBar.addFilter(this._dataURLFilterUI);
150
151 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13152 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37153 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13154 this._resourceCategoryFilterUI =
155 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20156 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37157 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13158 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37159 filterBar.addFilter(this._resourceCategoryFilterUI);
160
Tim van der Lippe0ed1d2b2020-02-04 13:45:13161 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
162 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
163 this._onlyIssuesFilterUI.addEventListener(
164 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41165 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37166 filterBar.addFilter(this._onlyIssuesFilterUI);
167
Sigurd Schneidera2afe0b2020-03-03 15:27:13168 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
169 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
170 this._onlyBlockedRequestsUI.addEventListener(
171 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
172 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
173 filterBar.addFilter(this._onlyBlockedRequestsUI);
174
Jan Scheffler1ae7c9e2019-12-03 15:48:37175
Tim van der Lippe0ed1d2b2020-02-04 13:45:13176 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
177 this._suggestionBuilder =
178 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37179 this._resetSuggestionBuilder();
180
181 this._dataGrid = this._columns.dataGrid();
182 this._setupDataGrid();
183 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49184 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13185 UI.Toolbar.ToolbarButton.Events.Click,
186 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37187
Tim van der Lippe0ed1d2b2020-02-04 13:45:13188 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37189
Tim van der Lippe0ed1d2b2020-02-04 13:45:13190 new UI.DropTarget.DropTarget(
191 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
192 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37193
Paul Lewis2d7d65c2020-03-16 17:26:30194 Common.Settings.Settings.instance()
195 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37196 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
197
Paul Lewisdaac1062020-03-05 14:37:10198 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27199 SDK.NetworkLog.NetworkLog.instance().addEventListener(
200 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
201 SDK.NetworkLog.NetworkLog.instance().addEventListener(
202 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
203 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37204
205 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30206 Common.Settings.Settings.instance()
207 .moduleSetting('network.group-by-frame')
208 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37209
210 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03211
212 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
213 if (this._textFilterSetting.get()) {
214 this.setTextFilterValue(this._textFilterSetting.get());
215 }
Blink Reformat4c46d092018-04-07 15:32:37216 }
217
Blink Reformat4c46d092018-04-07 15:32:37218 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30219 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37220 this._setGrouping(value ? 'Frame' : null);
221 }
222
223 /**
224 * @param {string} key
225 * @param {!Array<string>} values
226 */
227 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58228 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37229 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50230 const aPriority =
231 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
232 const bPriority =
233 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
234 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
235 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37236 });
237 } else {
238 values.sort();
239 }
240 }
241
242 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16243 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13244 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37245 * @return {boolean}
246 */
247 static _negativeFilter(filter, request) {
248 return !filter(request);
249 }
250
251 /**
252 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13253 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37254 * @return {boolean}
255 */
256 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34257 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37258 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34259 }
Blink Reformat4c46d092018-04-07 15:32:37260
261 return regex.test(request.path() + '/' + request.name());
262 }
263
264 /**
265 * @param {string} domain
266 * @return {!Array.<string>}
267 */
268 static _subdomains(domain) {
269 const result = [domain];
270 let indexOfPeriod = domain.indexOf('.');
271 while (indexOfPeriod !== -1) {
272 result.push('*' + domain.substring(indexOfPeriod));
273 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
274 }
275 return result;
276 }
277
278 /**
279 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16280 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37281 */
282 static _createRequestDomainFilter(value) {
283 /**
284 * @param {string} string
285 * @return {string}
286 */
287 function escapeForRegExp(string) {
288 return string.escapeForRegExp();
289 }
290 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58291 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37292 }
293
294 /**
295 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13296 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37297 * @return {boolean}
298 */
299 static _requestDomainFilter(regex, request) {
300 return regex.test(request.domain);
301 }
302
303 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13304 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37305 * @return {boolean}
306 */
307 static _runningRequestFilter(request) {
308 return !request.finished;
309 }
310
311 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13312 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37313 * @return {boolean}
314 */
315 static _fromCacheRequestFilter(request) {
316 return request.cached();
317 }
318
319 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13320 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05321 * @return {boolean}
322 */
323 static _interceptedByServiceWorkerFilter(request) {
324 return request.fetchedViaServiceWorker;
325 }
326
327 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05329 * @return {boolean}
330 */
331 static _initiatedByServiceWorkerFilter(request) {
332 return request.initiatedByServiceWorker();
333 }
334
335 /**
Blink Reformat4c46d092018-04-07 15:32:37336 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13337 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37338 * @return {boolean}
339 */
340 static _requestResponseHeaderFilter(value, request) {
341 return request.responseHeaderValue(value) !== undefined;
342 }
343
344 /**
345 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13346 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37347 * @return {boolean}
348 */
349 static _requestMethodFilter(value, request) {
350 return request.requestMethod === value;
351 }
352
353 /**
354 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13355 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37356 * @return {boolean}
357 */
358 static _requestPriorityFilter(value, request) {
359 return request.priority() === value;
360 }
361
362 /**
363 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13364 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37365 * @return {boolean}
366 */
367 static _requestMimeTypeFilter(value, request) {
368 return request.mimeType === value;
369 }
370
371 /**
Paul Lewis56509652019-12-06 12:51:58372 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13373 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37374 * @return {boolean}
375 */
376 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58377 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37378 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28379 }
380 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37381 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28382 }
383 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37384 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28385 }
386 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37387 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34388 }
Blink Reformat4c46d092018-04-07 15:32:37389
390 return false;
391 }
392
393 /**
394 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13395 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37396 * @return {boolean}
397 */
398 static _requestSchemeFilter(value, request) {
399 return request.scheme === value;
400 }
401
402 /**
403 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13404 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37405 * @return {boolean}
406 */
Jan Scheffler341eea52019-12-12 09:08:41407 static _requestCookieDomainFilter(value, request) {
408 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
409 }
410
411 /**
412 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13413 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41414 * @return {boolean}
415 */
416 static _requestCookieNameFilter(value, request) {
417 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
418 }
419
420 /**
421 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13422 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41423 * @return {boolean}
424 */
Simon Zündc9759102020-03-25 11:24:54425 static _requestCookiePathFilter(value, request) {
426 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
427 }
428
429 /**
430 * @param {string} value
431 * @param {!SDK.NetworkRequest.NetworkRequest} request
432 * @return {boolean}
433 */
Jan Scheffler341eea52019-12-12 09:08:41434 static _requestCookieValueFilter(value, request) {
435 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
436 }
437
438 /**
439 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13440 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41441 * @return {boolean}
442 */
Blink Reformat4c46d092018-04-07 15:32:37443 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41444 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37445 }
446
447 /**
448 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13449 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37450 * @return {boolean}
451 */
452 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41453 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37454 }
455
456 /**
457 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13458 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37459 * @return {boolean}
460 */
461 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41462 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37463 }
464
465 /**
466 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13467 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37468 * @return {boolean}
469 */
470 static _requestSizeLargerThanFilter(value, request) {
471 return request.transferSize >= value;
472 }
473
474 /**
475 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13476 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37477 * @return {boolean}
478 */
479 static _statusCodeFilter(value, request) {
480 return ('' + request.statusCode) === value;
481 }
482
483 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13484 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37485 * @return {boolean}
486 */
487 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58488 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37489 }
490
Sigurd Schneider464838b2020-08-24 13:53:03491
492 /**
493 * @param {string} value
494 * @param {!SDK.NetworkRequest.NetworkRequest} request
495 * @return {boolean}
496 */
497 static _resourceTypeFilter(value, request) {
498 return request.resourceType().name() === value;
499 }
500
Blink Reformat4c46d092018-04-07 15:32:37501 /**
Julian Geppertf8ce40c2020-09-01 18:02:03502 * @param {string} value
503 * @param {!SDK.NetworkRequest.NetworkRequest} request
504 * @return {boolean}
505 */
506 static _requestUrlFilter(value, request) {
507 const regex = new RegExp(value.escapeForRegExp(), 'i');
508 return regex.test(request.url());
509 }
510
511 /**
Blink Reformat4c46d092018-04-07 15:32:37512 * @param {number} windowStart
513 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13514 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37515 * @return {boolean}
516 */
517 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34518 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37519 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34520 }
521 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37522 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34523 }
Blink Reformat4c46d092018-04-07 15:32:37524 return true;
525 }
526
527 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13528 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37529 */
530 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13531 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37532 }
533
534 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13535 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37536 */
537 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13538 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37539 }
540
541 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13542 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37543 */
544 static async _copyResponse(request) {
545 const contentData = await request.contentData();
Tim van der Lippe224a8622020-09-23 12:14:37546 /** @type {?string} */
Ingvar Stepanyan1c771842018-10-10 14:35:08547 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34548 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40549 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37550 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08551 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34552 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13553 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37554 }
555
556 /**
557 * @param {!DataTransfer} dataTransfer
558 */
559 _handleDrop(dataTransfer) {
560 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34561 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37562 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34563 }
Blink Reformat4c46d092018-04-07 15:32:37564 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34565 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37566 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34567 }
Blink Reformat4c46d092018-04-07 15:32:37568
Joey Arhar0e1093c2019-05-21 00:34:22569 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37570 }
571
572 /**
Tim van der Lippe119690c2020-01-13 12:31:30573 * @override
Blink Reformat4c46d092018-04-07 15:32:37574 * @param {!File} file
575 */
Joey Arhar0e1093c2019-05-21 00:34:22576 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13577 const outputStream = new Common.StringOutputStream.StringOutputStream();
578 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37579 const success = await reader.read(outputStream);
580 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37581 const error = reader.error();
582 if (error) {
583 this._harLoadFailed(/** @type {*} */ (error).message);
584 }
Blink Reformat4c46d092018-04-07 15:32:37585 return;
586 }
587 let harRoot;
588 try {
589 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13590 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37591 } catch (e) {
592 this._harLoadFailed(e);
593 return;
594 }
Wolfgang Beyerd81fad62020-05-27 12:30:27595 SDK.NetworkLog.NetworkLog.instance().importRequests(
596 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37597 }
598
599 /**
600 * @param {string} message
601 */
602 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36603 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37604 }
605
606 /**
607 * @param {?string} groupKey
608 */
609 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34610 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37611 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34612 }
Blink Reformat4c46d092018-04-07 15:32:37613 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
614 this._activeGroupLookup = groupLookup;
615 this._invalidateAllItems();
616 }
617
618 /**
619 * @return {number}
620 */
621 _computeRowHeight() {
622 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
623 }
624
625 /**
Tim van der Lippe119690c2020-01-13 12:31:30626 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13627 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30628 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37629 */
630 nodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:37631 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37632 }
633
634 /**
Tim van der Lippe119690c2020-01-13 12:31:30635 * @override
Blink Reformat4c46d092018-04-07 15:32:37636 * @return {number}
637 */
638 headerHeight() {
639 return this._headerHeight;
640 }
641
642 /**
Tim van der Lippe119690c2020-01-13 12:31:30643 * @override
Blink Reformat4c46d092018-04-07 15:32:37644 * @param {boolean} recording
645 */
646 setRecording(recording) {
647 this._recording = recording;
648 this._updateSummaryBar();
649 }
650
651 /**
652 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13653 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37654 */
655 modelAdded(networkManager) {
656 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34657 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37658 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34659 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13660 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37661 if (resourceTreeModel) {
662 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
663 resourceTreeModel.addEventListener(
664 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
665 }
666 }
667
668 /**
669 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13670 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37671 */
672 modelRemoved(networkManager) {
673 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13674 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37675 if (resourceTreeModel) {
676 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
677 resourceTreeModel.removeEventListener(
678 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
679 }
680 }
681 }
682
683 /**
Tim van der Lippe119690c2020-01-13 12:31:30684 * @override
Simon Zündcdd72c92020-10-07 11:48:13685 * @return {!Components.Linkifier.Linkifier}
686 */
687 linkifier() {
688 return this._linkifier;
689 }
690
691 /**
692 * @override
Blink Reformat4c46d092018-04-07 15:32:37693 * @param {number} start
694 * @param {number} end
695 */
696 setWindow(start, end) {
697 if (!start && !end) {
698 this._timeFilter = null;
699 this._timeCalculator.setWindow(null);
700 } else {
Paul Lewis56509652019-12-06 12:51:58701 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30702 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37703 }
704 this._filterRequests();
705 }
706
Tim van der Lippe119690c2020-01-13 12:31:30707 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05708 resetFocus() {
709 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37710 }
711
712 _resetSuggestionBuilder() {
713 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58714 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
715 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
716 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
717 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
718 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
719 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
720 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37721 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
722 }
723
724 /**
Tim van der Lippec02a97c2020-02-14 14:39:27725 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37726 */
727 _filterChanged(event) {
728 this.removeAllNodeHighlights();
729 this._parseFilterQuery(this._textFilterUI.value());
730 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03731 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37732 }
733
Rajasekar Murugan3ad369e2020-02-19 18:20:12734 async resetFilter() {
735 this._textFilterUI.clear();
736 }
737
Blink Reformat4c46d092018-04-07 15:32:37738 _showRecordingHint() {
739 this._hideRecordingHint();
740 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
741 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18742
743 let reloadShortcutNode = null;
Tim van der Lippe9c9fb122020-09-08 15:06:17744 const reloadShortcut =
745 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
Jack Lynchb8fb3c72020-04-21 05:36:16746 if (reloadShortcut) {
Joey Arhar0585e6f2018-10-30 23:11:18747 reloadShortcutNode = this._recordingHint.createChild('b');
Jack Lynchb8fb3c72020-04-21 05:36:16748 reloadShortcutNode.textContent = reloadShortcut.title();
Joey Arhar0585e6f2018-10-30 23:11:18749 }
Blink Reformat4c46d092018-04-07 15:32:37750
751 if (this._recording) {
752 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38753 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18754 if (reloadShortcutNode) {
755 hintText.createChild('br');
756 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13757 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18758 }
Blink Reformat4c46d092018-04-07 15:32:37759 } else {
760 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17761 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37762 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Joey Arhar0585e6f2018-10-30 23:11:18763 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13764 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18765 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
766 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13767 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18768 }
Blink Reformat4c46d092018-04-07 15:32:37769 }
Kayce Basques5444c1b2019-02-15 20:32:53770 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13771 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53772 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43773 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11774
775 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57776 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37777 }
778
779 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11780 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34781 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37782 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34783 }
Brandon Goddardc992d522020-01-08 21:44:57784 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37785 this._recordingHint = null;
786 }
787
788 /**
Amanda Baker6761aae2019-11-05 18:59:11789 * @param {boolean} value
790 */
791 _setHidden(value) {
792 this._columns.setHidden(value);
793 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
794 }
795
796 /**
Blink Reformat4c46d092018-04-07 15:32:37797 * @override
798 * @return {!Array.<!Element>}
799 */
800 elementsToRestoreScrollPositionsFor() {
801 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34802 {
Blink Reformat4c46d092018-04-07 15:32:37803 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34804 }
Blink Reformat4c46d092018-04-07 15:32:37805 return [this._dataGrid.scrollContainer];
806 }
807
Tim van der Lippe119690c2020-01-13 12:31:30808 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37809 columnExtensionResolved() {
810 this._invalidateAllItems(true);
811 }
812
813 _setupDataGrid() {
814 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Andres Olivares03d9c752020-10-01 15:08:11815 const request = (/** @type {!NetworkNode} */ (node)).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34816 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37817 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34818 }
Blink Reformat4c46d092018-04-07 15:32:37819 });
820 this._dataGrid.setStickToBottom(true);
821 this._dataGrid.setName('networkLog');
822 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
823 this._dataGrid.element.classList.add('network-log-grid');
824 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
825 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
826 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05827 this._dataGrid.element.addEventListener('keydown', event => {
828 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05829 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05830 event.consume(true);
831 }
832 });
Brandon Goddard44934902020-03-25 16:03:18833 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
834 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37835 return this._dataGrid;
836 }
837
838 /**
839 * @param {!Event} event
840 */
841 _dataGridMouseMove(event) {
Tim van der Lippe224a8622020-09-23 12:14:37842 const mouseEvent = /** @type {!MouseEvent} */ (event);
Andres Olivares03d9c752020-10-01 15:08:11843 const node =
844 /** @type {!NetworkNode} */ (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (mouseEvent.target)));
Tim van der Lippe224a8622020-09-23 12:14:37845 const highlightInitiatorChain = mouseEvent.shiftKey;
Blink Reformat4c46d092018-04-07 15:32:37846 this._setHoveredNode(node, highlightInitiatorChain);
847 }
848
849 /**
Tim van der Lippe119690c2020-01-13 12:31:30850 * @override
851 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37852 */
853 hoveredNode() {
854 return this._hoveredNode;
855 }
856
857 /**
Tim van der Lippe119690c2020-01-13 12:31:30858 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37859 * @param {boolean=} highlightInitiatorChain
860 */
861 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34862 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37863 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34864 }
Blink Reformat4c46d092018-04-07 15:32:37865 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34866 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37867 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34868 }
Blink Reformat4c46d092018-04-07 15:32:37869 }
870
871 /**
872 * @param {!Event} event
873 */
874 _dataGridMouseDown(event) {
Tim van der Lippe224a8622020-09-23 12:14:37875 const mouseEvent = /** @type {!MouseEvent} */ (event);
876 if (!this._dataGrid.selectedNode && mouseEvent.button) {
877 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34878 }
Blink Reformat4c46d092018-04-07 15:32:37879 }
880
881 _updateSummaryBar() {
882 this._hideRecordingHint();
883
884 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20885 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37886 let selectedNodeNumber = 0;
887 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20888 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37889 let baseTime = -1;
890 let maxTime = -1;
891
892 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27893 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37894 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34895 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37896 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34897 }
Blink Reformat4c46d092018-04-07 15:32:37898 nodeCount++;
899 const requestTransferSize = request.transferSize;
900 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20901 const requestResourceSize = request.resourceSize;
902 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37903 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37904 selectedNodeNumber++;
905 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20906 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37907 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13908 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37909 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
910 // inspected url.
911 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13912 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
913 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37914 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34915 }
916 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37917 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34918 }
Blink Reformat4c46d092018-04-07 15:32:37919 }
920
921 if (!nodeCount) {
922 this._showRecordingHint();
923 return;
924 }
925
Joey Arhara86c14e2019-03-12 03:20:50926 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37927 /**
928 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50929 * @param {string=} title
Tim van der Lippe224a8622020-09-23 12:14:37930 * @return {!HTMLDivElement}
Blink Reformat4c46d092018-04-07 15:32:37931 */
Joey Arhara86c14e2019-03-12 03:20:50932 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13933 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50934 toolbarText.setTitle(title ? title : chunk);
935 this._summaryToolbar.appendToolbarItem(toolbarText);
Tim van der Lippe224a8622020-09-23 12:14:37936 return /** @type {!HTMLDivElement} */ (toolbarText.element);
Joey Arhara86c14e2019-03-12 03:20:50937 };
Blink Reformat4c46d092018-04-07 15:32:37938
939 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50940 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
941 this._summaryToolbar.appendSeparator();
942 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17943 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
944 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25945 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50946 this._summaryToolbar.appendSeparator();
947 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17948 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
949 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25950 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37951 } else {
Joey Arhara86c14e2019-03-12 03:20:50952 appendChunk(ls`${nodeCount} requests`);
953 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25954 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17955 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
956 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50957 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25958 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17959 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
960 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37961 }
Dan Beam87466b52018-12-01 18:41:20962
Blink Reformat4c46d092018-04-07 15:32:37963 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50964 this._summaryToolbar.appendSeparator();
965 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37966 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50967 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30968 const domContentLoadedText =
969 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58970 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37971 }
972 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50973 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30974 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58975 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37976 }
977 }
Blink Reformat4c46d092018-04-07 15:32:37978 }
979
Tim van der Lippe119690c2020-01-13 12:31:30980 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37981 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34982 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37983 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34984 }
Blink Reformat4c46d092018-04-07 15:32:37985
986 this._needsRefresh = true;
987
Tim van der Lippe1d6e57a2019-09-30 11:55:34988 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37989 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34990 }
Blink Reformat4c46d092018-04-07 15:32:37991 }
992
993 /**
Tim van der Lippe119690c2020-01-13 12:31:30994 * @override
Blink Reformat4c46d092018-04-07 15:32:37995 * @param {!Array<number>} times
996 */
997 addFilmStripFrames(times) {
998 this._columns.addEventDividers(times, 'network-frame-divider');
999 }
1000
1001 /**
Tim van der Lippe119690c2020-01-13 12:31:301002 * @override
Blink Reformat4c46d092018-04-07 15:32:371003 * @param {number} time
1004 */
1005 selectFilmStripFrame(time) {
1006 this._columns.selectFilmStripFrame(time);
1007 }
1008
Tim van der Lippe119690c2020-01-13 12:31:301009 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371010 clearFilmStripFrame() {
1011 this._columns.clearFilmStripFrame();
1012 }
1013
1014 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341015 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371016 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341017 }
Blink Reformat4c46d092018-04-07 15:32:371018 }
1019
1020 /**
1021 * @param {boolean=} deferUpdate
1022 */
1023 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271024 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341025 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371026 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341027 } else {
Blink Reformat4c46d092018-04-07 15:32:371028 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341029 }
Blink Reformat4c46d092018-04-07 15:32:371030 }
1031
1032 /**
Tim van der Lippe119690c2020-01-13 12:31:301033 * @override
1034 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371035 */
1036 timeCalculator() {
1037 return this._timeCalculator;
1038 }
1039
1040 /**
Tim van der Lippe119690c2020-01-13 12:31:301041 * @override
1042 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371043 */
1044 calculator() {
1045 return this._calculator;
1046 }
1047
1048 /**
Tim van der Lippe119690c2020-01-13 12:31:301049 * @override
1050 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371051 */
1052 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341053 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371054 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341055 }
Blink Reformat4c46d092018-04-07 15:32:371056
1057 if (this._calculator !== x) {
1058 this._calculator = x;
1059 this._columns.setCalculator(this._calculator);
1060 }
1061 this._calculator.reset();
1062
Tim van der Lippe1d6e57a2019-09-30 11:55:341063 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371064 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341065 } else {
Blink Reformat4c46d092018-04-07 15:32:371066 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341067 }
Blink Reformat4c46d092018-04-07 15:32:371068
1069 this._invalidateAllItems();
1070 }
1071
1072 /**
Tim van der Lippec02a97c2020-02-14 14:39:271073 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371074 */
1075 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341076 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371077 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341078 }
Blink Reformat4c46d092018-04-07 15:32:371079
1080 const time = /** @type {number} */ (event.data.loadTime);
1081 if (time) {
1082 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301083 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371084 }
1085 }
1086
1087 /**
Tim van der Lippec02a97c2020-02-14 14:39:271088 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371089 */
1090 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341091 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371092 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341093 }
Blink Reformat4c46d092018-04-07 15:32:371094 const data = /** @type {number} */ (event.data);
1095 if (data) {
1096 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301097 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371098 }
1099 }
1100
1101 /**
1102 * @override
1103 */
1104 wasShown() {
1105 this._refreshIfNeeded();
1106 this._columns.wasShown();
1107 }
1108
1109 /**
1110 * @override
1111 */
1112 willHide() {
1113 this._columns.willHide();
1114 }
1115
1116 /**
1117 * @override
1118 */
1119 onResize() {
1120 this._rowHeight = this._computeRowHeight();
1121 }
1122
1123 /**
Tim van der Lippe119690c2020-01-13 12:31:301124 * @override
1125 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371126 */
1127 flatNodesList() {
Andres Olivares21ab05b2020-10-21 14:00:021128 /** @type {!DataGrid.ViewportDataGrid.ViewportDataGridNode<!DataGrid.SortableDataGrid.SortableDataGridNode<!NetworkNode>>} */
1129 const rootNode = (this._dataGrid.rootNode());
1130 return /** @type {!Array<!NetworkNode>} */ (rootNode.flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371131 }
1132
Brandon Goddard44934902020-03-25 16:03:181133 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491134 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351135 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381136 }
Brandon Goddard44934902020-03-25 16:03:181137 this.updateNodeBackground();
1138 }
1139
1140 _onDataGridBlur() {
1141 this.element.classList.remove('grid-focused');
1142 this.updateNodeBackground();
1143 }
1144
Tim van der Lippe119690c2020-01-13 12:31:301145 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051146 updateNodeBackground() {
1147 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111148 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051149 }
1150 }
1151
1152 /**
Tim van der Lippe119690c2020-01-13 12:31:301153 * @override
Brandon Goddard88d885a2019-10-31 16:11:051154 * @param {boolean} isSelected
1155 */
1156 updateNodeSelectedClass(isSelected) {
1157 if (isSelected) {
1158 this.element.classList.remove('no-node-selected');
1159 } else {
1160 this.element.classList.add('no-node-selected');
1161 }
1162 }
1163
Tim van der Lippe119690c2020-01-13 12:31:301164 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371165 stylesChanged() {
1166 this._columns.scheduleRefresh();
1167 }
1168
1169 _refresh() {
1170 this._needsRefresh = false;
1171
1172 if (this._refreshRequestId) {
1173 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1174 this._refreshRequestId = null;
1175 }
1176
1177 this.removeAllNodeHighlights();
1178
1179 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1180 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1181 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1182 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1183
Tim van der Lippe224a8622020-09-23 12:14:371184 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371185 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301186 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371187 const nodesToRefresh = [];
1188
Tim van der Lippe119690c2020-01-13 12:31:301189 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371190 const staleNodes = new Set();
1191
1192 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1193 // node so we loop until we have no more stale requests.
1194 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371195 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371196 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371197 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341198 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371199 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341200 }
Blink Reformat4c46d092018-04-07 15:32:371201 staleNodes.add(node);
1202 }
1203
1204 for (const node of staleNodes) {
1205 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341206 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371207 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 }
Blink Reformat4c46d092018-04-07 15:32:371209
Tim van der Lippe1d6e57a2019-09-30 11:55:341210 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371211 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341212 }
Blink Reformat4c46d092018-04-07 15:32:371213 const request = node.request();
1214 this._timeCalculator.updateBoundaries(request);
1215 this._durationCalculator.updateBoundaries(request);
1216 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371217 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1218 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371219 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341220 }
Tim van der Lippe224a8622020-09-23 12:14:371221 if (isFilteredOut) {
1222 filteredNetworkRequests.add(node);
1223 } else {
1224 filteredNetworkRequests.delete(node);
1225 }
Blink Reformat4c46d092018-04-07 15:32:371226 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1227 if (removeFromParent) {
1228 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111229 if (!parent) {
1230 continue;
1231 }
Blink Reformat4c46d092018-04-07 15:32:371232 parent.removeChild(node);
1233 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111234 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371235 grandparent.removeChild(parent);
1236 parent = grandparent;
1237 }
1238 }
1239
Tim van der Lippe1d6e57a2019-09-30 11:55:341240 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371241 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341242 }
Blink Reformat4c46d092018-04-07 15:32:371243
1244 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111245 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371246 nodesToRefresh.push(newParent);
1247 }
1248 nodesToInsert.set(node, newParent);
1249 }
1250
Tim van der Lippe1d6e57a2019-09-30 11:55:341251 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371252 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341253 }
Blink Reformat4c46d092018-04-07 15:32:371254
Tim van der Lippe1d6e57a2019-09-30 11:55:341255 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371256 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341257 }
Blink Reformat4c46d092018-04-07 15:32:371258
1259 this._updateSummaryBar();
1260
Tim van der Lippe1d6e57a2019-09-30 11:55:341261 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371262 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341263 }
Blink Reformat4c46d092018-04-07 15:32:371264
1265 this._dataGrid.updateInstantly();
1266 this._didRefreshForTest();
1267 }
1268
1269 _didRefreshForTest() {
1270 }
1271
1272 /**
Tim van der Lippe119690c2020-01-13 12:31:301273 * @param {!NetworkRequestNode} node
1274 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371275 */
1276 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341277 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111278 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341279 }
Blink Reformat4c46d092018-04-07 15:32:371280
1281 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341282 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111283 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341284 }
Blink Reformat4c46d092018-04-07 15:32:371285 return groupNode;
1286 }
1287
1288 _reset() {
Simon Zünd98419832020-03-12 06:18:151289 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371290
1291 this._setHoveredNode(null);
1292 this._columns.reset();
1293
1294 this._timeFilter = null;
1295 this._calculator.reset();
1296
1297 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131298 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371299
Tim van der Lippe1d6e57a2019-09-30 11:55:341300 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371301 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341302 }
Blink Reformat4c46d092018-04-07 15:32:371303 this._staleRequests.clear();
1304 this._resetSuggestionBuilder();
1305
1306 this._mainRequestLoadTime = -1;
1307 this._mainRequestDOMContentLoadedTime = -1;
1308
1309 this._dataGrid.rootNode().removeChildren();
1310 this._updateSummaryBar();
1311 this._dataGrid.setStickToBottom(true);
1312 this.scheduleRefresh();
1313 }
1314
1315 /**
Tim van der Lippe119690c2020-01-13 12:31:301316 * @override
Blink Reformat4c46d092018-04-07 15:32:371317 * @param {string} filterString
1318 */
1319 setTextFilterValue(filterString) {
1320 this._textFilterUI.setValue(filterString);
1321 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371322 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131323 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371324 this._resourceCategoryFilterUI.reset();
1325 }
1326
1327 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371329 */
1330 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301331 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371332 networkRequestToNode.set(request, node);
1333 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371334
Tim van der Lippe1d6e57a2019-09-30 11:55:341335 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371336 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341337 }
Blink Reformat4c46d092018-04-07 15:32:371338 return node;
1339 }
1340
1341 /**
Tim van der Lippec02a97c2020-02-14 14:39:271342 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371343 */
1344 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131345 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371346 this._refreshRequest(request);
1347 }
1348
1349 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131350 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371351 */
1352 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581353 NetworkLogView._subdomains(request.domain)
1354 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1355 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1356 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1357 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1358 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Sigurd Schneider464838b2020-08-24 13:53:031359 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031360 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371361
1362 const priority = request.priority();
1363 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501364 this._suggestionBuilder.addItem(
1365 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371366 }
1367
1368 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581369 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371370 }
1371
1372 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581373 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371374 }
1375
1376 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581377 const suggestion =
1378 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1379 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381
1382 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341383 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581384 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341385 }
Jan Scheffler341eea52019-12-12 09:08:411386
1387 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581388 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1389 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1390 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371391 }
1392
Jan Scheffler341eea52019-12-12 09:08:411393 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1394 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1395 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541396 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411397 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1398 }
1399
Blink Reformat4c46d092018-04-07 15:32:371400 this._staleRequests.add(request);
1401 this.scheduleRefresh();
1402 }
1403
1404 /**
Tim van der Lippe119690c2020-01-13 12:31:301405 * @override
Blink Reformat4c46d092018-04-07 15:32:371406 * @return {number}
1407 */
1408 rowHeight() {
1409 return this._rowHeight;
1410 }
1411
1412 /**
Tim van der Lippe119690c2020-01-13 12:31:301413 * @override
Blink Reformat4c46d092018-04-07 15:32:371414 * @param {boolean} gridMode
1415 */
1416 switchViewMode(gridMode) {
1417 this._columns.switchViewMode(gridMode);
1418 }
1419
1420 /**
Tim van der Lippe119690c2020-01-13 12:31:301421 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1423 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371424 */
1425 handleContextMenuForRequest(contextMenu, request) {
1426 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131427 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371428 const footerSection = copyMenu.footerSection();
1429 if (request) {
1430 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131431 UI.UIUtils.copyLinkAddressLabel(),
1432 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1433 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371434 if (request.requestHeadersText()) {
1435 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131436 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371437 }
1438
1439 if (request.responseHeadersText) {
1440 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131441 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371442 }
1443
1444 if (request.finished) {
1445 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131446 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371447 }
1448
Harley Libcf41f92018-09-10 18:01:131449 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131450 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371451 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131452 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1453 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371454 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131455 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291456 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131457 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1458 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371459 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131460 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1461 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131462 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1464 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371465 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131466 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1467 footerSection.appendItem(
1468 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1469 footerSection.appendItem(
1470 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1471 footerSection.appendItem(
1472 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1473 footerSection.appendItem(
1474 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371475 } else {
Harley Libcf41f92018-09-10 18:01:131476 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131477 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291478 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131479 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1480 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131481 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131482 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1483 footerSection.appendItem(
1484 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1485 footerSection.appendItem(
1486 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1487 footerSection.appendItem(
1488 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371489 }
1490 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131491 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371492 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131493 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371494
Joey Arhar0e1093c2019-05-21 00:34:221495 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371496
Blink Reformat4c46d092018-04-07 15:32:371497 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131498 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1499 contextMenu.editSection().appendItem(
1500 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371501
1502 if (request) {
1503 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211504 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371505 let patterns = manager.blockedPatterns();
1506
Tim van der Lippeffa78622019-09-16 12:07:121507 /**
1508 * @param {string} url
1509 */
1510 function addBlockedURL(url) {
1511 patterns.push({enabled: true, url: url});
1512 manager.setBlockedPatterns(patterns);
1513 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261514 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121515 }
1516
1517 /**
1518 * @param {string} url
1519 */
1520 function removeBlockedURL(url) {
1521 patterns = patterns.filter(pattern => pattern.url !== url);
1522 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261523 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121524 }
1525
Blink Reformat4c46d092018-04-07 15:32:371526 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1527 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1528 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131529 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371530 } else if (urlWithoutScheme) {
1531 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1532 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131533 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371534 }
1535
1536 const domain = request.parsedURL.domain();
1537 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1538 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131539 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371540 } else if (domain) {
1541 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1542 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131543 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371544 }
1545
Tim van der Lippe0ed1d2b2020-02-04 13:45:131546 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371547 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131548 Common.UIString.UIString('Replay XHR'),
1549 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371550 }
Blink Reformat4c46d092018-04-07 15:32:371551 }
1552 }
1553
1554 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271555 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171556 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131557 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171558 });
Blink Reformat4c46d092018-04-07 15:32:371559 }
1560
1561 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131562 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1563 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371564 }
1565
1566 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131567 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371568 * @param {string} platform
1569 */
1570 async _copyCurlCommand(request, platform) {
1571 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371573 }
1574
1575 /**
1576 * @param {string} platform
1577 */
1578 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271579 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131580 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371581 }
1582
1583 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131584 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291585 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371586 */
Jan Scheffler7c50d1f2019-12-17 13:33:291587 async _copyFetchCall(request, includeCookies) {
1588 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131589 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371590 }
1591
Jan Scheffler7c50d1f2019-12-17 13:33:291592 /**
1593 * @param {boolean} includeCookies
1594 */
1595 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271596 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131597 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371598 }
1599
1600 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131601 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371602 */
1603 async _copyPowerShellCommand(request) {
1604 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131605 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371606 }
1607
1608 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271609 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131610 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371611 }
1612
Tim van der Lippe119690c2020-01-13 12:31:301613 /**
1614 * @override
Tim van der Lippe224a8622020-09-23 12:14:371615 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301616 */
Joey Arhar0e1093c2019-05-21 00:34:221617 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371618 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1619 if (!mainTarget) {
1620 return;
1621 }
1622 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131623 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371624 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131625 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371626
Tim van der Lippe1d6e57a2019-09-30 11:55:341627 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371628 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341629 }
Blink Reformat4c46d092018-04-07 15:32:371630
Tim van der Lippe0ed1d2b2020-02-04 13:45:131631 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371632 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301633 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371634 progressIndicator.done();
1635 stream.close();
1636 }
1637
1638 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131639 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211640 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341641 }
Blink Reformat4c46d092018-04-07 15:32:371642 }
1643
1644 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131645 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211646 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341647 }
Blink Reformat4c46d092018-04-07 15:32:371648 }
1649
1650 _removeAllHighlights() {
1651 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341652 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131653 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341654 }
Blink Reformat4c46d092018-04-07 15:32:371655 this._highlightedSubstringChanges = [];
1656 }
1657
1658 /**
Tim van der Lippe119690c2020-01-13 12:31:301659 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371660 * @return {boolean}
1661 */
1662 _applyFilter(node) {
1663 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341664 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371665 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341666 }
Blink Reformat4c46d092018-04-07 15:32:371667 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341668 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371669 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341670 }
1671 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371672 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341673 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221674 if (this._onlyIssuesFilterUI.checked() &&
1675 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371676 return false;
1677 }
Sigurd Schneider20088de2020-10-30 08:08:331678 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131679 return false;
1680 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341681 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371682 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341683 }
Blink Reformat4c46d092018-04-07 15:32:371684 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341685 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371686 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341687 }
Blink Reformat4c46d092018-04-07 15:32:371688 }
1689 return true;
1690 }
1691
1692 /**
1693 * @param {string} query
1694 */
1695 _parseFilterQuery(query) {
1696 const descriptors = this._filterParser.parse(query);
1697 this._filters = descriptors.map(descriptor => {
1698 const key = descriptor.key;
1699 const text = descriptor.text || '';
1700 const regex = descriptor.regex;
1701 let filter;
1702 if (key) {
1703 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581704 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1705 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371706 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581707 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371708 } else {
Paul Lewis56509652019-12-06 12:51:581709 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371710 }
Paul Lewis56509652019-12-06 12:51:581711 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371712 });
1713 }
1714
1715 /**
Paul Lewis56509652019-12-06 12:51:581716 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371717 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161718 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371719 */
1720 _createSpecialFilter(type, value) {
1721 switch (type) {
Paul Lewis56509652019-12-06 12:51:581722 case FilterType.Domain:
1723 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371724
Paul Lewis56509652019-12-06 12:51:581725 case FilterType.HasResponseHeader:
1726 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371727
Paul Lewis56509652019-12-06 12:51:581728 case FilterType.Is:
1729 if (value.toLowerCase() === IsFilterType.Running) {
1730 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 }
Paul Lewis56509652019-12-06 12:51:581732 if (value.toLowerCase() === IsFilterType.FromCache) {
1733 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341734 }
Paul Lewis56509652019-12-06 12:51:581735 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1736 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341737 }
Paul Lewis56509652019-12-06 12:51:581738 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1739 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341740 }
Blink Reformat4c46d092018-04-07 15:32:371741 break;
1742
Paul Lewis56509652019-12-06 12:51:581743 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371744 return this._createSizeFilter(value.toLowerCase());
1745
Paul Lewis56509652019-12-06 12:51:581746 case FilterType.Method:
1747 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371748
Paul Lewis56509652019-12-06 12:51:581749 case FilterType.MimeType:
1750 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371751
Paul Lewis56509652019-12-06 12:51:581752 case FilterType.MixedContent:
1753 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371754
Paul Lewis56509652019-12-06 12:51:581755 case FilterType.Scheme:
1756 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371757
Paul Lewis56509652019-12-06 12:51:581758 case FilterType.SetCookieDomain:
1759 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371760
Paul Lewis56509652019-12-06 12:51:581761 case FilterType.SetCookieName:
1762 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371763
Paul Lewis56509652019-12-06 12:51:581764 case FilterType.SetCookieValue:
1765 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371766
Jan Scheffler341eea52019-12-12 09:08:411767 case FilterType.CookieDomain:
1768 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1769
1770 case FilterType.CookieName:
1771 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1772
Simon Zündc9759102020-03-25 11:24:541773 case FilterType.CookiePath:
1774 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1775
Jan Scheffler341eea52019-12-12 09:08:411776 case FilterType.CookieValue:
1777 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1778
Paul Lewis56509652019-12-06 12:51:581779 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501780 return NetworkLogView._requestPriorityFilter.bind(
1781 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371782
Paul Lewis56509652019-12-06 12:51:581783 case FilterType.StatusCode:
1784 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031785
1786 case FilterType.ResourceType:
1787 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031788
1789 case FilterType.Url:
1790 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371791 }
1792 return null;
1793 }
1794
1795 /**
1796 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161797 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371798 */
1799 _createSizeFilter(value) {
1800 let multiplier = 1;
1801 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541802 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371803 value = value.substring(0, value.length - 1);
1804 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541805 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371806 value = value.substring(0, value.length - 1);
1807 }
1808 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341809 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371810 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341811 }
Paul Lewis56509652019-12-06 12:51:581812 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371813 }
1814
1815 _filterRequests() {
1816 this._removeAllHighlights();
1817 this._invalidateAllItems();
1818 }
1819
1820 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131821 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301822 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371823 */
1824 _reveal(request) {
1825 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371826 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341827 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371828 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341829 }
Brandon Goddard5e4244d2020-04-08 22:08:471830 // Viewport datagrid nodes do not reveal if not in the root node
1831 // list of flatChildren. For children of grouped frame nodes:
1832 // reveal and expand parent to ensure child is revealable.
1833 if (node.parent && node.parent instanceof NetworkGroupNode) {
1834 node.parent.reveal();
1835 node.parent.expand();
1836 }
Blink Reformat4c46d092018-04-07 15:32:371837 node.reveal();
1838 return node;
1839 }
1840
1841 /**
Tim van der Lippe119690c2020-01-13 12:31:301842 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131843 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371844 */
1845 revealAndHighlightRequest(request) {
1846 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341847 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371848 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341849 }
Blink Reformat4c46d092018-04-07 15:32:371850 }
1851
1852 /**
Tim van der Lippe119690c2020-01-13 12:31:301853 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131854 * @param {!SDK.NetworkRequest.NetworkRequest} request
chait pinnamaneni6bc1c122020-10-30 17:30:521855 * @param {!FilterOptions=} options - Optional parameters to change filter behavior
Blink Reformat4c46d092018-04-07 15:32:371856 */
chait pinnamaneni6bc1c122020-10-30 17:30:521857 selectRequest(request, options) {
1858 const defaultOptions = {clearFilter: true};
1859 const {clearFilter} = options || defaultOptions;
1860 if (clearFilter) {
1861 this.setTextFilterValue('');
1862 }
Blink Reformat4c46d092018-04-07 15:32:371863 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341864 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371865 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341866 }
Blink Reformat4c46d092018-04-07 15:32:371867 }
1868
Tim van der Lippe119690c2020-01-13 12:31:301869 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371870 removeAllNodeHighlights() {
1871 if (this._highlightedNode) {
1872 this._highlightedNode.element().classList.remove('highlighted-row');
1873 this._highlightedNode = null;
1874 }
1875 }
1876
1877 /**
Tim van der Lippe119690c2020-01-13 12:31:301878 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371879 */
1880 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131881 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371882 this._highlightedNode = node;
1883 }
1884
1885 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131886 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1887 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131888 */
1889 _filterOutBlobRequests(requests) {
1890 return requests.filter(request => !request.isBlobRequest());
1891 }
1892
1893 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131894 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291895 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371896 * @return {!Promise<string>}
1897 */
Jan Scheffler7c50d1f2019-12-17 13:33:291898 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371899 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371900 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371901 'method',
1902 'path',
1903 'scheme',
1904 'version',
Blink Reformat4c46d092018-04-07 15:32:371905
1906 // Unsafe headers
1907 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371908 'accept-charset',
1909 'accept-encoding',
1910 'access-control-request-headers',
1911 'access-control-request-method',
1912 'connection',
1913 'content-length',
1914 'cookie',
1915 'cookie2',
1916 'date',
1917 'dnt',
1918 'expect',
1919 'host',
1920 'keep-alive',
1921 'origin',
1922 'referer',
1923 'te',
1924 'trailer',
1925 'transfer-encoding',
1926 'upgrade',
1927 'via',
Blink Reformat4c46d092018-04-07 15:32:371928 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371929 'user-agent',
1930 ]);
Blink Reformat4c46d092018-04-07 15:32:371931
Tim van der Lippe224a8622020-09-23 12:14:371932 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371933
1934 const url = JSON.stringify(request.url());
1935
1936 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371937 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371938 const headerData = requestHeaders.reduce((result, header) => {
1939 const name = header.name;
1940
Tim van der Lippe224a8622020-09-23 12:14:371941 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371942 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341943 }
Blink Reformat4c46d092018-04-07 15:32:371944
1945 return result;
1946 }, new Headers());
1947
Tim van der Lippe224a8622020-09-23 12:14:371948 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371949 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341950 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411951 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341952 }
Blink Reformat4c46d092018-04-07 15:32:371953
Sigurd Schneider0e88b912020-05-08 08:28:231954 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371955 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411956 'include' :
1957 'omit';
Blink Reformat4c46d092018-04-07 15:32:371958
1959 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1960
1961 const referrer = referrerHeader ? referrerHeader.value : void 0;
1962
1963 const referrerPolicy = request.referrerPolicy() || void 0;
1964
1965 const requestBody = await request.requestFormData();
1966
Tim van der Lippe224a8622020-09-23 12:14:371967 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371968 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411969 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371970 referrer,
1971 referrerPolicy,
1972 body: requestBody,
1973 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371974 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371975 };
1976
Jan Scheffler7c50d1f2019-12-17 13:33:291977 if (includeCookies) {
1978 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1979 if (cookieHeader) {
1980 fetchOptions.headers = {
1981 ...headers,
1982 'cookie': cookieHeader.value,
1983 };
1984 }
1985 } else {
1986 fetchOptions.credentials = credentials;
1987 }
1988
Jan Scheffler172d5212020-01-02 14:42:561989 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371990 return `fetch(${url}, ${options});`;
1991 }
1992
1993 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131994 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291995 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131996 * @return {!Promise<string>}
1997 */
Jan Scheffler7c50d1f2019-12-17 13:33:291998 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131999 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:292000 const commands =
2001 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:132002 return commands.join(' ;\n');
2003 }
2004
2005 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132006 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372007 * @param {string} platform
2008 * @return {!Promise<string>}
2009 */
2010 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562011 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362012 // Most of these headers are derived from the URL and are automatically added by cURL.
2013 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372014 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372015
Tim van der Lippe224a8622020-09-23 12:14:372016 /**
2017 * @param {string} str
2018 */
Blink Reformat4c46d092018-04-07 15:32:372019 function escapeStringWin(str) {
2020 /* If there are no new line characters do not escape the " characters
2021 since it only uglifies the command.
2022
2023 Because cmd.exe parser and MS Crt arguments parsers use some of the
2024 same escape characters, they can interact with each other in
2025 horrible ways, the order of operations is critical.
2026
2027 Replace \ with \\ first because it is an escape character for certain
2028 conditions in both parsers.
2029
2030 Replace all " with \" to ensure the first parser does not remove it.
2031
2032 Then escape all characters we are not sure about with ^ to ensure it
2033 gets to MS Crt parser safely.
2034
2035 The % character is special because MS Crt parser will try and look for
2036 ENV variables and fill them in it's place. We cannot escape them with %
2037 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2038 parser); So we can get cmd.exe parser to escape the character after it,
2039 if it is followed by a valid beginning character of an ENV variable.
2040 This ensures we do not try and double escape another ^ if it was placed
2041 by the previous replace.
2042
2043 Lastly we replace new lines with ^ and TWO new lines because the first
2044 new line is there to enact the escape command the second is the character
2045 to escape (in this case new line).
2046 */
2047 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2048 return encapsChars +
2049 str.replace(/\\/g, '\\\\')
2050 .replace(/"/g, '\\"')
2051 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
2052 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
2053 .replace(/\r\n|[\n\r]/g, '^\n\n') +
2054 encapsChars;
2055 }
2056
2057 /**
2058 * @param {string} str
2059 * @return {string}
2060 */
2061 function escapeStringPosix(str) {
2062 /**
2063 * @param {string} x
2064 * @return {string}
2065 */
2066 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222067 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122068 let hexString = code.toString(16);
2069 // Zero pad to four digits to comply with ANSI-C Quoting:
2070 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342071 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122072 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342073 }
Joey Arhar2d21f712019-05-20 21:07:122074
2075 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372076 }
2077
Mathias Bynensf06e8c02020-02-28 13:58:282078 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372079 // Use ANSI-C quoting syntax.
2080 return '$\'' +
2081 str.replace(/\\/g, '\\\\')
2082 .replace(/\'/g, '\\\'')
2083 .replace(/\n/g, '\\n')
2084 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282085 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372086 '\'';
Blink Reformat4c46d092018-04-07 15:32:372087 }
Mathias Bynensf06e8c02020-02-28 13:58:282088 // Use single quote syntax.
2089 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372090 }
2091
2092 // cURL command expected to run on the same platform that DevTools run
2093 // (it may be different from the inspected page platform).
2094 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2095
2096 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2097
2098 let inferredMethod = 'GET';
2099 const data = [];
2100 const requestContentType = request.requestContentType();
2101 const formData = await request.requestFormData();
2102 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272103 // Note that formData is not necessarily urlencoded because it might for example
2104 // come from a fetch request made with an explicitly unencoded body.
2105 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372106 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372107 inferredMethod = 'POST';
2108 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112109 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372110 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372111 inferredMethod = 'POST';
2112 }
2113
2114 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292115 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372116 }
2117
2118 const requestHeaders = request.requestHeaders();
2119 for (let i = 0; i < requestHeaders.length; i++) {
2120 const header = requestHeaders[i];
2121 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372122 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372123 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342124 }
Jan Scheffler172d5212020-01-02 14:42:562125 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372126 }
2127 command = command.concat(data);
2128 command.push('--compressed');
2129
Tim van der Lippe1d6e57a2019-09-30 11:55:342130 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372131 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342132 }
Jan Scheffler172d5212020-01-02 14:42:562133 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372134 }
2135
2136 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132137 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132138 * @param {string} platform
2139 * @return {!Promise<string>}
2140 */
2141 async _generateAllCurlCommand(requests, platform) {
2142 const nonBlobRequests = this._filterOutBlobRequests(requests);
2143 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342144 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132145 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342146 }
Mathias Bynensf06e8c02020-02-28 13:58:282147 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132148 }
2149
2150 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132151 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372152 * @return {!Promise<string>}
2153 */
2154 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562155 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372156 const ignoredHeaders =
2157 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2158
2159 /**
2160 * @param {string} str
2161 * @return {string}
2162 */
2163 function escapeString(str) {
2164 return '"' +
2165 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2166 }
2167
Jan Scheffler172d5212020-01-02 14:42:562168 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372169
2170 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562171 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372172 }
2173
2174 const requestHeaders = request.requestHeaders();
2175 const headerNameValuePairs = [];
2176 for (const header of requestHeaders) {
2177 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342178 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372179 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342180 }
Blink Reformat4c46d092018-04-07 15:32:372181 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2182 }
2183 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562184 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372185 }
2186
2187 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2188 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562189 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372190 }
2191
2192 const formData = await request.requestFormData();
2193 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372194 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342195 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562196 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342197 } else {
Jan Scheffler172d5212020-01-02 14:42:562198 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342199 }
Blink Reformat4c46d092018-04-07 15:32:372200 }
2201
Jan Scheffler172d5212020-01-02 14:42:562202 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372203 }
Harley Libcf41f92018-09-10 18:01:132204
2205 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132206 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132207 * @return {!Promise<string>}
2208 */
2209 async _generateAllPowerShellCommand(requests) {
2210 const nonBlobRequests = this._filterOutBlobRequests(requests);
2211 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2212 return commands.join(';\r\n');
2213 }
Joey Arhara86c14e2019-03-12 03:20:502214
2215 /**
2216 * @return {string}
2217 */
2218 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512219 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502220 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342221 }
Joey Arhara86c14e2019-03-12 03:20:502222 return '#0867CB';
2223 }
2224
2225 /**
2226 * @return {string}
2227 */
2228 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512229 return ThemeSupport.ThemeSupport.instance().patchColorText(
2230 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502231 }
Paul Lewis56509652019-12-06 12:51:582232}
Blink Reformat4c46d092018-04-07 15:32:372233
Tim van der Lippe224a8622020-09-23 12:14:372234/** @type {!WeakSet<!NetworkRequestNode>} */
2235const filteredNetworkRequests = new WeakSet();
2236/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2237const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372238
Tim van der Lippe3dc5fd62020-09-22 13:12:222239/**
2240 * @param {!NetworkRequestNode} request
2241 * @return {boolean}
2242 */
2243export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372244 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222245}
2246
Paul Lewis56509652019-12-06 12:51:582247export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372248 'http': true,
2249 'https': true,
2250 'ws': true,
2251 'wss': true
2252};
2253
Blink Reformat4c46d092018-04-07 15:32:372254/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582255export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372256 Domain: 'domain',
2257 HasResponseHeader: 'has-response-header',
2258 Is: 'is',
2259 LargerThan: 'larger-than',
2260 Method: 'method',
2261 MimeType: 'mime-type',
2262 MixedContent: 'mixed-content',
2263 Priority: 'priority',
2264 Scheme: 'scheme',
2265 SetCookieDomain: 'set-cookie-domain',
2266 SetCookieName: 'set-cookie-name',
2267 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032268 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412269 CookieDomain: 'cookie-domain',
2270 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542271 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412272 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032273 StatusCode: 'status-code',
2274 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372275};
2276
2277/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582278export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372279 All: 'all',
2280 Displayed: 'displayed',
2281 Blocked: 'blocked',
2282 BlockOverridden: 'block-overridden'
2283};
2284
2285/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582286export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372287 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052288 FromCache: 'from-cache',
2289 ServiceWorkerIntercepted: 'service-worker-intercepted',
2290 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372291};
2292
2293/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372294export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372295
2296/**
2297 * @interface
2298 */
Paul Lewis56509652019-12-06 12:51:582299export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372300 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132301 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302302 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372303 */
Paul Lewis56509652019-12-06 12:51:582304 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372305 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582306 }
Blink Reformat4c46d092018-04-07 15:32:372307
Paul Lewis56509652019-12-06 12:51:582308 reset() {
2309 }
2310}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162311
2312/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372313// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162314export let Filter;