blob: bc8583aeb5666da48fadc85e278baeb6781e878d [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 Lippe05149e972021-01-15 11:40:4540import {ls} from '../platform/platform.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1341import * as SDK from '../sdk/sdk.js';
42import * as TextUtils from '../text_utils/text_utils.js';
Paul Lewisca569a52020-09-09 16:11:5143import * as ThemeSupport from '../theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1344import * as UI from '../ui/ui.js';
45
Tim van der Lippe119690c2020-01-13 12:31:3046import {HARWriter} from './HARWriter.js';
47import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
48import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
49import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
chait pinnamaneni6bc1c122020-10-30 17:30:5250import {FilterOptions} from './NetworkPanel.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe119690c2020-01-13 12:31:3051import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
52
Blink Reformat4c46d092018-04-07 15:32:3753/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3055 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3756 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1357export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3758 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1359 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3760 * @param {!Element} progressBarContainer
Tim van der Lippe224a8622020-09-23 12:14:3761 * @param {!Common.Settings.Setting<number>} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3762 */
63 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
64 super();
65 this.setMinimumSize(50, 64);
Jack Franklin71519f82020-11-03 12:08:5966 this.registerRequiredCSS('network/networkLogView.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3767
68 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0569 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3770
Paul Lewis2d7d65c2020-03-16 17:26:3071 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
72 this._networkShowIssuesOnlySetting =
73 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
74 this._networkOnlyBlockedRequestsSetting =
75 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
76 this._networkResourceTypeFiltersSetting =
77 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3778
79 this._rawRowHeight = 0;
80 this._progressBarContainer = progressBarContainer;
81 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
82 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
83
84 /**
Paul Lewis56509652019-12-06 12:51:5885 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3786 */
87 function updateRowHeight() {
Tim van der Lipped7cfd142021-01-07 12:17:2488 this._rawRowHeight = Boolean(this._networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:3789 this._rowHeight = this._computeRowHeight();
90 }
91 this._rawRowHeight = 0;
92 this._rowHeight = 0;
93 updateRowHeight.call(this);
94
Tim van der Lippe119690c2020-01-13 12:31:3095 /** @type {!NetworkTransferTimeCalculator} */
96 this._timeCalculator = new NetworkTransferTimeCalculator();
97 /** @type {!NetworkTransferDurationCalculator} */
98 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3799 this._calculator = this._timeCalculator;
100
Tim van der Lippe119690c2020-01-13 12:31:30101 this._columns =
102 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37103 this._columns.show(this.element);
104
Tim van der Lippe0ed1d2b2020-02-04 13:45:13105 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37106 this._staleRequests = new Set();
107 /** @type {number} */
108 this._mainRequestLoadTime = -1;
109 /** @type {number} */
110 this._mainRequestDOMContentLoadedTime = -1;
Tim van der Lippe224a8622020-09-23 12:14:37111 /** @type {*} */
Blink Reformat4c46d092018-04-07 15:32:37112 this._highlightedSubstringChanges = [];
113
Tim van der Lippeb1f2b6c2020-02-17 13:00:16114 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37115 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16116 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37117 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30118 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37119 this._hoveredNode = null;
120 /** @type {?Element} */
121 this._recordingHint = null;
122 /** @type {?number} */
123 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30124 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37125 this._highlightedNode = null;
126
Simon Zündcdd72c92020-10-07 11:48:13127 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37128
129 this._recording = false;
130 this._needsRefresh = false;
131
132 this._headerHeight = 0;
133
Paul Lewis56509652019-12-06 12:51:58134 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37135 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30136 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37137
Paul Lewis56509652019-12-06 12:51:58138 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37139 this._activeGroupLookup = null;
140
Tim van der Lippe0ed1d2b2020-02-04 13:45:13141 this._textFilterUI = new UI.FilterBar.TextFilterUI();
142 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37143 filterBar.addFilter(this._textFilterUI);
144
Tim van der Lippe0ed1d2b2020-02-04 13:45:13145 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
146 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
147 this._dataURLFilterUI.addEventListener(
148 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57149 UI.Tooltip.Tooltip.install(this._dataURLFilterUI.element(), ls`Hides data: and blob: URLs`);
Blink Reformat4c46d092018-04-07 15:32:37150 filterBar.addFilter(this._dataURLFilterUI);
151
152 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13153 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37154 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13155 this._resourceCategoryFilterUI =
156 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20157 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37158 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13159 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37160 filterBar.addFilter(this._resourceCategoryFilterUI);
161
Tim van der Lippe0ed1d2b2020-02-04 13:45:13162 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
163 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
164 this._onlyIssuesFilterUI.addEventListener(
165 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57166 UI.Tooltip.Tooltip.install(
167 this._onlyIssuesFilterUI.element(), ls`Only show requests with blocked response cookies`);
Jan Scheffler1ae7c9e2019-12-03 15:48:37168 filterBar.addFilter(this._onlyIssuesFilterUI);
169
Sigurd Schneidera2afe0b2020-03-03 15:27:13170 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
171 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
172 this._onlyBlockedRequestsUI.addEventListener(
173 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57174 UI.Tooltip.Tooltip.install(this._onlyBlockedRequestsUI.element(), ls`Only show blocked requests`);
Sigurd Schneidera2afe0b2020-03-03 15:27:13175 filterBar.addFilter(this._onlyBlockedRequestsUI);
176
Jan Scheffler1ae7c9e2019-12-03 15:48:37177
Tim van der Lippe0ed1d2b2020-02-04 13:45:13178 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
179 this._suggestionBuilder =
180 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37181 this._resetSuggestionBuilder();
182
183 this._dataGrid = this._columns.dataGrid();
184 this._setupDataGrid();
185 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49186 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13187 UI.Toolbar.ToolbarButton.Events.Click,
188 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37189
Tim van der Lippe0ed1d2b2020-02-04 13:45:13190 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37191
Tim van der Lippe0ed1d2b2020-02-04 13:45:13192 new UI.DropTarget.DropTarget(
193 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
194 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37195
Paul Lewis2d7d65c2020-03-16 17:26:30196 Common.Settings.Settings.instance()
197 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37198 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
199
Paul Lewisdaac1062020-03-05 14:37:10200 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27201 SDK.NetworkLog.NetworkLog.instance().addEventListener(
202 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
203 SDK.NetworkLog.NetworkLog.instance().addEventListener(
204 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
205 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37206
207 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30208 Common.Settings.Settings.instance()
209 .moduleSetting('network.group-by-frame')
210 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37211
212 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03213
214 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
215 if (this._textFilterSetting.get()) {
Jack Franklinec064412020-12-08 13:02:24216 this._textFilterUI.setValue(this._textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03217 }
Blink Reformat4c46d092018-04-07 15:32:37218 }
219
Blink Reformat4c46d092018-04-07 15:32:37220 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30221 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37222 this._setGrouping(value ? 'Frame' : null);
223 }
224
225 /**
226 * @param {string} key
227 * @param {!Array<string>} values
228 */
229 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58230 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37231 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50232 const aPriority =
233 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
234 const bPriority =
235 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
236 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
237 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37238 });
239 } else {
240 values.sort();
241 }
242 }
243
244 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16245 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13246 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37247 * @return {boolean}
248 */
249 static _negativeFilter(filter, request) {
250 return !filter(request);
251 }
252
253 /**
254 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13255 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37256 * @return {boolean}
257 */
258 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34259 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37260 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34261 }
Blink Reformat4c46d092018-04-07 15:32:37262
263 return regex.test(request.path() + '/' + request.name());
264 }
265
266 /**
267 * @param {string} domain
268 * @return {!Array.<string>}
269 */
270 static _subdomains(domain) {
271 const result = [domain];
272 let indexOfPeriod = domain.indexOf('.');
273 while (indexOfPeriod !== -1) {
274 result.push('*' + domain.substring(indexOfPeriod));
275 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
276 }
277 return result;
278 }
279
280 /**
281 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16282 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37283 */
284 static _createRequestDomainFilter(value) {
Tim van der Lippebafa3bd2021-01-20 12:19:17285 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58286 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37287 }
288
289 /**
290 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13291 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37292 * @return {boolean}
293 */
294 static _requestDomainFilter(regex, request) {
295 return regex.test(request.domain);
296 }
297
298 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13299 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37300 * @return {boolean}
301 */
302 static _runningRequestFilter(request) {
303 return !request.finished;
304 }
305
306 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13307 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37308 * @return {boolean}
309 */
310 static _fromCacheRequestFilter(request) {
311 return request.cached();
312 }
313
314 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13315 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05316 * @return {boolean}
317 */
318 static _interceptedByServiceWorkerFilter(request) {
319 return request.fetchedViaServiceWorker;
320 }
321
322 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13323 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05324 * @return {boolean}
325 */
326 static _initiatedByServiceWorkerFilter(request) {
327 return request.initiatedByServiceWorker();
328 }
329
330 /**
Blink Reformat4c46d092018-04-07 15:32:37331 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13332 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37333 * @return {boolean}
334 */
335 static _requestResponseHeaderFilter(value, request) {
336 return request.responseHeaderValue(value) !== undefined;
337 }
338
339 /**
340 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13341 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37342 * @return {boolean}
343 */
344 static _requestMethodFilter(value, request) {
345 return request.requestMethod === value;
346 }
347
348 /**
349 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13350 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37351 * @return {boolean}
352 */
353 static _requestPriorityFilter(value, request) {
354 return request.priority() === value;
355 }
356
357 /**
358 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13359 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37360 * @return {boolean}
361 */
362 static _requestMimeTypeFilter(value, request) {
363 return request.mimeType === value;
364 }
365
366 /**
Paul Lewis56509652019-12-06 12:51:58367 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13368 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37369 * @return {boolean}
370 */
371 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58372 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37373 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28374 }
375 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37376 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28377 }
378 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37379 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28380 }
381 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37382 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34383 }
Blink Reformat4c46d092018-04-07 15:32:37384
385 return false;
386 }
387
388 /**
389 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13390 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37391 * @return {boolean}
392 */
393 static _requestSchemeFilter(value, request) {
394 return request.scheme === value;
395 }
396
397 /**
398 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13399 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37400 * @return {boolean}
401 */
Jan Scheffler341eea52019-12-12 09:08:41402 static _requestCookieDomainFilter(value, request) {
403 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
404 }
405
406 /**
407 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13408 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41409 * @return {boolean}
410 */
411 static _requestCookieNameFilter(value, request) {
412 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
413 }
414
415 /**
416 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13417 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41418 * @return {boolean}
419 */
Simon Zündc9759102020-03-25 11:24:54420 static _requestCookiePathFilter(value, request) {
421 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
422 }
423
424 /**
425 * @param {string} value
426 * @param {!SDK.NetworkRequest.NetworkRequest} request
427 * @return {boolean}
428 */
Jan Scheffler341eea52019-12-12 09:08:41429 static _requestCookieValueFilter(value, request) {
430 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
431 }
432
433 /**
434 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13435 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41436 * @return {boolean}
437 */
Blink Reformat4c46d092018-04-07 15:32:37438 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41439 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37440 }
441
442 /**
443 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13444 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37445 * @return {boolean}
446 */
447 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41448 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37449 }
450
451 /**
452 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13453 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37454 * @return {boolean}
455 */
456 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41457 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37458 }
459
460 /**
461 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13462 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37463 * @return {boolean}
464 */
465 static _requestSizeLargerThanFilter(value, request) {
466 return request.transferSize >= value;
467 }
468
469 /**
470 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13471 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37472 * @return {boolean}
473 */
474 static _statusCodeFilter(value, request) {
Tim van der Lipped7cfd142021-01-07 12:17:24475 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37476 }
477
478 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13479 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37480 * @return {boolean}
481 */
482 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58483 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37484 }
485
Sigurd Schneider464838b2020-08-24 13:53:03486
487 /**
488 * @param {string} value
489 * @param {!SDK.NetworkRequest.NetworkRequest} request
490 * @return {boolean}
491 */
492 static _resourceTypeFilter(value, request) {
493 return request.resourceType().name() === value;
494 }
495
Blink Reformat4c46d092018-04-07 15:32:37496 /**
Julian Geppertf8ce40c2020-09-01 18:02:03497 * @param {string} value
498 * @param {!SDK.NetworkRequest.NetworkRequest} request
499 * @return {boolean}
500 */
501 static _requestUrlFilter(value, request) {
Tim van der Lippebafa3bd2021-01-20 12:19:17502 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03503 return regex.test(request.url());
504 }
505
506 /**
Blink Reformat4c46d092018-04-07 15:32:37507 * @param {number} windowStart
508 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13509 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37510 * @return {boolean}
511 */
512 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34513 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37514 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34515 }
516 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37517 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34518 }
Blink Reformat4c46d092018-04-07 15:32:37519 return true;
520 }
521
522 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13523 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37524 */
525 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13526 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37527 }
528
529 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13530 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37531 */
532 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13533 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37534 }
535
536 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13537 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37538 */
539 static async _copyResponse(request) {
540 const contentData = await request.contentData();
Tim van der Lippe224a8622020-09-23 12:14:37541 /** @type {?string} */
Ingvar Stepanyan1c771842018-10-10 14:35:08542 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34543 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40544 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37545 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08546 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34547 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13548 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37549 }
550
551 /**
552 * @param {!DataTransfer} dataTransfer
553 */
554 _handleDrop(dataTransfer) {
555 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34556 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37557 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34558 }
Blink Reformat4c46d092018-04-07 15:32:37559 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34560 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37561 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34562 }
Blink Reformat4c46d092018-04-07 15:32:37563
Joey Arhar0e1093c2019-05-21 00:34:22564 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37565 }
566
567 /**
Tim van der Lippe119690c2020-01-13 12:31:30568 * @override
Blink Reformat4c46d092018-04-07 15:32:37569 * @param {!File} file
570 */
Joey Arhar0e1093c2019-05-21 00:34:22571 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13572 const outputStream = new Common.StringOutputStream.StringOutputStream();
573 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37574 const success = await reader.read(outputStream);
575 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37576 const error = reader.error();
577 if (error) {
578 this._harLoadFailed(/** @type {*} */ (error).message);
579 }
Blink Reformat4c46d092018-04-07 15:32:37580 return;
581 }
582 let harRoot;
583 try {
584 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13585 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37586 } catch (e) {
587 this._harLoadFailed(e);
588 return;
589 }
Wolfgang Beyerd81fad62020-05-27 12:30:27590 SDK.NetworkLog.NetworkLog.instance().importRequests(
591 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37592 }
593
594 /**
595 * @param {string} message
596 */
597 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36598 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37599 }
600
601 /**
602 * @param {?string} groupKey
603 */
604 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34605 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37606 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34607 }
Blink Reformat4c46d092018-04-07 15:32:37608 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
609 this._activeGroupLookup = groupLookup;
610 this._invalidateAllItems();
611 }
612
613 /**
614 * @return {number}
615 */
616 _computeRowHeight() {
617 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
618 }
619
620 /**
Tim van der Lippe119690c2020-01-13 12:31:30621 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13622 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30623 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37624 */
625 nodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:37626 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37627 }
628
629 /**
Tim van der Lippe119690c2020-01-13 12:31:30630 * @override
Blink Reformat4c46d092018-04-07 15:32:37631 * @return {number}
632 */
633 headerHeight() {
634 return this._headerHeight;
635 }
636
637 /**
Tim van der Lippe119690c2020-01-13 12:31:30638 * @override
Blink Reformat4c46d092018-04-07 15:32:37639 * @param {boolean} recording
640 */
641 setRecording(recording) {
642 this._recording = recording;
643 this._updateSummaryBar();
644 }
645
646 /**
647 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13648 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37649 */
650 modelAdded(networkManager) {
651 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34652 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37653 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34654 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13655 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37656 if (resourceTreeModel) {
657 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
658 resourceTreeModel.addEventListener(
659 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
660 }
661 }
662
663 /**
664 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13665 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37666 */
667 modelRemoved(networkManager) {
668 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13669 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37670 if (resourceTreeModel) {
671 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
672 resourceTreeModel.removeEventListener(
673 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
674 }
675 }
676 }
677
678 /**
Tim van der Lippe119690c2020-01-13 12:31:30679 * @override
Simon Zündcdd72c92020-10-07 11:48:13680 * @return {!Components.Linkifier.Linkifier}
681 */
682 linkifier() {
683 return this._linkifier;
684 }
685
686 /**
687 * @override
Blink Reformat4c46d092018-04-07 15:32:37688 * @param {number} start
689 * @param {number} end
690 */
691 setWindow(start, end) {
692 if (!start && !end) {
693 this._timeFilter = null;
694 this._timeCalculator.setWindow(null);
695 } else {
Paul Lewis56509652019-12-06 12:51:58696 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30697 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37698 }
699 this._filterRequests();
700 }
701
Tim van der Lippe119690c2020-01-13 12:31:30702 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05703 resetFocus() {
704 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37705 }
706
707 _resetSuggestionBuilder() {
708 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58709 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
710 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
711 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
712 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
713 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
714 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
715 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37716 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
717 }
718
719 /**
Tim van der Lippec02a97c2020-02-14 14:39:27720 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37721 */
722 _filterChanged(event) {
723 this.removeAllNodeHighlights();
724 this._parseFilterQuery(this._textFilterUI.value());
725 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03726 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37727 }
728
Rajasekar Murugan3ad369e2020-02-19 18:20:12729 async resetFilter() {
730 this._textFilterUI.clear();
731 }
732
Blink Reformat4c46d092018-04-07 15:32:37733 _showRecordingHint() {
734 this._hideRecordingHint();
735 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
736 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18737
Blink Reformat4c46d092018-04-07 15:32:37738 if (this._recording) {
Wolfgang Beyer5c385b92020-11-09 15:20:04739 let reloadShortcutNode = null;
740 const reloadShortcut =
741 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
742 if (reloadShortcut) {
743 reloadShortcutNode = this._recordingHint.createChild('b');
744 reloadShortcutNode.textContent = reloadShortcut.title();
745 }
746
Blink Reformat4c46d092018-04-07 15:32:37747 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38748 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18749 if (reloadShortcutNode) {
750 hintText.createChild('br');
751 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13752 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18753 }
Blink Reformat4c46d092018-04-07 15:32:37754 } else {
755 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17756 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37757 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Wolfgang Beyer5c385b92020-11-09 15:20:04758 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Blink Reformat4c46d092018-04-07 15:32:37759 }
Kayce Basques5444c1b2019-02-15 20:32:53760 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13761 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53762 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43763 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11764
765 this._setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37766 }
767
768 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11769 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34770 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37771 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34772 }
Brandon Goddard6f4e54f2021-01-08 17:01:33773 UI.ARIAUtils.alert(ls`Network Data Available`, this._summaryToolbar.element);
Blink Reformat4c46d092018-04-07 15:32:37774 this._recordingHint = null;
775 }
776
777 /**
Amanda Baker6761aae2019-11-05 18:59:11778 * @param {boolean} value
779 */
780 _setHidden(value) {
781 this._columns.setHidden(value);
782 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
783 }
784
785 /**
Blink Reformat4c46d092018-04-07 15:32:37786 * @override
787 * @return {!Array.<!Element>}
788 */
789 elementsToRestoreScrollPositionsFor() {
790 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 {
Blink Reformat4c46d092018-04-07 15:32:37792 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 }
Blink Reformat4c46d092018-04-07 15:32:37794 return [this._dataGrid.scrollContainer];
795 }
796
Tim van der Lippe119690c2020-01-13 12:31:30797 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37798 columnExtensionResolved() {
799 this._invalidateAllItems(true);
800 }
801
802 _setupDataGrid() {
803 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Andres Olivares03d9c752020-10-01 15:08:11804 const request = (/** @type {!NetworkNode} */ (node)).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34805 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37806 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34807 }
Blink Reformat4c46d092018-04-07 15:32:37808 });
809 this._dataGrid.setStickToBottom(true);
810 this._dataGrid.setName('networkLog');
811 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
812 this._dataGrid.element.classList.add('network-log-grid');
813 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
814 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
815 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05816 this._dataGrid.element.addEventListener('keydown', event => {
817 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05818 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05819 event.consume(true);
820 }
821 });
Brandon Goddard44934902020-03-25 16:03:18822 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
823 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37824 return this._dataGrid;
825 }
826
827 /**
828 * @param {!Event} event
829 */
830 _dataGridMouseMove(event) {
Tim van der Lippe224a8622020-09-23 12:14:37831 const mouseEvent = /** @type {!MouseEvent} */ (event);
Andres Olivares03d9c752020-10-01 15:08:11832 const node =
833 /** @type {!NetworkNode} */ (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (mouseEvent.target)));
Tim van der Lippe224a8622020-09-23 12:14:37834 const highlightInitiatorChain = mouseEvent.shiftKey;
Blink Reformat4c46d092018-04-07 15:32:37835 this._setHoveredNode(node, highlightInitiatorChain);
836 }
837
838 /**
Tim van der Lippe119690c2020-01-13 12:31:30839 * @override
840 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37841 */
842 hoveredNode() {
843 return this._hoveredNode;
844 }
845
846 /**
Tim van der Lippe119690c2020-01-13 12:31:30847 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37848 * @param {boolean=} highlightInitiatorChain
849 */
850 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34851 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37852 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34853 }
Blink Reformat4c46d092018-04-07 15:32:37854 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34855 if (this._hoveredNode) {
Tim van der Lipped7cfd142021-01-07 12:17:24856 this._hoveredNode.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:34857 }
Blink Reformat4c46d092018-04-07 15:32:37858 }
859
860 /**
861 * @param {!Event} event
862 */
863 _dataGridMouseDown(event) {
Tim van der Lippe224a8622020-09-23 12:14:37864 const mouseEvent = /** @type {!MouseEvent} */ (event);
865 if (!this._dataGrid.selectedNode && mouseEvent.button) {
866 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34867 }
Blink Reformat4c46d092018-04-07 15:32:37868 }
869
870 _updateSummaryBar() {
871 this._hideRecordingHint();
872
873 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20874 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37875 let selectedNodeNumber = 0;
876 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20877 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37878 let baseTime = -1;
879 let maxTime = -1;
880
881 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27882 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37883 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34884 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37885 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34886 }
Blink Reformat4c46d092018-04-07 15:32:37887 nodeCount++;
888 const requestTransferSize = request.transferSize;
889 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20890 const requestResourceSize = request.resourceSize;
891 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37892 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37893 selectedNodeNumber++;
894 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20895 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37896 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13897 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37898 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
899 // inspected url.
900 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13901 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
902 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37903 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34904 }
905 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37906 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34907 }
Blink Reformat4c46d092018-04-07 15:32:37908 }
909
910 if (!nodeCount) {
911 this._showRecordingHint();
912 return;
913 }
914
Joey Arhara86c14e2019-03-12 03:20:50915 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37916 /**
917 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50918 * @param {string=} title
Tim van der Lippe224a8622020-09-23 12:14:37919 * @return {!HTMLDivElement}
Blink Reformat4c46d092018-04-07 15:32:37920 */
Joey Arhara86c14e2019-03-12 03:20:50921 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13922 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50923 toolbarText.setTitle(title ? title : chunk);
924 this._summaryToolbar.appendToolbarItem(toolbarText);
Tim van der Lippe224a8622020-09-23 12:14:37925 return /** @type {!HTMLDivElement} */ (toolbarText.element);
Joey Arhara86c14e2019-03-12 03:20:50926 };
Blink Reformat4c46d092018-04-07 15:32:37927
928 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50929 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
930 this._summaryToolbar.appendSeparator();
931 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17932 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
933 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25934 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50935 this._summaryToolbar.appendSeparator();
936 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17937 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
938 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25939 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37940 } else {
Joey Arhara86c14e2019-03-12 03:20:50941 appendChunk(ls`${nodeCount} requests`);
942 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25943 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17944 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
945 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50946 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25947 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17948 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
949 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37950 }
Dan Beam87466b52018-12-01 18:41:20951
Blink Reformat4c46d092018-04-07 15:32:37952 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50953 this._summaryToolbar.appendSeparator();
954 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37955 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50956 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30957 const domContentLoadedText =
958 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58959 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37960 }
961 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50962 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30963 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58964 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37965 }
966 }
Blink Reformat4c46d092018-04-07 15:32:37967 }
968
Tim van der Lippe119690c2020-01-13 12:31:30969 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37970 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34971 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37972 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34973 }
Blink Reformat4c46d092018-04-07 15:32:37974
975 this._needsRefresh = true;
976
Tim van der Lippe1d6e57a2019-09-30 11:55:34977 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37978 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34979 }
Blink Reformat4c46d092018-04-07 15:32:37980 }
981
982 /**
Tim van der Lippe119690c2020-01-13 12:31:30983 * @override
Blink Reformat4c46d092018-04-07 15:32:37984 * @param {!Array<number>} times
985 */
986 addFilmStripFrames(times) {
987 this._columns.addEventDividers(times, 'network-frame-divider');
988 }
989
990 /**
Tim van der Lippe119690c2020-01-13 12:31:30991 * @override
Blink Reformat4c46d092018-04-07 15:32:37992 * @param {number} time
993 */
994 selectFilmStripFrame(time) {
995 this._columns.selectFilmStripFrame(time);
996 }
997
Tim van der Lippe119690c2020-01-13 12:31:30998 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37999 clearFilmStripFrame() {
1000 this._columns.clearFilmStripFrame();
1001 }
1002
1003 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341004 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371005 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 }
Blink Reformat4c46d092018-04-07 15:32:371007 }
1008
1009 /**
1010 * @param {boolean=} deferUpdate
1011 */
1012 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271013 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341014 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371015 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341016 } else {
Blink Reformat4c46d092018-04-07 15:32:371017 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341018 }
Blink Reformat4c46d092018-04-07 15:32:371019 }
1020
1021 /**
Tim van der Lippe119690c2020-01-13 12:31:301022 * @override
1023 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371024 */
1025 timeCalculator() {
1026 return this._timeCalculator;
1027 }
1028
1029 /**
Tim van der Lippe119690c2020-01-13 12:31:301030 * @override
1031 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371032 */
1033 calculator() {
1034 return this._calculator;
1035 }
1036
1037 /**
Tim van der Lippe119690c2020-01-13 12:31:301038 * @override
1039 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371040 */
1041 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341042 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371043 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341044 }
Blink Reformat4c46d092018-04-07 15:32:371045
1046 if (this._calculator !== x) {
1047 this._calculator = x;
1048 this._columns.setCalculator(this._calculator);
1049 }
1050 this._calculator.reset();
1051
Tim van der Lippe1d6e57a2019-09-30 11:55:341052 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371053 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341054 } else {
Blink Reformat4c46d092018-04-07 15:32:371055 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341056 }
Blink Reformat4c46d092018-04-07 15:32:371057
1058 this._invalidateAllItems();
1059 }
1060
1061 /**
Tim van der Lippec02a97c2020-02-14 14:39:271062 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371063 */
1064 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341065 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371066 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341067 }
Blink Reformat4c46d092018-04-07 15:32:371068
1069 const time = /** @type {number} */ (event.data.loadTime);
1070 if (time) {
1071 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301072 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371073 }
1074 }
1075
1076 /**
Tim van der Lippec02a97c2020-02-14 14:39:271077 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371078 */
1079 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341080 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371081 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341082 }
Blink Reformat4c46d092018-04-07 15:32:371083 const data = /** @type {number} */ (event.data);
1084 if (data) {
1085 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301086 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371087 }
1088 }
1089
1090 /**
1091 * @override
1092 */
1093 wasShown() {
1094 this._refreshIfNeeded();
1095 this._columns.wasShown();
1096 }
1097
1098 /**
1099 * @override
1100 */
1101 willHide() {
1102 this._columns.willHide();
1103 }
1104
1105 /**
1106 * @override
1107 */
1108 onResize() {
1109 this._rowHeight = this._computeRowHeight();
1110 }
1111
1112 /**
Tim van der Lippe119690c2020-01-13 12:31:301113 * @override
1114 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371115 */
1116 flatNodesList() {
Andres Olivares21ab05b2020-10-21 14:00:021117 /** @type {!DataGrid.ViewportDataGrid.ViewportDataGridNode<!DataGrid.SortableDataGrid.SortableDataGridNode<!NetworkNode>>} */
1118 const rootNode = (this._dataGrid.rootNode());
1119 return /** @type {!Array<!NetworkNode>} */ (rootNode.flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371120 }
1121
Brandon Goddard44934902020-03-25 16:03:181122 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491123 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351124 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381125 }
Brandon Goddard44934902020-03-25 16:03:181126 this.updateNodeBackground();
1127 }
1128
1129 _onDataGridBlur() {
1130 this.element.classList.remove('grid-focused');
1131 this.updateNodeBackground();
1132 }
1133
Tim van der Lippe119690c2020-01-13 12:31:301134 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051135 updateNodeBackground() {
1136 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111137 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051138 }
1139 }
1140
1141 /**
Tim van der Lippe119690c2020-01-13 12:31:301142 * @override
Brandon Goddard88d885a2019-10-31 16:11:051143 * @param {boolean} isSelected
1144 */
1145 updateNodeSelectedClass(isSelected) {
1146 if (isSelected) {
1147 this.element.classList.remove('no-node-selected');
1148 } else {
1149 this.element.classList.add('no-node-selected');
1150 }
1151 }
1152
Tim van der Lippe119690c2020-01-13 12:31:301153 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371154 stylesChanged() {
1155 this._columns.scheduleRefresh();
1156 }
1157
1158 _refresh() {
1159 this._needsRefresh = false;
1160
1161 if (this._refreshRequestId) {
1162 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1163 this._refreshRequestId = null;
1164 }
1165
1166 this.removeAllNodeHighlights();
1167
1168 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1169 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1170 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1171 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1172
Tim van der Lippe224a8622020-09-23 12:14:371173 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371174 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301175 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371176 const nodesToRefresh = [];
1177
Tim van der Lippe119690c2020-01-13 12:31:301178 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371179 const staleNodes = new Set();
1180
1181 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1182 // node so we loop until we have no more stale requests.
1183 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371184 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371185 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371186 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341187 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371188 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341189 }
Blink Reformat4c46d092018-04-07 15:32:371190 staleNodes.add(node);
1191 }
1192
1193 for (const node of staleNodes) {
1194 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371196 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 }
Blink Reformat4c46d092018-04-07 15:32:371198
Tim van der Lippe1d6e57a2019-09-30 11:55:341199 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371200 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341201 }
Blink Reformat4c46d092018-04-07 15:32:371202 const request = node.request();
1203 this._timeCalculator.updateBoundaries(request);
1204 this._durationCalculator.updateBoundaries(request);
1205 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371206 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1207 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371208 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341209 }
Tim van der Lippe224a8622020-09-23 12:14:371210 if (isFilteredOut) {
1211 filteredNetworkRequests.add(node);
1212 } else {
1213 filteredNetworkRequests.delete(node);
1214 }
Blink Reformat4c46d092018-04-07 15:32:371215 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1216 if (removeFromParent) {
1217 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111218 if (!parent) {
1219 continue;
1220 }
Blink Reformat4c46d092018-04-07 15:32:371221 parent.removeChild(node);
1222 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111223 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371224 grandparent.removeChild(parent);
1225 parent = grandparent;
1226 }
1227 }
1228
Tim van der Lippe1d6e57a2019-09-30 11:55:341229 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371230 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341231 }
Blink Reformat4c46d092018-04-07 15:32:371232
1233 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111234 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371235 nodesToRefresh.push(newParent);
1236 }
1237 nodesToInsert.set(node, newParent);
1238 }
1239
Tim van der Lippe1d6e57a2019-09-30 11:55:341240 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371241 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341242 }
Blink Reformat4c46d092018-04-07 15:32:371243
Tim van der Lippe1d6e57a2019-09-30 11:55:341244 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371245 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341246 }
Blink Reformat4c46d092018-04-07 15:32:371247
1248 this._updateSummaryBar();
1249
Tim van der Lippe1d6e57a2019-09-30 11:55:341250 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371251 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341252 }
Blink Reformat4c46d092018-04-07 15:32:371253
1254 this._dataGrid.updateInstantly();
1255 this._didRefreshForTest();
1256 }
1257
1258 _didRefreshForTest() {
1259 }
1260
1261 /**
Tim van der Lippe119690c2020-01-13 12:31:301262 * @param {!NetworkRequestNode} node
1263 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371264 */
1265 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341266 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111267 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341268 }
Blink Reformat4c46d092018-04-07 15:32:371269
1270 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341271 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111272 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341273 }
Blink Reformat4c46d092018-04-07 15:32:371274 return groupNode;
1275 }
1276
1277 _reset() {
Simon Zünd98419832020-03-12 06:18:151278 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371279
1280 this._setHoveredNode(null);
1281 this._columns.reset();
1282
1283 this._timeFilter = null;
1284 this._calculator.reset();
1285
1286 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131287 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371288
Tim van der Lippe1d6e57a2019-09-30 11:55:341289 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371290 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341291 }
Blink Reformat4c46d092018-04-07 15:32:371292 this._staleRequests.clear();
1293 this._resetSuggestionBuilder();
1294
1295 this._mainRequestLoadTime = -1;
1296 this._mainRequestDOMContentLoadedTime = -1;
1297
1298 this._dataGrid.rootNode().removeChildren();
1299 this._updateSummaryBar();
1300 this._dataGrid.setStickToBottom(true);
1301 this.scheduleRefresh();
1302 }
1303
1304 /**
Tim van der Lippe119690c2020-01-13 12:31:301305 * @override
Blink Reformat4c46d092018-04-07 15:32:371306 * @param {string} filterString
1307 */
1308 setTextFilterValue(filterString) {
1309 this._textFilterUI.setValue(filterString);
1310 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371311 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131312 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371313 this._resourceCategoryFilterUI.reset();
1314 }
1315
1316 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131317 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371318 */
1319 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301320 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371321 networkRequestToNode.set(request, node);
1322 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371323
Tim van der Lippe1d6e57a2019-09-30 11:55:341324 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371325 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341326 }
Blink Reformat4c46d092018-04-07 15:32:371327 return node;
1328 }
1329
1330 /**
Tim van der Lippec02a97c2020-02-14 14:39:271331 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371332 */
1333 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131334 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371335 this._refreshRequest(request);
1336 }
1337
1338 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131339 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371340 */
1341 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581342 NetworkLogView._subdomains(request.domain)
1343 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1344 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1345 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
Tim van der Lipped7cfd142021-01-07 12:17:241346 this._suggestionBuilder.addItem(FilterType.Scheme, String(request.scheme));
1347 this._suggestionBuilder.addItem(FilterType.StatusCode, String(request.statusCode));
Sigurd Schneider464838b2020-08-24 13:53:031348 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031349 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371350
1351 const priority = request.priority();
1352 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501353 this._suggestionBuilder.addItem(
1354 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371355 }
1356
1357 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581358 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371359 }
1360
1361 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581362 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371363 }
1364
1365 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581366 const suggestion =
1367 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1368 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371369 }
1370
1371 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341372 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581373 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341374 }
Jan Scheffler341eea52019-12-12 09:08:411375
1376 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581377 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1378 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1379 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381
Jan Scheffler341eea52019-12-12 09:08:411382 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1383 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1384 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541385 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411386 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1387 }
1388
Blink Reformat4c46d092018-04-07 15:32:371389 this._staleRequests.add(request);
1390 this.scheduleRefresh();
1391 }
1392
1393 /**
Tim van der Lippe119690c2020-01-13 12:31:301394 * @override
Blink Reformat4c46d092018-04-07 15:32:371395 * @return {number}
1396 */
1397 rowHeight() {
1398 return this._rowHeight;
1399 }
1400
1401 /**
Tim van der Lippe119690c2020-01-13 12:31:301402 * @override
Blink Reformat4c46d092018-04-07 15:32:371403 * @param {boolean} gridMode
1404 */
1405 switchViewMode(gridMode) {
1406 this._columns.switchViewMode(gridMode);
1407 }
1408
1409 /**
Tim van der Lippe119690c2020-01-13 12:31:301410 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131411 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1412 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371413 */
1414 handleContextMenuForRequest(contextMenu, request) {
1415 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131416 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371417 const footerSection = copyMenu.footerSection();
1418 if (request) {
1419 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131420 UI.UIUtils.copyLinkAddressLabel(),
1421 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1422 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371423 if (request.requestHeadersText()) {
1424 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131425 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371426 }
1427
1428 if (request.responseHeadersText) {
1429 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131430 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371431 }
1432
1433 if (request.finished) {
1434 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371436 }
1437
Tim van der Lippeb4faf5a2020-11-06 15:02:021438 const initiator = request.initiator();
1439
1440 if (initiator) {
1441 const stack = initiator.stack;
1442 if (stack) {
1443 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1444 // has any context solely based on the top frame. Sometimes, the top frame does not have
1445 // any callFrames, but its parent frames do.
1446 const stackTraceText = computeStackTraceText(stack);
1447 if (stackTraceText !== '') {
1448 copyMenu.defaultSection().appendItem(Common.UIString.UIString('Copy stacktrace'), () => {
1449 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1450 });
1451 }
1452 }
1453 }
1454
Harley Libcf41f92018-09-10 18:01:131455 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131456 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371457 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131458 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1459 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371460 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131461 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291462 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1464 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371465 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131466 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1467 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131468 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131469 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1470 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371471 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131472 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1473 footerSection.appendItem(
1474 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1475 footerSection.appendItem(
1476 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1477 footerSection.appendItem(
1478 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1479 footerSection.appendItem(
1480 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371481 } else {
Harley Libcf41f92018-09-10 18:01:131482 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131483 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291484 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131485 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1486 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131487 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131488 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1489 footerSection.appendItem(
1490 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1491 footerSection.appendItem(
1492 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1493 footerSection.appendItem(
1494 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371495 }
1496 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131497 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371498 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131499 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371500
Joey Arhar0e1093c2019-05-21 00:34:221501 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371502
Blink Reformat4c46d092018-04-07 15:32:371503 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131504 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1505 contextMenu.editSection().appendItem(
1506 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371507
1508 if (request) {
1509 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211510 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371511 let patterns = manager.blockedPatterns();
1512
Tim van der Lippeffa78622019-09-16 12:07:121513 /**
1514 * @param {string} url
1515 */
1516 function addBlockedURL(url) {
1517 patterns.push({enabled: true, url: url});
1518 manager.setBlockedPatterns(patterns);
1519 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261520 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121521 }
1522
1523 /**
1524 * @param {string} url
1525 */
1526 function removeBlockedURL(url) {
1527 patterns = patterns.filter(pattern => pattern.url !== url);
1528 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261529 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121530 }
1531
Blink Reformat4c46d092018-04-07 15:32:371532 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1533 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1534 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131535 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371536 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311537 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371538 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131539 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371540 }
1541
1542 const domain = request.parsedURL.domain();
1543 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1544 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131545 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371546 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311547 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371548 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131549 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371550 }
1551
Tim van der Lippe0ed1d2b2020-02-04 13:45:131552 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371553 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131554 Common.UIString.UIString('Replay XHR'),
1555 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371556 }
Blink Reformat4c46d092018-04-07 15:32:371557 }
1558 }
1559
1560 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271561 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171562 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131563 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171564 });
Blink Reformat4c46d092018-04-07 15:32:371565 }
1566
1567 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131568 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1569 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371570 }
1571
1572 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131573 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371574 * @param {string} platform
1575 */
1576 async _copyCurlCommand(request, platform) {
1577 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131578 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371579 }
1580
1581 /**
1582 * @param {string} platform
1583 */
1584 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271585 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131586 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371587 }
1588
1589 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131590 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291591 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371592 */
Jan Scheffler7c50d1f2019-12-17 13:33:291593 async _copyFetchCall(request, includeCookies) {
1594 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131595 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371596 }
1597
Jan Scheffler7c50d1f2019-12-17 13:33:291598 /**
1599 * @param {boolean} includeCookies
1600 */
1601 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271602 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131603 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371604 }
1605
1606 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131607 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371608 */
1609 async _copyPowerShellCommand(request) {
1610 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131611 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371612 }
1613
1614 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271615 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131616 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371617 }
1618
Tim van der Lippe119690c2020-01-13 12:31:301619 /**
1620 * @override
Tim van der Lippe224a8622020-09-23 12:14:371621 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301622 */
Joey Arhar0e1093c2019-05-21 00:34:221623 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371624 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1625 if (!mainTarget) {
1626 return;
1627 }
1628 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131629 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371630 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131631 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371632
Tim van der Lippe1d6e57a2019-09-30 11:55:341633 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371634 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341635 }
Blink Reformat4c46d092018-04-07 15:32:371636
Tim van der Lippe0ed1d2b2020-02-04 13:45:131637 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371638 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301639 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371640 progressIndicator.done();
1641 stream.close();
1642 }
1643
1644 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131645 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211646 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341647 }
Blink Reformat4c46d092018-04-07 15:32:371648 }
1649
1650 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131651 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211652 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341653 }
Blink Reformat4c46d092018-04-07 15:32:371654 }
1655
1656 _removeAllHighlights() {
1657 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341658 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131659 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341660 }
Blink Reformat4c46d092018-04-07 15:32:371661 this._highlightedSubstringChanges = [];
1662 }
1663
1664 /**
Tim van der Lippe119690c2020-01-13 12:31:301665 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371666 * @return {boolean}
1667 */
1668 _applyFilter(node) {
1669 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341670 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371671 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341672 }
Blink Reformat4c46d092018-04-07 15:32:371673 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341674 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371675 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341676 }
1677 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371678 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341679 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221680 if (this._onlyIssuesFilterUI.checked() &&
1681 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371682 return false;
1683 }
Sigurd Schneider20088de2020-10-30 08:08:331684 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131685 return false;
1686 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341687 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371688 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341689 }
Blink Reformat4c46d092018-04-07 15:32:371690 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341691 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371692 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341693 }
Blink Reformat4c46d092018-04-07 15:32:371694 }
1695 return true;
1696 }
1697
1698 /**
1699 * @param {string} query
1700 */
1701 _parseFilterQuery(query) {
1702 const descriptors = this._filterParser.parse(query);
1703 this._filters = descriptors.map(descriptor => {
1704 const key = descriptor.key;
1705 const text = descriptor.text || '';
1706 const regex = descriptor.regex;
1707 let filter;
1708 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171709 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Paul Lewis56509652019-12-06 12:51:581710 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1711 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371712 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581713 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371714 } else {
Tim van der Lippebafa3bd2021-01-20 12:19:171715 filter = NetworkLogView._requestPathFilter.bind(
1716 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371717 }
Paul Lewis56509652019-12-06 12:51:581718 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371719 });
1720 }
1721
1722 /**
Paul Lewis56509652019-12-06 12:51:581723 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371724 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161725 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371726 */
1727 _createSpecialFilter(type, value) {
1728 switch (type) {
Paul Lewis56509652019-12-06 12:51:581729 case FilterType.Domain:
1730 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371731
Paul Lewis56509652019-12-06 12:51:581732 case FilterType.HasResponseHeader:
1733 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371734
Paul Lewis56509652019-12-06 12:51:581735 case FilterType.Is:
1736 if (value.toLowerCase() === IsFilterType.Running) {
1737 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341738 }
Paul Lewis56509652019-12-06 12:51:581739 if (value.toLowerCase() === IsFilterType.FromCache) {
1740 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341741 }
Paul Lewis56509652019-12-06 12:51:581742 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1743 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341744 }
Paul Lewis56509652019-12-06 12:51:581745 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1746 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341747 }
Blink Reformat4c46d092018-04-07 15:32:371748 break;
1749
Paul Lewis56509652019-12-06 12:51:581750 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371751 return this._createSizeFilter(value.toLowerCase());
1752
Paul Lewis56509652019-12-06 12:51:581753 case FilterType.Method:
1754 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371755
Paul Lewis56509652019-12-06 12:51:581756 case FilterType.MimeType:
1757 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371758
Paul Lewis56509652019-12-06 12:51:581759 case FilterType.MixedContent:
1760 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371761
Paul Lewis56509652019-12-06 12:51:581762 case FilterType.Scheme:
1763 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371764
Paul Lewis56509652019-12-06 12:51:581765 case FilterType.SetCookieDomain:
1766 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371767
Paul Lewis56509652019-12-06 12:51:581768 case FilterType.SetCookieName:
1769 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371770
Paul Lewis56509652019-12-06 12:51:581771 case FilterType.SetCookieValue:
1772 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371773
Jan Scheffler341eea52019-12-12 09:08:411774 case FilterType.CookieDomain:
1775 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1776
1777 case FilterType.CookieName:
1778 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1779
Simon Zündc9759102020-03-25 11:24:541780 case FilterType.CookiePath:
1781 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1782
Jan Scheffler341eea52019-12-12 09:08:411783 case FilterType.CookieValue:
1784 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1785
Paul Lewis56509652019-12-06 12:51:581786 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501787 return NetworkLogView._requestPriorityFilter.bind(
1788 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371789
Paul Lewis56509652019-12-06 12:51:581790 case FilterType.StatusCode:
1791 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031792
1793 case FilterType.ResourceType:
1794 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031795
1796 case FilterType.Url:
1797 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371798 }
1799 return null;
1800 }
1801
1802 /**
1803 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161804 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371805 */
1806 _createSizeFilter(value) {
1807 let multiplier = 1;
1808 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541809 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371810 value = value.substring(0, value.length - 1);
1811 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541812 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371813 value = value.substring(0, value.length - 1);
1814 }
1815 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341816 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371817 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341818 }
Paul Lewis56509652019-12-06 12:51:581819 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371820 }
1821
1822 _filterRequests() {
1823 this._removeAllHighlights();
1824 this._invalidateAllItems();
1825 }
1826
1827 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131828 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301829 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371830 */
1831 _reveal(request) {
1832 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371833 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341834 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371835 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341836 }
Brandon Goddard5e4244d2020-04-08 22:08:471837 // Viewport datagrid nodes do not reveal if not in the root node
1838 // list of flatChildren. For children of grouped frame nodes:
1839 // reveal and expand parent to ensure child is revealable.
1840 if (node.parent && node.parent instanceof NetworkGroupNode) {
1841 node.parent.reveal();
1842 node.parent.expand();
1843 }
Blink Reformat4c46d092018-04-07 15:32:371844 node.reveal();
1845 return node;
1846 }
1847
1848 /**
Tim van der Lippe119690c2020-01-13 12:31:301849 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131850 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371851 */
1852 revealAndHighlightRequest(request) {
1853 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341854 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371855 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341856 }
Blink Reformat4c46d092018-04-07 15:32:371857 }
1858
1859 /**
Tim van der Lippe119690c2020-01-13 12:31:301860 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131861 * @param {!SDK.NetworkRequest.NetworkRequest} request
chait pinnamaneni6bc1c122020-10-30 17:30:521862 * @param {!FilterOptions=} options - Optional parameters to change filter behavior
Blink Reformat4c46d092018-04-07 15:32:371863 */
chait pinnamaneni6bc1c122020-10-30 17:30:521864 selectRequest(request, options) {
1865 const defaultOptions = {clearFilter: true};
1866 const {clearFilter} = options || defaultOptions;
1867 if (clearFilter) {
1868 this.setTextFilterValue('');
1869 }
Blink Reformat4c46d092018-04-07 15:32:371870 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341871 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371872 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341873 }
Blink Reformat4c46d092018-04-07 15:32:371874 }
1875
Tim van der Lippe119690c2020-01-13 12:31:301876 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371877 removeAllNodeHighlights() {
1878 if (this._highlightedNode) {
1879 this._highlightedNode.element().classList.remove('highlighted-row');
1880 this._highlightedNode = null;
1881 }
1882 }
1883
1884 /**
Tim van der Lippe119690c2020-01-13 12:31:301885 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371886 */
1887 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131888 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371889 this._highlightedNode = node;
1890 }
1891
1892 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131893 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1894 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131895 */
1896 _filterOutBlobRequests(requests) {
1897 return requests.filter(request => !request.isBlobRequest());
1898 }
1899
1900 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131901 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291902 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371903 * @return {!Promise<string>}
1904 */
Jan Scheffler7c50d1f2019-12-17 13:33:291905 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371906 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371907 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371908 'method',
1909 'path',
1910 'scheme',
1911 'version',
Blink Reformat4c46d092018-04-07 15:32:371912
1913 // Unsafe headers
1914 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371915 'accept-charset',
1916 'accept-encoding',
1917 'access-control-request-headers',
1918 'access-control-request-method',
1919 'connection',
1920 'content-length',
1921 'cookie',
1922 'cookie2',
1923 'date',
1924 'dnt',
1925 'expect',
1926 'host',
1927 'keep-alive',
1928 'origin',
1929 'referer',
1930 'te',
1931 'trailer',
1932 'transfer-encoding',
1933 'upgrade',
1934 'via',
Blink Reformat4c46d092018-04-07 15:32:371935 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371936 'user-agent',
1937 ]);
Blink Reformat4c46d092018-04-07 15:32:371938
Tim van der Lippe224a8622020-09-23 12:14:371939 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371940
1941 const url = JSON.stringify(request.url());
1942
1943 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371944 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371945 const headerData = requestHeaders.reduce((result, header) => {
1946 const name = header.name;
1947
Tim van der Lippe224a8622020-09-23 12:14:371948 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371949 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341950 }
Blink Reformat4c46d092018-04-07 15:32:371951
1952 return result;
1953 }, new Headers());
1954
Tim van der Lippe224a8622020-09-23 12:14:371955 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371956 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341957 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411958 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341959 }
Blink Reformat4c46d092018-04-07 15:32:371960
Sigurd Schneider0e88b912020-05-08 08:28:231961 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371962 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411963 'include' :
1964 'omit';
Blink Reformat4c46d092018-04-07 15:32:371965
1966 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1967
1968 const referrer = referrerHeader ? referrerHeader.value : void 0;
1969
1970 const referrerPolicy = request.referrerPolicy() || void 0;
1971
1972 const requestBody = await request.requestFormData();
1973
Tim van der Lippe224a8622020-09-23 12:14:371974 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371975 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411976 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371977 referrer,
1978 referrerPolicy,
1979 body: requestBody,
1980 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371981 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371982 };
1983
Jan Scheffler7c50d1f2019-12-17 13:33:291984 if (includeCookies) {
1985 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1986 if (cookieHeader) {
1987 fetchOptions.headers = {
1988 ...headers,
1989 'cookie': cookieHeader.value,
1990 };
1991 }
1992 } else {
1993 fetchOptions.credentials = credentials;
1994 }
1995
Jan Scheffler172d5212020-01-02 14:42:561996 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371997 return `fetch(${url}, ${options});`;
1998 }
1999
2000 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132001 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:292002 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:132003 * @return {!Promise<string>}
2004 */
Jan Scheffler7c50d1f2019-12-17 13:33:292005 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:132006 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:292007 const commands =
2008 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:132009 return commands.join(' ;\n');
2010 }
2011
2012 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132013 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372014 * @param {string} platform
2015 * @return {!Promise<string>}
2016 */
2017 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562018 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362019 // Most of these headers are derived from the URL and are automatically added by cURL.
2020 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372021 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372022
Tim van der Lippe224a8622020-09-23 12:14:372023 /**
2024 * @param {string} str
2025 */
Blink Reformat4c46d092018-04-07 15:32:372026 function escapeStringWin(str) {
2027 /* If there are no new line characters do not escape the " characters
2028 since it only uglifies the command.
2029
2030 Because cmd.exe parser and MS Crt arguments parsers use some of the
2031 same escape characters, they can interact with each other in
2032 horrible ways, the order of operations is critical.
2033
2034 Replace \ with \\ first because it is an escape character for certain
2035 conditions in both parsers.
2036
2037 Replace all " with \" to ensure the first parser does not remove it.
2038
2039 Then escape all characters we are not sure about with ^ to ensure it
2040 gets to MS Crt parser safely.
2041
2042 The % character is special because MS Crt parser will try and look for
2043 ENV variables and fill them in it's place. We cannot escape them with %
2044 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2045 parser); So we can get cmd.exe parser to escape the character after it,
2046 if it is followed by a valid beginning character of an ENV variable.
2047 This ensures we do not try and double escape another ^ if it was placed
2048 by the previous replace.
2049
2050 Lastly we replace new lines with ^ and TWO new lines because the first
2051 new line is there to enact the escape command the second is the character
2052 to escape (in this case new line).
2053 */
2054 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2055 return encapsChars +
2056 str.replace(/\\/g, '\\\\')
2057 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542058 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372059 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542060 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372061 encapsChars;
2062 }
2063
2064 /**
2065 * @param {string} str
2066 * @return {string}
2067 */
2068 function escapeStringPosix(str) {
2069 /**
2070 * @param {string} x
2071 * @return {string}
2072 */
2073 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222074 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122075 let hexString = code.toString(16);
2076 // Zero pad to four digits to comply with ANSI-C Quoting:
2077 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342078 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122079 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342080 }
Joey Arhar2d21f712019-05-20 21:07:122081
2082 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372083 }
2084
Mathias Bynensf06e8c02020-02-28 13:58:282085 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372086 // Use ANSI-C quoting syntax.
2087 return '$\'' +
2088 str.replace(/\\/g, '\\\\')
2089 .replace(/\'/g, '\\\'')
2090 .replace(/\n/g, '\\n')
2091 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282092 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372093 '\'';
Blink Reformat4c46d092018-04-07 15:32:372094 }
Mathias Bynensf06e8c02020-02-28 13:58:282095 // Use single quote syntax.
2096 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372097 }
2098
2099 // cURL command expected to run on the same platform that DevTools run
2100 // (it may be different from the inspected page platform).
2101 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2102
2103 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2104
2105 let inferredMethod = 'GET';
2106 const data = [];
2107 const requestContentType = request.requestContentType();
2108 const formData = await request.requestFormData();
2109 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272110 // Note that formData is not necessarily urlencoded because it might for example
2111 // come from a fetch request made with an explicitly unencoded body.
2112 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372113 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372114 inferredMethod = 'POST';
2115 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112116 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372117 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372118 inferredMethod = 'POST';
2119 }
2120
2121 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292122 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372123 }
2124
2125 const requestHeaders = request.requestHeaders();
2126 for (let i = 0; i < requestHeaders.length; i++) {
2127 const header = requestHeaders[i];
2128 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372129 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372130 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342131 }
Jan Scheffler172d5212020-01-02 14:42:562132 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372133 }
2134 command = command.concat(data);
2135 command.push('--compressed');
2136
Tim van der Lippe1d6e57a2019-09-30 11:55:342137 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372138 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342139 }
Jan Scheffler172d5212020-01-02 14:42:562140 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372141 }
2142
2143 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132144 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132145 * @param {string} platform
2146 * @return {!Promise<string>}
2147 */
2148 async _generateAllCurlCommand(requests, platform) {
2149 const nonBlobRequests = this._filterOutBlobRequests(requests);
2150 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342151 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132152 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342153 }
Mathias Bynensf06e8c02020-02-28 13:58:282154 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132155 }
2156
2157 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132158 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372159 * @return {!Promise<string>}
2160 */
2161 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562162 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372163 const ignoredHeaders =
2164 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2165
2166 /**
2167 * @param {string} str
2168 * @return {string}
2169 */
2170 function escapeString(str) {
2171 return '"' +
2172 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2173 }
2174
Jan Scheffler172d5212020-01-02 14:42:562175 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372176
2177 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562178 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372179 }
2180
2181 const requestHeaders = request.requestHeaders();
2182 const headerNameValuePairs = [];
2183 for (const header of requestHeaders) {
2184 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342185 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372186 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342187 }
Blink Reformat4c46d092018-04-07 15:32:372188 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2189 }
2190 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562191 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372192 }
2193
2194 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2195 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562196 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372197 }
2198
2199 const formData = await request.requestFormData();
2200 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372201 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342202 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562203 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342204 } else {
Jan Scheffler172d5212020-01-02 14:42:562205 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342206 }
Blink Reformat4c46d092018-04-07 15:32:372207 }
2208
Jan Scheffler172d5212020-01-02 14:42:562209 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372210 }
Harley Libcf41f92018-09-10 18:01:132211
2212 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132213 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132214 * @return {!Promise<string>}
2215 */
2216 async _generateAllPowerShellCommand(requests) {
2217 const nonBlobRequests = this._filterOutBlobRequests(requests);
2218 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2219 return commands.join(';\r\n');
2220 }
Joey Arhara86c14e2019-03-12 03:20:502221
2222 /**
2223 * @return {string}
2224 */
2225 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512226 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502227 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342228 }
Joey Arhara86c14e2019-03-12 03:20:502229 return '#0867CB';
2230 }
2231
2232 /**
2233 * @return {string}
2234 */
2235 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512236 return ThemeSupport.ThemeSupport.instance().patchColorText(
2237 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502238 }
Paul Lewis56509652019-12-06 12:51:582239}
Blink Reformat4c46d092018-04-07 15:32:372240
Tim van der Lippeb4faf5a2020-11-06 15:02:022241/**
2242 * @param {!Protocol.Runtime.StackTrace} stackTrace
2243 */
2244export function computeStackTraceText(stackTrace) {
2245 let stackTraceText = '';
2246 for (const frame of stackTrace.callFrames) {
2247 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2248 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2249 }
2250 if (stackTrace.parent) {
2251 stackTraceText += computeStackTraceText(stackTrace.parent);
2252 }
2253 return stackTraceText;
2254}
2255
Tim van der Lippe224a8622020-09-23 12:14:372256/** @type {!WeakSet<!NetworkRequestNode>} */
2257const filteredNetworkRequests = new WeakSet();
2258/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2259const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372260
Tim van der Lippe3dc5fd62020-09-22 13:12:222261/**
2262 * @param {!NetworkRequestNode} request
2263 * @return {boolean}
2264 */
2265export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372266 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222267}
2268
Paul Lewis56509652019-12-06 12:51:582269export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372270 'http': true,
2271 'https': true,
2272 'ws': true,
2273 'wss': true
2274};
2275
Blink Reformat4c46d092018-04-07 15:32:372276/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582277export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372278 Domain: 'domain',
2279 HasResponseHeader: 'has-response-header',
2280 Is: 'is',
2281 LargerThan: 'larger-than',
2282 Method: 'method',
2283 MimeType: 'mime-type',
2284 MixedContent: 'mixed-content',
2285 Priority: 'priority',
2286 Scheme: 'scheme',
2287 SetCookieDomain: 'set-cookie-domain',
2288 SetCookieName: 'set-cookie-name',
2289 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032290 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412291 CookieDomain: 'cookie-domain',
2292 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542293 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412294 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032295 StatusCode: 'status-code',
2296 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372297};
2298
2299/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582300export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372301 All: 'all',
2302 Displayed: 'displayed',
2303 Blocked: 'blocked',
2304 BlockOverridden: 'block-overridden'
2305};
2306
2307/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582308export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372309 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052310 FromCache: 'from-cache',
2311 ServiceWorkerIntercepted: 'service-worker-intercepted',
2312 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372313};
2314
2315/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372316export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372317
2318/**
2319 * @interface
2320 */
Paul Lewis56509652019-12-06 12:51:582321export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372322 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132323 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302324 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372325 */
Paul Lewis56509652019-12-06 12:51:582326 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372327 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582328 }
Blink Reformat4c46d092018-04-07 15:32:372329
Paul Lewis56509652019-12-06 12:51:582330 reset() {
2331 }
2332}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162333
2334/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372335// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162336export let Filter;