blob: 9bc707c14b45b658223631a250fd9c41621990ba [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() {
Tim van der Lippe224a8622020-09-23 12:14:371127 return /** @type {!Array<!NetworkNode>} */ (this._dataGrid.rootNode().flatChildren());
Blink Reformat4c46d092018-04-07 15:32:371128 }
1129
Brandon Goddard44934902020-03-25 16:03:181130 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491131 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351132 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381133 }
Brandon Goddard44934902020-03-25 16:03:181134 this.updateNodeBackground();
1135 }
1136
1137 _onDataGridBlur() {
1138 this.element.classList.remove('grid-focused');
1139 this.updateNodeBackground();
1140 }
1141
Tim van der Lippe119690c2020-01-13 12:31:301142 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051143 updateNodeBackground() {
1144 if (this._dataGrid.selectedNode) {
Andres Olivares03d9c752020-10-01 15:08:111145 (/** @type {!NetworkNode} */ (this._dataGrid.selectedNode)).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051146 }
1147 }
1148
1149 /**
Tim van der Lippe119690c2020-01-13 12:31:301150 * @override
Brandon Goddard88d885a2019-10-31 16:11:051151 * @param {boolean} isSelected
1152 */
1153 updateNodeSelectedClass(isSelected) {
1154 if (isSelected) {
1155 this.element.classList.remove('no-node-selected');
1156 } else {
1157 this.element.classList.add('no-node-selected');
1158 }
1159 }
1160
Tim van der Lippe119690c2020-01-13 12:31:301161 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371162 stylesChanged() {
1163 this._columns.scheduleRefresh();
1164 }
1165
1166 _refresh() {
1167 this._needsRefresh = false;
1168
1169 if (this._refreshRequestId) {
1170 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1171 this._refreshRequestId = null;
1172 }
1173
1174 this.removeAllNodeHighlights();
1175
1176 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1177 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1178 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1179 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1180
Tim van der Lippe224a8622020-09-23 12:14:371181 /** @type {!Map<!NetworkNode, !NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371182 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301183 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371184 const nodesToRefresh = [];
1185
Tim van der Lippe119690c2020-01-13 12:31:301186 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371187 const staleNodes = new Set();
1188
1189 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1190 // node so we loop until we have no more stale requests.
1191 while (this._staleRequests.size) {
Tim van der Lippe224a8622020-09-23 12:14:371192 const request = this._staleRequests.values().next().value;
Blink Reformat4c46d092018-04-07 15:32:371193 this._staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371194 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371196 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 }
Blink Reformat4c46d092018-04-07 15:32:371198 staleNodes.add(node);
1199 }
1200
1201 for (const node of staleNodes) {
1202 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341203 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371204 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341205 }
Blink Reformat4c46d092018-04-07 15:32:371206
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371208 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341209 }
Blink Reformat4c46d092018-04-07 15:32:371210 const request = node.request();
1211 this._timeCalculator.updateBoundaries(request);
1212 this._durationCalculator.updateBoundaries(request);
1213 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371214 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1215 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371216 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341217 }
Tim van der Lippe224a8622020-09-23 12:14:371218 if (isFilteredOut) {
1219 filteredNetworkRequests.add(node);
1220 } else {
1221 filteredNetworkRequests.delete(node);
1222 }
Blink Reformat4c46d092018-04-07 15:32:371223 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1224 if (removeFromParent) {
1225 let parent = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111226 if (!parent) {
1227 continue;
1228 }
Blink Reformat4c46d092018-04-07 15:32:371229 parent.removeChild(node);
1230 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Andres Olivares03d9c752020-10-01 15:08:111231 const grandparent = /** @type {!NetworkNode} */ (parent.parent);
Blink Reformat4c46d092018-04-07 15:32:371232 grandparent.removeChild(parent);
1233 parent = grandparent;
1234 }
1235 }
1236
Tim van der Lippe1d6e57a2019-09-30 11:55:341237 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371238 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341239 }
Blink Reformat4c46d092018-04-07 15:32:371240
1241 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Andres Olivares03d9c752020-10-01 15:08:111242 nodesToInsert.set(newParent, /** @type {!NetworkNode} */ (this._dataGrid.rootNode()));
Blink Reformat4c46d092018-04-07 15:32:371243 nodesToRefresh.push(newParent);
1244 }
1245 nodesToInsert.set(node, newParent);
1246 }
1247
Tim van der Lippe1d6e57a2019-09-30 11:55:341248 for (const node of nodesToInsert.keys()) {
Tim van der Lippe224a8622020-09-23 12:14:371249 /** @type {!NetworkNode} */ (nodesToInsert.get(node)).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341250 }
Blink Reformat4c46d092018-04-07 15:32:371251
Tim van der Lippe1d6e57a2019-09-30 11:55:341252 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371253 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341254 }
Blink Reformat4c46d092018-04-07 15:32:371255
1256 this._updateSummaryBar();
1257
Tim van der Lippe1d6e57a2019-09-30 11:55:341258 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371259 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341260 }
Blink Reformat4c46d092018-04-07 15:32:371261
1262 this._dataGrid.updateInstantly();
1263 this._didRefreshForTest();
1264 }
1265
1266 _didRefreshForTest() {
1267 }
1268
1269 /**
Tim van der Lippe119690c2020-01-13 12:31:301270 * @param {!NetworkRequestNode} node
1271 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371272 */
1273 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341274 if (!this._activeGroupLookup) {
Andres Olivares03d9c752020-10-01 15:08:111275 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 }
Blink Reformat4c46d092018-04-07 15:32:371277
1278 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341279 if (!groupNode) {
Andres Olivares03d9c752020-10-01 15:08:111280 return /** @type {!NetworkNode} */ (this._dataGrid.rootNode());
Tim van der Lippe1d6e57a2019-09-30 11:55:341281 }
Blink Reformat4c46d092018-04-07 15:32:371282 return groupNode;
1283 }
1284
1285 _reset() {
Simon Zünd98419832020-03-12 06:18:151286 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371287
1288 this._setHoveredNode(null);
1289 this._columns.reset();
1290
1291 this._timeFilter = null;
1292 this._calculator.reset();
1293
1294 this._timeCalculator.setWindow(null);
Simon Zündcdd72c92020-10-07 11:48:131295 this._linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371296
Tim van der Lippe1d6e57a2019-09-30 11:55:341297 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371298 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341299 }
Blink Reformat4c46d092018-04-07 15:32:371300 this._staleRequests.clear();
1301 this._resetSuggestionBuilder();
1302
1303 this._mainRequestLoadTime = -1;
1304 this._mainRequestDOMContentLoadedTime = -1;
1305
1306 this._dataGrid.rootNode().removeChildren();
1307 this._updateSummaryBar();
1308 this._dataGrid.setStickToBottom(true);
1309 this.scheduleRefresh();
1310 }
1311
1312 /**
Tim van der Lippe119690c2020-01-13 12:31:301313 * @override
Blink Reformat4c46d092018-04-07 15:32:371314 * @param {string} filterString
1315 */
1316 setTextFilterValue(filterString) {
1317 this._textFilterUI.setValue(filterString);
1318 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371319 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131320 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371321 this._resourceCategoryFilterUI.reset();
1322 }
1323
1324 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131325 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371326 */
1327 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301328 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371329 networkRequestToNode.set(request, node);
1330 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371331
Tim van der Lippe1d6e57a2019-09-30 11:55:341332 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371333 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341334 }
Blink Reformat4c46d092018-04-07 15:32:371335 return node;
1336 }
1337
1338 /**
Tim van der Lippec02a97c2020-02-14 14:39:271339 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371340 */
1341 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131342 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371343 this._refreshRequest(request);
1344 }
1345
1346 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131347 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371348 */
1349 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581350 NetworkLogView._subdomains(request.domain)
1351 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1352 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1353 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1354 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1355 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Sigurd Schneider464838b2020-08-24 13:53:031356 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031357 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371358
1359 const priority = request.priority();
1360 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501361 this._suggestionBuilder.addItem(
1362 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371363 }
1364
1365 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581366 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371367 }
1368
1369 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581370 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371371 }
1372
1373 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581374 const suggestion =
1375 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1376 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371377 }
1378
1379 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341380 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581381 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341382 }
Jan Scheffler341eea52019-12-12 09:08:411383
1384 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581385 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1386 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1387 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371388 }
1389
Jan Scheffler341eea52019-12-12 09:08:411390 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1391 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1392 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541393 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411394 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1395 }
1396
Blink Reformat4c46d092018-04-07 15:32:371397 this._staleRequests.add(request);
1398 this.scheduleRefresh();
1399 }
1400
1401 /**
Tim van der Lippe119690c2020-01-13 12:31:301402 * @override
Blink Reformat4c46d092018-04-07 15:32:371403 * @return {number}
1404 */
1405 rowHeight() {
1406 return this._rowHeight;
1407 }
1408
1409 /**
Tim van der Lippe119690c2020-01-13 12:31:301410 * @override
Blink Reformat4c46d092018-04-07 15:32:371411 * @param {boolean} gridMode
1412 */
1413 switchViewMode(gridMode) {
1414 this._columns.switchViewMode(gridMode);
1415 }
1416
1417 /**
Tim van der Lippe119690c2020-01-13 12:31:301418 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131419 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1420 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371421 */
1422 handleContextMenuForRequest(contextMenu, request) {
1423 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131424 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371425 const footerSection = copyMenu.footerSection();
1426 if (request) {
1427 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131428 UI.UIUtils.copyLinkAddressLabel(),
1429 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1430 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371431 if (request.requestHeadersText()) {
1432 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131433 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371434 }
1435
1436 if (request.responseHeadersText) {
1437 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131438 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371439 }
1440
1441 if (request.finished) {
1442 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131443 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371444 }
1445
Harley Libcf41f92018-09-10 18:01:131446 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131447 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371448 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131449 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1450 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371451 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131452 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291453 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131454 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1455 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371456 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131457 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1458 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131459 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131460 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1461 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371462 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1464 footerSection.appendItem(
1465 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1466 footerSection.appendItem(
1467 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1468 footerSection.appendItem(
1469 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1470 footerSection.appendItem(
1471 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371472 } else {
Harley Libcf41f92018-09-10 18:01:131473 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131474 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291475 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1477 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131478 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131479 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1480 footerSection.appendItem(
1481 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1482 footerSection.appendItem(
1483 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1484 footerSection.appendItem(
1485 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371486 }
1487 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131488 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371489 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131490 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371491
Joey Arhar0e1093c2019-05-21 00:34:221492 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371493
Blink Reformat4c46d092018-04-07 15:32:371494 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131495 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1496 contextMenu.editSection().appendItem(
1497 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371498
1499 if (request) {
1500 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211501 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371502 let patterns = manager.blockedPatterns();
1503
Tim van der Lippeffa78622019-09-16 12:07:121504 /**
1505 * @param {string} url
1506 */
1507 function addBlockedURL(url) {
1508 patterns.push({enabled: true, url: url});
1509 manager.setBlockedPatterns(patterns);
1510 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261511 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121512 }
1513
1514 /**
1515 * @param {string} url
1516 */
1517 function removeBlockedURL(url) {
1518 patterns = patterns.filter(pattern => pattern.url !== url);
1519 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261520 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121521 }
1522
Blink Reformat4c46d092018-04-07 15:32:371523 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1524 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1525 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131526 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371527 } else if (urlWithoutScheme) {
1528 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1529 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131530 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371531 }
1532
1533 const domain = request.parsedURL.domain();
1534 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1535 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131536 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371537 } else if (domain) {
1538 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1539 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131540 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371541 }
1542
Tim van der Lippe0ed1d2b2020-02-04 13:45:131543 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371544 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131545 Common.UIString.UIString('Replay XHR'),
1546 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371547 }
Blink Reformat4c46d092018-04-07 15:32:371548 }
1549 }
1550
1551 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271552 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171553 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131554 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171555 });
Blink Reformat4c46d092018-04-07 15:32:371556 }
1557
1558 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131559 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1560 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371561 }
1562
1563 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131564 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371565 * @param {string} platform
1566 */
1567 async _copyCurlCommand(request, platform) {
1568 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131569 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371570 }
1571
1572 /**
1573 * @param {string} platform
1574 */
1575 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271576 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131577 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371578 }
1579
1580 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131581 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291582 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371583 */
Jan Scheffler7c50d1f2019-12-17 13:33:291584 async _copyFetchCall(request, includeCookies) {
1585 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131586 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371587 }
1588
Jan Scheffler7c50d1f2019-12-17 13:33:291589 /**
1590 * @param {boolean} includeCookies
1591 */
1592 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271593 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131594 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371595 }
1596
1597 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131598 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371599 */
1600 async _copyPowerShellCommand(request) {
1601 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131602 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371603 }
1604
1605 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271606 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131607 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371608 }
1609
Tim van der Lippe119690c2020-01-13 12:31:301610 /**
1611 * @override
Tim van der Lippe224a8622020-09-23 12:14:371612 * @return {!Promise<void>}
Tim van der Lippe119690c2020-01-13 12:31:301613 */
Joey Arhar0e1093c2019-05-21 00:34:221614 async exportAll() {
Tim van der Lippe224a8622020-09-23 12:14:371615 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
1616 if (!mainTarget) {
1617 return;
1618 }
1619 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131620 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371621 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131622 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371623
Tim van der Lippe1d6e57a2019-09-30 11:55:341624 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371625 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341626 }
Blink Reformat4c46d092018-04-07 15:32:371627
Tim van der Lippe0ed1d2b2020-02-04 13:45:131628 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371629 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301630 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371631 progressIndicator.done();
1632 stream.close();
1633 }
1634
1635 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131636 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211637 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341638 }
Blink Reformat4c46d092018-04-07 15:32:371639 }
1640
1641 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131642 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211643 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341644 }
Blink Reformat4c46d092018-04-07 15:32:371645 }
1646
1647 _removeAllHighlights() {
1648 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341649 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131650 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341651 }
Blink Reformat4c46d092018-04-07 15:32:371652 this._highlightedSubstringChanges = [];
1653 }
1654
1655 /**
Tim van der Lippe119690c2020-01-13 12:31:301656 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371657 * @return {boolean}
1658 */
1659 _applyFilter(node) {
1660 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341661 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371662 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 }
Blink Reformat4c46d092018-04-07 15:32:371664 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341665 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371666 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341667 }
1668 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371669 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341670 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221671 if (this._onlyIssuesFilterUI.checked() &&
1672 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371673 return false;
1674 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131675 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1676 return false;
1677 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341678 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371679 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341680 }
Blink Reformat4c46d092018-04-07 15:32:371681 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341682 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371683 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341684 }
Blink Reformat4c46d092018-04-07 15:32:371685 }
1686 return true;
1687 }
1688
1689 /**
1690 * @param {string} query
1691 */
1692 _parseFilterQuery(query) {
1693 const descriptors = this._filterParser.parse(query);
1694 this._filters = descriptors.map(descriptor => {
1695 const key = descriptor.key;
1696 const text = descriptor.text || '';
1697 const regex = descriptor.regex;
1698 let filter;
1699 if (key) {
1700 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581701 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1702 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371703 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581704 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371705 } else {
Paul Lewis56509652019-12-06 12:51:581706 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371707 }
Paul Lewis56509652019-12-06 12:51:581708 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371709 });
1710 }
1711
1712 /**
Paul Lewis56509652019-12-06 12:51:581713 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371714 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161715 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371716 */
1717 _createSpecialFilter(type, value) {
1718 switch (type) {
Paul Lewis56509652019-12-06 12:51:581719 case FilterType.Domain:
1720 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371721
Paul Lewis56509652019-12-06 12:51:581722 case FilterType.HasResponseHeader:
1723 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371724
Paul Lewis56509652019-12-06 12:51:581725 case FilterType.Is:
1726 if (value.toLowerCase() === IsFilterType.Running) {
1727 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341728 }
Paul Lewis56509652019-12-06 12:51:581729 if (value.toLowerCase() === IsFilterType.FromCache) {
1730 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 }
Paul Lewis56509652019-12-06 12:51:581732 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1733 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341734 }
Paul Lewis56509652019-12-06 12:51:581735 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1736 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341737 }
Blink Reformat4c46d092018-04-07 15:32:371738 break;
1739
Paul Lewis56509652019-12-06 12:51:581740 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371741 return this._createSizeFilter(value.toLowerCase());
1742
Paul Lewis56509652019-12-06 12:51:581743 case FilterType.Method:
1744 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371745
Paul Lewis56509652019-12-06 12:51:581746 case FilterType.MimeType:
1747 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371748
Paul Lewis56509652019-12-06 12:51:581749 case FilterType.MixedContent:
1750 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371751
Paul Lewis56509652019-12-06 12:51:581752 case FilterType.Scheme:
1753 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371754
Paul Lewis56509652019-12-06 12:51:581755 case FilterType.SetCookieDomain:
1756 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371757
Paul Lewis56509652019-12-06 12:51:581758 case FilterType.SetCookieName:
1759 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371760
Paul Lewis56509652019-12-06 12:51:581761 case FilterType.SetCookieValue:
1762 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371763
Jan Scheffler341eea52019-12-12 09:08:411764 case FilterType.CookieDomain:
1765 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1766
1767 case FilterType.CookieName:
1768 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1769
Simon Zündc9759102020-03-25 11:24:541770 case FilterType.CookiePath:
1771 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1772
Jan Scheffler341eea52019-12-12 09:08:411773 case FilterType.CookieValue:
1774 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1775
Paul Lewis56509652019-12-06 12:51:581776 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501777 return NetworkLogView._requestPriorityFilter.bind(
1778 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371779
Paul Lewis56509652019-12-06 12:51:581780 case FilterType.StatusCode:
1781 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031782
1783 case FilterType.ResourceType:
1784 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031785
1786 case FilterType.Url:
1787 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371788 }
1789 return null;
1790 }
1791
1792 /**
1793 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161794 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371795 */
1796 _createSizeFilter(value) {
1797 let multiplier = 1;
1798 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411799 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371800 value = value.substring(0, value.length - 1);
1801 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411802 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371803 value = value.substring(0, value.length - 1);
1804 }
1805 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341806 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371807 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341808 }
Paul Lewis56509652019-12-06 12:51:581809 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371810 }
1811
1812 _filterRequests() {
1813 this._removeAllHighlights();
1814 this._invalidateAllItems();
1815 }
1816
1817 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131818 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301819 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371820 */
1821 _reveal(request) {
1822 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371823 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341824 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371825 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341826 }
Brandon Goddard5e4244d2020-04-08 22:08:471827 // Viewport datagrid nodes do not reveal if not in the root node
1828 // list of flatChildren. For children of grouped frame nodes:
1829 // reveal and expand parent to ensure child is revealable.
1830 if (node.parent && node.parent instanceof NetworkGroupNode) {
1831 node.parent.reveal();
1832 node.parent.expand();
1833 }
Blink Reformat4c46d092018-04-07 15:32:371834 node.reveal();
1835 return node;
1836 }
1837
1838 /**
Tim van der Lippe119690c2020-01-13 12:31:301839 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131840 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371841 */
1842 revealAndHighlightRequest(request) {
1843 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341844 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371845 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341846 }
Blink Reformat4c46d092018-04-07 15:32:371847 }
1848
1849 /**
Tim van der Lippe119690c2020-01-13 12:31:301850 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131851 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371852 */
1853 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141854 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371855 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341856 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371857 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341858 }
Blink Reformat4c46d092018-04-07 15:32:371859 }
1860
Tim van der Lippe119690c2020-01-13 12:31:301861 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371862 removeAllNodeHighlights() {
1863 if (this._highlightedNode) {
1864 this._highlightedNode.element().classList.remove('highlighted-row');
1865 this._highlightedNode = null;
1866 }
1867 }
1868
1869 /**
Tim van der Lippe119690c2020-01-13 12:31:301870 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371871 */
1872 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131873 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371874 this._highlightedNode = node;
1875 }
1876
1877 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131878 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1879 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131880 */
1881 _filterOutBlobRequests(requests) {
1882 return requests.filter(request => !request.isBlobRequest());
1883 }
1884
1885 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131886 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291887 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371888 * @return {!Promise<string>}
1889 */
Jan Scheffler7c50d1f2019-12-17 13:33:291890 async _generateFetchCall(request, includeCookies) {
Tim van der Lippe224a8622020-09-23 12:14:371891 const ignoredHeaders = new Set([
Blink Reformat4c46d092018-04-07 15:32:371892 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:371893 'method',
1894 'path',
1895 'scheme',
1896 'version',
Blink Reformat4c46d092018-04-07 15:32:371897
1898 // Unsafe headers
1899 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:371900 'accept-charset',
1901 'accept-encoding',
1902 'access-control-request-headers',
1903 'access-control-request-method',
1904 'connection',
1905 'content-length',
1906 'cookie',
1907 'cookie2',
1908 'date',
1909 'dnt',
1910 'expect',
1911 'host',
1912 'keep-alive',
1913 'origin',
1914 'referer',
1915 'te',
1916 'trailer',
1917 'transfer-encoding',
1918 'upgrade',
1919 'via',
Blink Reformat4c46d092018-04-07 15:32:371920 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:371921 'user-agent',
1922 ]);
Blink Reformat4c46d092018-04-07 15:32:371923
Tim van der Lippe224a8622020-09-23 12:14:371924 const credentialHeaders = new Set(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:371925
1926 const url = JSON.stringify(request.url());
1927
1928 const requestHeaders = request.requestHeaders();
Tim van der Lippe224a8622020-09-23 12:14:371929 /** @type {!Headers} */
Blink Reformat4c46d092018-04-07 15:32:371930 const headerData = requestHeaders.reduce((result, header) => {
1931 const name = header.name;
1932
Tim van der Lippe224a8622020-09-23 12:14:371933 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371934 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341935 }
Blink Reformat4c46d092018-04-07 15:32:371936
1937 return result;
1938 }, new Headers());
1939
Tim van der Lippe224a8622020-09-23 12:14:371940 /** @type {!HeadersInit} */
Blink Reformat4c46d092018-04-07 15:32:371941 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341942 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411943 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341944 }
Blink Reformat4c46d092018-04-07 15:32:371945
Sigurd Schneider0e88b912020-05-08 08:28:231946 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:371947 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:411948 'include' :
1949 'omit';
Blink Reformat4c46d092018-04-07 15:32:371950
1951 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1952
1953 const referrer = referrerHeader ? referrerHeader.value : void 0;
1954
1955 const referrerPolicy = request.referrerPolicy() || void 0;
1956
1957 const requestBody = await request.requestFormData();
1958
Tim van der Lippe224a8622020-09-23 12:14:371959 /** @type {!RequestInit} */
Blink Reformat4c46d092018-04-07 15:32:371960 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411961 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371962 referrer,
1963 referrerPolicy,
1964 body: requestBody,
1965 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:371966 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:371967 };
1968
Jan Scheffler7c50d1f2019-12-17 13:33:291969 if (includeCookies) {
1970 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1971 if (cookieHeader) {
1972 fetchOptions.headers = {
1973 ...headers,
1974 'cookie': cookieHeader.value,
1975 };
1976 }
1977 } else {
1978 fetchOptions.credentials = credentials;
1979 }
1980
Jan Scheffler172d5212020-01-02 14:42:561981 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371982 return `fetch(${url}, ${options});`;
1983 }
1984
1985 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131986 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291987 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131988 * @return {!Promise<string>}
1989 */
Jan Scheffler7c50d1f2019-12-17 13:33:291990 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131991 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291992 const commands =
1993 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131994 return commands.join(' ;\n');
1995 }
1996
1997 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131998 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371999 * @param {string} platform
2000 * @return {!Promise<string>}
2001 */
2002 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:562003 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:362004 // Most of these headers are derived from the URL and are automatically added by cURL.
2005 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Tim van der Lippe224a8622020-09-23 12:14:372006 const ignoredHeaders = new Set(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372007
Tim van der Lippe224a8622020-09-23 12:14:372008 /**
2009 * @param {string} str
2010 */
Blink Reformat4c46d092018-04-07 15:32:372011 function escapeStringWin(str) {
2012 /* If there are no new line characters do not escape the " characters
2013 since it only uglifies the command.
2014
2015 Because cmd.exe parser and MS Crt arguments parsers use some of the
2016 same escape characters, they can interact with each other in
2017 horrible ways, the order of operations is critical.
2018
2019 Replace \ with \\ first because it is an escape character for certain
2020 conditions in both parsers.
2021
2022 Replace all " with \" to ensure the first parser does not remove it.
2023
2024 Then escape all characters we are not sure about with ^ to ensure it
2025 gets to MS Crt parser safely.
2026
2027 The % character is special because MS Crt parser will try and look for
2028 ENV variables and fill them in it's place. We cannot escape them with %
2029 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2030 parser); So we can get cmd.exe parser to escape the character after it,
2031 if it is followed by a valid beginning character of an ENV variable.
2032 This ensures we do not try and double escape another ^ if it was placed
2033 by the previous replace.
2034
2035 Lastly we replace new lines with ^ and TWO new lines because the first
2036 new line is there to enact the escape command the second is the character
2037 to escape (in this case new line).
2038 */
2039 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2040 return encapsChars +
2041 str.replace(/\\/g, '\\\\')
2042 .replace(/"/g, '\\"')
2043 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
2044 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
2045 .replace(/\r\n|[\n\r]/g, '^\n\n') +
2046 encapsChars;
2047 }
2048
2049 /**
2050 * @param {string} str
2051 * @return {string}
2052 */
2053 function escapeStringPosix(str) {
2054 /**
2055 * @param {string} x
2056 * @return {string}
2057 */
2058 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222059 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122060 let hexString = code.toString(16);
2061 // Zero pad to four digits to comply with ANSI-C Quoting:
2062 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342063 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122064 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342065 }
Joey Arhar2d21f712019-05-20 21:07:122066
2067 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372068 }
2069
Mathias Bynensf06e8c02020-02-28 13:58:282070 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372071 // Use ANSI-C quoting syntax.
2072 return '$\'' +
2073 str.replace(/\\/g, '\\\\')
2074 .replace(/\'/g, '\\\'')
2075 .replace(/\n/g, '\\n')
2076 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282077 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372078 '\'';
Blink Reformat4c46d092018-04-07 15:32:372079 }
Mathias Bynensf06e8c02020-02-28 13:58:282080 // Use single quote syntax.
2081 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372082 }
2083
2084 // cURL command expected to run on the same platform that DevTools run
2085 // (it may be different from the inspected page platform).
2086 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2087
2088 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2089
2090 let inferredMethod = 'GET';
2091 const data = [];
2092 const requestContentType = request.requestContentType();
2093 const formData = await request.requestFormData();
2094 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272095 // Note that formData is not necessarily urlencoded because it might for example
2096 // come from a fetch request made with an explicitly unencoded body.
2097 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372098 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372099 inferredMethod = 'POST';
2100 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:562101 data.push('--data-binary ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372102 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372103 inferredMethod = 'POST';
2104 }
2105
2106 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292107 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372108 }
2109
2110 const requestHeaders = request.requestHeaders();
2111 for (let i = 0; i < requestHeaders.length; i++) {
2112 const header = requestHeaders[i];
2113 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372114 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372115 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342116 }
Jan Scheffler172d5212020-01-02 14:42:562117 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372118 }
2119 command = command.concat(data);
2120 command.push('--compressed');
2121
Tim van der Lippe1d6e57a2019-09-30 11:55:342122 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372123 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342124 }
Jan Scheffler172d5212020-01-02 14:42:562125 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372126 }
2127
2128 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132129 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132130 * @param {string} platform
2131 * @return {!Promise<string>}
2132 */
2133 async _generateAllCurlCommand(requests, platform) {
2134 const nonBlobRequests = this._filterOutBlobRequests(requests);
2135 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342136 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132137 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342138 }
Mathias Bynensf06e8c02020-02-28 13:58:282139 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132140 }
2141
2142 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132143 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372144 * @return {!Promise<string>}
2145 */
2146 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562147 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372148 const ignoredHeaders =
2149 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2150
2151 /**
2152 * @param {string} str
2153 * @return {string}
2154 */
2155 function escapeString(str) {
2156 return '"' +
2157 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2158 }
2159
Jan Scheffler172d5212020-01-02 14:42:562160 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372161
2162 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562163 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372164 }
2165
2166 const requestHeaders = request.requestHeaders();
2167 const headerNameValuePairs = [];
2168 for (const header of requestHeaders) {
2169 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342170 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372171 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342172 }
Blink Reformat4c46d092018-04-07 15:32:372173 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2174 }
2175 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562176 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372177 }
2178
2179 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2180 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562181 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372182 }
2183
2184 const formData = await request.requestFormData();
2185 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372186 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342187 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562188 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342189 } else {
Jan Scheffler172d5212020-01-02 14:42:562190 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342191 }
Blink Reformat4c46d092018-04-07 15:32:372192 }
2193
Jan Scheffler172d5212020-01-02 14:42:562194 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372195 }
Harley Libcf41f92018-09-10 18:01:132196
2197 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132198 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132199 * @return {!Promise<string>}
2200 */
2201 async _generateAllPowerShellCommand(requests) {
2202 const nonBlobRequests = this._filterOutBlobRequests(requests);
2203 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2204 return commands.join(';\r\n');
2205 }
Joey Arhara86c14e2019-03-12 03:20:502206
2207 /**
2208 * @return {string}
2209 */
2210 static getDCLEventColor() {
Paul Lewisca569a52020-09-09 16:11:512211 if (ThemeSupport.ThemeSupport.instance().themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502212 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342213 }
Joey Arhara86c14e2019-03-12 03:20:502214 return '#0867CB';
2215 }
2216
2217 /**
2218 * @return {string}
2219 */
2220 static getLoadEventColor() {
Paul Lewisca569a52020-09-09 16:11:512221 return ThemeSupport.ThemeSupport.instance().patchColorText(
2222 '#B31412', ThemeSupport.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502223 }
Paul Lewis56509652019-12-06 12:51:582224}
Blink Reformat4c46d092018-04-07 15:32:372225
Tim van der Lippe224a8622020-09-23 12:14:372226/** @type {!WeakSet<!NetworkRequestNode>} */
2227const filteredNetworkRequests = new WeakSet();
2228/** @type {!WeakMap<!SDK.NetworkRequest.NetworkRequest, !NetworkRequestNode>} */
2229const networkRequestToNode = new WeakMap();
Blink Reformat4c46d092018-04-07 15:32:372230
Tim van der Lippe3dc5fd62020-09-22 13:12:222231/**
2232 * @param {!NetworkRequestNode} request
2233 * @return {boolean}
2234 */
2235export function isRequestFilteredOut(request) {
Tim van der Lippe224a8622020-09-23 12:14:372236 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222237}
2238
Paul Lewis56509652019-12-06 12:51:582239export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372240 'http': true,
2241 'https': true,
2242 'ws': true,
2243 'wss': true
2244};
2245
Blink Reformat4c46d092018-04-07 15:32:372246/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582247export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372248 Domain: 'domain',
2249 HasResponseHeader: 'has-response-header',
2250 Is: 'is',
2251 LargerThan: 'larger-than',
2252 Method: 'method',
2253 MimeType: 'mime-type',
2254 MixedContent: 'mixed-content',
2255 Priority: 'priority',
2256 Scheme: 'scheme',
2257 SetCookieDomain: 'set-cookie-domain',
2258 SetCookieName: 'set-cookie-name',
2259 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032260 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412261 CookieDomain: 'cookie-domain',
2262 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542263 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412264 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032265 StatusCode: 'status-code',
2266 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372267};
2268
2269/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582270export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372271 All: 'all',
2272 Displayed: 'displayed',
2273 Blocked: 'blocked',
2274 BlockOverridden: 'block-overridden'
2275};
2276
2277/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582278export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372279 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052280 FromCache: 'from-cache',
2281 ServiceWorkerIntercepted: 'service-worker-intercepted',
2282 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372283};
2284
2285/** @type {!Array<string>} */
Tim van der Lippe224a8622020-09-23 12:14:372286export const _searchKeys = Object.values(FilterType);
Blink Reformat4c46d092018-04-07 15:32:372287
2288/**
2289 * @interface
2290 */
Paul Lewis56509652019-12-06 12:51:582291export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372292 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132293 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302294 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372295 */
Paul Lewis56509652019-12-06 12:51:582296 groupNodeForRequest(request) {
Tim van der Lippe224a8622020-09-23 12:14:372297 throw new Error('Not implemented yet');
Paul Lewis56509652019-12-06 12:51:582298 }
Blink Reformat4c46d092018-04-07 15:32:372299
Paul Lewis56509652019-12-06 12:51:582300 reset() {
2301 }
2302}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162303
2304/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
Tim van der Lippe224a8622020-09-23 12:14:372305// @ts-ignore typedef
Tim van der Lippeb1f2b6c2020-02-17 13:00:162306export let Filter;