blob: 680b7b61358bc35547173ea941c4619c7085fb3c [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lippe0ed1d2b2020-02-04 13:45:1331import * as Bindings from '../bindings/bindings.js';
Sigurd Schneiderba818512020-04-29 10:54:3732import * as BrowserSDK from '../browser_sdk/browser_sdk.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1333import * as Common from '../common/common.js';
34import * as Components from '../components/components.js';
35import * as DataGrid from '../data_grid/data_grid.js';
36import * as HARImporter from '../har_importer/har_importer.js';
37import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5038import * as PerfUI from '../perf_ui/perf_ui.js';
Jack Franklin9c225ca2020-04-29 09:55:1739import * as Platform from '../platform/platform.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1340import * as SDK from '../sdk/sdk.js';
41import * as TextUtils from '../text_utils/text_utils.js';
Paul Lewisca569a52020-09-09 16:11:5142import * as ThemeSupport from '../theme_support/theme_support.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1343import * as UI from '../ui/ui.js';
44
Tim van der Lippe119690c2020-01-13 12:31:3045import {HARWriter} from './HARWriter.js';
46import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
47import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
48import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
chait pinnamaneni6bc1c122020-10-30 17:30:5249import {FilterOptions} from './NetworkPanel.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe119690c2020-01-13 12:31:3050import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
51
Blink Reformat4c46d092018-04-07 15:32:3752/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1353 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3054 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3755 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3757 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1358 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3759 * @param {!Element} progressBarContainer
Tim van der Lippe224a8622020-09-23 12:14:3760 * @param {!Common.Settings.Setting<number>} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3761 */
62 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
63 super();
64 this.setMinimumSize(50, 64);
Jack Franklin71519f82020-11-03 12:08:5965 this.registerRequiredCSS('network/networkLogView.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3766
67 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0568 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3769
Paul Lewis2d7d65c2020-03-16 17:26:3070 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
71 this._networkShowIssuesOnlySetting =
72 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
73 this._networkOnlyBlockedRequestsSetting =
74 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
75 this._networkResourceTypeFiltersSetting =
76 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3777
78 this._rawRowHeight = 0;
79 this._progressBarContainer = progressBarContainer;
80 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
81 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
82
83 /**
Paul Lewis56509652019-12-06 12:51:5884 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3785 */
86 function updateRowHeight() {
Tim van der Lipped7cfd142021-01-07 12:17:2487 this._rawRowHeight = Boolean(this._networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:3788 this._rowHeight = this._computeRowHeight();
89 }
90 this._rawRowHeight = 0;
91 this._rowHeight = 0;
92 updateRowHeight.call(this);
93
Tim van der Lippe119690c2020-01-13 12:31:3094 /** @type {!NetworkTransferTimeCalculator} */
95 this._timeCalculator = new NetworkTransferTimeCalculator();
96 /** @type {!NetworkTransferDurationCalculator} */
97 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3798 this._calculator = this._timeCalculator;
99
Tim van der Lippe119690c2020-01-13 12:31:30100 this._columns =
101 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37102 this._columns.show(this.element);
103
Tim van der Lippe0ed1d2b2020-02-04 13:45:13104 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37105 this._staleRequests = new Set();
106 /** @type {number} */
107 this._mainRequestLoadTime = -1;
108 /** @type {number} */
109 this._mainRequestDOMContentLoadedTime = -1;
Tim van der Lippe224a8622020-09-23 12:14:37110 /** @type {*} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._highlightedSubstringChanges = [];
112
Tim van der Lippeb1f2b6c2020-02-17 13:00:16113 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16115 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37116 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30117 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37118 this._hoveredNode = null;
119 /** @type {?Element} */
120 this._recordingHint = null;
121 /** @type {?number} */
122 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30123 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37124 this._highlightedNode = null;
125
Simon Zündcdd72c92020-10-07 11:48:13126 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37127
128 this._recording = false;
129 this._needsRefresh = false;
130
131 this._headerHeight = 0;
132
Paul Lewis56509652019-12-06 12:51:58133 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37134 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30135 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37136
Paul Lewis56509652019-12-06 12:51:58137 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37138 this._activeGroupLookup = null;
139
Tim van der Lippe0ed1d2b2020-02-04 13:45:13140 this._textFilterUI = new UI.FilterBar.TextFilterUI();
141 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37142 filterBar.addFilter(this._textFilterUI);
143
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
145 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
146 this._dataURLFilterUI.addEventListener(
147 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57148 UI.Tooltip.Tooltip.install(this._dataURLFilterUI.element(), ls`Hides data: and blob: URLs`);
Blink Reformat4c46d092018-04-07 15:32:37149 filterBar.addFilter(this._dataURLFilterUI);
150
151 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13152 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37153 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13154 this._resourceCategoryFilterUI =
155 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20156 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37157 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13158 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37159 filterBar.addFilter(this._resourceCategoryFilterUI);
160
Tim van der Lippe0ed1d2b2020-02-04 13:45:13161 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
162 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
163 this._onlyIssuesFilterUI.addEventListener(
164 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57165 UI.Tooltip.Tooltip.install(
166 this._onlyIssuesFilterUI.element(), ls`Only show requests with blocked response cookies`);
Jan Scheffler1ae7c9e2019-12-03 15:48:37167 filterBar.addFilter(this._onlyIssuesFilterUI);
168
Sigurd Schneidera2afe0b2020-03-03 15:27:13169 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
170 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
171 this._onlyBlockedRequestsUI.addEventListener(
172 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Tim van der Lippe70842f32020-11-23 16:56:57173 UI.Tooltip.Tooltip.install(this._onlyBlockedRequestsUI.element(), ls`Only show blocked requests`);
Sigurd Schneidera2afe0b2020-03-03 15:27:13174 filterBar.addFilter(this._onlyBlockedRequestsUI);
175
Jan Scheffler1ae7c9e2019-12-03 15:48:37176
Tim van der Lippe0ed1d2b2020-02-04 13:45:13177 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
178 this._suggestionBuilder =
179 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37180 this._resetSuggestionBuilder();
181
182 this._dataGrid = this._columns.dataGrid();
183 this._setupDataGrid();
184 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49185 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13186 UI.Toolbar.ToolbarButton.Events.Click,
187 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37188
Tim van der Lippe0ed1d2b2020-02-04 13:45:13189 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37190
Tim van der Lippe0ed1d2b2020-02-04 13:45:13191 new UI.DropTarget.DropTarget(
192 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
193 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37194
Paul Lewis2d7d65c2020-03-16 17:26:30195 Common.Settings.Settings.instance()
196 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37197 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
198
Paul Lewisdaac1062020-03-05 14:37:10199 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27200 SDK.NetworkLog.NetworkLog.instance().addEventListener(
201 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
202 SDK.NetworkLog.NetworkLog.instance().addEventListener(
203 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
204 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37205
206 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30207 Common.Settings.Settings.instance()
208 .moduleSetting('network.group-by-frame')
209 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37210
211 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03212
213 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
214 if (this._textFilterSetting.get()) {
Jack Franklinec064412020-12-08 13:02:24215 this._textFilterUI.setValue(this._textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03216 }
Blink Reformat4c46d092018-04-07 15:32:37217 }
218
Blink Reformat4c46d092018-04-07 15:32:37219 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30220 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37221 this._setGrouping(value ? 'Frame' : null);
222 }
223
224 /**
225 * @param {string} key
226 * @param {!Array<string>} values
227 */
228 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58229 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37230 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50231 const aPriority =
232 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
233 const bPriority =
234 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
235 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
236 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37237 });
238 } else {
239 values.sort();
240 }
241 }
242
243 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16244 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13245 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37246 * @return {boolean}
247 */
248 static _negativeFilter(filter, request) {
249 return !filter(request);
250 }
251
252 /**
253 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13254 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37255 * @return {boolean}
256 */
257 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34258 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37259 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34260 }
Blink Reformat4c46d092018-04-07 15:32:37261
262 return regex.test(request.path() + '/' + request.name());
263 }
264
265 /**
266 * @param {string} domain
267 * @return {!Array.<string>}
268 */
269 static _subdomains(domain) {
270 const result = [domain];
271 let indexOfPeriod = domain.indexOf('.');
272 while (indexOfPeriod !== -1) {
273 result.push('*' + domain.substring(indexOfPeriod));
274 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
275 }
276 return result;
277 }
278
279 /**
280 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16281 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37282 */
283 static _createRequestDomainFilter(value) {
284 /**
285 * @param {string} string
286 * @return {string}
287 */
288 function escapeForRegExp(string) {
289 return string.escapeForRegExp();
290 }
291 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58292 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37293 }
294
295 /**
296 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13297 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37298 * @return {boolean}
299 */
300 static _requestDomainFilter(regex, request) {
301 return regex.test(request.domain);
302 }
303
304 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13305 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37306 * @return {boolean}
307 */
308 static _runningRequestFilter(request) {
309 return !request.finished;
310 }
311
312 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13313 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37314 * @return {boolean}
315 */
316 static _fromCacheRequestFilter(request) {
317 return request.cached();
318 }
319
320 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13321 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05322 * @return {boolean}
323 */
324 static _interceptedByServiceWorkerFilter(request) {
325 return request.fetchedViaServiceWorker;
326 }
327
328 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13329 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05330 * @return {boolean}
331 */
332 static _initiatedByServiceWorkerFilter(request) {
333 return request.initiatedByServiceWorker();
334 }
335
336 /**
Blink Reformat4c46d092018-04-07 15:32:37337 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13338 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37339 * @return {boolean}
340 */
341 static _requestResponseHeaderFilter(value, request) {
342 return request.responseHeaderValue(value) !== undefined;
343 }
344
345 /**
346 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13347 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37348 * @return {boolean}
349 */
350 static _requestMethodFilter(value, request) {
351 return request.requestMethod === value;
352 }
353
354 /**
355 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13356 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37357 * @return {boolean}
358 */
359 static _requestPriorityFilter(value, request) {
360 return request.priority() === value;
361 }
362
363 /**
364 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13365 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37366 * @return {boolean}
367 */
368 static _requestMimeTypeFilter(value, request) {
369 return request.mimeType === value;
370 }
371
372 /**
Paul Lewis56509652019-12-06 12:51:58373 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13374 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37375 * @return {boolean}
376 */
377 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58378 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37379 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28380 }
381 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37382 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28383 }
384 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37385 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28386 }
387 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37388 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34389 }
Blink Reformat4c46d092018-04-07 15:32:37390
391 return false;
392 }
393
394 /**
395 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13396 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37397 * @return {boolean}
398 */
399 static _requestSchemeFilter(value, request) {
400 return request.scheme === value;
401 }
402
403 /**
404 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13405 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37406 * @return {boolean}
407 */
Jan Scheffler341eea52019-12-12 09:08:41408 static _requestCookieDomainFilter(value, request) {
409 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
410 }
411
412 /**
413 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13414 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41415 * @return {boolean}
416 */
417 static _requestCookieNameFilter(value, request) {
418 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
419 }
420
421 /**
422 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13423 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41424 * @return {boolean}
425 */
Simon Zündc9759102020-03-25 11:24:54426 static _requestCookiePathFilter(value, request) {
427 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
428 }
429
430 /**
431 * @param {string} value
432 * @param {!SDK.NetworkRequest.NetworkRequest} request
433 * @return {boolean}
434 */
Jan Scheffler341eea52019-12-12 09:08:41435 static _requestCookieValueFilter(value, request) {
436 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
437 }
438
439 /**
440 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13441 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41442 * @return {boolean}
443 */
Blink Reformat4c46d092018-04-07 15:32:37444 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41445 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37446 }
447
448 /**
449 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13450 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37451 * @return {boolean}
452 */
453 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41454 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37455 }
456
457 /**
458 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13459 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37460 * @return {boolean}
461 */
462 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41463 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37464 }
465
466 /**
467 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13468 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37469 * @return {boolean}
470 */
471 static _requestSizeLargerThanFilter(value, request) {
472 return request.transferSize >= value;
473 }
474
475 /**
476 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13477 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37478 * @return {boolean}
479 */
480 static _statusCodeFilter(value, request) {
Tim van der Lipped7cfd142021-01-07 12:17:24481 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37482 }
483
484 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13485 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37486 * @return {boolean}
487 */
488 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58489 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37490 }
491
Sigurd Schneider464838b2020-08-24 13:53:03492
493 /**
494 * @param {string} value
495 * @param {!SDK.NetworkRequest.NetworkRequest} request
496 * @return {boolean}
497 */
498 static _resourceTypeFilter(value, request) {
499 return request.resourceType().name() === value;
500 }
501
Blink Reformat4c46d092018-04-07 15:32:37502 /**
Julian Geppertf8ce40c2020-09-01 18:02:03503 * @param {string} value
504 * @param {!SDK.NetworkRequest.NetworkRequest} request
505 * @return {boolean}
506 */
507 static _requestUrlFilter(value, request) {
508 const regex = new RegExp(value.escapeForRegExp(), 'i');
509 return regex.test(request.url());
510 }
511
512 /**
Blink Reformat4c46d092018-04-07 15:32:37513 * @param {number} windowStart
514 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13515 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37516 * @return {boolean}
517 */
518 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37520 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34521 }
522 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37523 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34524 }
Blink Reformat4c46d092018-04-07 15:32:37525 return true;
526 }
527
528 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13529 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37530 */
531 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13532 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37533 }
534
535 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13536 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37537 */
538 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13539 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37540 }
541
542 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13543 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37544 */
545 static async _copyResponse(request) {
546 const contentData = await request.contentData();
Tim van der Lippe224a8622020-09-23 12:14:37547 /** @type {?string} */
Ingvar Stepanyan1c771842018-10-10 14:35:08548 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34549 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40550 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37551 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08552 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34553 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13554 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37555 }
556
557 /**
558 * @param {!DataTransfer} dataTransfer
559 */
560 _handleDrop(dataTransfer) {
561 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34562 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37563 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34564 }
Blink Reformat4c46d092018-04-07 15:32:37565 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34566 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37567 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34568 }
Blink Reformat4c46d092018-04-07 15:32:37569
Joey Arhar0e1093c2019-05-21 00:34:22570 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37571 }
572
573 /**
Tim van der Lippe119690c2020-01-13 12:31:30574 * @override
Blink Reformat4c46d092018-04-07 15:32:37575 * @param {!File} file
576 */
Joey Arhar0e1093c2019-05-21 00:34:22577 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13578 const outputStream = new Common.StringOutputStream.StringOutputStream();
579 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37580 const success = await reader.read(outputStream);
581 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37582 const error = reader.error();
583 if (error) {
584 this._harLoadFailed(/** @type {*} */ (error).message);
585 }
Blink Reformat4c46d092018-04-07 15:32:37586 return;
587 }
588 let harRoot;
589 try {
590 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13591 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37592 } catch (e) {
593 this._harLoadFailed(e);
594 return;
595 }
Wolfgang Beyerd81fad62020-05-27 12:30:27596 SDK.NetworkLog.NetworkLog.instance().importRequests(
597 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37598 }
599
600 /**
601 * @param {string} message
602 */
603 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36604 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37605 }
606
607 /**
608 * @param {?string} groupKey
609 */
610 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34611 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37612 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34613 }
Blink Reformat4c46d092018-04-07 15:32:37614 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
615 this._activeGroupLookup = groupLookup;
616 this._invalidateAllItems();
617 }
618
619 /**
620 * @return {number}
621 */
622 _computeRowHeight() {
623 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
624 }
625
626 /**
Tim van der Lippe119690c2020-01-13 12:31:30627 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13628 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30629 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37630 */
631 nodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:37632 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37633 }
634
635 /**
Tim van der Lippe119690c2020-01-13 12:31:30636 * @override
Blink Reformat4c46d092018-04-07 15:32:37637 * @return {number}
638 */
639 headerHeight() {
640 return this._headerHeight;
641 }
642
643 /**
Tim van der Lippe119690c2020-01-13 12:31:30644 * @override
Blink Reformat4c46d092018-04-07 15:32:37645 * @param {boolean} recording
646 */
647 setRecording(recording) {
648 this._recording = recording;
649 this._updateSummaryBar();
650 }
651
652 /**
653 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13654 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37655 */
656 modelAdded(networkManager) {
657 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34658 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37659 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34660 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13661 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37662 if (resourceTreeModel) {
663 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
664 resourceTreeModel.addEventListener(
665 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
666 }
667 }
668
669 /**
670 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13671 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37672 */
673 modelRemoved(networkManager) {
674 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13675 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37676 if (resourceTreeModel) {
677 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
678 resourceTreeModel.removeEventListener(
679 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
680 }
681 }
682 }
683
684 /**
Tim van der Lippe119690c2020-01-13 12:31:30685 * @override
Simon Zündcdd72c92020-10-07 11:48:13686 * @return {!Components.Linkifier.Linkifier}
687 */
688 linkifier() {
689 return this._linkifier;
690 }
691
692 /**
693 * @override
Blink Reformat4c46d092018-04-07 15:32:37694 * @param {number} start
695 * @param {number} end
696 */
697 setWindow(start, end) {
698 if (!start && !end) {
699 this._timeFilter = null;
700 this._timeCalculator.setWindow(null);
701 } else {
Paul Lewis56509652019-12-06 12:51:58702 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30703 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37704 }
705 this._filterRequests();
706 }
707
Tim van der Lippe119690c2020-01-13 12:31:30708 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05709 resetFocus() {
710 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37711 }
712
713 _resetSuggestionBuilder() {
714 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58715 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
716 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
717 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
718 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
719 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
720 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
721 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37722 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
723 }
724
725 /**
Tim van der Lippec02a97c2020-02-14 14:39:27726 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37727 */
728 _filterChanged(event) {
729 this.removeAllNodeHighlights();
730 this._parseFilterQuery(this._textFilterUI.value());
731 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03732 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37733 }
734
Rajasekar Murugan3ad369e2020-02-19 18:20:12735 async resetFilter() {
736 this._textFilterUI.clear();
737 }
738
Blink Reformat4c46d092018-04-07 15:32:37739 _showRecordingHint() {
740 this._hideRecordingHint();
741 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
742 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18743
Blink Reformat4c46d092018-04-07 15:32:37744 if (this._recording) {
Wolfgang Beyer5c385b92020-11-09 15:20:04745 let reloadShortcutNode = null;
746 const reloadShortcut =
747 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
748 if (reloadShortcut) {
749 reloadShortcutNode = this._recordingHint.createChild('b');
750 reloadShortcutNode.textContent = reloadShortcut.title();
751 }
752
Blink Reformat4c46d092018-04-07 15:32:37753 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38754 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18755 if (reloadShortcutNode) {
756 hintText.createChild('br');
757 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13758 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18759 }
Blink Reformat4c46d092018-04-07 15:32:37760 } else {
761 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17762 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37763 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Wolfgang Beyer5c385b92020-11-09 15:20:04764 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Blink Reformat4c46d092018-04-07 15:32:37765 }
Kayce Basques5444c1b2019-02-15 20:32:53766 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13767 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53768 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43769 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11770
771 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57772 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37773 }
774
775 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11776 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34777 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37778 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34779 }
Brandon Goddardc992d522020-01-08 21:44:57780 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37781 this._recordingHint = null;
782 }
783
784 /**
Amanda Baker6761aae2019-11-05 18:59:11785 * @param {boolean} value
786 */
787 _setHidden(value) {
788 this._columns.setHidden(value);
789 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
790 }
791
792 /**
Blink Reformat4c46d092018-04-07 15:32:37793 * @override
794 * @return {!Array.<!Element>}
795 */
796 elementsToRestoreScrollPositionsFor() {
797 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34798 {
Blink Reformat4c46d092018-04-07 15:32:37799 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34800 }
Blink Reformat4c46d092018-04-07 15:32:37801 return [this._dataGrid.scrollContainer];
802 }
803
Tim van der Lippe119690c2020-01-13 12:31:30804 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37805 columnExtensionResolved() {
806 this._invalidateAllItems(true);
807 }
808
809 _setupDataGrid() {
810 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Andres Olivares03d9c752020-10-01 15:08:11811 const request = (/** @type {!NetworkNode} */ (node)).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34812 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37813 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34814 }
Blink Reformat4c46d092018-04-07 15:32:37815 });
816 this._dataGrid.setStickToBottom(true);
817 this._dataGrid.setName('networkLog');
818 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
819 this._dataGrid.element.classList.add('network-log-grid');
820 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
821 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
822 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05823 this._dataGrid.element.addEventListener('keydown', event => {
824 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05825 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05826 event.consume(true);
827 }
828 });
Brandon Goddard44934902020-03-25 16:03:18829 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
830 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37831 return this._dataGrid;
832 }
833
834 /**
835 * @param {!Event} event
836 */
837 _dataGridMouseMove(event) {
Tim van der Lippe224a8622020-09-23 12:14:37838 const mouseEvent = /** @type {!MouseEvent} */ (event);
Andres Olivares03d9c752020-10-01 15:08:11839 const node =
840 /** @type {!NetworkNode} */ (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (mouseEvent.target)));
Tim van der Lippe224a8622020-09-23 12:14:37841 const highlightInitiatorChain = mouseEvent.shiftKey;
Blink Reformat4c46d092018-04-07 15:32:37842 this._setHoveredNode(node, highlightInitiatorChain);
843 }
844
845 /**
Tim van der Lippe119690c2020-01-13 12:31:30846 * @override
847 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37848 */
849 hoveredNode() {
850 return this._hoveredNode;
851 }
852
853 /**
Tim van der Lippe119690c2020-01-13 12:31:30854 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37855 * @param {boolean=} highlightInitiatorChain
856 */
857 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34858 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37859 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34860 }
Blink Reformat4c46d092018-04-07 15:32:37861 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34862 if (this._hoveredNode) {
Tim van der Lipped7cfd142021-01-07 12:17:24863 this._hoveredNode.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:34864 }
Blink Reformat4c46d092018-04-07 15:32:37865 }
866
867 /**
868 * @param {!Event} event
869 */
870 _dataGridMouseDown(event) {
Tim van der Lippe224a8622020-09-23 12:14:37871 const mouseEvent = /** @type {!MouseEvent} */ (event);
872 if (!this._dataGrid.selectedNode && mouseEvent.button) {
873 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34874 }
Blink Reformat4c46d092018-04-07 15:32:37875 }
876
877 _updateSummaryBar() {
878 this._hideRecordingHint();
879
880 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20881 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37882 let selectedNodeNumber = 0;
883 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20884 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37885 let baseTime = -1;
886 let maxTime = -1;
887
888 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27889 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37890 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34891 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37892 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34893 }
Blink Reformat4c46d092018-04-07 15:32:37894 nodeCount++;
895 const requestTransferSize = request.transferSize;
896 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20897 const requestResourceSize = request.resourceSize;
898 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37899 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37900 selectedNodeNumber++;
901 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20902 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37903 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13904 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37905 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
906 // inspected url.
907 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13908 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
909 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37910 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34911 }
912 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37913 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 }
Blink Reformat4c46d092018-04-07 15:32:37915 }
916
917 if (!nodeCount) {
918 this._showRecordingHint();
919 return;
920 }
921
Joey Arhara86c14e2019-03-12 03:20:50922 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37923 /**
924 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50925 * @param {string=} title
Tim van der Lippe224a8622020-09-23 12:14:37926 * @return {!HTMLDivElement}
Blink Reformat4c46d092018-04-07 15:32:37927 */
Joey Arhara86c14e2019-03-12 03:20:50928 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13929 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50930 toolbarText.setTitle(title ? title : chunk);
931 this._summaryToolbar.appendToolbarItem(toolbarText);
Tim van der Lippe224a8622020-09-23 12:14:37932 return /** @type {!HTMLDivElement} */ (toolbarText.element);
Joey Arhara86c14e2019-03-12 03:20:50933 };
Blink Reformat4c46d092018-04-07 15:32:37934
935 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50936 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
937 this._summaryToolbar.appendSeparator();
938 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17939 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
940 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25941 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50942 this._summaryToolbar.appendSeparator();
943 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17944 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
945 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25946 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37947 } else {
Joey Arhara86c14e2019-03-12 03:20:50948 appendChunk(ls`${nodeCount} requests`);
949 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25950 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17951 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
952 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50953 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25954 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17955 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
956 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37957 }
Dan Beam87466b52018-12-01 18:41:20958
Blink Reformat4c46d092018-04-07 15:32:37959 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50960 this._summaryToolbar.appendSeparator();
961 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37962 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50963 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30964 const domContentLoadedText =
965 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58966 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37967 }
968 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50969 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30970 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58971 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37972 }
973 }
Blink Reformat4c46d092018-04-07 15:32:37974 }
975
Tim van der Lippe119690c2020-01-13 12:31:30976 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37977 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34978 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37979 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34980 }
Blink Reformat4c46d092018-04-07 15:32:37981
982 this._needsRefresh = true;
983
Tim van der Lippe1d6e57a2019-09-30 11:55:34984 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37985 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34986 }
Blink Reformat4c46d092018-04-07 15:32:37987 }
988
989 /**
Tim van der Lippe119690c2020-01-13 12:31:30990 * @override
Blink Reformat4c46d092018-04-07 15:32:37991 * @param {!Array<number>} times
992 */
993 addFilmStripFrames(times) {
994 this._columns.addEventDividers(times, 'network-frame-divider');
995 }
996
997 /**
Tim van der Lippe119690c2020-01-13 12:31:30998 * @override
Blink Reformat4c46d092018-04-07 15:32:37999 * @param {number} time
1000 */
1001 selectFilmStripFrame(time) {
1002 this._columns.selectFilmStripFrame(time);
1003 }
1004
Tim van der Lippe119690c2020-01-13 12:31:301005 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371006 clearFilmStripFrame() {
1007 this._columns.clearFilmStripFrame();
1008 }
1009
1010 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341011 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371012 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341013 }
Blink Reformat4c46d092018-04-07 15:32:371014 }
1015
1016 /**
1017 * @param {boolean=} deferUpdate
1018 */
1019 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271020 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341021 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371022 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341023 } else {
Blink Reformat4c46d092018-04-07 15:32:371024 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341025 }
Blink Reformat4c46d092018-04-07 15:32:371026 }
1027
1028 /**
Tim van der Lippe119690c2020-01-13 12:31:301029 * @override
1030 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371031 */
1032 timeCalculator() {
1033 return this._timeCalculator;
1034 }
1035
1036 /**
Tim van der Lippe119690c2020-01-13 12:31:301037 * @override
1038 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371039 */
1040 calculator() {
1041 return this._calculator;
1042 }
1043
1044 /**
Tim van der Lippe119690c2020-01-13 12:31:301045 * @override
1046 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371047 */
1048 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341049 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371050 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341051 }
Blink Reformat4c46d092018-04-07 15:32:371052
1053 if (this._calculator !== x) {
1054 this._calculator = x;
1055 this._columns.setCalculator(this._calculator);
1056 }
1057 this._calculator.reset();
1058
Tim van der Lippe1d6e57a2019-09-30 11:55:341059 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371060 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341061 } else {
Blink Reformat4c46d092018-04-07 15:32:371062 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341063 }
Blink Reformat4c46d092018-04-07 15:32:371064
1065 this._invalidateAllItems();
1066 }
1067
1068 /**
Tim van der Lippec02a97c2020-02-14 14:39:271069 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371070 */
1071 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341072 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371073 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341074 }
Blink Reformat4c46d092018-04-07 15:32:371075
1076 const time = /** @type {number} */ (event.data.loadTime);
1077 if (time) {
1078 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301079 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371080 }
1081 }
1082
1083 /**
Tim van der Lippec02a97c2020-02-14 14:39:271084 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371085 */
1086 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341087 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371088 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341089 }
Blink Reformat4c46d092018-04-07 15:32:371090 const data = /** @type {number} */ (event.data);
1091 if (data) {
1092 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301093 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371094 }
1095 }
1096
1097 /**
1098 * @override
1099 */
1100 wasShown() {
1101 this._refreshIfNeeded();
1102 this._columns.wasShown();
1103 }
1104
1105 /**
1106 * @override
1107 */
1108 willHide() {
1109 this._columns.willHide();
1110 }
1111
1112 /**
1113 * @override
1114 */
1115 onResize() {
1116 this._rowHeight = this._computeRowHeight();
1117 }
1118
1119 /**
Tim van der Lippe119690c2020-01-13 12:31:301120 * @override
1121 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371122 */
1123 flatNodesList() {
Andres Olivares21ab05b2020-10-21 14:00:021124 /** @type {!DataGrid.ViewportDataGrid.ViewportDataGridNode<!DataGrid.SortableDataGrid.SortableDataGridNode<!NetworkNode>>} */
1125 const rootNode = (this._dataGrid.rootNode());
1126 return /** @type {!Array<!NetworkNode>} */ (rootNode.flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371127 }
1128
Brandon Goddard44934902020-03-25 16:03:181129 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491130 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351131 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381132 }
Brandon Goddard44934902020-03-25 16:03:181133 this.updateNodeBackground();
1134 }
1135
1136 _onDataGridBlur() {
1137 this.element.classList.remove('grid-focused');
1138 this.updateNodeBackground();
1139 }
1140
Tim van der Lippe119690c2020-01-13 12:31:301141 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051142 updateNodeBackground() {
1143 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111144 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051145 }
1146 }
1147
1148 /**
Tim van der Lippe119690c2020-01-13 12:31:301149 * @override
Brandon Goddard88d885a2019-10-31 16:11:051150 * @param {boolean} isSelected
1151 */
1152 updateNodeSelectedClass(isSelected) {
1153 if (isSelected) {
1154 this.element.classList.remove('no-node-selected');
1155 } else {
1156 this.element.classList.add('no-node-selected');
1157 }
1158 }
1159
Tim van der Lippe119690c2020-01-13 12:31:301160 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371161 stylesChanged() {
1162 this._columns.scheduleRefresh();
1163 }
1164
1165 _refresh() {
1166 this._needsRefresh = false;
1167
1168 if (this._refreshRequestId) {
1169 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1170 this._refreshRequestId = null;
1171 }
1172
1173 this.removeAllNodeHighlights();
1174
1175 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1176 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1177 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1178 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1179
Tim van der Lippe224a8622020-09-23 12:14:371180 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371181 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301182 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371183 const nodesToRefresh = [];
1184
Tim van der Lippe119690c2020-01-13 12:31:301185 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371186 const staleNodes = new Set();
1187
1188 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1189 // node so we loop until we have no more stale requests.
1190 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371191 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371192 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371193 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341194 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371195 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341196 }
Blink Reformat4c46d092018-04-07 15:32:371197 staleNodes.add(node);
1198 }
1199
1200 for (const node of staleNodes) {
1201 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341202 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371203 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341204 }
Blink Reformat4c46d092018-04-07 15:32:371205
Tim van der Lippe1d6e57a2019-09-30 11:55:341206 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371207 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 }
Blink Reformat4c46d092018-04-07 15:32:371209 const request = node.request();
1210 this._timeCalculator.updateBoundaries(request);
1211 this._durationCalculator.updateBoundaries(request);
1212 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371213 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1214 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371215 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341216 }
Tim van der Lippe224a8622020-09-23 12:14:371217 if (isFilteredOut) {
1218 filteredNetworkRequests.add(node);
1219 } else {
1220 filteredNetworkRequests.delete(node);
1221 }
Blink Reformat4c46d092018-04-07 15:32:371222 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1223 if (removeFromParent) {
1224 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111225 if (!parent) {
1226 continue;
1227 }
Blink Reformat4c46d092018-04-07 15:32:371228 parent.removeChild(node);
1229 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111230 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371231 grandparent.removeChild(parent);
1232 parent = grandparent;
1233 }
1234 }
1235
Tim van der Lippe1d6e57a2019-09-30 11:55:341236 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371237 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341238 }
Blink Reformat4c46d092018-04-07 15:32:371239
1240 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111241 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371242 nodesToRefresh.push(newParent);
1243 }
1244 nodesToInsert.set(node, newParent);
1245 }
1246
Tim van der Lippe1d6e57a2019-09-30 11:55:341247 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371248 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341249 }
Blink Reformat4c46d092018-04-07 15:32:371250
Tim van der Lippe1d6e57a2019-09-30 11:55:341251 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371252 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341253 }
Blink Reformat4c46d092018-04-07 15:32:371254
1255 this._updateSummaryBar();
1256
Tim van der Lippe1d6e57a2019-09-30 11:55:341257 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371258 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341259 }
Blink Reformat4c46d092018-04-07 15:32:371260
1261 this._dataGrid.updateInstantly();
1262 this._didRefreshForTest();
1263 }
1264
1265 _didRefreshForTest() {
1266 }
1267
1268 /**
Tim van der Lippe119690c2020-01-13 12:31:301269 * @param {!NetworkRequestNode} node
1270 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371271 */
1272 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341273 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111274 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341275 }
Blink Reformat4c46d092018-04-07 15:32:371276
1277 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341278 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111279 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341280 }
Blink Reformat4c46d092018-04-07 15:32:371281 return groupNode;
1282 }
1283
1284 _reset() {
Simon Zünd98419832020-03-12 06:18:151285 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371286
1287 this._setHoveredNode(null);
1288 this._columns.reset();
1289
1290 this._timeFilter = null;
1291 this._calculator.reset();
1292
1293 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131294 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371295
Tim van der Lippe1d6e57a2019-09-30 11:55:341296 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371297 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341298 }
Blink Reformat4c46d092018-04-07 15:32:371299 this._staleRequests.clear();
1300 this._resetSuggestionBuilder();
1301
1302 this._mainRequestLoadTime = -1;
1303 this._mainRequestDOMContentLoadedTime = -1;
1304
1305 this._dataGrid.rootNode().removeChildren();
1306 this._updateSummaryBar();
1307 this._dataGrid.setStickToBottom(true);
1308 this.scheduleRefresh();
1309 }
1310
1311 /**
Tim van der Lippe119690c2020-01-13 12:31:301312 * @override
Blink Reformat4c46d092018-04-07 15:32:371313 * @param {string} filterString
1314 */
1315 setTextFilterValue(filterString) {
1316 this._textFilterUI.setValue(filterString);
1317 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371318 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131319 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371320 this._resourceCategoryFilterUI.reset();
1321 }
1322
1323 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131324 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371325 */
1326 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301327 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371328 networkRequestToNode.set(request, node);
1329 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371330
Tim van der Lippe1d6e57a2019-09-30 11:55:341331 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371332 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341333 }
Blink Reformat4c46d092018-04-07 15:32:371334 return node;
1335 }
1336
1337 /**
Tim van der Lippec02a97c2020-02-14 14:39:271338 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371339 */
1340 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131341 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371342 this._refreshRequest(request);
1343 }
1344
1345 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131346 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371347 */
1348 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581349 NetworkLogView._subdomains(request.domain)
1350 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1351 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1352 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
Tim van der Lipped7cfd142021-01-07 12:17:241353 this._suggestionBuilder.addItem(FilterType.Scheme, String(request.scheme));
1354 this._suggestionBuilder.addItem(FilterType.StatusCode, String(request.statusCode));
Sigurd Schneider464838b2020-08-24 13:53:031355 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031356 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371357
1358 const priority = request.priority();
1359 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501360 this._suggestionBuilder.addItem(
1361 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371362 }
1363
1364 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581365 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371366 }
1367
1368 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581369 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371370 }
1371
1372 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581373 const suggestion =
1374 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1375 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371376 }
1377
1378 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341379 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581380 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341381 }
Jan Scheffler341eea52019-12-12 09:08:411382
1383 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581384 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1385 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1386 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371387 }
1388
Jan Scheffler341eea52019-12-12 09:08:411389 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1390 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1391 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541392 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411393 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1394 }
1395
Blink Reformat4c46d092018-04-07 15:32:371396 this._staleRequests.add(request);
1397 this.scheduleRefresh();
1398 }
1399
1400 /**
Tim van der Lippe119690c2020-01-13 12:31:301401 * @override
Blink Reformat4c46d092018-04-07 15:32:371402 * @return {number}
1403 */
1404 rowHeight() {
1405 return this._rowHeight;
1406 }
1407
1408 /**
Tim van der Lippe119690c2020-01-13 12:31:301409 * @override
Blink Reformat4c46d092018-04-07 15:32:371410 * @param {boolean} gridMode
1411 */
1412 switchViewMode(gridMode) {
1413 this._columns.switchViewMode(gridMode);
1414 }
1415
1416 /**
Tim van der Lippe119690c2020-01-13 12:31:301417 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131418 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1419 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371420 */
1421 handleContextMenuForRequest(contextMenu, request) {
1422 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131423 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371424 const footerSection = copyMenu.footerSection();
1425 if (request) {
1426 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131427 UI.UIUtils.copyLinkAddressLabel(),
1428 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1429 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371430 if (request.requestHeadersText()) {
1431 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131432 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371433 }
1434
1435 if (request.responseHeadersText) {
1436 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131437 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371438 }
1439
1440 if (request.finished) {
1441 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131442 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371443 }
1444
Tim van der Lippeb4faf5a2020-11-06 15:02:021445 const initiator = request.initiator();
1446
1447 if (initiator) {
1448 const stack = initiator.stack;
1449 if (stack) {
1450 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1451 // has any context solely based on the top frame. Sometimes, the top frame does not have
1452 // any callFrames, but its parent frames do.
1453 const stackTraceText = computeStackTraceText(stack);
1454 if (stackTraceText !== '') {
1455 copyMenu.defaultSection().appendItem(Common.UIString.UIString('Copy stacktrace'), () => {
1456 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1457 });
1458 }
1459 }
1460 }
1461
Harley Libcf41f92018-09-10 18:01:131462 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371464 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131465 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1466 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371467 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131468 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291469 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131470 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1471 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371472 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131473 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1474 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131475 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1477 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371478 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131479 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1480 footerSection.appendItem(
1481 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1482 footerSection.appendItem(
1483 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1484 footerSection.appendItem(
1485 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1486 footerSection.appendItem(
1487 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371488 } else {
Harley Libcf41f92018-09-10 18:01:131489 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131490 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291491 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131492 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1493 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131494 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131495 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1496 footerSection.appendItem(
1497 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1498 footerSection.appendItem(
1499 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1500 footerSection.appendItem(
1501 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371502 }
1503 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131504 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371505 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131506 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371507
Joey Arhar0e1093c2019-05-21 00:34:221508 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371509
Blink Reformat4c46d092018-04-07 15:32:371510 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131511 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1512 contextMenu.editSection().appendItem(
1513 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371514
1515 if (request) {
1516 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211517 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371518 let patterns = manager.blockedPatterns();
1519
Tim van der Lippeffa78622019-09-16 12:07:121520 /**
1521 * @param {string} url
1522 */
1523 function addBlockedURL(url) {
1524 patterns.push({enabled: true, url: url});
1525 manager.setBlockedPatterns(patterns);
1526 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261527 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121528 }
1529
1530 /**
1531 * @param {string} url
1532 */
1533 function removeBlockedURL(url) {
1534 patterns = patterns.filter(pattern => pattern.url !== url);
1535 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261536 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121537 }
1538
Blink Reformat4c46d092018-04-07 15:32:371539 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1540 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1541 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131542 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371543 } else if (urlWithoutScheme) {
1544 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1545 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131546 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371547 }
1548
1549 const domain = request.parsedURL.domain();
1550 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1551 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131552 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371553 } else if (domain) {
1554 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1555 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131556 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371557 }
1558
Tim van der Lippe0ed1d2b2020-02-04 13:45:131559 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371560 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131561 Common.UIString.UIString('Replay XHR'),
1562 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371563 }
Blink Reformat4c46d092018-04-07 15:32:371564 }
1565 }
1566
1567 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271568 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171569 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131570 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171571 });
Blink Reformat4c46d092018-04-07 15:32:371572 }
1573
1574 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131575 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1576 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371577 }
1578
1579 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131580 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371581 * @param {string} platform
1582 */
1583 async _copyCurlCommand(request, platform) {
1584 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131585 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371586 }
1587
1588 /**
1589 * @param {string} platform
1590 */
1591 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271592 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131593 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371594 }
1595
1596 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131597 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291598 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371599 */
Jan Scheffler7c50d1f2019-12-17 13:33:291600 async _copyFetchCall(request, includeCookies) {
1601 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131602 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371603 }
1604
Jan Scheffler7c50d1f2019-12-17 13:33:291605 /**
1606 * @param {boolean} includeCookies
1607 */
1608 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271609 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131610 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371611 }
1612
1613 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131614 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371615 */
1616 async _copyPowerShellCommand(request) {
1617 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131618 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371619 }
1620
1621 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271622 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131623 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371624 }
1625
Tim van der Lippe119690c2020-01-13 12:31:301626 /**
1627 * @override
Tim van der Lippe224a8622020-09-23 12:14:371628 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301629 */
Joey Arhar0e1093c2019-05-21 00:34:221630 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371631 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1632 if (!mainTarget) {
1633 return;
1634 }
1635 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131636 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371637 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131638 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371639
Tim van der Lippe1d6e57a2019-09-30 11:55:341640 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371641 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341642 }
Blink Reformat4c46d092018-04-07 15:32:371643
Tim van der Lippe0ed1d2b2020-02-04 13:45:131644 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371645 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301646 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371647 progressIndicator.done();
1648 stream.close();
1649 }
1650
1651 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131652 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211653 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341654 }
Blink Reformat4c46d092018-04-07 15:32:371655 }
1656
1657 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131658 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211659 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341660 }
Blink Reformat4c46d092018-04-07 15:32:371661 }
1662
1663 _removeAllHighlights() {
1664 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341665 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131666 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341667 }
Blink Reformat4c46d092018-04-07 15:32:371668 this._highlightedSubstringChanges = [];
1669 }
1670
1671 /**
Tim van der Lippe119690c2020-01-13 12:31:301672 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371673 * @return {boolean}
1674 */
1675 _applyFilter(node) {
1676 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341677 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371678 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341679 }
Blink Reformat4c46d092018-04-07 15:32:371680 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341681 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371682 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341683 }
1684 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371685 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341686 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221687 if (this._onlyIssuesFilterUI.checked() &&
1688 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371689 return false;
1690 }
Sigurd Schneider20088de2020-10-30 08:08:331691 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131692 return false;
1693 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341694 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371695 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341696 }
Blink Reformat4c46d092018-04-07 15:32:371697 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341698 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371699 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341700 }
Blink Reformat4c46d092018-04-07 15:32:371701 }
1702 return true;
1703 }
1704
1705 /**
1706 * @param {string} query
1707 */
1708 _parseFilterQuery(query) {
1709 const descriptors = this._filterParser.parse(query);
1710 this._filters = descriptors.map(descriptor => {
1711 const key = descriptor.key;
1712 const text = descriptor.text || '';
1713 const regex = descriptor.regex;
1714 let filter;
1715 if (key) {
1716 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581717 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1718 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371719 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581720 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371721 } else {
Paul Lewis56509652019-12-06 12:51:581722 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371723 }
Paul Lewis56509652019-12-06 12:51:581724 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371725 });
1726 }
1727
1728 /**
Paul Lewis56509652019-12-06 12:51:581729 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371730 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161731 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371732 */
1733 _createSpecialFilter(type, value) {
1734 switch (type) {
Paul Lewis56509652019-12-06 12:51:581735 case FilterType.Domain:
1736 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371737
Paul Lewis56509652019-12-06 12:51:581738 case FilterType.HasResponseHeader:
1739 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371740
Paul Lewis56509652019-12-06 12:51:581741 case FilterType.Is:
1742 if (value.toLowerCase() === IsFilterType.Running) {
1743 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341744 }
Paul Lewis56509652019-12-06 12:51:581745 if (value.toLowerCase() === IsFilterType.FromCache) {
1746 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341747 }
Paul Lewis56509652019-12-06 12:51:581748 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1749 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341750 }
Paul Lewis56509652019-12-06 12:51:581751 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1752 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341753 }
Blink Reformat4c46d092018-04-07 15:32:371754 break;
1755
Paul Lewis56509652019-12-06 12:51:581756 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371757 return this._createSizeFilter(value.toLowerCase());
1758
Paul Lewis56509652019-12-06 12:51:581759 case FilterType.Method:
1760 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371761
Paul Lewis56509652019-12-06 12:51:581762 case FilterType.MimeType:
1763 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371764
Paul Lewis56509652019-12-06 12:51:581765 case FilterType.MixedContent:
1766 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371767
Paul Lewis56509652019-12-06 12:51:581768 case FilterType.Scheme:
1769 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371770
Paul Lewis56509652019-12-06 12:51:581771 case FilterType.SetCookieDomain:
1772 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371773
Paul Lewis56509652019-12-06 12:51:581774 case FilterType.SetCookieName:
1775 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371776
Paul Lewis56509652019-12-06 12:51:581777 case FilterType.SetCookieValue:
1778 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371779
Jan Scheffler341eea52019-12-12 09:08:411780 case FilterType.CookieDomain:
1781 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1782
1783 case FilterType.CookieName:
1784 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1785
Simon Zündc9759102020-03-25 11:24:541786 case FilterType.CookiePath:
1787 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1788
Jan Scheffler341eea52019-12-12 09:08:411789 case FilterType.CookieValue:
1790 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1791
Paul Lewis56509652019-12-06 12:51:581792 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501793 return NetworkLogView._requestPriorityFilter.bind(
1794 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371795
Paul Lewis56509652019-12-06 12:51:581796 case FilterType.StatusCode:
1797 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031798
1799 case FilterType.ResourceType:
1800 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031801
1802 case FilterType.Url:
1803 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371804 }
1805 return null;
1806 }
1807
1808 /**
1809 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161810 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371811 */
1812 _createSizeFilter(value) {
1813 let multiplier = 1;
1814 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541815 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371816 value = value.substring(0, value.length - 1);
1817 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541818 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371819 value = value.substring(0, value.length - 1);
1820 }
1821 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341822 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371823 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341824 }
Paul Lewis56509652019-12-06 12:51:581825 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371826 }
1827
1828 _filterRequests() {
1829 this._removeAllHighlights();
1830 this._invalidateAllItems();
1831 }
1832
1833 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131834 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301835 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371836 */
1837 _reveal(request) {
1838 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371839 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341840 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371841 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341842 }
Brandon Goddard5e4244d2020-04-08 22:08:471843 // Viewport datagrid nodes do not reveal if not in the root node
1844 // list of flatChildren. For children of grouped frame nodes:
1845 // reveal and expand parent to ensure child is revealable.
1846 if (node.parent && node.parent instanceof NetworkGroupNode) {
1847 node.parent.reveal();
1848 node.parent.expand();
1849 }
Blink Reformat4c46d092018-04-07 15:32:371850 node.reveal();
1851 return node;
1852 }
1853
1854 /**
Tim van der Lippe119690c2020-01-13 12:31:301855 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131856 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371857 */
1858 revealAndHighlightRequest(request) {
1859 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341860 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371861 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341862 }
Blink Reformat4c46d092018-04-07 15:32:371863 }
1864
1865 /**
Tim van der Lippe119690c2020-01-13 12:31:301866 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131867 * @param {!SDK.NetworkRequest.NetworkRequest} request
chait pinnamaneni6bc1c122020-10-30 17:30:521868 * @param {!FilterOptions=} options - Optional parameters to change filter behavior
Blink Reformat4c46d092018-04-07 15:32:371869 */
chait pinnamaneni6bc1c122020-10-30 17:30:521870 selectRequest(request, options) {
1871 const defaultOptions = {clearFilter: true};
1872 const {clearFilter} = options || defaultOptions;
1873 if (clearFilter) {
1874 this.setTextFilterValue('');
1875 }
Blink Reformat4c46d092018-04-07 15:32:371876 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341877 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371878 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341879 }
Blink Reformat4c46d092018-04-07 15:32:371880 }
1881
Tim van der Lippe119690c2020-01-13 12:31:301882 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371883 removeAllNodeHighlights() {
1884 if (this._highlightedNode) {
1885 this._highlightedNode.element().classList.remove('highlighted-row');
1886 this._highlightedNode = null;
1887 }
1888 }
1889
1890 /**
Tim van der Lippe119690c2020-01-13 12:31:301891 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371892 */
1893 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131894 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371895 this._highlightedNode = node;
1896 }
1897
1898 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131899 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1900 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131901 */
1902 _filterOutBlobRequests(requests) {
1903 return requests.filter(request => !request.isBlobRequest());
1904 }
1905
1906 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131907 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291908 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371909 * @return {!Promise<string>}
1910 */
Jan Scheffler7c50d1f2019-12-17 13:33:291911 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371912 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371913 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371914 'method',
1915 'path',
1916 'scheme',
1917 'version',
Blink Reformat4c46d092018-04-07 15:32:371918
1919 // Unsafe headers
1920 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371921 'accept-charset',
1922 'accept-encoding',
1923 'access-control-request-headers',
1924 'access-control-request-method',
1925 'connection',
1926 'content-length',
1927 'cookie',
1928 'cookie2',
1929 'date',
1930 'dnt',
1931 'expect',
1932 'host',
1933 'keep-alive',
1934 'origin',
1935 'referer',
1936 'te',
1937 'trailer',
1938 'transfer-encoding',
1939 'upgrade',
1940 'via',
Blink Reformat4c46d092018-04-07 15:32:371941 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371942 'user-agent',
1943 ]);
Blink Reformat4c46d092018-04-07 15:32:371944
Tim van der Lippe224a8622020-09-23 12:14:371945 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371946
1947 const url = JSON.stringify(request.url());
1948
1949 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371950 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371951 const headerData = requestHeaders.reduce((result, header) => {
1952 const name = header.name;
1953
Tim van der Lippe224a8622020-09-23 12:14:371954 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371955 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341956 }
Blink Reformat4c46d092018-04-07 15:32:371957
1958 return result;
1959 }, new Headers());
1960
Tim van der Lippe224a8622020-09-23 12:14:371961 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371962 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341963 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411964 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341965 }
Blink Reformat4c46d092018-04-07 15:32:371966
Sigurd Schneider0e88b912020-05-08 08:28:231967 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371968 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411969 'include' :
1970 'omit';
Blink Reformat4c46d092018-04-07 15:32:371971
1972 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1973
1974 const referrer = referrerHeader ? referrerHeader.value : void 0;
1975
1976 const referrerPolicy = request.referrerPolicy() || void 0;
1977
1978 const requestBody = await request.requestFormData();
1979
Tim van der Lippe224a8622020-09-23 12:14:371980 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371981 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411982 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371983 referrer,
1984 referrerPolicy,
1985 body: requestBody,
1986 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371987 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371988 };
1989
Jan Scheffler7c50d1f2019-12-17 13:33:291990 if (includeCookies) {
1991 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1992 if (cookieHeader) {
1993 fetchOptions.headers = {
1994 ...headers,
1995 'cookie': cookieHeader.value,
1996 };
1997 }
1998 } else {
1999 fetchOptions.credentials = credentials;
2000 }
2001
Jan Scheffler172d5212020-01-02 14:42:562002 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372003 return `fetch(${url}, ${options});`;
2004 }
2005
2006 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132007 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:292008 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:132009 * @return {!Promise<string>}
2010 */
Jan Scheffler7c50d1f2019-12-17 13:33:292011 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:132012 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:292013 const commands =
2014 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:132015 return commands.join(' ;\n');
2016 }
2017
2018 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132019 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372020 * @param {string} platform
2021 * @return {!Promise<string>}
2022 */
2023 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562024 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362025 // Most of these headers are derived from the URL and are automatically added by cURL.
2026 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372027 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372028
Tim van der Lippe224a8622020-09-23 12:14:372029 /**
2030 * @param {string} str
2031 */
Blink Reformat4c46d092018-04-07 15:32:372032 function escapeStringWin(str) {
2033 /* If there are no new line characters do not escape the " characters
2034 since it only uglifies the command.
2035
2036 Because cmd.exe parser and MS Crt arguments parsers use some of the
2037 same escape characters, they can interact with each other in
2038 horrible ways, the order of operations is critical.
2039
2040 Replace \ with \\ first because it is an escape character for certain
2041 conditions in both parsers.
2042
2043 Replace all " with \" to ensure the first parser does not remove it.
2044
2045 Then escape all characters we are not sure about with ^ to ensure it
2046 gets to MS Crt parser safely.
2047
2048 The % character is special because MS Crt parser will try and look for
2049 ENV variables and fill them in it's place. We cannot escape them with %
2050 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2051 parser); So we can get cmd.exe parser to escape the character after it,
2052 if it is followed by a valid beginning character of an ENV variable.
2053 This ensures we do not try and double escape another ^ if it was placed
2054 by the previous replace.
2055
2056 Lastly we replace new lines with ^ and TWO new lines because the first
2057 new line is there to enact the escape command the second is the character
2058 to escape (in this case new line).
2059 */
2060 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2061 return encapsChars +
2062 str.replace(/\\/g, '\\\\')
2063 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542064 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372065 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542066 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372067 encapsChars;
2068 }
2069
2070 /**
2071 * @param {string} str
2072 * @return {string}
2073 */
2074 function escapeStringPosix(str) {
2075 /**
2076 * @param {string} x
2077 * @return {string}
2078 */
2079 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222080 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122081 let hexString = code.toString(16);
2082 // Zero pad to four digits to comply with ANSI-C Quoting:
2083 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342084 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122085 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342086 }
Joey Arhar2d21f712019-05-20 21:07:122087
2088 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372089 }
2090
Mathias Bynensf06e8c02020-02-28 13:58:282091 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372092 // Use ANSI-C quoting syntax.
2093 return '$\'' +
2094 str.replace(/\\/g, '\\\\')
2095 .replace(/\'/g, '\\\'')
2096 .replace(/\n/g, '\\n')
2097 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282098 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372099 '\'';
Blink Reformat4c46d092018-04-07 15:32:372100 }
Mathias Bynensf06e8c02020-02-28 13:58:282101 // Use single quote syntax.
2102 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372103 }
2104
2105 // cURL command expected to run on the same platform that DevTools run
2106 // (it may be different from the inspected page platform).
2107 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2108
2109 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2110
2111 let inferredMethod = 'GET';
2112 const data = [];
2113 const requestContentType = request.requestContentType();
2114 const formData = await request.requestFormData();
2115 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272116 // Note that formData is not necessarily urlencoded because it might for example
2117 // come from a fetch request made with an explicitly unencoded body.
2118 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372119 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372120 inferredMethod = 'POST';
2121 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112122 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372123 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372124 inferredMethod = 'POST';
2125 }
2126
2127 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292128 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372129 }
2130
2131 const requestHeaders = request.requestHeaders();
2132 for (let i = 0; i < requestHeaders.length; i++) {
2133 const header = requestHeaders[i];
2134 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372135 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372136 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342137 }
Jan Scheffler172d5212020-01-02 14:42:562138 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372139 }
2140 command = command.concat(data);
2141 command.push('--compressed');
2142
Tim van der Lippe1d6e57a2019-09-30 11:55:342143 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372144 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342145 }
Jan Scheffler172d5212020-01-02 14:42:562146 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372147 }
2148
2149 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132150 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132151 * @param {string} platform
2152 * @return {!Promise<string>}
2153 */
2154 async _generateAllCurlCommand(requests, platform) {
2155 const nonBlobRequests = this._filterOutBlobRequests(requests);
2156 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342157 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132158 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342159 }
Mathias Bynensf06e8c02020-02-28 13:58:282160 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132161 }
2162
2163 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132164 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372165 * @return {!Promise<string>}
2166 */
2167 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562168 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372169 const ignoredHeaders =
2170 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2171
2172 /**
2173 * @param {string} str
2174 * @return {string}
2175 */
2176 function escapeString(str) {
2177 return '"' +
2178 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2179 }
2180
Jan Scheffler172d5212020-01-02 14:42:562181 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372182
2183 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562184 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372185 }
2186
2187 const requestHeaders = request.requestHeaders();
2188 const headerNameValuePairs = [];
2189 for (const header of requestHeaders) {
2190 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342191 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372192 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342193 }
Blink Reformat4c46d092018-04-07 15:32:372194 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2195 }
2196 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562197 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372198 }
2199
2200 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2201 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562202 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372203 }
2204
2205 const formData = await request.requestFormData();
2206 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372207 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342208 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562209 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342210 } else {
Jan Scheffler172d5212020-01-02 14:42:562211 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342212 }
Blink Reformat4c46d092018-04-07 15:32:372213 }
2214
Jan Scheffler172d5212020-01-02 14:42:562215 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372216 }
Harley Libcf41f92018-09-10 18:01:132217
2218 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132219 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132220 * @return {!Promise<string>}
2221 */
2222 async _generateAllPowerShellCommand(requests) {
2223 const nonBlobRequests = this._filterOutBlobRequests(requests);
2224 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2225 return commands.join(';\r\n');
2226 }
Joey Arhara86c14e2019-03-12 03:20:502227
2228 /**
2229 * @return {string}
2230 */
2231 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512232 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502233 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342234 }
Joey Arhara86c14e2019-03-12 03:20:502235 return '#0867CB';
2236 }
2237
2238 /**
2239 * @return {string}
2240 */
2241 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512242 return ThemeSupport.ThemeSupport.instance().patchColorText(
2243 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502244 }
Paul Lewis56509652019-12-06 12:51:582245}
Blink Reformat4c46d092018-04-07 15:32:372246
Tim van der Lippeb4faf5a2020-11-06 15:02:022247/**
2248 * @param {!Protocol.Runtime.StackTrace} stackTrace
2249 */
2250export function computeStackTraceText(stackTrace) {
2251 let stackTraceText = '';
2252 for (const frame of stackTrace.callFrames) {
2253 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2254 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2255 }
2256 if (stackTrace.parent) {
2257 stackTraceText += computeStackTraceText(stackTrace.parent);
2258 }
2259 return stackTraceText;
2260}
2261
Tim van der Lippe224a8622020-09-23 12:14:372262/** @type {!WeakSet<!NetworkRequestNode>} */
2263const filteredNetworkRequests = new WeakSet();
2264/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2265const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372266
Tim van der Lippe3dc5fd62020-09-22 13:12:222267/**
2268 * @param {!NetworkRequestNode} request
2269 * @return {boolean}
2270 */
2271export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372272 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222273}
2274
Paul Lewis56509652019-12-06 12:51:582275export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372276 'http': true,
2277 'https': true,
2278 'ws': true,
2279 'wss': true
2280};
2281
Blink Reformat4c46d092018-04-07 15:32:372282/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582283export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372284 Domain: 'domain',
2285 HasResponseHeader: 'has-response-header',
2286 Is: 'is',
2287 LargerThan: 'larger-than',
2288 Method: 'method',
2289 MimeType: 'mime-type',
2290 MixedContent: 'mixed-content',
2291 Priority: 'priority',
2292 Scheme: 'scheme',
2293 SetCookieDomain: 'set-cookie-domain',
2294 SetCookieName: 'set-cookie-name',
2295 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032296 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412297 CookieDomain: 'cookie-domain',
2298 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542299 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412300 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032301 StatusCode: 'status-code',
2302 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372303};
2304
2305/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582306export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372307 All: 'all',
2308 Displayed: 'displayed',
2309 Blocked: 'blocked',
2310 BlockOverridden: 'block-overridden'
2311};
2312
2313/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582314export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372315 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052316 FromCache: 'from-cache',
2317 ServiceWorkerIntercepted: 'service-worker-intercepted',
2318 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372319};
2320
2321/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372322export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372323
2324/**
2325 * @interface
2326 */
Paul Lewis56509652019-12-06 12:51:582327export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372328 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132329 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302330 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372331 */
Paul Lewis56509652019-12-06 12:51:582332 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372333 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582334 }
Blink Reformat4c46d092018-04-07 15:32:372335
Paul Lewis56509652019-12-06 12:51:582336 reset() {
2337 }
2338}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162339
2340/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372341// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162342export let Filter;