blob: 74a5fd6e92003627ec96059fb7dce302a0c1921e [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';
49import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
50
Blink Reformat4c46d092018-04-07 15:32:3751/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1352 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3053 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3754 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1355export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3756 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1357 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3758 * @param {!Element} progressBarContainer
Tim van der Lippe224a8622020-09-23 12:14:3759 * @param {!Common.Settings.Setting<number>} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3760 */
61 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
62 super();
63 this.setMinimumSize(50, 64);
64 this.registerRequiredCSS('network/networkLogView.css');
65
66 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0567 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3768
Paul Lewis2d7d65c2020-03-16 17:26:3069 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
70 this._networkShowIssuesOnlySetting =
71 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
72 this._networkOnlyBlockedRequestsSetting =
73 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
74 this._networkResourceTypeFiltersSetting =
75 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3776
77 this._rawRowHeight = 0;
78 this._progressBarContainer = progressBarContainer;
79 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
80 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
81
82 /**
Paul Lewis56509652019-12-06 12:51:5883 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3784 */
85 function updateRowHeight() {
86 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
87 this._rowHeight = this._computeRowHeight();
88 }
89 this._rawRowHeight = 0;
90 this._rowHeight = 0;
91 updateRowHeight.call(this);
92
Tim van der Lippe119690c2020-01-13 12:31:3093 /** @type {!NetworkTransferTimeCalculator} */
94 this._timeCalculator = new NetworkTransferTimeCalculator();
95 /** @type {!NetworkTransferDurationCalculator} */
96 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3797 this._calculator = this._timeCalculator;
98
Tim van der Lippe119690c2020-01-13 12:31:3099 this._columns =
100 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37101 this._columns.show(this.element);
102
Tim van der Lippe0ed1d2b2020-02-04 13:45:13103 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37104 this._staleRequests = new Set();
105 /** @type {number} */
106 this._mainRequestLoadTime = -1;
107 /** @type {number} */
108 this._mainRequestDOMContentLoadedTime = -1;
Tim van der Lippe224a8622020-09-23 12:14:37109 /** @type {*} */
Blink Reformat4c46d092018-04-07 15:32:37110 this._highlightedSubstringChanges = [];
111
Tim van der Lippeb1f2b6c2020-02-17 13:00:16112 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37113 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16114 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37115 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30116 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37117 this._hoveredNode = null;
118 /** @type {?Element} */
119 this._recordingHint = null;
120 /** @type {?number} */
121 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30122 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37123 this._highlightedNode = null;
124
Simon Zündcdd72c92020-10-07 11:48:13125 this._linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37126
127 this._recording = false;
128 this._needsRefresh = false;
129
130 this._headerHeight = 0;
131
Paul Lewis56509652019-12-06 12:51:58132 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37133 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30134 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37135
Paul Lewis56509652019-12-06 12:51:58136 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37137 this._activeGroupLookup = null;
138
Tim van der Lippe0ed1d2b2020-02-04 13:45:13139 this._textFilterUI = new UI.FilterBar.TextFilterUI();
140 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37141 filterBar.addFilter(this._textFilterUI);
142
Tim van der Lippe0ed1d2b2020-02-04 13:45:13143 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
144 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
145 this._dataURLFilterUI.addEventListener(
146 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48147 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37148 filterBar.addFilter(this._dataURLFilterUI);
149
150 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13151 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37152 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13153 this._resourceCategoryFilterUI =
154 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20155 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37156 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13157 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37158 filterBar.addFilter(this._resourceCategoryFilterUI);
159
Tim van der Lippe0ed1d2b2020-02-04 13:45:13160 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
161 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
162 this._onlyIssuesFilterUI.addEventListener(
163 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41164 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37165 filterBar.addFilter(this._onlyIssuesFilterUI);
166
Sigurd Schneidera2afe0b2020-03-03 15:27:13167 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
168 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
169 this._onlyBlockedRequestsUI.addEventListener(
170 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
171 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
172 filterBar.addFilter(this._onlyBlockedRequestsUI);
173
Jan Scheffler1ae7c9e2019-12-03 15:48:37174
Tim van der Lippe0ed1d2b2020-02-04 13:45:13175 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
176 this._suggestionBuilder =
177 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37178 this._resetSuggestionBuilder();
179
180 this._dataGrid = this._columns.dataGrid();
181 this._setupDataGrid();
182 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49183 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13184 UI.Toolbar.ToolbarButton.Events.Click,
185 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37186
Tim van der Lippe0ed1d2b2020-02-04 13:45:13187 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37188
Tim van der Lippe0ed1d2b2020-02-04 13:45:13189 new UI.DropTarget.DropTarget(
190 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
191 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37192
Paul Lewis2d7d65c2020-03-16 17:26:30193 Common.Settings.Settings.instance()
194 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37195 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
196
Paul Lewisdaac1062020-03-05 14:37:10197 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27198 SDK.NetworkLog.NetworkLog.instance().addEventListener(
199 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
200 SDK.NetworkLog.NetworkLog.instance().addEventListener(
201 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
202 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37203
204 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30205 Common.Settings.Settings.instance()
206 .moduleSetting('network.group-by-frame')
207 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37208
209 this._filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03210
211 this._textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
212 if (this._textFilterSetting.get()) {
213 this.setTextFilterValue(this._textFilterSetting.get());
214 }
Blink Reformat4c46d092018-04-07 15:32:37215 }
216
Blink Reformat4c46d092018-04-07 15:32:37217 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30218 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37219 this._setGrouping(value ? 'Frame' : null);
220 }
221
222 /**
223 * @param {string} key
224 * @param {!Array<string>} values
225 */
226 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58227 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37228 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50229 const aPriority =
230 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
231 const bPriority =
232 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
233 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
234 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37235 });
236 } else {
237 values.sort();
238 }
239 }
240
241 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16242 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13243 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37244 * @return {boolean}
245 */
246 static _negativeFilter(filter, request) {
247 return !filter(request);
248 }
249
250 /**
251 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13252 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37253 * @return {boolean}
254 */
255 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34256 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37257 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34258 }
Blink Reformat4c46d092018-04-07 15:32:37259
260 return regex.test(request.path() + '/' + request.name());
261 }
262
263 /**
264 * @param {string} domain
265 * @return {!Array.<string>}
266 */
267 static _subdomains(domain) {
268 const result = [domain];
269 let indexOfPeriod = domain.indexOf('.');
270 while (indexOfPeriod !== -1) {
271 result.push('*' + domain.substring(indexOfPeriod));
272 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
273 }
274 return result;
275 }
276
277 /**
278 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16279 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37280 */
281 static _createRequestDomainFilter(value) {
282 /**
283 * @param {string} string
284 * @return {string}
285 */
286 function escapeForRegExp(string) {
287 return string.escapeForRegExp();
288 }
289 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58290 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37291 }
292
293 /**
294 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13295 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37296 * @return {boolean}
297 */
298 static _requestDomainFilter(regex, request) {
299 return regex.test(request.domain);
300 }
301
302 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13303 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37304 * @return {boolean}
305 */
306 static _runningRequestFilter(request) {
307 return !request.finished;
308 }
309
310 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13311 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37312 * @return {boolean}
313 */
314 static _fromCacheRequestFilter(request) {
315 return request.cached();
316 }
317
318 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13319 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05320 * @return {boolean}
321 */
322 static _interceptedByServiceWorkerFilter(request) {
323 return request.fetchedViaServiceWorker;
324 }
325
326 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13327 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05328 * @return {boolean}
329 */
330 static _initiatedByServiceWorkerFilter(request) {
331 return request.initiatedByServiceWorker();
332 }
333
334 /**
Blink Reformat4c46d092018-04-07 15:32:37335 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13336 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37337 * @return {boolean}
338 */
339 static _requestResponseHeaderFilter(value, request) {
340 return request.responseHeaderValue(value) !== undefined;
341 }
342
343 /**
344 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13345 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37346 * @return {boolean}
347 */
348 static _requestMethodFilter(value, request) {
349 return request.requestMethod === value;
350 }
351
352 /**
353 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13354 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37355 * @return {boolean}
356 */
357 static _requestPriorityFilter(value, request) {
358 return request.priority() === value;
359 }
360
361 /**
362 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13363 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37364 * @return {boolean}
365 */
366 static _requestMimeTypeFilter(value, request) {
367 return request.mimeType === value;
368 }
369
370 /**
Paul Lewis56509652019-12-06 12:51:58371 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13372 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37373 * @return {boolean}
374 */
375 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58376 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37377 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28378 }
379 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37380 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28381 }
382 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37383 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28384 }
385 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37386 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34387 }
Blink Reformat4c46d092018-04-07 15:32:37388
389 return false;
390 }
391
392 /**
393 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13394 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37395 * @return {boolean}
396 */
397 static _requestSchemeFilter(value, request) {
398 return request.scheme === value;
399 }
400
401 /**
402 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13403 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37404 * @return {boolean}
405 */
Jan Scheffler341eea52019-12-12 09:08:41406 static _requestCookieDomainFilter(value, request) {
407 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
408 }
409
410 /**
411 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13412 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41413 * @return {boolean}
414 */
415 static _requestCookieNameFilter(value, request) {
416 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
417 }
418
419 /**
420 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13421 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41422 * @return {boolean}
423 */
Simon Zündc9759102020-03-25 11:24:54424 static _requestCookiePathFilter(value, request) {
425 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
426 }
427
428 /**
429 * @param {string} value
430 * @param {!SDK.NetworkRequest.NetworkRequest} request
431 * @return {boolean}
432 */
Jan Scheffler341eea52019-12-12 09:08:41433 static _requestCookieValueFilter(value, request) {
434 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
435 }
436
437 /**
438 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13439 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41440 * @return {boolean}
441 */
Blink Reformat4c46d092018-04-07 15:32:37442 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41443 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37444 }
445
446 /**
447 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13448 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37449 * @return {boolean}
450 */
451 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41452 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37453 }
454
455 /**
456 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13457 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37458 * @return {boolean}
459 */
460 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41461 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37462 }
463
464 /**
465 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13466 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37467 * @return {boolean}
468 */
469 static _requestSizeLargerThanFilter(value, request) {
470 return request.transferSize >= value;
471 }
472
473 /**
474 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13475 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37476 * @return {boolean}
477 */
478 static _statusCodeFilter(value, request) {
479 return ('' + request.statusCode) === value;
480 }
481
482 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13483 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37484 * @return {boolean}
485 */
486 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58487 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37488 }
489
Sigurd Schneider464838b2020-08-24 13:53:03490
491 /**
492 * @param {string} value
493 * @param {!SDK.NetworkRequest.NetworkRequest} request
494 * @return {boolean}
495 */
496 static _resourceTypeFilter(value, request) {
497 return request.resourceType().name() === value;
498 }
499
Blink Reformat4c46d092018-04-07 15:32:37500 /**
Julian Geppertf8ce40c2020-09-01 18:02:03501 * @param {string} value
502 * @param {!SDK.NetworkRequest.NetworkRequest} request
503 * @return {boolean}
504 */
505 static _requestUrlFilter(value, request) {
506 const regex = new RegExp(value.escapeForRegExp(), 'i');
507 return regex.test(request.url());
508 }
509
510 /**
Blink Reformat4c46d092018-04-07 15:32:37511 * @param {number} windowStart
512 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13513 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37514 * @return {boolean}
515 */
516 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34517 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37518 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 }
520 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37521 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34522 }
Blink Reformat4c46d092018-04-07 15:32:37523 return true;
524 }
525
526 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13527 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37528 */
529 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13530 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37531 }
532
533 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13534 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37535 */
536 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13537 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37538 }
539
540 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13541 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37542 */
543 static async _copyResponse(request) {
544 const contentData = await request.contentData();
Tim van der Lippe224a8622020-09-23 12:14:37545 /** @type {?string} */
Ingvar Stepanyan1c771842018-10-10 14:35:08546 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34547 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40548 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37549 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08550 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34551 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13552 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37553 }
554
555 /**
556 * @param {!DataTransfer} dataTransfer
557 */
558 _handleDrop(dataTransfer) {
559 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34560 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37561 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34562 }
Blink Reformat4c46d092018-04-07 15:32:37563 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34564 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37565 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34566 }
Blink Reformat4c46d092018-04-07 15:32:37567
Joey Arhar0e1093c2019-05-21 00:34:22568 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37569 }
570
571 /**
Tim van der Lippe119690c2020-01-13 12:31:30572 * @override
Blink Reformat4c46d092018-04-07 15:32:37573 * @param {!File} file
574 */
Joey Arhar0e1093c2019-05-21 00:34:22575 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13576 const outputStream = new Common.StringOutputStream.StringOutputStream();
577 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37578 const success = await reader.read(outputStream);
579 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37580 const error = reader.error();
581 if (error) {
582 this._harLoadFailed(/** @type {*} */ (error).message);
583 }
Blink Reformat4c46d092018-04-07 15:32:37584 return;
585 }
586 let harRoot;
587 try {
588 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13589 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37590 } catch (e) {
591 this._harLoadFailed(e);
592 return;
593 }
Wolfgang Beyerd81fad62020-05-27 12:30:27594 SDK.NetworkLog.NetworkLog.instance().importRequests(
595 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37596 }
597
598 /**
599 * @param {string} message
600 */
601 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36602 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37603 }
604
605 /**
606 * @param {?string} groupKey
607 */
608 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34609 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37610 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34611 }
Blink Reformat4c46d092018-04-07 15:32:37612 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
613 this._activeGroupLookup = groupLookup;
614 this._invalidateAllItems();
615 }
616
617 /**
618 * @return {number}
619 */
620 _computeRowHeight() {
621 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
622 }
623
624 /**
Tim van der Lippe119690c2020-01-13 12:31:30625 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13626 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30627 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37628 */
629 nodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:37630 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37631 }
632
633 /**
Tim van der Lippe119690c2020-01-13 12:31:30634 * @override
Blink Reformat4c46d092018-04-07 15:32:37635 * @return {number}
636 */
637 headerHeight() {
638 return this._headerHeight;
639 }
640
641 /**
Tim van der Lippe119690c2020-01-13 12:31:30642 * @override
Blink Reformat4c46d092018-04-07 15:32:37643 * @param {boolean} recording
644 */
645 setRecording(recording) {
646 this._recording = recording;
647 this._updateSummaryBar();
648 }
649
650 /**
651 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13652 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37653 */
654 modelAdded(networkManager) {
655 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34656 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37657 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34658 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13659 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37660 if (resourceTreeModel) {
661 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
662 resourceTreeModel.addEventListener(
663 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
664 }
665 }
666
667 /**
668 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13669 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37670 */
671 modelRemoved(networkManager) {
672 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13673 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37674 if (resourceTreeModel) {
675 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
676 resourceTreeModel.removeEventListener(
677 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
678 }
679 }
680 }
681
682 /**
Tim van der Lippe119690c2020-01-13 12:31:30683 * @override
Simon Zündcdd72c92020-10-07 11:48:13684 * @return {!Components.Linkifier.Linkifier}
685 */
686 linkifier() {
687 return this._linkifier;
688 }
689
690 /**
691 * @override
Blink Reformat4c46d092018-04-07 15:32:37692 * @param {number} start
693 * @param {number} end
694 */
695 setWindow(start, end) {
696 if (!start && !end) {
697 this._timeFilter = null;
698 this._timeCalculator.setWindow(null);
699 } else {
Paul Lewis56509652019-12-06 12:51:58700 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30701 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37702 }
703 this._filterRequests();
704 }
705
Tim van der Lippe119690c2020-01-13 12:31:30706 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05707 resetFocus() {
708 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37709 }
710
711 _resetSuggestionBuilder() {
712 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58713 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
714 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
715 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
716 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
717 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
718 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
719 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37720 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
721 }
722
723 /**
Tim van der Lippec02a97c2020-02-14 14:39:27724 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37725 */
726 _filterChanged(event) {
727 this.removeAllNodeHighlights();
728 this._parseFilterQuery(this._textFilterUI.value());
729 this._filterRequests();
Jack Frankline3cb2802020-09-07 09:58:03730 this._textFilterSetting.set(this._textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37731 }
732
Rajasekar Murugan3ad369e2020-02-19 18:20:12733 async resetFilter() {
734 this._textFilterUI.clear();
735 }
736
Blink Reformat4c46d092018-04-07 15:32:37737 _showRecordingHint() {
738 this._hideRecordingHint();
739 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
740 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18741
742 let reloadShortcutNode = null;
Tim van der Lippe9c9fb122020-09-08 15:06:17743 const reloadShortcut =
744 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
Jack Lynchb8fb3c72020-04-21 05:36:16745 if (reloadShortcut) {
Joey Arhar0585e6f2018-10-30 23:11:18746 reloadShortcutNode = this._recordingHint.createChild('b');
Jack Lynchb8fb3c72020-04-21 05:36:16747 reloadShortcutNode.textContent = reloadShortcut.title();
Joey Arhar0585e6f2018-10-30 23:11:18748 }
Blink Reformat4c46d092018-04-07 15:32:37749
750 if (this._recording) {
751 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38752 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18753 if (reloadShortcutNode) {
754 hintText.createChild('br');
755 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13756 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18757 }
Blink Reformat4c46d092018-04-07 15:32:37758 } else {
759 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17760 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37761 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Joey Arhar0585e6f2018-10-30 23:11:18762 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13763 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18764 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
765 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13766 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18767 }
Blink Reformat4c46d092018-04-07 15:32:37768 }
Kayce Basques5444c1b2019-02-15 20:32:53769 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13770 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53771 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43772 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11773
774 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57775 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37776 }
777
778 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11779 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34780 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37781 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34782 }
Brandon Goddardc992d522020-01-08 21:44:57783 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37784 this._recordingHint = null;
785 }
786
787 /**
Amanda Baker6761aae2019-11-05 18:59:11788 * @param {boolean} value
789 */
790 _setHidden(value) {
791 this._columns.setHidden(value);
792 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
793 }
794
795 /**
Blink Reformat4c46d092018-04-07 15:32:37796 * @override
797 * @return {!Array.<!Element>}
798 */
799 elementsToRestoreScrollPositionsFor() {
800 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34801 {
Blink Reformat4c46d092018-04-07 15:32:37802 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34803 }
Blink Reformat4c46d092018-04-07 15:32:37804 return [this._dataGrid.scrollContainer];
805 }
806
Tim van der Lippe119690c2020-01-13 12:31:30807 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37808 columnExtensionResolved() {
809 this._invalidateAllItems(true);
810 }
811
812 _setupDataGrid() {
813 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Andres Olivares03d9c752020-10-01 15:08:11814 const request = (/** @type {!NetworkNode} */ (node)).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34815 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37816 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34817 }
Blink Reformat4c46d092018-04-07 15:32:37818 });
819 this._dataGrid.setStickToBottom(true);
820 this._dataGrid.setName('networkLog');
821 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
822 this._dataGrid.element.classList.add('network-log-grid');
823 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
824 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
825 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05826 this._dataGrid.element.addEventListener('keydown', event => {
827 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05828 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05829 event.consume(true);
830 }
831 });
Brandon Goddard44934902020-03-25 16:03:18832 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
833 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37834 return this._dataGrid;
835 }
836
837 /**
838 * @param {!Event} event
839 */
840 _dataGridMouseMove(event) {
Tim van der Lippe224a8622020-09-23 12:14:37841 const mouseEvent = /** @type {!MouseEvent} */ (event);
Andres Olivares03d9c752020-10-01 15:08:11842 const node =
843 /** @type {!NetworkNode} */ (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (mouseEvent.target)));
Tim van der Lippe224a8622020-09-23 12:14:37844 const highlightInitiatorChain = mouseEvent.shiftKey;
Blink Reformat4c46d092018-04-07 15:32:37845 this._setHoveredNode(node, highlightInitiatorChain);
846 }
847
848 /**
Tim van der Lippe119690c2020-01-13 12:31:30849 * @override
850 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37851 */
852 hoveredNode() {
853 return this._hoveredNode;
854 }
855
856 /**
Tim van der Lippe119690c2020-01-13 12:31:30857 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37858 * @param {boolean=} highlightInitiatorChain
859 */
860 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34861 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37862 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34863 }
Blink Reformat4c46d092018-04-07 15:32:37864 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34865 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37866 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34867 }
Blink Reformat4c46d092018-04-07 15:32:37868 }
869
870 /**
871 * @param {!Event} event
872 */
873 _dataGridMouseDown(event) {
Tim van der Lippe224a8622020-09-23 12:14:37874 const mouseEvent = /** @type {!MouseEvent} */ (event);
875 if (!this._dataGrid.selectedNode && mouseEvent.button) {
876 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34877 }
Blink Reformat4c46d092018-04-07 15:32:37878 }
879
880 _updateSummaryBar() {
881 this._hideRecordingHint();
882
883 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20884 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37885 let selectedNodeNumber = 0;
886 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20887 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37888 let baseTime = -1;
889 let maxTime = -1;
890
891 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27892 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:37893 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34894 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37895 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34896 }
Blink Reformat4c46d092018-04-07 15:32:37897 nodeCount++;
898 const requestTransferSize = request.transferSize;
899 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20900 const requestResourceSize = request.resourceSize;
901 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:37902 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:37903 selectedNodeNumber++;
904 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20905 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37906 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13907 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37908 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
909 // inspected url.
910 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13911 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
912 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37913 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 }
915 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37916 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34917 }
Blink Reformat4c46d092018-04-07 15:32:37918 }
919
920 if (!nodeCount) {
921 this._showRecordingHint();
922 return;
923 }
924
Joey Arhara86c14e2019-03-12 03:20:50925 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37926 /**
927 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50928 * @param {string=} title
Tim van der Lippe224a8622020-09-23 12:14:37929 * @return {!HTMLDivElement}
Blink Reformat4c46d092018-04-07 15:32:37930 */
Joey Arhara86c14e2019-03-12 03:20:50931 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13932 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50933 toolbarText.setTitle(title ? title : chunk);
934 this._summaryToolbar.appendToolbarItem(toolbarText);
Tim van der Lippe224a8622020-09-23 12:14:37935 return /** @type {!HTMLDivElement} */ (toolbarText.element);
Joey Arhara86c14e2019-03-12 03:20:50936 };
Blink Reformat4c46d092018-04-07 15:32:37937
938 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50939 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
940 this._summaryToolbar.appendSeparator();
941 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17942 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
943 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25944 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50945 this._summaryToolbar.appendSeparator();
946 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17947 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
948 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25949 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37950 } else {
Joey Arhara86c14e2019-03-12 03:20:50951 appendChunk(ls`${nodeCount} requests`);
952 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25953 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17954 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
955 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50956 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25957 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17958 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
959 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37960 }
Dan Beam87466b52018-12-01 18:41:20961
Blink Reformat4c46d092018-04-07 15:32:37962 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50963 this._summaryToolbar.appendSeparator();
964 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37965 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50966 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30967 const domContentLoadedText =
968 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58969 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37970 }
971 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50972 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30973 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58974 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37975 }
976 }
Blink Reformat4c46d092018-04-07 15:32:37977 }
978
Tim van der Lippe119690c2020-01-13 12:31:30979 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37980 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34981 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37982 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34983 }
Blink Reformat4c46d092018-04-07 15:32:37984
985 this._needsRefresh = true;
986
Tim van der Lippe1d6e57a2019-09-30 11:55:34987 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37988 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34989 }
Blink Reformat4c46d092018-04-07 15:32:37990 }
991
992 /**
Tim van der Lippe119690c2020-01-13 12:31:30993 * @override
Blink Reformat4c46d092018-04-07 15:32:37994 * @param {!Array<number>} times
995 */
996 addFilmStripFrames(times) {
997 this._columns.addEventDividers(times, 'network-frame-divider');
998 }
999
1000 /**
Tim van der Lippe119690c2020-01-13 12:31:301001 * @override
Blink Reformat4c46d092018-04-07 15:32:371002 * @param {number} time
1003 */
1004 selectFilmStripFrame(time) {
1005 this._columns.selectFilmStripFrame(time);
1006 }
1007
Tim van der Lippe119690c2020-01-13 12:31:301008 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371009 clearFilmStripFrame() {
1010 this._columns.clearFilmStripFrame();
1011 }
1012
1013 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341014 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371015 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341016 }
Blink Reformat4c46d092018-04-07 15:32:371017 }
1018
1019 /**
1020 * @param {boolean=} deferUpdate
1021 */
1022 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271023 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341024 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371025 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341026 } else {
Blink Reformat4c46d092018-04-07 15:32:371027 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341028 }
Blink Reformat4c46d092018-04-07 15:32:371029 }
1030
1031 /**
Tim van der Lippe119690c2020-01-13 12:31:301032 * @override
1033 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371034 */
1035 timeCalculator() {
1036 return this._timeCalculator;
1037 }
1038
1039 /**
Tim van der Lippe119690c2020-01-13 12:31:301040 * @override
1041 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371042 */
1043 calculator() {
1044 return this._calculator;
1045 }
1046
1047 /**
Tim van der Lippe119690c2020-01-13 12:31:301048 * @override
1049 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371050 */
1051 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341052 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371053 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341054 }
Blink Reformat4c46d092018-04-07 15:32:371055
1056 if (this._calculator !== x) {
1057 this._calculator = x;
1058 this._columns.setCalculator(this._calculator);
1059 }
1060 this._calculator.reset();
1061
Tim van der Lippe1d6e57a2019-09-30 11:55:341062 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371063 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341064 } else {
Blink Reformat4c46d092018-04-07 15:32:371065 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341066 }
Blink Reformat4c46d092018-04-07 15:32:371067
1068 this._invalidateAllItems();
1069 }
1070
1071 /**
Tim van der Lippec02a97c2020-02-14 14:39:271072 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371073 */
1074 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341075 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371076 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341077 }
Blink Reformat4c46d092018-04-07 15:32:371078
1079 const time = /** @type {number} */ (event.data.loadTime);
1080 if (time) {
1081 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301082 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371083 }
1084 }
1085
1086 /**
Tim van der Lippec02a97c2020-02-14 14:39:271087 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371088 */
1089 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341090 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371091 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341092 }
Blink Reformat4c46d092018-04-07 15:32:371093 const data = /** @type {number} */ (event.data);
1094 if (data) {
1095 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301096 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371097 }
1098 }
1099
1100 /**
1101 * @override
1102 */
1103 wasShown() {
1104 this._refreshIfNeeded();
1105 this._columns.wasShown();
1106 }
1107
1108 /**
1109 * @override
1110 */
1111 willHide() {
1112 this._columns.willHide();
1113 }
1114
1115 /**
1116 * @override
1117 */
1118 onResize() {
1119 this._rowHeight = this._computeRowHeight();
1120 }
1121
1122 /**
Tim van der Lippe119690c2020-01-13 12:31:301123 * @override
1124 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371125 */
1126 flatNodesList() {
Andres Olivares21ab05b2020-10-21 14:00:021127 /** @type {!DataGrid.ViewportDataGrid.ViewportDataGridNode<!DataGrid.SortableDataGrid.SortableDataGridNode<!NetworkNode>>} */
1128 const rootNode = (this._dataGrid.rootNode());
1129 return /** @type {!Array<!NetworkNode>} */ (rootNode.flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371130 }
1131
Brandon Goddard44934902020-03-25 16:03:181132 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491133 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351134 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381135 }
Brandon Goddard44934902020-03-25 16:03:181136 this.updateNodeBackground();
1137 }
1138
1139 _onDataGridBlur() {
1140 this.element.classList.remove('grid-focused');
1141 this.updateNodeBackground();
1142 }
1143
Tim van der Lippe119690c2020-01-13 12:31:301144 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051145 updateNodeBackground() {
1146 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111147 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051148 }
1149 }
1150
1151 /**
Tim van der Lippe119690c2020-01-13 12:31:301152 * @override
Brandon Goddard88d885a2019-10-31 16:11:051153 * @param {boolean} isSelected
1154 */
1155 updateNodeSelectedClass(isSelected) {
1156 if (isSelected) {
1157 this.element.classList.remove('no-node-selected');
1158 } else {
1159 this.element.classList.add('no-node-selected');
1160 }
1161 }
1162
Tim van der Lippe119690c2020-01-13 12:31:301163 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371164 stylesChanged() {
1165 this._columns.scheduleRefresh();
1166 }
1167
1168 _refresh() {
1169 this._needsRefresh = false;
1170
1171 if (this._refreshRequestId) {
1172 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1173 this._refreshRequestId = null;
1174 }
1175
1176 this.removeAllNodeHighlights();
1177
1178 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1179 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1180 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1181 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1182
Tim van der Lippe224a8622020-09-23 12:14:371183 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371184 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301185 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371186 const nodesToRefresh = [];
1187
Tim van der Lippe119690c2020-01-13 12:31:301188 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371189 const staleNodes = new Set();
1190
1191 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1192 // node so we loop until we have no more stale requests.
1193 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371194 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371195 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371196 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371198 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341199 }
Blink Reformat4c46d092018-04-07 15:32:371200 staleNodes.add(node);
1201 }
1202
1203 for (const node of staleNodes) {
1204 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341205 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371206 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 }
Blink Reformat4c46d092018-04-07 15:32:371208
Tim van der Lippe1d6e57a2019-09-30 11:55:341209 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371210 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341211 }
Blink Reformat4c46d092018-04-07 15:32:371212 const request = node.request();
1213 this._timeCalculator.updateBoundaries(request);
1214 this._durationCalculator.updateBoundaries(request);
1215 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371216 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1217 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371218 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341219 }
Tim van der Lippe224a8622020-09-23 12:14:371220 if (isFilteredOut) {
1221 filteredNetworkRequests.add(node);
1222 } else {
1223 filteredNetworkRequests.delete(node);
1224 }
Blink Reformat4c46d092018-04-07 15:32:371225 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1226 if (removeFromParent) {
1227 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111228 if (!parent) {
1229 continue;
1230 }
Blink Reformat4c46d092018-04-07 15:32:371231 parent.removeChild(node);
1232 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111233 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371234 grandparent.removeChild(parent);
1235 parent = grandparent;
1236 }
1237 }
1238
Tim van der Lippe1d6e57a2019-09-30 11:55:341239 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371240 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341241 }
Blink Reformat4c46d092018-04-07 15:32:371242
1243 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111244 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371245 nodesToRefresh.push(newParent);
1246 }
1247 nodesToInsert.set(node, newParent);
1248 }
1249
Tim van der Lippe1d6e57a2019-09-30 11:55:341250 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371251 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341252 }
Blink Reformat4c46d092018-04-07 15:32:371253
Tim van der Lippe1d6e57a2019-09-30 11:55:341254 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371255 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341256 }
Blink Reformat4c46d092018-04-07 15:32:371257
1258 this._updateSummaryBar();
1259
Tim van der Lippe1d6e57a2019-09-30 11:55:341260 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371261 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341262 }
Blink Reformat4c46d092018-04-07 15:32:371263
1264 this._dataGrid.updateInstantly();
1265 this._didRefreshForTest();
1266 }
1267
1268 _didRefreshForTest() {
1269 }
1270
1271 /**
Tim van der Lippe119690c2020-01-13 12:31:301272 * @param {!NetworkRequestNode} node
1273 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371274 */
1275 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111277 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341278 }
Blink Reformat4c46d092018-04-07 15:32:371279
1280 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341281 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111282 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341283 }
Blink Reformat4c46d092018-04-07 15:32:371284 return groupNode;
1285 }
1286
1287 _reset() {
Simon Zünd98419832020-03-12 06:18:151288 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371289
1290 this._setHoveredNode(null);
1291 this._columns.reset();
1292
1293 this._timeFilter = null;
1294 this._calculator.reset();
1295
1296 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131297 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371298
Tim van der Lippe1d6e57a2019-09-30 11:55:341299 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371300 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341301 }
Blink Reformat4c46d092018-04-07 15:32:371302 this._staleRequests.clear();
1303 this._resetSuggestionBuilder();
1304
1305 this._mainRequestLoadTime = -1;
1306 this._mainRequestDOMContentLoadedTime = -1;
1307
1308 this._dataGrid.rootNode().removeChildren();
1309 this._updateSummaryBar();
1310 this._dataGrid.setStickToBottom(true);
1311 this.scheduleRefresh();
1312 }
1313
1314 /**
Tim van der Lippe119690c2020-01-13 12:31:301315 * @override
Blink Reformat4c46d092018-04-07 15:32:371316 * @param {string} filterString
1317 */
1318 setTextFilterValue(filterString) {
1319 this._textFilterUI.setValue(filterString);
1320 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371321 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131322 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371323 this._resourceCategoryFilterUI.reset();
1324 }
1325
1326 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131327 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371328 */
1329 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301330 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371331 networkRequestToNode.set(request, node);
1332 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371333
Tim van der Lippe1d6e57a2019-09-30 11:55:341334 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371335 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341336 }
Blink Reformat4c46d092018-04-07 15:32:371337 return node;
1338 }
1339
1340 /**
Tim van der Lippec02a97c2020-02-14 14:39:271341 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371342 */
1343 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131344 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371345 this._refreshRequest(request);
1346 }
1347
1348 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131349 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371350 */
1351 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581352 NetworkLogView._subdomains(request.domain)
1353 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1354 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1355 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1356 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1357 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Sigurd Schneider464838b2020-08-24 13:53:031358 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031359 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371360
1361 const priority = request.priority();
1362 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501363 this._suggestionBuilder.addItem(
1364 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371365 }
1366
1367 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581368 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371369 }
1370
1371 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581372 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371373 }
1374
1375 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581376 const suggestion =
1377 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1378 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371379 }
1380
1381 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341382 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581383 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341384 }
Jan Scheffler341eea52019-12-12 09:08:411385
1386 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581387 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1388 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1389 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371390 }
1391
Jan Scheffler341eea52019-12-12 09:08:411392 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1393 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1394 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541395 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411396 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1397 }
1398
Blink Reformat4c46d092018-04-07 15:32:371399 this._staleRequests.add(request);
1400 this.scheduleRefresh();
1401 }
1402
1403 /**
Tim van der Lippe119690c2020-01-13 12:31:301404 * @override
Blink Reformat4c46d092018-04-07 15:32:371405 * @return {number}
1406 */
1407 rowHeight() {
1408 return this._rowHeight;
1409 }
1410
1411 /**
Tim van der Lippe119690c2020-01-13 12:31:301412 * @override
Blink Reformat4c46d092018-04-07 15:32:371413 * @param {boolean} gridMode
1414 */
1415 switchViewMode(gridMode) {
1416 this._columns.switchViewMode(gridMode);
1417 }
1418
1419 /**
Tim van der Lippe119690c2020-01-13 12:31:301420 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131421 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1422 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371423 */
1424 handleContextMenuForRequest(contextMenu, request) {
1425 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131426 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371427 const footerSection = copyMenu.footerSection();
1428 if (request) {
1429 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131430 UI.UIUtils.copyLinkAddressLabel(),
1431 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1432 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371433 if (request.requestHeadersText()) {
1434 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371436 }
1437
1438 if (request.responseHeadersText) {
1439 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131440 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371441 }
1442
1443 if (request.finished) {
1444 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131445 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371446 }
1447
Harley Libcf41f92018-09-10 18:01:131448 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131449 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371450 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131451 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1452 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371453 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131454 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291455 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131456 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1457 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371458 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131459 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1460 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131461 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131462 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1463 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371464 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131465 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1466 footerSection.appendItem(
1467 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1468 footerSection.appendItem(
1469 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1470 footerSection.appendItem(
1471 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1472 footerSection.appendItem(
1473 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371474 } else {
Harley Libcf41f92018-09-10 18:01:131475 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291477 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131478 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1479 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131480 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131481 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1482 footerSection.appendItem(
1483 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1484 footerSection.appendItem(
1485 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1486 footerSection.appendItem(
1487 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371488 }
1489 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131490 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371491 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131492 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371493
Joey Arhar0e1093c2019-05-21 00:34:221494 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371495
Blink Reformat4c46d092018-04-07 15:32:371496 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131497 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1498 contextMenu.editSection().appendItem(
1499 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371500
1501 if (request) {
1502 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211503 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371504 let patterns = manager.blockedPatterns();
1505
Tim van der Lippeffa78622019-09-16 12:07:121506 /**
1507 * @param {string} url
1508 */
1509 function addBlockedURL(url) {
1510 patterns.push({enabled: true, url: url});
1511 manager.setBlockedPatterns(patterns);
1512 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261513 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121514 }
1515
1516 /**
1517 * @param {string} url
1518 */
1519 function removeBlockedURL(url) {
1520 patterns = patterns.filter(pattern => pattern.url !== url);
1521 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261522 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121523 }
1524
Blink Reformat4c46d092018-04-07 15:32:371525 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1526 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1527 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131528 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371529 } else if (urlWithoutScheme) {
1530 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1531 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131532 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371533 }
1534
1535 const domain = request.parsedURL.domain();
1536 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1537 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131538 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371539 } else if (domain) {
1540 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1541 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131542 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371543 }
1544
Tim van der Lippe0ed1d2b2020-02-04 13:45:131545 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371546 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131547 Common.UIString.UIString('Replay XHR'),
1548 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371549 }
Blink Reformat4c46d092018-04-07 15:32:371550 }
1551 }
1552
1553 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271554 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171555 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131556 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171557 });
Blink Reformat4c46d092018-04-07 15:32:371558 }
1559
1560 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131561 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1562 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371563 }
1564
1565 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131566 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371567 * @param {string} platform
1568 */
1569 async _copyCurlCommand(request, platform) {
1570 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131571 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371572 }
1573
1574 /**
1575 * @param {string} platform
1576 */
1577 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271578 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131579 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371580 }
1581
1582 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131583 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291584 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371585 */
Jan Scheffler7c50d1f2019-12-17 13:33:291586 async _copyFetchCall(request, includeCookies) {
1587 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131588 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371589 }
1590
Jan Scheffler7c50d1f2019-12-17 13:33:291591 /**
1592 * @param {boolean} includeCookies
1593 */
1594 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271595 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131596 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371597 }
1598
1599 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131600 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371601 */
1602 async _copyPowerShellCommand(request) {
1603 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131604 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371605 }
1606
1607 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271608 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131609 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371610 }
1611
Tim van der Lippe119690c2020-01-13 12:31:301612 /**
1613 * @override
Tim van der Lippe224a8622020-09-23 12:14:371614 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301615 */
Joey Arhar0e1093c2019-05-21 00:34:221616 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371617 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1618 if (!mainTarget) {
1619 return;
1620 }
1621 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131622 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371623 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131624 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371625
Tim van der Lippe1d6e57a2019-09-30 11:55:341626 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371627 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341628 }
Blink Reformat4c46d092018-04-07 15:32:371629
Tim van der Lippe0ed1d2b2020-02-04 13:45:131630 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371631 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301632 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371633 progressIndicator.done();
1634 stream.close();
1635 }
1636
1637 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131638 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211639 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341640 }
Blink Reformat4c46d092018-04-07 15:32:371641 }
1642
1643 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131644 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211645 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341646 }
Blink Reformat4c46d092018-04-07 15:32:371647 }
1648
1649 _removeAllHighlights() {
1650 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341651 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131652 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341653 }
Blink Reformat4c46d092018-04-07 15:32:371654 this._highlightedSubstringChanges = [];
1655 }
1656
1657 /**
Tim van der Lippe119690c2020-01-13 12:31:301658 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371659 * @return {boolean}
1660 */
1661 _applyFilter(node) {
1662 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371664 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341665 }
Blink Reformat4c46d092018-04-07 15:32:371666 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341667 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371668 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341669 }
1670 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371671 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341672 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221673 if (this._onlyIssuesFilterUI.checked() &&
1674 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371675 return false;
1676 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131677 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1678 return false;
1679 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341680 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371681 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341682 }
Blink Reformat4c46d092018-04-07 15:32:371683 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341684 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371685 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341686 }
Blink Reformat4c46d092018-04-07 15:32:371687 }
1688 return true;
1689 }
1690
1691 /**
1692 * @param {string} query
1693 */
1694 _parseFilterQuery(query) {
1695 const descriptors = this._filterParser.parse(query);
1696 this._filters = descriptors.map(descriptor => {
1697 const key = descriptor.key;
1698 const text = descriptor.text || '';
1699 const regex = descriptor.regex;
1700 let filter;
1701 if (key) {
1702 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581703 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1704 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371705 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581706 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371707 } else {
Paul Lewis56509652019-12-06 12:51:581708 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371709 }
Paul Lewis56509652019-12-06 12:51:581710 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371711 });
1712 }
1713
1714 /**
Paul Lewis56509652019-12-06 12:51:581715 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371716 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161717 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371718 */
1719 _createSpecialFilter(type, value) {
1720 switch (type) {
Paul Lewis56509652019-12-06 12:51:581721 case FilterType.Domain:
1722 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371723
Paul Lewis56509652019-12-06 12:51:581724 case FilterType.HasResponseHeader:
1725 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371726
Paul Lewis56509652019-12-06 12:51:581727 case FilterType.Is:
1728 if (value.toLowerCase() === IsFilterType.Running) {
1729 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341730 }
Paul Lewis56509652019-12-06 12:51:581731 if (value.toLowerCase() === IsFilterType.FromCache) {
1732 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341733 }
Paul Lewis56509652019-12-06 12:51:581734 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1735 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341736 }
Paul Lewis56509652019-12-06 12:51:581737 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1738 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341739 }
Blink Reformat4c46d092018-04-07 15:32:371740 break;
1741
Paul Lewis56509652019-12-06 12:51:581742 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371743 return this._createSizeFilter(value.toLowerCase());
1744
Paul Lewis56509652019-12-06 12:51:581745 case FilterType.Method:
1746 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371747
Paul Lewis56509652019-12-06 12:51:581748 case FilterType.MimeType:
1749 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371750
Paul Lewis56509652019-12-06 12:51:581751 case FilterType.MixedContent:
1752 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371753
Paul Lewis56509652019-12-06 12:51:581754 case FilterType.Scheme:
1755 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371756
Paul Lewis56509652019-12-06 12:51:581757 case FilterType.SetCookieDomain:
1758 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371759
Paul Lewis56509652019-12-06 12:51:581760 case FilterType.SetCookieName:
1761 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371762
Paul Lewis56509652019-12-06 12:51:581763 case FilterType.SetCookieValue:
1764 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371765
Jan Scheffler341eea52019-12-12 09:08:411766 case FilterType.CookieDomain:
1767 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1768
1769 case FilterType.CookieName:
1770 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1771
Simon Zündc9759102020-03-25 11:24:541772 case FilterType.CookiePath:
1773 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1774
Jan Scheffler341eea52019-12-12 09:08:411775 case FilterType.CookieValue:
1776 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1777
Paul Lewis56509652019-12-06 12:51:581778 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501779 return NetworkLogView._requestPriorityFilter.bind(
1780 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371781
Paul Lewis56509652019-12-06 12:51:581782 case FilterType.StatusCode:
1783 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031784
1785 case FilterType.ResourceType:
1786 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031787
1788 case FilterType.Url:
1789 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371790 }
1791 return null;
1792 }
1793
1794 /**
1795 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161796 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371797 */
1798 _createSizeFilter(value) {
1799 let multiplier = 1;
1800 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541801 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371802 value = value.substring(0, value.length - 1);
1803 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541804 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371805 value = value.substring(0, value.length - 1);
1806 }
1807 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341808 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371809 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341810 }
Paul Lewis56509652019-12-06 12:51:581811 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371812 }
1813
1814 _filterRequests() {
1815 this._removeAllHighlights();
1816 this._invalidateAllItems();
1817 }
1818
1819 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131820 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301821 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371822 */
1823 _reveal(request) {
1824 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371825 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341826 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371827 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341828 }
Brandon Goddard5e4244d2020-04-08 22:08:471829 // Viewport datagrid nodes do not reveal if not in the root node
1830 // list of flatChildren. For children of grouped frame nodes:
1831 // reveal and expand parent to ensure child is revealable.
1832 if (node.parent && node.parent instanceof NetworkGroupNode) {
1833 node.parent.reveal();
1834 node.parent.expand();
1835 }
Blink Reformat4c46d092018-04-07 15:32:371836 node.reveal();
1837 return node;
1838 }
1839
1840 /**
Tim van der Lippe119690c2020-01-13 12:31:301841 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131842 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371843 */
1844 revealAndHighlightRequest(request) {
1845 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341846 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371847 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341848 }
Blink Reformat4c46d092018-04-07 15:32:371849 }
1850
1851 /**
Tim van der Lippe119690c2020-01-13 12:31:301852 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131853 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371854 */
Simon Zünd6801ec82020-10-28 07:34:001855 selectRequest(request) {
1856 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371857 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341858 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371859 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341860 }
Blink Reformat4c46d092018-04-07 15:32:371861 }
1862
Tim van der Lippe119690c2020-01-13 12:31:301863 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371864 removeAllNodeHighlights() {
1865 if (this._highlightedNode) {
1866 this._highlightedNode.element().classList.remove('highlighted-row');
1867 this._highlightedNode = null;
1868 }
1869 }
1870
1871 /**
Tim van der Lippe119690c2020-01-13 12:31:301872 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371873 */
1874 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131875 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371876 this._highlightedNode = node;
1877 }
1878
1879 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131880 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1881 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131882 */
1883 _filterOutBlobRequests(requests) {
1884 return requests.filter(request => !request.isBlobRequest());
1885 }
1886
1887 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131888 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291889 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371890 * @return {!Promise<string>}
1891 */
Jan Scheffler7c50d1f2019-12-17 13:33:291892 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371893 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371894 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371895 'method',
1896 'path',
1897 'scheme',
1898 'version',
Blink Reformat4c46d092018-04-07 15:32:371899
1900 // Unsafe headers
1901 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371902 'accept-charset',
1903 'accept-encoding',
1904 'access-control-request-headers',
1905 'access-control-request-method',
1906 'connection',
1907 'content-length',
1908 'cookie',
1909 'cookie2',
1910 'date',
1911 'dnt',
1912 'expect',
1913 'host',
1914 'keep-alive',
1915 'origin',
1916 'referer',
1917 'te',
1918 'trailer',
1919 'transfer-encoding',
1920 'upgrade',
1921 'via',
Blink Reformat4c46d092018-04-07 15:32:371922 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371923 'user-agent',
1924 ]);
Blink Reformat4c46d092018-04-07 15:32:371925
Tim van der Lippe224a8622020-09-23 12:14:371926 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371927
1928 const url = JSON.stringify(request.url());
1929
1930 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371931 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371932 const headerData = requestHeaders.reduce((result, header) => {
1933 const name = header.name;
1934
Tim van der Lippe224a8622020-09-23 12:14:371935 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371936 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341937 }
Blink Reformat4c46d092018-04-07 15:32:371938
1939 return result;
1940 }, new Headers());
1941
Tim van der Lippe224a8622020-09-23 12:14:371942 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371943 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341944 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411945 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341946 }
Blink Reformat4c46d092018-04-07 15:32:371947
Sigurd Schneider0e88b912020-05-08 08:28:231948 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371949 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411950 'include' :
1951 'omit';
Blink Reformat4c46d092018-04-07 15:32:371952
1953 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1954
1955 const referrer = referrerHeader ? referrerHeader.value : void 0;
1956
1957 const referrerPolicy = request.referrerPolicy() || void 0;
1958
1959 const requestBody = await request.requestFormData();
1960
Tim van der Lippe224a8622020-09-23 12:14:371961 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371962 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411963 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371964 referrer,
1965 referrerPolicy,
1966 body: requestBody,
1967 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371968 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371969 };
1970
Jan Scheffler7c50d1f2019-12-17 13:33:291971 if (includeCookies) {
1972 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1973 if (cookieHeader) {
1974 fetchOptions.headers = {
1975 ...headers,
1976 'cookie': cookieHeader.value,
1977 };
1978 }
1979 } else {
1980 fetchOptions.credentials = credentials;
1981 }
1982
Jan Scheffler172d5212020-01-02 14:42:561983 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371984 return `fetch(${url}, ${options});`;
1985 }
1986
1987 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131988 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291989 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131990 * @return {!Promise<string>}
1991 */
Jan Scheffler7c50d1f2019-12-17 13:33:291992 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131993 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291994 const commands =
1995 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131996 return commands.join(' ;\n');
1997 }
1998
1999 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132000 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372001 * @param {string} platform
2002 * @return {!Promise<string>}
2003 */
2004 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562005 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362006 // Most of these headers are derived from the URL and are automatically added by cURL.
2007 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372008 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372009
Tim van der Lippe224a8622020-09-23 12:14:372010 /**
2011 * @param {string} str
2012 */
Blink Reformat4c46d092018-04-07 15:32:372013 function escapeStringWin(str) {
2014 /* If there are no new line characters do not escape the " characters
2015 since it only uglifies the command.
2016
2017 Because cmd.exe parser and MS Crt arguments parsers use some of the
2018 same escape characters, they can interact with each other in
2019 horrible ways, the order of operations is critical.
2020
2021 Replace \ with \\ first because it is an escape character for certain
2022 conditions in both parsers.
2023
2024 Replace all " with \" to ensure the first parser does not remove it.
2025
2026 Then escape all characters we are not sure about with ^ to ensure it
2027 gets to MS Crt parser safely.
2028
2029 The % character is special because MS Crt parser will try and look for
2030 ENV variables and fill them in it's place. We cannot escape them with %
2031 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2032 parser); So we can get cmd.exe parser to escape the character after it,
2033 if it is followed by a valid beginning character of an ENV variable.
2034 This ensures we do not try and double escape another ^ if it was placed
2035 by the previous replace.
2036
2037 Lastly we replace new lines with ^ and TWO new lines because the first
2038 new line is there to enact the escape command the second is the character
2039 to escape (in this case new line).
2040 */
2041 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2042 return encapsChars +
2043 str.replace(/\\/g, '\\\\')
2044 .replace(/"/g, '\\"')
2045 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
2046 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
2047 .replace(/\r\n|[\n\r]/g, '^\n\n') +
2048 encapsChars;
2049 }
2050
2051 /**
2052 * @param {string} str
2053 * @return {string}
2054 */
2055 function escapeStringPosix(str) {
2056 /**
2057 * @param {string} x
2058 * @return {string}
2059 */
2060 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222061 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122062 let hexString = code.toString(16);
2063 // Zero pad to four digits to comply with ANSI-C Quoting:
2064 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342065 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122066 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342067 }
Joey Arhar2d21f712019-05-20 21:07:122068
2069 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372070 }
2071
Mathias Bynensf06e8c02020-02-28 13:58:282072 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372073 // Use ANSI-C quoting syntax.
2074 return '$\'' +
2075 str.replace(/\\/g, '\\\\')
2076 .replace(/\'/g, '\\\'')
2077 .replace(/\n/g, '\\n')
2078 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282079 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372080 '\'';
Blink Reformat4c46d092018-04-07 15:32:372081 }
Mathias Bynensf06e8c02020-02-28 13:58:282082 // Use single quote syntax.
2083 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372084 }
2085
2086 // cURL command expected to run on the same platform that DevTools run
2087 // (it may be different from the inspected page platform).
2088 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2089
2090 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2091
2092 let inferredMethod = 'GET';
2093 const data = [];
2094 const requestContentType = request.requestContentType();
2095 const formData = await request.requestFormData();
2096 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272097 // Note that formData is not necessarily urlencoded because it might for example
2098 // come from a fetch request made with an explicitly unencoded body.
2099 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372100 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372101 inferredMethod = 'POST';
2102 } else if (formData) {
Jan Schefflerd2663ac2020-10-26 09:05:112103 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372104 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372105 inferredMethod = 'POST';
2106 }
2107
2108 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292109 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372110 }
2111
2112 const requestHeaders = request.requestHeaders();
2113 for (let i = 0; i < requestHeaders.length; i++) {
2114 const header = requestHeaders[i];
2115 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372116 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372117 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342118 }
Jan Scheffler172d5212020-01-02 14:42:562119 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372120 }
2121 command = command.concat(data);
2122 command.push('--compressed');
2123
Tim van der Lippe1d6e57a2019-09-30 11:55:342124 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372125 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342126 }
Jan Scheffler172d5212020-01-02 14:42:562127 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372128 }
2129
2130 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132131 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132132 * @param {string} platform
2133 * @return {!Promise<string>}
2134 */
2135 async _generateAllCurlCommand(requests, platform) {
2136 const nonBlobRequests = this._filterOutBlobRequests(requests);
2137 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342138 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132139 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342140 }
Mathias Bynensf06e8c02020-02-28 13:58:282141 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132142 }
2143
2144 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132145 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372146 * @return {!Promise<string>}
2147 */
2148 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562149 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372150 const ignoredHeaders =
2151 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2152
2153 /**
2154 * @param {string} str
2155 * @return {string}
2156 */
2157 function escapeString(str) {
2158 return '"' +
2159 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2160 }
2161
Jan Scheffler172d5212020-01-02 14:42:562162 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372163
2164 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562165 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372166 }
2167
2168 const requestHeaders = request.requestHeaders();
2169 const headerNameValuePairs = [];
2170 for (const header of requestHeaders) {
2171 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342172 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372173 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342174 }
Blink Reformat4c46d092018-04-07 15:32:372175 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2176 }
2177 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562178 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372179 }
2180
2181 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2182 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562183 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372184 }
2185
2186 const formData = await request.requestFormData();
2187 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372188 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342189 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562190 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342191 } else {
Jan Scheffler172d5212020-01-02 14:42:562192 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342193 }
Blink Reformat4c46d092018-04-07 15:32:372194 }
2195
Jan Scheffler172d5212020-01-02 14:42:562196 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372197 }
Harley Libcf41f92018-09-10 18:01:132198
2199 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132200 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132201 * @return {!Promise<string>}
2202 */
2203 async _generateAllPowerShellCommand(requests) {
2204 const nonBlobRequests = this._filterOutBlobRequests(requests);
2205 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2206 return commands.join(';\r\n');
2207 }
Joey Arhara86c14e2019-03-12 03:20:502208
2209 /**
2210 * @return {string}
2211 */
2212 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512213 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502214 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342215 }
Joey Arhara86c14e2019-03-12 03:20:502216 return '#0867CB';
2217 }
2218
2219 /**
2220 * @return {string}
2221 */
2222 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512223 return ThemeSupport.ThemeSupport.instance().patchColorText(
2224 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502225 }
Paul Lewis56509652019-12-06 12:51:582226}
Blink Reformat4c46d092018-04-07 15:32:372227
Tim van der Lippe224a8622020-09-23 12:14:372228/** @type {!WeakSet<!NetworkRequestNode>} */
2229const filteredNetworkRequests = new WeakSet();
2230/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2231const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372232
Tim van der Lippe3dc5fd62020-09-22 13:12:222233/**
2234 * @param {!NetworkRequestNode} request
2235 * @return {boolean}
2236 */
2237export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372238 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222239}
2240
Paul Lewis56509652019-12-06 12:51:582241export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372242 'http': true,
2243 'https': true,
2244 'ws': true,
2245 'wss': true
2246};
2247
Blink Reformat4c46d092018-04-07 15:32:372248/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582249export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372250 Domain: 'domain',
2251 HasResponseHeader: 'has-response-header',
2252 Is: 'is',
2253 LargerThan: 'larger-than',
2254 Method: 'method',
2255 MimeType: 'mime-type',
2256 MixedContent: 'mixed-content',
2257 Priority: 'priority',
2258 Scheme: 'scheme',
2259 SetCookieDomain: 'set-cookie-domain',
2260 SetCookieName: 'set-cookie-name',
2261 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032262 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412263 CookieDomain: 'cookie-domain',
2264 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542265 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412266 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032267 StatusCode: 'status-code',
2268 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372269};
2270
2271/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582272export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372273 All: 'all',
2274 Displayed: 'displayed',
2275 Blocked: 'blocked',
2276 BlockOverridden: 'block-overridden'
2277};
2278
2279/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582280export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372281 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052282 FromCache: 'from-cache',
2283 ServiceWorkerIntercepted: 'service-worker-intercepted',
2284 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372285};
2286
2287/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372288export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372289
2290/**
2291 * @interface
2292 */
Paul Lewis56509652019-12-06 12:51:582293export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372294 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132295 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302296 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372297 */
Paul Lewis56509652019-12-06 12:51:582298 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372299 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582300 }
Blink Reformat4c46d092018-04-07 15:32:372301
Paul Lewis56509652019-12-06 12:51:582302 reset() {
2303 }
2304}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162305
2306/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372307// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162308export let Filter;