blob: 909e7e36f136197c353f4885b818d208616ca43d [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() {
87 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
88 this._rowHeight = this._computeRowHeight();
89 }
90 this._rawRowHeight = 0;
91 this._rowHeight = 0;
92 updateRowHeight.call(this);
93
Tim van der Lippe119690c2020-01-13 12:31:3094 /** @type {!NetworkTransferTimeCalculator} */
95 this._timeCalculator = new NetworkTransferTimeCalculator();
96 /** @type {!NetworkTransferDurationCalculator} */
97 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3798 this._calculator = this._timeCalculator;
99
Tim van der Lippe119690c2020-01-13 12:31:30100 this._columns =
101 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37102 this._columns.show(this.element);
103
Tim van der Lippe0ed1d2b2020-02-04 13:45:13104 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37105 this._staleRequests = new Set();
106 /** @type {number} */
107 this._mainRequestLoadTime = -1;
108 /** @type {number} */
109 this._mainRequestDOMContentLoadedTime = -1;
Tim van der Lippe224a8622020-09-23 12:14:37110 /** @type {*} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._highlightedSubstringChanges = [];
112
Tim van der Lippeb1f2b6c2020-02-17 13:00:16113 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16115 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37116 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30117 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37118 this._hoveredNode = null;
119 /** @type {?Element} */
120 this._recordingHint = null;
121 /** @type {?number} */
122 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30123 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37124 this._highlightedNode = null;
125
Simon Zündcdd72c92020-10-07 11:48:13126 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37127
128 this._recording = false;
129 this._needsRefresh = false;
130
131 this._headerHeight = 0;
132
Paul Lewis56509652019-12-06 12:51:58133 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37134 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30135 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37136
Paul Lewis56509652019-12-06 12:51:58137 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37138 this._activeGroupLookup = null;
139
Tim van der Lippe0ed1d2b2020-02-04 13:45:13140 this._textFilterUI = new UI.FilterBar.TextFilterUI();
141 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37142 filterBar.addFilter(this._textFilterUI);
143
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
145 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
146 this._dataURLFilterUI.addEventListener(
147 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48148 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37149 filterBar.addFilter(this._dataURLFilterUI);
150
151 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13152 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37153 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13154 this._resourceCategoryFilterUI =
155 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20156 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37157 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13158 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37159 filterBar.addFilter(this._resourceCategoryFilterUI);
160
Tim van der Lippe0ed1d2b2020-02-04 13:45:13161 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
162 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
163 this._onlyIssuesFilterUI.addEventListener(
164 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41165 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37166 filterBar.addFilter(this._onlyIssuesFilterUI);
167
Sigurd Schneidera2afe0b2020-03-03 15:27:13168 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
169 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
170 this._onlyBlockedRequestsUI.addEventListener(
171 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
172 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
173 filterBar.addFilter(this._onlyBlockedRequestsUI);
174
Jan Scheffler1ae7c9e2019-12-03 15:48:37175
Tim van der Lippe0ed1d2b2020-02-04 13:45:13176 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
177 this._suggestionBuilder =
178 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37179 this._resetSuggestionBuilder();
180
181 this._dataGrid = this._columns.dataGrid();
182 this._setupDataGrid();
183 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49184 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13185 UI.Toolbar.ToolbarButton.Events.Click,
186 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37187
Tim van der Lippe0ed1d2b2020-02-04 13:45:13188 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37189
Tim van der Lippe0ed1d2b2020-02-04 13:45:13190 new UI.DropTarget.DropTarget(
191 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
192 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37193
Paul Lewis2d7d65c2020-03-16 17:26:30194 Common.Settings.Settings.instance()
195 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37196 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
197
Paul Lewisdaac1062020-03-05 14:37:10198 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27199 SDK.NetworkLog.NetworkLog.instance().addEventListener(
200 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
201 SDK.NetworkLog.NetworkLog.instance().addEventListener(
202 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
203 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37204
205 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30206 Common.Settings.Settings.instance()
207 .moduleSetting('network.group-by-frame')
208 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37209
210 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03211
212 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
213 if (this._textFilterSetting.get()) {
214 this.setTextFilterValue(this._textFilterSetting.get());
215 }
Blink Reformat4c46d092018-04-07 15:32:37216 }
217
Blink Reformat4c46d092018-04-07 15:32:37218 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30219 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37220 this._setGrouping(value ? 'Frame' : null);
221 }
222
223 /**
224 * @param {string} key
225 * @param {!Array<string>} values
226 */
227 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58228 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37229 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50230 const aPriority =
231 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
232 const bPriority =
233 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
234 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
235 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37236 });
237 } else {
238 values.sort();
239 }
240 }
241
242 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16243 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13244 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37245 * @return {boolean}
246 */
247 static _negativeFilter(filter, request) {
248 return !filter(request);
249 }
250
251 /**
252 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13253 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37254 * @return {boolean}
255 */
256 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34257 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37258 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34259 }
Blink Reformat4c46d092018-04-07 15:32:37260
261 return regex.test(request.path() + '/' + request.name());
262 }
263
264 /**
265 * @param {string} domain
266 * @return {!Array.<string>}
267 */
268 static _subdomains(domain) {
269 const result = [domain];
270 let indexOfPeriod = domain.indexOf('.');
271 while (indexOfPeriod !== -1) {
272 result.push('*' + domain.substring(indexOfPeriod));
273 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
274 }
275 return result;
276 }
277
278 /**
279 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16280 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37281 */
282 static _createRequestDomainFilter(value) {
283 /**
284 * @param {string} string
285 * @return {string}
286 */
287 function escapeForRegExp(string) {
288 return string.escapeForRegExp();
289 }
290 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58291 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37292 }
293
294 /**
295 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13296 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37297 * @return {boolean}
298 */
299 static _requestDomainFilter(regex, request) {
300 return regex.test(request.domain);
301 }
302
303 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13304 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37305 * @return {boolean}
306 */
307 static _runningRequestFilter(request) {
308 return !request.finished;
309 }
310
311 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13312 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37313 * @return {boolean}
314 */
315 static _fromCacheRequestFilter(request) {
316 return request.cached();
317 }
318
319 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13320 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05321 * @return {boolean}
322 */
323 static _interceptedByServiceWorkerFilter(request) {
324 return request.fetchedViaServiceWorker;
325 }
326
327 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05329 * @return {boolean}
330 */
331 static _initiatedByServiceWorkerFilter(request) {
332 return request.initiatedByServiceWorker();
333 }
334
335 /**
Blink Reformat4c46d092018-04-07 15:32:37336 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13337 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37338 * @return {boolean}
339 */
340 static _requestResponseHeaderFilter(value, request) {
341 return request.responseHeaderValue(value) !== undefined;
342 }
343
344 /**
345 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13346 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37347 * @return {boolean}
348 */
349 static _requestMethodFilter(value, request) {
350 return request.requestMethod === value;
351 }
352
353 /**
354 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13355 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37356 * @return {boolean}
357 */
358 static _requestPriorityFilter(value, request) {
359 return request.priority() === value;
360 }
361
362 /**
363 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13364 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37365 * @return {boolean}
366 */
367 static _requestMimeTypeFilter(value, request) {
368 return request.mimeType === value;
369 }
370
371 /**
Paul Lewis56509652019-12-06 12:51:58372 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13373 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37374 * @return {boolean}
375 */
376 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58377 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37378 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28379 }
380 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37381 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28382 }
383 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37384 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28385 }
386 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37387 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34388 }
Blink Reformat4c46d092018-04-07 15:32:37389
390 return false;
391 }
392
393 /**
394 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13395 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37396 * @return {boolean}
397 */
398 static _requestSchemeFilter(value, request) {
399 return request.scheme === value;
400 }
401
402 /**
403 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13404 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37405 * @return {boolean}
406 */
Jan Scheffler341eea52019-12-12 09:08:41407 static _requestCookieDomainFilter(value, request) {
408 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
409 }
410
411 /**
412 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13413 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41414 * @return {boolean}
415 */
416 static _requestCookieNameFilter(value, request) {
417 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
418 }
419
420 /**
421 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13422 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41423 * @return {boolean}
424 */
Simon Zündc9759102020-03-25 11:24:54425 static _requestCookiePathFilter(value, request) {
426 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
427 }
428
429 /**
430 * @param {string} value
431 * @param {!SDK.NetworkRequest.NetworkRequest} request
432 * @return {boolean}
433 */
Jan Scheffler341eea52019-12-12 09:08:41434 static _requestCookieValueFilter(value, request) {
435 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
436 }
437
438 /**
439 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13440 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41441 * @return {boolean}
442 */
Blink Reformat4c46d092018-04-07 15:32:37443 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41444 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37445 }
446
447 /**
448 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13449 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37450 * @return {boolean}
451 */
452 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41453 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37454 }
455
456 /**
457 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13458 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37459 * @return {boolean}
460 */
461 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41462 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37463 }
464
465 /**
466 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13467 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37468 * @return {boolean}
469 */
470 static _requestSizeLargerThanFilter(value, request) {
471 return request.transferSize >= value;
472 }
473
474 /**
475 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13476 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37477 * @return {boolean}
478 */
479 static _statusCodeFilter(value, request) {
480 return ('' + request.statusCode) === value;
481 }
482
483 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13484 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37485 * @return {boolean}
486 */
487 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58488 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37489 }
490
Sigurd Schneider464838b2020-08-24 13:53:03491
492 /**
493 * @param {string} value
494 * @param {!SDK.NetworkRequest.NetworkRequest} request
495 * @return {boolean}
496 */
497 static _resourceTypeFilter(value, request) {
498 return request.resourceType().name() === value;
499 }
500
Blink Reformat4c46d092018-04-07 15:32:37501 /**
Julian Geppertf8ce40c2020-09-01 18:02:03502 * @param {string} value
503 * @param {!SDK.NetworkRequest.NetworkRequest} request
504 * @return {boolean}
505 */
506 static _requestUrlFilter(value, request) {
507 const regex = new RegExp(value.escapeForRegExp(), 'i');
508 return regex.test(request.url());
509 }
510
511 /**
Blink Reformat4c46d092018-04-07 15:32:37512 * @param {number} windowStart
513 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13514 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37515 * @return {boolean}
516 */
517 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34518 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37519 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34520 }
521 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37522 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34523 }
Blink Reformat4c46d092018-04-07 15:32:37524 return true;
525 }
526
527 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13528 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37529 */
530 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13531 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37532 }
533
534 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13535 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37536 */
537 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13538 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37539 }
540
541 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13542 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37543 */
544 static async _copyResponse(request) {
545 const contentData = await request.contentData();
Tim van der Lippe224a8622020-09-23 12:14:37546 /** @type {?string} */
Ingvar Stepanyan1c771842018-10-10 14:35:08547 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34548 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40549 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37550 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08551 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34552 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13553 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37554 }
555
556 /**
557 * @param {!DataTransfer} dataTransfer
558 */
559 _handleDrop(dataTransfer) {
560 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34561 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37562 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34563 }
Blink Reformat4c46d092018-04-07 15:32:37564 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34565 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37566 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34567 }
Blink Reformat4c46d092018-04-07 15:32:37568
Joey Arhar0e1093c2019-05-21 00:34:22569 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37570 }
571
572 /**
Tim van der Lippe119690c2020-01-13 12:31:30573 * @override
Blink Reformat4c46d092018-04-07 15:32:37574 * @param {!File} file
575 */
Joey Arhar0e1093c2019-05-21 00:34:22576 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13577 const outputStream = new Common.StringOutputStream.StringOutputStream();
578 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37579 const success = await reader.read(outputStream);
580 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37581 const error = reader.error();
582 if (error) {
583 this._harLoadFailed(/** @type {*} */ (error).message);
584 }
Blink Reformat4c46d092018-04-07 15:32:37585 return;
586 }
587 let harRoot;
588 try {
589 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13590 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37591 } catch (e) {
592 this._harLoadFailed(e);
593 return;
594 }
Wolfgang Beyerd81fad62020-05-27 12:30:27595 SDK.NetworkLog.NetworkLog.instance().importRequests(
596 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37597 }
598
599 /**
600 * @param {string} message
601 */
602 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36603 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37604 }
605
606 /**
607 * @param {?string} groupKey
608 */
609 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34610 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37611 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34612 }
Blink Reformat4c46d092018-04-07 15:32:37613 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
614 this._activeGroupLookup = groupLookup;
615 this._invalidateAllItems();
616 }
617
618 /**
619 * @return {number}
620 */
621 _computeRowHeight() {
622 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
623 }
624
625 /**
Tim van der Lippe119690c2020-01-13 12:31:30626 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13627 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30628 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37629 */
630 nodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:37631 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37632 }
633
634 /**
Tim van der Lippe119690c2020-01-13 12:31:30635 * @override
Blink Reformat4c46d092018-04-07 15:32:37636 * @return {number}
637 */
638 headerHeight() {
639 return this._headerHeight;
640 }
641
642 /**
Tim van der Lippe119690c2020-01-13 12:31:30643 * @override
Blink Reformat4c46d092018-04-07 15:32:37644 * @param {boolean} recording
645 */
646 setRecording(recording) {
647 this._recording = recording;
648 this._updateSummaryBar();
649 }
650
651 /**
652 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13653 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37654 */
655 modelAdded(networkManager) {
656 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34657 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37658 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34659 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13660 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37661 if (resourceTreeModel) {
662 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
663 resourceTreeModel.addEventListener(
664 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
665 }
666 }
667
668 /**
669 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13670 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37671 */
672 modelRemoved(networkManager) {
673 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13674 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37675 if (resourceTreeModel) {
676 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
677 resourceTreeModel.removeEventListener(
678 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
679 }
680 }
681 }
682
683 /**
Tim van der Lippe119690c2020-01-13 12:31:30684 * @override
Simon Zündcdd72c92020-10-07 11:48:13685 * @return {!Components.Linkifier.Linkifier}
686 */
687 linkifier() {
688 return this._linkifier;
689 }
690
691 /**
692 * @override
Blink Reformat4c46d092018-04-07 15:32:37693 * @param {number} start
694 * @param {number} end
695 */
696 setWindow(start, end) {
697 if (!start && !end) {
698 this._timeFilter = null;
699 this._timeCalculator.setWindow(null);
700 } else {
Paul Lewis56509652019-12-06 12:51:58701 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30702 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37703 }
704 this._filterRequests();
705 }
706
Tim van der Lippe119690c2020-01-13 12:31:30707 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05708 resetFocus() {
709 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37710 }
711
712 _resetSuggestionBuilder() {
713 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58714 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
715 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
716 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
717 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
718 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
719 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
720 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37721 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
722 }
723
724 /**
Tim van der Lippec02a97c2020-02-14 14:39:27725 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37726 */
727 _filterChanged(event) {
728 this.removeAllNodeHighlights();
729 this._parseFilterQuery(this._textFilterUI.value());
730 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03731 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37732 }
733
Rajasekar Murugan3ad369e2020-02-19 18:20:12734 async resetFilter() {
735 this._textFilterUI.clear();
736 }
737
Blink Reformat4c46d092018-04-07 15:32:37738 _showRecordingHint() {
739 this._hideRecordingHint();
740 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
741 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18742
Blink Reformat4c46d092018-04-07 15:32:37743 if (this._recording) {
Wolfgang Beyer5c385b92020-11-09 15:20:04744 let reloadShortcutNode = null;
745 const reloadShortcut =
746 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
747 if (reloadShortcut) {
748 reloadShortcutNode = this._recordingHint.createChild('b');
749 reloadShortcutNode.textContent = reloadShortcut.title();
750 }
751
Blink Reformat4c46d092018-04-07 15:32:37752 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38753 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18754 if (reloadShortcutNode) {
755 hintText.createChild('br');
756 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13757 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18758 }
Blink Reformat4c46d092018-04-07 15:32:37759 } else {
760 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17761 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37762 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Wolfgang Beyer5c385b92020-11-09 15:20:04763 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Blink Reformat4c46d092018-04-07 15:32:37764 }
Kayce Basques5444c1b2019-02-15 20:32:53765 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13766 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53767 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43768 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11769
770 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57771 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37772 }
773
774 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11775 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34776 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37777 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34778 }
Brandon Goddardc992d522020-01-08 21:44:57779 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37780 this._recordingHint = null;
781 }
782
783 /**
Amanda Baker6761aae2019-11-05 18:59:11784 * @param {boolean} value
785 */
786 _setHidden(value) {
787 this._columns.setHidden(value);
788 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
789 }
790
791 /**
Blink Reformat4c46d092018-04-07 15:32:37792 * @override
793 * @return {!Array.<!Element>}
794 */
795 elementsToRestoreScrollPositionsFor() {
796 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34797 {
Blink Reformat4c46d092018-04-07 15:32:37798 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34799 }
Blink Reformat4c46d092018-04-07 15:32:37800 return [this._dataGrid.scrollContainer];
801 }
802
Tim van der Lippe119690c2020-01-13 12:31:30803 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37804 columnExtensionResolved() {
805 this._invalidateAllItems(true);
806 }
807
808 _setupDataGrid() {
809 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Andres Olivares03d9c752020-10-01 15:08:11810 const request = (/** @type {!NetworkNode} */ (node)).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34811 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37812 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34813 }
Blink Reformat4c46d092018-04-07 15:32:37814 });
815 this._dataGrid.setStickToBottom(true);
816 this._dataGrid.setName('networkLog');
817 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
818 this._dataGrid.element.classList.add('network-log-grid');
819 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
820 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
821 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05822 this._dataGrid.element.addEventListener('keydown', event => {
823 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05824 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05825 event.consume(true);
826 }
827 });
Brandon Goddard44934902020-03-25 16:03:18828 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
829 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37830 return this._dataGrid;
831 }
832
833 /**
834 * @param {!Event} event
835 */
836 _dataGridMouseMove(event) {
Tim van der Lippe224a8622020-09-23 12:14:37837 const mouseEvent = /** @type {!MouseEvent} */ (event);
Andres Olivares03d9c752020-10-01 15:08:11838 const node =
839 /** @type {!NetworkNode} */ (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (mouseEvent.target)));
Tim van der Lippe224a8622020-09-23 12:14:37840 const highlightInitiatorChain = mouseEvent.shiftKey;
Blink Reformat4c46d092018-04-07 15:32:37841 this._setHoveredNode(node, highlightInitiatorChain);
842 }
843
844 /**
Tim van der Lippe119690c2020-01-13 12:31:30845 * @override
846 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37847 */
848 hoveredNode() {
849 return this._hoveredNode;
850 }
851
852 /**
Tim van der Lippe119690c2020-01-13 12:31:30853 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37854 * @param {boolean=} highlightInitiatorChain
855 */
856 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34857 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37858 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34859 }
Blink Reformat4c46d092018-04-07 15:32:37860 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34861 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37862 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34863 }
Blink Reformat4c46d092018-04-07 15:32:37864 }
865
866 /**
867 * @param {!Event} event
868 */
869 _dataGridMouseDown(event) {
Tim van der Lippe224a8622020-09-23 12:14:37870 const mouseEvent = /** @type {!MouseEvent} */ (event);
871 if (!this._dataGrid.selectedNode && mouseEvent.button) {
872 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34873 }
Blink Reformat4c46d092018-04-07 15:32:37874 }
875
876 _updateSummaryBar() {
877 this._hideRecordingHint();
878
879 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20880 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37881 let selectedNodeNumber = 0;
882 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20883 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37884 let baseTime = -1;
885 let maxTime = -1;
886
887 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27888 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37889 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34890 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37891 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34892 }
Blink Reformat4c46d092018-04-07 15:32:37893 nodeCount++;
894 const requestTransferSize = request.transferSize;
895 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20896 const requestResourceSize = request.resourceSize;
897 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37898 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37899 selectedNodeNumber++;
900 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20901 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37902 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13903 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37904 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
905 // inspected url.
906 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13907 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
908 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37909 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34910 }
911 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37912 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34913 }
Blink Reformat4c46d092018-04-07 15:32:37914 }
915
916 if (!nodeCount) {
917 this._showRecordingHint();
918 return;
919 }
920
Joey Arhara86c14e2019-03-12 03:20:50921 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37922 /**
923 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50924 * @param {string=} title
Tim van der Lippe224a8622020-09-23 12:14:37925 * @return {!HTMLDivElement}
Blink Reformat4c46d092018-04-07 15:32:37926 */
Joey Arhara86c14e2019-03-12 03:20:50927 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13928 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50929 toolbarText.setTitle(title ? title : chunk);
930 this._summaryToolbar.appendToolbarItem(toolbarText);
Tim van der Lippe224a8622020-09-23 12:14:37931 return /** @type {!HTMLDivElement} */ (toolbarText.element);
Joey Arhara86c14e2019-03-12 03:20:50932 };
Blink Reformat4c46d092018-04-07 15:32:37933
934 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50935 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
936 this._summaryToolbar.appendSeparator();
937 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17938 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
939 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25940 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50941 this._summaryToolbar.appendSeparator();
942 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17943 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
944 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25945 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37946 } else {
Joey Arhara86c14e2019-03-12 03:20:50947 appendChunk(ls`${nodeCount} requests`);
948 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25949 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17950 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
951 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50952 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25953 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17954 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
955 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37956 }
Dan Beam87466b52018-12-01 18:41:20957
Blink Reformat4c46d092018-04-07 15:32:37958 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50959 this._summaryToolbar.appendSeparator();
960 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37961 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50962 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30963 const domContentLoadedText =
964 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58965 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37966 }
967 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50968 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30969 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58970 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37971 }
972 }
Blink Reformat4c46d092018-04-07 15:32:37973 }
974
Tim van der Lippe119690c2020-01-13 12:31:30975 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37976 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34977 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37978 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34979 }
Blink Reformat4c46d092018-04-07 15:32:37980
981 this._needsRefresh = true;
982
Tim van der Lippe1d6e57a2019-09-30 11:55:34983 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37984 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34985 }
Blink Reformat4c46d092018-04-07 15:32:37986 }
987
988 /**
Tim van der Lippe119690c2020-01-13 12:31:30989 * @override
Blink Reformat4c46d092018-04-07 15:32:37990 * @param {!Array<number>} times
991 */
992 addFilmStripFrames(times) {
993 this._columns.addEventDividers(times, 'network-frame-divider');
994 }
995
996 /**
Tim van der Lippe119690c2020-01-13 12:31:30997 * @override
Blink Reformat4c46d092018-04-07 15:32:37998 * @param {number} time
999 */
1000 selectFilmStripFrame(time) {
1001 this._columns.selectFilmStripFrame(time);
1002 }
1003
Tim van der Lippe119690c2020-01-13 12:31:301004 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371005 clearFilmStripFrame() {
1006 this._columns.clearFilmStripFrame();
1007 }
1008
1009 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341010 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371011 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341012 }
Blink Reformat4c46d092018-04-07 15:32:371013 }
1014
1015 /**
1016 * @param {boolean=} deferUpdate
1017 */
1018 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271019 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341020 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371021 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341022 } else {
Blink Reformat4c46d092018-04-07 15:32:371023 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341024 }
Blink Reformat4c46d092018-04-07 15:32:371025 }
1026
1027 /**
Tim van der Lippe119690c2020-01-13 12:31:301028 * @override
1029 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371030 */
1031 timeCalculator() {
1032 return this._timeCalculator;
1033 }
1034
1035 /**
Tim van der Lippe119690c2020-01-13 12:31:301036 * @override
1037 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371038 */
1039 calculator() {
1040 return this._calculator;
1041 }
1042
1043 /**
Tim van der Lippe119690c2020-01-13 12:31:301044 * @override
1045 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371046 */
1047 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341048 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371049 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341050 }
Blink Reformat4c46d092018-04-07 15:32:371051
1052 if (this._calculator !== x) {
1053 this._calculator = x;
1054 this._columns.setCalculator(this._calculator);
1055 }
1056 this._calculator.reset();
1057
Tim van der Lippe1d6e57a2019-09-30 11:55:341058 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371059 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341060 } else {
Blink Reformat4c46d092018-04-07 15:32:371061 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341062 }
Blink Reformat4c46d092018-04-07 15:32:371063
1064 this._invalidateAllItems();
1065 }
1066
1067 /**
Tim van der Lippec02a97c2020-02-14 14:39:271068 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371069 */
1070 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341071 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371072 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341073 }
Blink Reformat4c46d092018-04-07 15:32:371074
1075 const time = /** @type {number} */ (event.data.loadTime);
1076 if (time) {
1077 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301078 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371079 }
1080 }
1081
1082 /**
Tim van der Lippec02a97c2020-02-14 14:39:271083 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371084 */
1085 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371087 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341088 }
Blink Reformat4c46d092018-04-07 15:32:371089 const data = /** @type {number} */ (event.data);
1090 if (data) {
1091 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301092 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371093 }
1094 }
1095
1096 /**
1097 * @override
1098 */
1099 wasShown() {
1100 this._refreshIfNeeded();
1101 this._columns.wasShown();
1102 }
1103
1104 /**
1105 * @override
1106 */
1107 willHide() {
1108 this._columns.willHide();
1109 }
1110
1111 /**
1112 * @override
1113 */
1114 onResize() {
1115 this._rowHeight = this._computeRowHeight();
1116 }
1117
1118 /**
Tim van der Lippe119690c2020-01-13 12:31:301119 * @override
1120 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371121 */
1122 flatNodesList() {
Andres Olivares21ab05b2020-10-21 14:00:021123 /** @type {!DataGrid.ViewportDataGrid.ViewportDataGridNode<!DataGrid.SortableDataGrid.SortableDataGridNode<!NetworkNode>>} */
1124 const rootNode = (this._dataGrid.rootNode());
1125 return /** @type {!Array<!NetworkNode>} */ (rootNode.flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371126 }
1127
Brandon Goddard44934902020-03-25 16:03:181128 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491129 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351130 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381131 }
Brandon Goddard44934902020-03-25 16:03:181132 this.updateNodeBackground();
1133 }
1134
1135 _onDataGridBlur() {
1136 this.element.classList.remove('grid-focused');
1137 this.updateNodeBackground();
1138 }
1139
Tim van der Lippe119690c2020-01-13 12:31:301140 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051141 updateNodeBackground() {
1142 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111143 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051144 }
1145 }
1146
1147 /**
Tim van der Lippe119690c2020-01-13 12:31:301148 * @override
Brandon Goddard88d885a2019-10-31 16:11:051149 * @param {boolean} isSelected
1150 */
1151 updateNodeSelectedClass(isSelected) {
1152 if (isSelected) {
1153 this.element.classList.remove('no-node-selected');
1154 } else {
1155 this.element.classList.add('no-node-selected');
1156 }
1157 }
1158
Tim van der Lippe119690c2020-01-13 12:31:301159 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371160 stylesChanged() {
1161 this._columns.scheduleRefresh();
1162 }
1163
1164 _refresh() {
1165 this._needsRefresh = false;
1166
1167 if (this._refreshRequestId) {
1168 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1169 this._refreshRequestId = null;
1170 }
1171
1172 this.removeAllNodeHighlights();
1173
1174 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1175 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1176 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1177 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1178
Tim van der Lippe224a8622020-09-23 12:14:371179 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371180 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301181 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371182 const nodesToRefresh = [];
1183
Tim van der Lippe119690c2020-01-13 12:31:301184 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371185 const staleNodes = new Set();
1186
1187 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1188 // node so we loop until we have no more stale requests.
1189 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371190 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371191 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371192 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341193 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371194 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 }
Blink Reformat4c46d092018-04-07 15:32:371196 staleNodes.add(node);
1197 }
1198
1199 for (const node of staleNodes) {
1200 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341201 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371202 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341203 }
Blink Reformat4c46d092018-04-07 15:32:371204
Tim van der Lippe1d6e57a2019-09-30 11:55:341205 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371206 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 }
Blink Reformat4c46d092018-04-07 15:32:371208 const request = node.request();
1209 this._timeCalculator.updateBoundaries(request);
1210 this._durationCalculator.updateBoundaries(request);
1211 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371212 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1213 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371214 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341215 }
Tim van der Lippe224a8622020-09-23 12:14:371216 if (isFilteredOut) {
1217 filteredNetworkRequests.add(node);
1218 } else {
1219 filteredNetworkRequests.delete(node);
1220 }
Blink Reformat4c46d092018-04-07 15:32:371221 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1222 if (removeFromParent) {
1223 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111224 if (!parent) {
1225 continue;
1226 }
Blink Reformat4c46d092018-04-07 15:32:371227 parent.removeChild(node);
1228 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111229 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371230 grandparent.removeChild(parent);
1231 parent = grandparent;
1232 }
1233 }
1234
Tim van der Lippe1d6e57a2019-09-30 11:55:341235 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371236 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341237 }
Blink Reformat4c46d092018-04-07 15:32:371238
1239 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111240 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371241 nodesToRefresh.push(newParent);
1242 }
1243 nodesToInsert.set(node, newParent);
1244 }
1245
Tim van der Lippe1d6e57a2019-09-30 11:55:341246 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371247 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341248 }
Blink Reformat4c46d092018-04-07 15:32:371249
Tim van der Lippe1d6e57a2019-09-30 11:55:341250 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371251 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341252 }
Blink Reformat4c46d092018-04-07 15:32:371253
1254 this._updateSummaryBar();
1255
Tim van der Lippe1d6e57a2019-09-30 11:55:341256 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371257 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341258 }
Blink Reformat4c46d092018-04-07 15:32:371259
1260 this._dataGrid.updateInstantly();
1261 this._didRefreshForTest();
1262 }
1263
1264 _didRefreshForTest() {
1265 }
1266
1267 /**
Tim van der Lippe119690c2020-01-13 12:31:301268 * @param {!NetworkRequestNode} node
1269 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371270 */
1271 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341272 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111273 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341274 }
Blink Reformat4c46d092018-04-07 15:32:371275
1276 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341277 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111278 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341279 }
Blink Reformat4c46d092018-04-07 15:32:371280 return groupNode;
1281 }
1282
1283 _reset() {
Simon Zünd98419832020-03-12 06:18:151284 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371285
1286 this._setHoveredNode(null);
1287 this._columns.reset();
1288
1289 this._timeFilter = null;
1290 this._calculator.reset();
1291
1292 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131293 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371294
Tim van der Lippe1d6e57a2019-09-30 11:55:341295 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371296 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341297 }
Blink Reformat4c46d092018-04-07 15:32:371298 this._staleRequests.clear();
1299 this._resetSuggestionBuilder();
1300
1301 this._mainRequestLoadTime = -1;
1302 this._mainRequestDOMContentLoadedTime = -1;
1303
1304 this._dataGrid.rootNode().removeChildren();
1305 this._updateSummaryBar();
1306 this._dataGrid.setStickToBottom(true);
1307 this.scheduleRefresh();
1308 }
1309
1310 /**
Tim van der Lippe119690c2020-01-13 12:31:301311 * @override
Blink Reformat4c46d092018-04-07 15:32:371312 * @param {string} filterString
1313 */
1314 setTextFilterValue(filterString) {
1315 this._textFilterUI.setValue(filterString);
1316 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371317 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131318 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371319 this._resourceCategoryFilterUI.reset();
1320 }
1321
1322 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131323 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371324 */
1325 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301326 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371327 networkRequestToNode.set(request, node);
1328 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371329
Tim van der Lippe1d6e57a2019-09-30 11:55:341330 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371331 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341332 }
Blink Reformat4c46d092018-04-07 15:32:371333 return node;
1334 }
1335
1336 /**
Tim van der Lippec02a97c2020-02-14 14:39:271337 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371338 */
1339 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131340 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371341 this._refreshRequest(request);
1342 }
1343
1344 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131345 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371346 */
1347 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581348 NetworkLogView._subdomains(request.domain)
1349 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1350 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1351 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1352 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1353 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Sigurd Schneider464838b2020-08-24 13:53:031354 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031355 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371356
1357 const priority = request.priority();
1358 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501359 this._suggestionBuilder.addItem(
1360 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371361 }
1362
1363 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581364 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371365 }
1366
1367 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581368 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371369 }
1370
1371 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581372 const suggestion =
1373 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1374 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371375 }
1376
1377 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341378 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581379 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341380 }
Jan Scheffler341eea52019-12-12 09:08:411381
1382 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581383 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1384 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1385 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371386 }
1387
Jan Scheffler341eea52019-12-12 09:08:411388 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1389 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1390 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541391 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411392 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1393 }
1394
Blink Reformat4c46d092018-04-07 15:32:371395 this._staleRequests.add(request);
1396 this.scheduleRefresh();
1397 }
1398
1399 /**
Tim van der Lippe119690c2020-01-13 12:31:301400 * @override
Blink Reformat4c46d092018-04-07 15:32:371401 * @return {number}
1402 */
1403 rowHeight() {
1404 return this._rowHeight;
1405 }
1406
1407 /**
Tim van der Lippe119690c2020-01-13 12:31:301408 * @override
Blink Reformat4c46d092018-04-07 15:32:371409 * @param {boolean} gridMode
1410 */
1411 switchViewMode(gridMode) {
1412 this._columns.switchViewMode(gridMode);
1413 }
1414
1415 /**
Tim van der Lippe119690c2020-01-13 12:31:301416 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131417 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1418 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371419 */
1420 handleContextMenuForRequest(contextMenu, request) {
1421 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371423 const footerSection = copyMenu.footerSection();
1424 if (request) {
1425 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131426 UI.UIUtils.copyLinkAddressLabel(),
1427 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1428 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371429 if (request.requestHeadersText()) {
1430 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131431 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371432 }
1433
1434 if (request.responseHeadersText) {
1435 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131436 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371437 }
1438
1439 if (request.finished) {
1440 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131441 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371442 }
1443
Tim van der Lippeb4faf5a2020-11-06 15:02:021444 const initiator = request.initiator();
1445
1446 if (initiator) {
1447 const stack = initiator.stack;
1448 if (stack) {
1449 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
1450 // has any context solely based on the top frame. Sometimes, the top frame does not have
1451 // any callFrames, but its parent frames do.
1452 const stackTraceText = computeStackTraceText(stack);
1453 if (stackTraceText !== '') {
1454 copyMenu.defaultSection().appendItem(Common.UIString.UIString('Copy stacktrace'), () => {
1455 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1456 });
1457 }
1458 }
1459 }
1460
Harley Libcf41f92018-09-10 18:01:131461 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131462 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371463 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131464 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1465 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371466 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131467 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291468 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131469 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1470 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371471 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131472 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1473 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131474 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131475 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1476 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371477 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131478 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1479 footerSection.appendItem(
1480 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1481 footerSection.appendItem(
1482 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1483 footerSection.appendItem(
1484 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1485 footerSection.appendItem(
1486 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371487 } else {
Harley Libcf41f92018-09-10 18:01:131488 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131489 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291490 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131491 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1492 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131493 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1495 footerSection.appendItem(
1496 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1497 footerSection.appendItem(
1498 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1499 footerSection.appendItem(
1500 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371501 }
1502 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131503 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371504 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131505 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371506
Joey Arhar0e1093c2019-05-21 00:34:221507 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371508
Blink Reformat4c46d092018-04-07 15:32:371509 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131510 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1511 contextMenu.editSection().appendItem(
1512 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371513
1514 if (request) {
1515 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211516 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371517 let patterns = manager.blockedPatterns();
1518
Tim van der Lippeffa78622019-09-16 12:07:121519 /**
1520 * @param {string} url
1521 */
1522 function addBlockedURL(url) {
1523 patterns.push({enabled: true, url: url});
1524 manager.setBlockedPatterns(patterns);
1525 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261526 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121527 }
1528
1529 /**
1530 * @param {string} url
1531 */
1532 function removeBlockedURL(url) {
1533 patterns = patterns.filter(pattern => pattern.url !== url);
1534 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261535 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121536 }
1537
Blink Reformat4c46d092018-04-07 15:32:371538 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1539 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1540 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131541 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371542 } else if (urlWithoutScheme) {
1543 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1544 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131545 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371546 }
1547
1548 const domain = request.parsedURL.domain();
1549 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1550 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131551 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371552 } else if (domain) {
1553 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1554 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131555 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371556 }
1557
Tim van der Lippe0ed1d2b2020-02-04 13:45:131558 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371559 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131560 Common.UIString.UIString('Replay XHR'),
1561 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371562 }
Blink Reformat4c46d092018-04-07 15:32:371563 }
1564 }
1565
1566 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271567 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171568 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131569 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171570 });
Blink Reformat4c46d092018-04-07 15:32:371571 }
1572
1573 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131574 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1575 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371576 }
1577
1578 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131579 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371580 * @param {string} platform
1581 */
1582 async _copyCurlCommand(request, platform) {
1583 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131584 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371585 }
1586
1587 /**
1588 * @param {string} platform
1589 */
1590 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271591 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131592 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371593 }
1594
1595 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131596 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291597 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371598 */
Jan Scheffler7c50d1f2019-12-17 13:33:291599 async _copyFetchCall(request, includeCookies) {
1600 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131601 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371602 }
1603
Jan Scheffler7c50d1f2019-12-17 13:33:291604 /**
1605 * @param {boolean} includeCookies
1606 */
1607 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271608 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131609 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371610 }
1611
1612 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131613 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371614 */
1615 async _copyPowerShellCommand(request) {
1616 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131617 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371618 }
1619
1620 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271621 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131622 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371623 }
1624
Tim van der Lippe119690c2020-01-13 12:31:301625 /**
1626 * @override
Tim van der Lippe224a8622020-09-23 12:14:371627 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301628 */
Joey Arhar0e1093c2019-05-21 00:34:221629 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371630 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1631 if (!mainTarget) {
1632 return;
1633 }
1634 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131635 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371636 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131637 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371638
Tim van der Lippe1d6e57a2019-09-30 11:55:341639 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371640 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341641 }
Blink Reformat4c46d092018-04-07 15:32:371642
Tim van der Lippe0ed1d2b2020-02-04 13:45:131643 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371644 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301645 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371646 progressIndicator.done();
1647 stream.close();
1648 }
1649
1650 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131651 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211652 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341653 }
Blink Reformat4c46d092018-04-07 15:32:371654 }
1655
1656 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131657 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211658 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341659 }
Blink Reformat4c46d092018-04-07 15:32:371660 }
1661
1662 _removeAllHighlights() {
1663 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341664 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131665 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341666 }
Blink Reformat4c46d092018-04-07 15:32:371667 this._highlightedSubstringChanges = [];
1668 }
1669
1670 /**
Tim van der Lippe119690c2020-01-13 12:31:301671 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371672 * @return {boolean}
1673 */
1674 _applyFilter(node) {
1675 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341676 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371677 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341678 }
Blink Reformat4c46d092018-04-07 15:32:371679 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341680 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371681 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341682 }
1683 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371684 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341685 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221686 if (this._onlyIssuesFilterUI.checked() &&
1687 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371688 return false;
1689 }
Sigurd Schneider20088de2020-10-30 08:08:331690 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131691 return false;
1692 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341693 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371694 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341695 }
Blink Reformat4c46d092018-04-07 15:32:371696 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341697 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371698 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341699 }
Blink Reformat4c46d092018-04-07 15:32:371700 }
1701 return true;
1702 }
1703
1704 /**
1705 * @param {string} query
1706 */
1707 _parseFilterQuery(query) {
1708 const descriptors = this._filterParser.parse(query);
1709 this._filters = descriptors.map(descriptor => {
1710 const key = descriptor.key;
1711 const text = descriptor.text || '';
1712 const regex = descriptor.regex;
1713 let filter;
1714 if (key) {
1715 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581716 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1717 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371718 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581719 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371720 } else {
Paul Lewis56509652019-12-06 12:51:581721 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371722 }
Paul Lewis56509652019-12-06 12:51:581723 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371724 });
1725 }
1726
1727 /**
Paul Lewis56509652019-12-06 12:51:581728 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371729 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161730 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371731 */
1732 _createSpecialFilter(type, value) {
1733 switch (type) {
Paul Lewis56509652019-12-06 12:51:581734 case FilterType.Domain:
1735 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371736
Paul Lewis56509652019-12-06 12:51:581737 case FilterType.HasResponseHeader:
1738 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371739
Paul Lewis56509652019-12-06 12:51:581740 case FilterType.Is:
1741 if (value.toLowerCase() === IsFilterType.Running) {
1742 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341743 }
Paul Lewis56509652019-12-06 12:51:581744 if (value.toLowerCase() === IsFilterType.FromCache) {
1745 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341746 }
Paul Lewis56509652019-12-06 12:51:581747 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1748 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341749 }
Paul Lewis56509652019-12-06 12:51:581750 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1751 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341752 }
Blink Reformat4c46d092018-04-07 15:32:371753 break;
1754
Paul Lewis56509652019-12-06 12:51:581755 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371756 return this._createSizeFilter(value.toLowerCase());
1757
Paul Lewis56509652019-12-06 12:51:581758 case FilterType.Method:
1759 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371760
Paul Lewis56509652019-12-06 12:51:581761 case FilterType.MimeType:
1762 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371763
Paul Lewis56509652019-12-06 12:51:581764 case FilterType.MixedContent:
1765 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371766
Paul Lewis56509652019-12-06 12:51:581767 case FilterType.Scheme:
1768 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371769
Paul Lewis56509652019-12-06 12:51:581770 case FilterType.SetCookieDomain:
1771 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371772
Paul Lewis56509652019-12-06 12:51:581773 case FilterType.SetCookieName:
1774 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371775
Paul Lewis56509652019-12-06 12:51:581776 case FilterType.SetCookieValue:
1777 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371778
Jan Scheffler341eea52019-12-12 09:08:411779 case FilterType.CookieDomain:
1780 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1781
1782 case FilterType.CookieName:
1783 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1784
Simon Zündc9759102020-03-25 11:24:541785 case FilterType.CookiePath:
1786 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1787
Jan Scheffler341eea52019-12-12 09:08:411788 case FilterType.CookieValue:
1789 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1790
Paul Lewis56509652019-12-06 12:51:581791 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501792 return NetworkLogView._requestPriorityFilter.bind(
1793 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371794
Paul Lewis56509652019-12-06 12:51:581795 case FilterType.StatusCode:
1796 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031797
1798 case FilterType.ResourceType:
1799 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031800
1801 case FilterType.Url:
1802 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371803 }
1804 return null;
1805 }
1806
1807 /**
1808 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161809 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371810 */
1811 _createSizeFilter(value) {
1812 let multiplier = 1;
1813 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541814 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371815 value = value.substring(0, value.length - 1);
1816 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541817 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371818 value = value.substring(0, value.length - 1);
1819 }
1820 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341821 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371822 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341823 }
Paul Lewis56509652019-12-06 12:51:581824 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371825 }
1826
1827 _filterRequests() {
1828 this._removeAllHighlights();
1829 this._invalidateAllItems();
1830 }
1831
1832 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131833 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301834 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371835 */
1836 _reveal(request) {
1837 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371838 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341839 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371840 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341841 }
Brandon Goddard5e4244d2020-04-08 22:08:471842 // Viewport datagrid nodes do not reveal if not in the root node
1843 // list of flatChildren. For children of grouped frame nodes:
1844 // reveal and expand parent to ensure child is revealable.
1845 if (node.parent && node.parent instanceof NetworkGroupNode) {
1846 node.parent.reveal();
1847 node.parent.expand();
1848 }
Blink Reformat4c46d092018-04-07 15:32:371849 node.reveal();
1850 return node;
1851 }
1852
1853 /**
Tim van der Lippe119690c2020-01-13 12:31:301854 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131855 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371856 */
1857 revealAndHighlightRequest(request) {
1858 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341859 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371860 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341861 }
Blink Reformat4c46d092018-04-07 15:32:371862 }
1863
1864 /**
Tim van der Lippe119690c2020-01-13 12:31:301865 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131866 * @param {!SDK.NetworkRequest.NetworkRequest} request
chait pinnamaneni6bc1c122020-10-30 17:30:521867 * @param {!FilterOptions=} options - Optional parameters to change filter behavior
Blink Reformat4c46d092018-04-07 15:32:371868 */
chait pinnamaneni6bc1c122020-10-30 17:30:521869 selectRequest(request, options) {
1870 const defaultOptions = {clearFilter: true};
1871 const {clearFilter} = options || defaultOptions;
1872 if (clearFilter) {
1873 this.setTextFilterValue('');
1874 }
Blink Reformat4c46d092018-04-07 15:32:371875 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341876 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371877 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341878 }
Blink Reformat4c46d092018-04-07 15:32:371879 }
1880
Tim van der Lippe119690c2020-01-13 12:31:301881 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371882 removeAllNodeHighlights() {
1883 if (this._highlightedNode) {
1884 this._highlightedNode.element().classList.remove('highlighted-row');
1885 this._highlightedNode = null;
1886 }
1887 }
1888
1889 /**
Tim van der Lippe119690c2020-01-13 12:31:301890 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371891 */
1892 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131893 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371894 this._highlightedNode = node;
1895 }
1896
1897 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131898 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1899 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131900 */
1901 _filterOutBlobRequests(requests) {
1902 return requests.filter(request => !request.isBlobRequest());
1903 }
1904
1905 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131906 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291907 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371908 * @return {!Promise<string>}
1909 */
Jan Scheffler7c50d1f2019-12-17 13:33:291910 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371911 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371912 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371913 'method',
1914 'path',
1915 'scheme',
1916 'version',
Blink Reformat4c46d092018-04-07 15:32:371917
1918 // Unsafe headers
1919 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371920 'accept-charset',
1921 'accept-encoding',
1922 'access-control-request-headers',
1923 'access-control-request-method',
1924 'connection',
1925 'content-length',
1926 'cookie',
1927 'cookie2',
1928 'date',
1929 'dnt',
1930 'expect',
1931 'host',
1932 'keep-alive',
1933 'origin',
1934 'referer',
1935 'te',
1936 'trailer',
1937 'transfer-encoding',
1938 'upgrade',
1939 'via',
Blink Reformat4c46d092018-04-07 15:32:371940 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371941 'user-agent',
1942 ]);
Blink Reformat4c46d092018-04-07 15:32:371943
Tim van der Lippe224a8622020-09-23 12:14:371944 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371945
1946 const url = JSON.stringify(request.url());
1947
1948 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371949 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371950 const headerData = requestHeaders.reduce((result, header) => {
1951 const name = header.name;
1952
Tim van der Lippe224a8622020-09-23 12:14:371953 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371954 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341955 }
Blink Reformat4c46d092018-04-07 15:32:371956
1957 return result;
1958 }, new Headers());
1959
Tim van der Lippe224a8622020-09-23 12:14:371960 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371961 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341962 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411963 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341964 }
Blink Reformat4c46d092018-04-07 15:32:371965
Sigurd Schneider0e88b912020-05-08 08:28:231966 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371967 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411968 'include' :
1969 'omit';
Blink Reformat4c46d092018-04-07 15:32:371970
1971 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1972
1973 const referrer = referrerHeader ? referrerHeader.value : void 0;
1974
1975 const referrerPolicy = request.referrerPolicy() || void 0;
1976
1977 const requestBody = await request.requestFormData();
1978
Tim van der Lippe224a8622020-09-23 12:14:371979 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371980 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411981 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371982 referrer,
1983 referrerPolicy,
1984 body: requestBody,
1985 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371986 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371987 };
1988
Jan Scheffler7c50d1f2019-12-17 13:33:291989 if (includeCookies) {
1990 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1991 if (cookieHeader) {
1992 fetchOptions.headers = {
1993 ...headers,
1994 'cookie': cookieHeader.value,
1995 };
1996 }
1997 } else {
1998 fetchOptions.credentials = credentials;
1999 }
2000
Jan Scheffler172d5212020-01-02 14:42:562001 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372002 return `fetch(${url}, ${options});`;
2003 }
2004
2005 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132006 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:292007 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:132008 * @return {!Promise<string>}
2009 */
Jan Scheffler7c50d1f2019-12-17 13:33:292010 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:132011 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:292012 const commands =
2013 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:132014 return commands.join(' ;\n');
2015 }
2016
2017 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132018 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372019 * @param {string} platform
2020 * @return {!Promise<string>}
2021 */
2022 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562023 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362024 // Most of these headers are derived from the URL and are automatically added by cURL.
2025 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372026 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372027
Tim van der Lippe224a8622020-09-23 12:14:372028 /**
2029 * @param {string} str
2030 */
Blink Reformat4c46d092018-04-07 15:32:372031 function escapeStringWin(str) {
2032 /* If there are no new line characters do not escape the " characters
2033 since it only uglifies the command.
2034
2035 Because cmd.exe parser and MS Crt arguments parsers use some of the
2036 same escape characters, they can interact with each other in
2037 horrible ways, the order of operations is critical.
2038
2039 Replace \ with \\ first because it is an escape character for certain
2040 conditions in both parsers.
2041
2042 Replace all " with \" to ensure the first parser does not remove it.
2043
2044 Then escape all characters we are not sure about with ^ to ensure it
2045 gets to MS Crt parser safely.
2046
2047 The % character is special because MS Crt parser will try and look for
2048 ENV variables and fill them in it's place. We cannot escape them with %
2049 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2050 parser); So we can get cmd.exe parser to escape the character after it,
2051 if it is followed by a valid beginning character of an ENV variable.
2052 This ensures we do not try and double escape another ^ if it was placed
2053 by the previous replace.
2054
2055 Lastly we replace new lines with ^ and TWO new lines because the first
2056 new line is there to enact the escape command the second is the character
2057 to escape (in this case new line).
2058 */
2059 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2060 return encapsChars +
2061 str.replace(/\\/g, '\\\\')
2062 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542063 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372064 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542065 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372066 encapsChars;
2067 }
2068
2069 /**
2070 * @param {string} str
2071 * @return {string}
2072 */
2073 function escapeStringPosix(str) {
2074 /**
2075 * @param {string} x
2076 * @return {string}
2077 */
2078 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222079 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122080 let hexString = code.toString(16);
2081 // Zero pad to four digits to comply with ANSI-C Quoting:
2082 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342083 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122084 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342085 }
Joey Arhar2d21f712019-05-20 21:07:122086
2087 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372088 }
2089
Mathias Bynensf06e8c02020-02-28 13:58:282090 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372091 // Use ANSI-C quoting syntax.
2092 return '$\'' +
2093 str.replace(/\\/g, '\\\\')
2094 .replace(/\'/g, '\\\'')
2095 .replace(/\n/g, '\\n')
2096 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282097 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372098 '\'';
Blink Reformat4c46d092018-04-07 15:32:372099 }
Mathias Bynensf06e8c02020-02-28 13:58:282100 // Use single quote syntax.
2101 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372102 }
2103
2104 // cURL command expected to run on the same platform that DevTools run
2105 // (it may be different from the inspected page platform).
2106 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2107
2108 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2109
2110 let inferredMethod = 'GET';
2111 const data = [];
2112 const requestContentType = request.requestContentType();
2113 const formData = await request.requestFormData();
2114 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272115 // Note that formData is not necessarily urlencoded because it might for example
2116 // come from a fetch request made with an explicitly unencoded body.
2117 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372118 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372119 inferredMethod = 'POST';
2120 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112121 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372122 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372123 inferredMethod = 'POST';
2124 }
2125
2126 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292127 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372128 }
2129
2130 const requestHeaders = request.requestHeaders();
2131 for (let i = 0; i < requestHeaders.length; i++) {
2132 const header = requestHeaders[i];
2133 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372134 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372135 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342136 }
Jan Scheffler172d5212020-01-02 14:42:562137 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372138 }
2139 command = command.concat(data);
2140 command.push('--compressed');
2141
Tim van der Lippe1d6e57a2019-09-30 11:55:342142 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372143 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342144 }
Jan Scheffler172d5212020-01-02 14:42:562145 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372146 }
2147
2148 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132149 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132150 * @param {string} platform
2151 * @return {!Promise<string>}
2152 */
2153 async _generateAllCurlCommand(requests, platform) {
2154 const nonBlobRequests = this._filterOutBlobRequests(requests);
2155 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342156 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132157 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342158 }
Mathias Bynensf06e8c02020-02-28 13:58:282159 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132160 }
2161
2162 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132163 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372164 * @return {!Promise<string>}
2165 */
2166 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562167 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372168 const ignoredHeaders =
2169 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2170
2171 /**
2172 * @param {string} str
2173 * @return {string}
2174 */
2175 function escapeString(str) {
2176 return '"' +
2177 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2178 }
2179
Jan Scheffler172d5212020-01-02 14:42:562180 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372181
2182 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562183 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372184 }
2185
2186 const requestHeaders = request.requestHeaders();
2187 const headerNameValuePairs = [];
2188 for (const header of requestHeaders) {
2189 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342190 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372191 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342192 }
Blink Reformat4c46d092018-04-07 15:32:372193 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2194 }
2195 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562196 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372197 }
2198
2199 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2200 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562201 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372202 }
2203
2204 const formData = await request.requestFormData();
2205 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372206 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342207 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562208 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342209 } else {
Jan Scheffler172d5212020-01-02 14:42:562210 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342211 }
Blink Reformat4c46d092018-04-07 15:32:372212 }
2213
Jan Scheffler172d5212020-01-02 14:42:562214 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372215 }
Harley Libcf41f92018-09-10 18:01:132216
2217 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132218 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132219 * @return {!Promise<string>}
2220 */
2221 async _generateAllPowerShellCommand(requests) {
2222 const nonBlobRequests = this._filterOutBlobRequests(requests);
2223 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2224 return commands.join(';\r\n');
2225 }
Joey Arhara86c14e2019-03-12 03:20:502226
2227 /**
2228 * @return {string}
2229 */
2230 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512231 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502232 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342233 }
Joey Arhara86c14e2019-03-12 03:20:502234 return '#0867CB';
2235 }
2236
2237 /**
2238 * @return {string}
2239 */
2240 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512241 return ThemeSupport.ThemeSupport.instance().patchColorText(
2242 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502243 }
Paul Lewis56509652019-12-06 12:51:582244}
Blink Reformat4c46d092018-04-07 15:32:372245
Tim van der Lippeb4faf5a2020-11-06 15:02:022246/**
2247 * @param {!Protocol.Runtime.StackTrace} stackTrace
2248 */
2249export function computeStackTraceText(stackTrace) {
2250 let stackTraceText = '';
2251 for (const frame of stackTrace.callFrames) {
2252 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2253 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2254 }
2255 if (stackTrace.parent) {
2256 stackTraceText += computeStackTraceText(stackTrace.parent);
2257 }
2258 return stackTraceText;
2259}
2260
Tim van der Lippe224a8622020-09-23 12:14:372261/** @type {!WeakSet<!NetworkRequestNode>} */
2262const filteredNetworkRequests = new WeakSet();
2263/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2264const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372265
Tim van der Lippe3dc5fd62020-09-22 13:12:222266/**
2267 * @param {!NetworkRequestNode} request
2268 * @return {boolean}
2269 */
2270export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372271 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222272}
2273
Paul Lewis56509652019-12-06 12:51:582274export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372275 'http': true,
2276 'https': true,
2277 'ws': true,
2278 'wss': true
2279};
2280
Blink Reformat4c46d092018-04-07 15:32:372281/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582282export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372283 Domain: 'domain',
2284 HasResponseHeader: 'has-response-header',
2285 Is: 'is',
2286 LargerThan: 'larger-than',
2287 Method: 'method',
2288 MimeType: 'mime-type',
2289 MixedContent: 'mixed-content',
2290 Priority: 'priority',
2291 Scheme: 'scheme',
2292 SetCookieDomain: 'set-cookie-domain',
2293 SetCookieName: 'set-cookie-name',
2294 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032295 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412296 CookieDomain: 'cookie-domain',
2297 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542298 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412299 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032300 StatusCode: 'status-code',
2301 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372302};
2303
2304/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582305export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372306 All: 'all',
2307 Displayed: 'displayed',
2308 Blocked: 'blocked',
2309 BlockOverridden: 'block-overridden'
2310};
2311
2312/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582313export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372314 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052315 FromCache: 'from-cache',
2316 ServiceWorkerIntercepted: 'service-worker-intercepted',
2317 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372318};
2319
2320/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372321export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372322
2323/**
2324 * @interface
2325 */
Paul Lewis56509652019-12-06 12:51:582326export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372327 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302329 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372330 */
Paul Lewis56509652019-12-06 12:51:582331 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372332 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582333 }
Blink Reformat4c46d092018-04-07 15:32:372334
Paul Lewis56509652019-12-06 12:51:582335 reset() {
2336 }
2337}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162338
2339/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372340// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162341export let Filter;