blob: cc2c55ba9214ad042c7b42844cd9a705c200d3fa [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';
32import * as Common from '../common/common.js';
33import * as Components from '../components/components.js';
34import * as DataGrid from '../data_grid/data_grid.js';
35import * as HARImporter from '../har_importer/har_importer.js';
36import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5037import * as PerfUI from '../perf_ui/perf_ui.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1338import * as SDK from '../sdk/sdk.js';
39import * as TextUtils from '../text_utils/text_utils.js';
40import * as UI from '../ui/ui.js';
41
Tim van der Lippe119690c2020-01-13 12:31:3042import {HARWriter} from './HARWriter.js';
43import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
44import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
45import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
46import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
47
Blink Reformat4c46d092018-04-07 15:32:3748/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1349 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3050 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3751 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1352export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3753 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3755 * @param {!Element} progressBarContainer
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356 * @param {!Common.Settings.Setting} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3757 */
58 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
59 super();
60 this.setMinimumSize(50, 64);
61 this.registerRequiredCSS('network/networkLogView.css');
62
63 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0564 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3765
Paul Lewis2d7d65c2020-03-16 17:26:3066 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
67 this._networkShowIssuesOnlySetting =
68 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
69 this._networkOnlyBlockedRequestsSetting =
70 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
71 this._networkResourceTypeFiltersSetting =
72 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3773
74 this._rawRowHeight = 0;
75 this._progressBarContainer = progressBarContainer;
76 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
77 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
78
79 /**
Paul Lewis56509652019-12-06 12:51:5880 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3781 */
82 function updateRowHeight() {
83 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
84 this._rowHeight = this._computeRowHeight();
85 }
86 this._rawRowHeight = 0;
87 this._rowHeight = 0;
88 updateRowHeight.call(this);
89
Tim van der Lippe119690c2020-01-13 12:31:3090 /** @type {!NetworkTransferTimeCalculator} */
91 this._timeCalculator = new NetworkTransferTimeCalculator();
92 /** @type {!NetworkTransferDurationCalculator} */
93 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3794 this._calculator = this._timeCalculator;
95
Tim van der Lippe119690c2020-01-13 12:31:3096 this._columns =
97 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:3798 this._columns.show(this.element);
99
Tim van der Lippe0ed1d2b2020-02-04 13:45:13100 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37101 this._staleRequests = new Set();
102 /** @type {number} */
103 this._mainRequestLoadTime = -1;
104 /** @type {number} */
105 this._mainRequestDOMContentLoadedTime = -1;
106 this._highlightedSubstringChanges = [];
107
Tim van der Lippeb1f2b6c2020-02-17 13:00:16108 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37109 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16110 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30112 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37113 this._hoveredNode = null;
114 /** @type {?Element} */
115 this._recordingHint = null;
116 /** @type {?number} */
117 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30118 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37119 this._highlightedNode = null;
120
Tim van der Lippe0ed1d2b2020-02-04 13:45:13121 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37122
123 this._recording = false;
124 this._needsRefresh = false;
125
126 this._headerHeight = 0;
127
Paul Lewis56509652019-12-06 12:51:58128 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37129 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30130 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37131
Paul Lewis56509652019-12-06 12:51:58132 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37133 this._activeGroupLookup = null;
134
Tim van der Lippe0ed1d2b2020-02-04 13:45:13135 this._textFilterUI = new UI.FilterBar.TextFilterUI();
136 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37137 filterBar.addFilter(this._textFilterUI);
138
Tim van der Lippe0ed1d2b2020-02-04 13:45:13139 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
140 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
141 this._dataURLFilterUI.addEventListener(
142 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48143 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37144 filterBar.addFilter(this._dataURLFilterUI);
145
146 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13147 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37148 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13149 this._resourceCategoryFilterUI =
150 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20151 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37152 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13153 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37154 filterBar.addFilter(this._resourceCategoryFilterUI);
155
Tim van der Lippe0ed1d2b2020-02-04 13:45:13156 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
157 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
158 this._onlyIssuesFilterUI.addEventListener(
159 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41160 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37161 filterBar.addFilter(this._onlyIssuesFilterUI);
162
Sigurd Schneidera2afe0b2020-03-03 15:27:13163 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
164 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
165 this._onlyBlockedRequestsUI.addEventListener(
166 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
167 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
168 filterBar.addFilter(this._onlyBlockedRequestsUI);
169
Jan Scheffler1ae7c9e2019-12-03 15:48:37170
Tim van der Lippe0ed1d2b2020-02-04 13:45:13171 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
172 this._suggestionBuilder =
173 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37174 this._resetSuggestionBuilder();
175
176 this._dataGrid = this._columns.dataGrid();
177 this._setupDataGrid();
178 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49179 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13180 UI.Toolbar.ToolbarButton.Events.Click,
181 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37182
Tim van der Lippe0ed1d2b2020-02-04 13:45:13183 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37184
Tim van der Lippe0ed1d2b2020-02-04 13:45:13185 new UI.DropTarget.DropTarget(
186 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
187 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37188
Paul Lewis2d7d65c2020-03-16 17:26:30189 Common.Settings.Settings.instance()
190 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37191 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
192
Paul Lewisdaac1062020-03-05 14:37:10193 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Paul Lewisca3665d2020-01-24 13:31:16194 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
195 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
196 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37197
198 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30199 Common.Settings.Settings.instance()
200 .moduleSetting('network.group-by-frame')
201 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37202
203 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37204 }
205
Blink Reformat4c46d092018-04-07 15:32:37206 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30207 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37208 this._setGrouping(value ? 'Frame' : null);
209 }
210
211 /**
212 * @param {string} key
213 * @param {!Array<string>} values
214 */
215 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58216 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37217 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50218 const aPriority =
219 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
220 const bPriority =
221 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
222 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
223 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37224 });
225 } else {
226 values.sort();
227 }
228 }
229
230 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16231 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13232 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37233 * @return {boolean}
234 */
235 static _negativeFilter(filter, request) {
236 return !filter(request);
237 }
238
239 /**
240 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13241 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37242 * @return {boolean}
243 */
244 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34245 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37246 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34247 }
Blink Reformat4c46d092018-04-07 15:32:37248
249 return regex.test(request.path() + '/' + request.name());
250 }
251
252 /**
253 * @param {string} domain
254 * @return {!Array.<string>}
255 */
256 static _subdomains(domain) {
257 const result = [domain];
258 let indexOfPeriod = domain.indexOf('.');
259 while (indexOfPeriod !== -1) {
260 result.push('*' + domain.substring(indexOfPeriod));
261 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
262 }
263 return result;
264 }
265
266 /**
267 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16268 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37269 */
270 static _createRequestDomainFilter(value) {
271 /**
272 * @param {string} string
273 * @return {string}
274 */
275 function escapeForRegExp(string) {
276 return string.escapeForRegExp();
277 }
278 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58279 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37280 }
281
282 /**
283 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13284 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37285 * @return {boolean}
286 */
287 static _requestDomainFilter(regex, request) {
288 return regex.test(request.domain);
289 }
290
291 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13292 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37293 * @return {boolean}
294 */
295 static _runningRequestFilter(request) {
296 return !request.finished;
297 }
298
299 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13300 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37301 * @return {boolean}
302 */
303 static _fromCacheRequestFilter(request) {
304 return request.cached();
305 }
306
307 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13308 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05309 * @return {boolean}
310 */
311 static _interceptedByServiceWorkerFilter(request) {
312 return request.fetchedViaServiceWorker;
313 }
314
315 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13316 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05317 * @return {boolean}
318 */
319 static _initiatedByServiceWorkerFilter(request) {
320 return request.initiatedByServiceWorker();
321 }
322
323 /**
Blink Reformat4c46d092018-04-07 15:32:37324 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13325 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37326 * @return {boolean}
327 */
328 static _requestResponseHeaderFilter(value, request) {
329 return request.responseHeaderValue(value) !== undefined;
330 }
331
332 /**
333 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13334 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37335 * @return {boolean}
336 */
337 static _requestMethodFilter(value, request) {
338 return request.requestMethod === value;
339 }
340
341 /**
342 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13343 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37344 * @return {boolean}
345 */
346 static _requestPriorityFilter(value, request) {
347 return request.priority() === value;
348 }
349
350 /**
351 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13352 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37353 * @return {boolean}
354 */
355 static _requestMimeTypeFilter(value, request) {
356 return request.mimeType === value;
357 }
358
359 /**
Paul Lewis56509652019-12-06 12:51:58360 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13361 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37362 * @return {boolean}
363 */
364 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58365 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37366 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28367 }
368 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37369 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28370 }
371 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37372 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28373 }
374 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37375 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34376 }
Blink Reformat4c46d092018-04-07 15:32:37377
378 return false;
379 }
380
381 /**
382 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13383 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37384 * @return {boolean}
385 */
386 static _requestSchemeFilter(value, request) {
387 return request.scheme === value;
388 }
389
390 /**
391 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13392 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37393 * @return {boolean}
394 */
Jan Scheffler341eea52019-12-12 09:08:41395 static _requestCookieDomainFilter(value, request) {
396 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
397 }
398
399 /**
400 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13401 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41402 * @return {boolean}
403 */
404 static _requestCookieNameFilter(value, request) {
405 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
406 }
407
408 /**
409 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13410 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41411 * @return {boolean}
412 */
Simon Zündc9759102020-03-25 11:24:54413 static _requestCookiePathFilter(value, request) {
414 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
415 }
416
417 /**
418 * @param {string} value
419 * @param {!SDK.NetworkRequest.NetworkRequest} request
420 * @return {boolean}
421 */
Jan Scheffler341eea52019-12-12 09:08:41422 static _requestCookieValueFilter(value, request) {
423 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
424 }
425
426 /**
427 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13428 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41429 * @return {boolean}
430 */
Blink Reformat4c46d092018-04-07 15:32:37431 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41432 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37433 }
434
435 /**
436 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13437 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37438 * @return {boolean}
439 */
440 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41441 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37442 }
443
444 /**
445 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13446 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37447 * @return {boolean}
448 */
449 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41450 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37451 }
452
453 /**
454 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13455 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37456 * @return {boolean}
457 */
458 static _requestSizeLargerThanFilter(value, request) {
459 return request.transferSize >= value;
460 }
461
462 /**
463 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13464 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37465 * @return {boolean}
466 */
467 static _statusCodeFilter(value, request) {
468 return ('' + request.statusCode) === value;
469 }
470
471 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13472 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37473 * @return {boolean}
474 */
475 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58476 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37477 }
478
479 /**
Blink Reformat4c46d092018-04-07 15:32:37480 * @param {number} windowStart
481 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13482 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37483 * @return {boolean}
484 */
485 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34486 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37487 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34488 }
489 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37490 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34491 }
Blink Reformat4c46d092018-04-07 15:32:37492 return true;
493 }
494
495 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13496 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37497 */
498 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13499 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37500 }
501
502 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13503 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37504 */
505 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13506 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37507 }
508
509 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13510 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37511 */
512 static async _copyResponse(request) {
513 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08514 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34515 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40516 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34517 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08518 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13520 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37521 }
522
523 /**
524 * @param {!DataTransfer} dataTransfer
525 */
526 _handleDrop(dataTransfer) {
527 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34528 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37529 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34530 }
Blink Reformat4c46d092018-04-07 15:32:37531 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34532 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37533 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34534 }
Blink Reformat4c46d092018-04-07 15:32:37535
Joey Arhar0e1093c2019-05-21 00:34:22536 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37537 }
538
539 /**
Tim van der Lippe119690c2020-01-13 12:31:30540 * @override
Blink Reformat4c46d092018-04-07 15:32:37541 * @param {!File} file
542 */
Joey Arhar0e1093c2019-05-21 00:34:22543 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13544 const outputStream = new Common.StringOutputStream.StringOutputStream();
545 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37546 const success = await reader.read(outputStream);
547 if (!success) {
548 this._harLoadFailed(reader.error().message);
549 return;
550 }
551 let harRoot;
552 try {
553 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13554 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37555 } catch (e) {
556 this._harLoadFailed(e);
557 return;
558 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13559 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37560 }
561
562 /**
563 * @param {string} message
564 */
565 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36566 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37567 }
568
569 /**
570 * @param {?string} groupKey
571 */
572 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34573 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37574 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34575 }
Blink Reformat4c46d092018-04-07 15:32:37576 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
577 this._activeGroupLookup = groupLookup;
578 this._invalidateAllItems();
579 }
580
581 /**
582 * @return {number}
583 */
584 _computeRowHeight() {
585 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
586 }
587
588 /**
Tim van der Lippe119690c2020-01-13 12:31:30589 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13590 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30591 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37592 */
593 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58594 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37595 }
596
597 /**
Tim van der Lippe119690c2020-01-13 12:31:30598 * @override
Blink Reformat4c46d092018-04-07 15:32:37599 * @return {number}
600 */
601 headerHeight() {
602 return this._headerHeight;
603 }
604
605 /**
Tim van der Lippe119690c2020-01-13 12:31:30606 * @override
Blink Reformat4c46d092018-04-07 15:32:37607 * @param {boolean} recording
608 */
609 setRecording(recording) {
610 this._recording = recording;
611 this._updateSummaryBar();
612 }
613
614 /**
615 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13616 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37617 */
618 modelAdded(networkManager) {
619 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34620 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37621 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34622 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13623 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37624 if (resourceTreeModel) {
625 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
626 resourceTreeModel.addEventListener(
627 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
628 }
629 }
630
631 /**
632 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13633 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37634 */
635 modelRemoved(networkManager) {
636 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13637 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37638 if (resourceTreeModel) {
639 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
640 resourceTreeModel.removeEventListener(
641 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
642 }
643 }
644 }
645
646 /**
Tim van der Lippe119690c2020-01-13 12:31:30647 * @override
Blink Reformat4c46d092018-04-07 15:32:37648 * @param {number} start
649 * @param {number} end
650 */
651 setWindow(start, end) {
652 if (!start && !end) {
653 this._timeFilter = null;
654 this._timeCalculator.setWindow(null);
655 } else {
Paul Lewis56509652019-12-06 12:51:58656 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30657 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37658 }
659 this._filterRequests();
660 }
661
Tim van der Lippe119690c2020-01-13 12:31:30662 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05663 resetFocus() {
664 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37665 }
666
667 _resetSuggestionBuilder() {
668 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58669 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
670 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
671 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
672 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
673 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
674 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
675 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37676 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
677 }
678
679 /**
Tim van der Lippec02a97c2020-02-14 14:39:27680 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37681 */
682 _filterChanged(event) {
683 this.removeAllNodeHighlights();
684 this._parseFilterQuery(this._textFilterUI.value());
685 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37686 }
687
Rajasekar Murugan3ad369e2020-02-19 18:20:12688 async resetFilter() {
689 this._textFilterUI.clear();
690 }
691
Blink Reformat4c46d092018-04-07 15:32:37692 _showRecordingHint() {
693 this._hideRecordingHint();
694 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
695 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18696
697 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40698 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18699 if (reloadShortcutDescriptor) {
700 reloadShortcutNode = this._recordingHint.createChild('b');
701 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
702 }
Blink Reformat4c46d092018-04-07 15:32:37703
704 if (this._recording) {
705 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38706 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18707 if (reloadShortcutNode) {
708 hintText.createChild('br');
709 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13710 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18711 }
Blink Reformat4c46d092018-04-07 15:32:37712 } else {
713 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40714 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18715 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13716 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18717 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
718 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13719 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18720 }
Blink Reformat4c46d092018-04-07 15:32:37721 }
Kayce Basques5444c1b2019-02-15 20:32:53722 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13723 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53724 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
725 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11726
727 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57728 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37729 }
730
731 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11732 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34733 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37734 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34735 }
Brandon Goddardc992d522020-01-08 21:44:57736 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37737 this._recordingHint = null;
738 }
739
740 /**
Amanda Baker6761aae2019-11-05 18:59:11741 * @param {boolean} value
742 */
743 _setHidden(value) {
744 this._columns.setHidden(value);
745 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
746 }
747
748 /**
Blink Reformat4c46d092018-04-07 15:32:37749 * @override
750 * @return {!Array.<!Element>}
751 */
752 elementsToRestoreScrollPositionsFor() {
753 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34754 {
Blink Reformat4c46d092018-04-07 15:32:37755 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34756 }
Blink Reformat4c46d092018-04-07 15:32:37757 return [this._dataGrid.scrollContainer];
758 }
759
Tim van der Lippe119690c2020-01-13 12:31:30760 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37761 columnExtensionResolved() {
762 this._invalidateAllItems(true);
763 }
764
765 _setupDataGrid() {
766 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
767 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34768 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37769 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34770 }
Blink Reformat4c46d092018-04-07 15:32:37771 });
772 this._dataGrid.setStickToBottom(true);
773 this._dataGrid.setName('networkLog');
774 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
775 this._dataGrid.element.classList.add('network-log-grid');
776 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
777 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
778 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05779 this._dataGrid.element.addEventListener('keydown', event => {
780 if (isEnterOrSpaceKey(event)) {
Simon Zünd98419832020-03-12 06:18:15781 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true});
Brandon Goddard88d885a2019-10-31 16:11:05782 event.consume(true);
783 }
784 });
Brandon Goddard44934902020-03-25 16:03:18785 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
786 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37787 return this._dataGrid;
788 }
789
790 /**
791 * @param {!Event} event
792 */
793 _dataGridMouseMove(event) {
794 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
795 const highlightInitiatorChain = event.shiftKey;
796 this._setHoveredNode(node, highlightInitiatorChain);
797 }
798
799 /**
Tim van der Lippe119690c2020-01-13 12:31:30800 * @override
801 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37802 */
803 hoveredNode() {
804 return this._hoveredNode;
805 }
806
807 /**
Tim van der Lippe119690c2020-01-13 12:31:30808 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37809 * @param {boolean=} highlightInitiatorChain
810 */
811 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34812 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37813 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34814 }
Blink Reformat4c46d092018-04-07 15:32:37815 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34816 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37817 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34818 }
Blink Reformat4c46d092018-04-07 15:32:37819 }
820
821 /**
822 * @param {!Event} event
823 */
824 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34825 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37826 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34827 }
Blink Reformat4c46d092018-04-07 15:32:37828 }
829
830 _updateSummaryBar() {
831 this._hideRecordingHint();
832
833 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20834 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37835 let selectedNodeNumber = 0;
836 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20837 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37838 let baseTime = -1;
839 let maxTime = -1;
840
841 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16842 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58843 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34844 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37845 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34846 }
Blink Reformat4c46d092018-04-07 15:32:37847 nodeCount++;
848 const requestTransferSize = request.transferSize;
849 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20850 const requestResourceSize = request.resourceSize;
851 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30852 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37853 selectedNodeNumber++;
854 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20855 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37856 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13857 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37858 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
859 // inspected url.
860 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13861 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
862 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37863 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34864 }
865 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37866 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34867 }
Blink Reformat4c46d092018-04-07 15:32:37868 }
869
870 if (!nodeCount) {
871 this._showRecordingHint();
872 return;
873 }
874
Joey Arhara86c14e2019-03-12 03:20:50875 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37876 /**
877 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50878 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37879 * @return {!Element}
880 */
Joey Arhara86c14e2019-03-12 03:20:50881 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13882 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50883 toolbarText.setTitle(title ? title : chunk);
884 this._summaryToolbar.appendToolbarItem(toolbarText);
885 return toolbarText.element;
886 };
Blink Reformat4c46d092018-04-07 15:32:37887
888 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50889 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
890 this._summaryToolbar.appendSeparator();
891 appendChunk(
892 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25893 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50894 this._summaryToolbar.appendSeparator();
895 appendChunk(
896 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25897 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37898 } else {
Joey Arhara86c14e2019-03-12 03:20:50899 appendChunk(ls`${nodeCount} requests`);
900 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25901 appendChunk(
902 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50903 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25904 appendChunk(
905 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37906 }
Dan Beam87466b52018-12-01 18:41:20907
Blink Reformat4c46d092018-04-07 15:32:37908 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50909 this._summaryToolbar.appendSeparator();
910 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37911 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50912 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30913 const domContentLoadedText =
914 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58915 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37916 }
917 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50918 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30919 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58920 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37921 }
922 }
Blink Reformat4c46d092018-04-07 15:32:37923 }
924
Tim van der Lippe119690c2020-01-13 12:31:30925 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37926 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34927 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37928 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34929 }
Blink Reformat4c46d092018-04-07 15:32:37930
931 this._needsRefresh = true;
932
Tim van der Lippe1d6e57a2019-09-30 11:55:34933 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37934 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34935 }
Blink Reformat4c46d092018-04-07 15:32:37936 }
937
938 /**
Tim van der Lippe119690c2020-01-13 12:31:30939 * @override
Blink Reformat4c46d092018-04-07 15:32:37940 * @param {!Array<number>} times
941 */
942 addFilmStripFrames(times) {
943 this._columns.addEventDividers(times, 'network-frame-divider');
944 }
945
946 /**
Tim van der Lippe119690c2020-01-13 12:31:30947 * @override
Blink Reformat4c46d092018-04-07 15:32:37948 * @param {number} time
949 */
950 selectFilmStripFrame(time) {
951 this._columns.selectFilmStripFrame(time);
952 }
953
Tim van der Lippe119690c2020-01-13 12:31:30954 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37955 clearFilmStripFrame() {
956 this._columns.clearFilmStripFrame();
957 }
958
959 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34960 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37961 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34962 }
Blink Reformat4c46d092018-04-07 15:32:37963 }
964
965 /**
966 * @param {boolean=} deferUpdate
967 */
968 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16969 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34970 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37971 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34972 } else {
Blink Reformat4c46d092018-04-07 15:32:37973 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34974 }
Blink Reformat4c46d092018-04-07 15:32:37975 }
976
977 /**
Tim van der Lippe119690c2020-01-13 12:31:30978 * @override
979 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37980 */
981 timeCalculator() {
982 return this._timeCalculator;
983 }
984
985 /**
Tim van der Lippe119690c2020-01-13 12:31:30986 * @override
987 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37988 */
989 calculator() {
990 return this._calculator;
991 }
992
993 /**
Tim van der Lippe119690c2020-01-13 12:31:30994 * @override
995 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37996 */
997 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34998 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37999 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341000 }
Blink Reformat4c46d092018-04-07 15:32:371001
1002 if (this._calculator !== x) {
1003 this._calculator = x;
1004 this._columns.setCalculator(this._calculator);
1005 }
1006 this._calculator.reset();
1007
Tim van der Lippe1d6e57a2019-09-30 11:55:341008 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371009 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341010 } else {
Blink Reformat4c46d092018-04-07 15:32:371011 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341012 }
Blink Reformat4c46d092018-04-07 15:32:371013
1014 this._invalidateAllItems();
1015 }
1016
1017 /**
Tim van der Lippec02a97c2020-02-14 14:39:271018 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371019 */
1020 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341021 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371022 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341023 }
Blink Reformat4c46d092018-04-07 15:32:371024
1025 const time = /** @type {number} */ (event.data.loadTime);
1026 if (time) {
1027 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301028 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371029 }
1030 }
1031
1032 /**
Tim van der Lippec02a97c2020-02-14 14:39:271033 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371034 */
1035 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341036 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371037 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341038 }
Blink Reformat4c46d092018-04-07 15:32:371039 const data = /** @type {number} */ (event.data);
1040 if (data) {
1041 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301042 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371043 }
1044 }
1045
1046 /**
1047 * @override
1048 */
1049 wasShown() {
1050 this._refreshIfNeeded();
1051 this._columns.wasShown();
1052 }
1053
1054 /**
1055 * @override
1056 */
1057 willHide() {
1058 this._columns.willHide();
1059 }
1060
1061 /**
1062 * @override
1063 */
1064 onResize() {
1065 this._rowHeight = this._computeRowHeight();
1066 }
1067
1068 /**
Tim van der Lippe119690c2020-01-13 12:31:301069 * @override
1070 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371071 */
1072 flatNodesList() {
1073 return this._dataGrid.rootNode().flatChildren();
1074 }
1075
Brandon Goddard44934902020-03-25 16:03:181076 _onDataGridFocus() {
1077 this.element.classList.add('grid-focused');
1078 this.updateNodeBackground();
1079 }
1080
1081 _onDataGridBlur() {
1082 this.element.classList.remove('grid-focused');
1083 this.updateNodeBackground();
1084 }
1085
Tim van der Lippe119690c2020-01-13 12:31:301086 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051087 updateNodeBackground() {
1088 if (this._dataGrid.selectedNode) {
1089 this._dataGrid.selectedNode.updateBackgroundColor();
1090 }
1091 }
1092
1093 /**
Tim van der Lippe119690c2020-01-13 12:31:301094 * @override
Brandon Goddard88d885a2019-10-31 16:11:051095 * @param {boolean} isSelected
1096 */
1097 updateNodeSelectedClass(isSelected) {
1098 if (isSelected) {
1099 this.element.classList.remove('no-node-selected');
1100 } else {
1101 this.element.classList.add('no-node-selected');
1102 }
1103 }
1104
Tim van der Lippe119690c2020-01-13 12:31:301105 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371106 stylesChanged() {
1107 this._columns.scheduleRefresh();
1108 }
1109
1110 _refresh() {
1111 this._needsRefresh = false;
1112
1113 if (this._refreshRequestId) {
1114 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1115 this._refreshRequestId = null;
1116 }
1117
1118 this.removeAllNodeHighlights();
1119
1120 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1121 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1122 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1123 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1124
Tim van der Lippe119690c2020-01-13 12:31:301125 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371126 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301127 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371128 const nodesToRefresh = [];
1129
Tim van der Lippe119690c2020-01-13 12:31:301130 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371131 const staleNodes = new Set();
1132
1133 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1134 // node so we loop until we have no more stale requests.
1135 while (this._staleRequests.size) {
1136 const request = this._staleRequests.firstValue();
1137 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581138 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341139 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371140 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341141 }
Blink Reformat4c46d092018-04-07 15:32:371142 staleNodes.add(node);
1143 }
1144
1145 for (const node of staleNodes) {
1146 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341147 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371148 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341149 }
Blink Reformat4c46d092018-04-07 15:32:371150
Tim van der Lippe1d6e57a2019-09-30 11:55:341151 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371152 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341153 }
Blink Reformat4c46d092018-04-07 15:32:371154 const request = node.request();
1155 this._timeCalculator.updateBoundaries(request);
1156 this._durationCalculator.updateBoundaries(request);
1157 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301158 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371159 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341160 }
Tim van der Lippe119690c2020-01-13 12:31:301161 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371162 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1163 if (removeFromParent) {
1164 let parent = node.parent;
1165 parent.removeChild(node);
1166 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1167 const grandparent = parent.parent;
1168 grandparent.removeChild(parent);
1169 parent = grandparent;
1170 }
1171 }
1172
Tim van der Lippe1d6e57a2019-09-30 11:55:341173 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371174 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341175 }
Blink Reformat4c46d092018-04-07 15:32:371176
1177 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1178 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1179 nodesToRefresh.push(newParent);
1180 }
1181 nodesToInsert.set(node, newParent);
1182 }
1183
Tim van der Lippe1d6e57a2019-09-30 11:55:341184 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371185 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341186 }
Blink Reformat4c46d092018-04-07 15:32:371187
Tim van der Lippe1d6e57a2019-09-30 11:55:341188 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371189 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341190 }
Blink Reformat4c46d092018-04-07 15:32:371191
1192 this._updateSummaryBar();
1193
Tim van der Lippe1d6e57a2019-09-30 11:55:341194 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371195 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341196 }
Blink Reformat4c46d092018-04-07 15:32:371197
1198 this._dataGrid.updateInstantly();
1199 this._didRefreshForTest();
1200 }
1201
1202 _didRefreshForTest() {
1203 }
1204
1205 /**
Tim van der Lippe119690c2020-01-13 12:31:301206 * @param {!NetworkRequestNode} node
1207 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371208 */
1209 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341210 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371211 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341212 }
Blink Reformat4c46d092018-04-07 15:32:371213
1214 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341215 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371216 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341217 }
Blink Reformat4c46d092018-04-07 15:32:371218 return groupNode;
1219 }
1220
1221 _reset() {
Simon Zünd98419832020-03-12 06:18:151222 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371223
1224 this._setHoveredNode(null);
1225 this._columns.reset();
1226
1227 this._timeFilter = null;
1228 this._calculator.reset();
1229
1230 this._timeCalculator.setWindow(null);
1231 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371232
Tim van der Lippe1d6e57a2019-09-30 11:55:341233 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371234 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341235 }
Blink Reformat4c46d092018-04-07 15:32:371236 this._staleRequests.clear();
1237 this._resetSuggestionBuilder();
1238
1239 this._mainRequestLoadTime = -1;
1240 this._mainRequestDOMContentLoadedTime = -1;
1241
1242 this._dataGrid.rootNode().removeChildren();
1243 this._updateSummaryBar();
1244 this._dataGrid.setStickToBottom(true);
1245 this.scheduleRefresh();
1246 }
1247
1248 /**
Tim van der Lippe119690c2020-01-13 12:31:301249 * @override
Blink Reformat4c46d092018-04-07 15:32:371250 * @param {string} filterString
1251 */
1252 setTextFilterValue(filterString) {
1253 this._textFilterUI.setValue(filterString);
1254 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371255 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131256 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371257 this._resourceCategoryFilterUI.reset();
1258 }
1259
1260 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131261 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371262 */
1263 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301264 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581265 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301266 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371267
Tim van der Lippe1d6e57a2019-09-30 11:55:341268 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371269 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341270 }
Blink Reformat4c46d092018-04-07 15:32:371271 return node;
1272 }
1273
1274 /**
Tim van der Lippec02a97c2020-02-14 14:39:271275 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371276 */
1277 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131278 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371279 this._refreshRequest(request);
1280 }
1281
1282 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131283 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371284 */
1285 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581286 NetworkLogView._subdomains(request.domain)
1287 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1288 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1289 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1290 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1291 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371292
1293 const priority = request.priority();
1294 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501295 this._suggestionBuilder.addItem(
1296 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371297 }
1298
1299 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581300 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371301 }
1302
1303 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581304 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371305 }
1306
1307 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581308 const suggestion =
1309 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1310 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371311 }
1312
1313 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341314 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581315 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341316 }
Jan Scheffler341eea52019-12-12 09:08:411317
1318 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581319 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1320 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1321 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371322 }
1323
Jan Scheffler341eea52019-12-12 09:08:411324 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1325 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1326 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541327 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411328 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1329 }
1330
Blink Reformat4c46d092018-04-07 15:32:371331 this._staleRequests.add(request);
1332 this.scheduleRefresh();
1333 }
1334
1335 /**
Tim van der Lippe119690c2020-01-13 12:31:301336 * @override
Blink Reformat4c46d092018-04-07 15:32:371337 * @return {number}
1338 */
1339 rowHeight() {
1340 return this._rowHeight;
1341 }
1342
1343 /**
Tim van der Lippe119690c2020-01-13 12:31:301344 * @override
Blink Reformat4c46d092018-04-07 15:32:371345 * @param {boolean} gridMode
1346 */
1347 switchViewMode(gridMode) {
1348 this._columns.switchViewMode(gridMode);
1349 }
1350
1351 /**
Tim van der Lippe119690c2020-01-13 12:31:301352 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131353 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1354 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371355 */
1356 handleContextMenuForRequest(contextMenu, request) {
1357 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131358 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371359 const footerSection = copyMenu.footerSection();
1360 if (request) {
1361 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131362 UI.UIUtils.copyLinkAddressLabel(),
1363 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1364 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371365 if (request.requestHeadersText()) {
1366 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131367 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371368 }
1369
1370 if (request.responseHeadersText) {
1371 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131372 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371373 }
1374
1375 if (request.finished) {
1376 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131377 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371378 }
1379
Harley Libcf41f92018-09-10 18:01:131380 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131381 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371382 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131383 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1384 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371385 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131386 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291387 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131388 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1389 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371390 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131391 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1392 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131393 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131394 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1395 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371396 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131397 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1398 footerSection.appendItem(
1399 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1400 footerSection.appendItem(
1401 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1402 footerSection.appendItem(
1403 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1404 footerSection.appendItem(
1405 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371406 } else {
Harley Libcf41f92018-09-10 18:01:131407 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131408 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291409 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131410 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1411 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131412 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131413 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1414 footerSection.appendItem(
1415 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1416 footerSection.appendItem(
1417 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1418 footerSection.appendItem(
1419 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371420 }
1421 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371423 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131424 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371425
Joey Arhar0e1093c2019-05-21 00:34:221426 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371427
Blink Reformat4c46d092018-04-07 15:32:371428 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131429 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1430 contextMenu.editSection().appendItem(
1431 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371432
1433 if (request) {
1434 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081435 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371436 let patterns = manager.blockedPatterns();
1437
Tim van der Lippeffa78622019-09-16 12:07:121438 /**
1439 * @param {string} url
1440 */
1441 function addBlockedURL(url) {
1442 patterns.push({enabled: true, url: url});
1443 manager.setBlockedPatterns(patterns);
1444 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261445 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121446 }
1447
1448 /**
1449 * @param {string} url
1450 */
1451 function removeBlockedURL(url) {
1452 patterns = patterns.filter(pattern => pattern.url !== url);
1453 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261454 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121455 }
1456
Blink Reformat4c46d092018-04-07 15:32:371457 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1458 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1459 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131460 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371461 } else if (urlWithoutScheme) {
1462 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1463 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131464 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371465 }
1466
1467 const domain = request.parsedURL.domain();
1468 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1469 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131470 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371471 } else if (domain) {
1472 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1473 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131474 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371475 }
1476
Tim van der Lippe0ed1d2b2020-02-04 13:45:131477 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371478 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131479 Common.UIString.UIString('Replay XHR'),
1480 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371481 }
Blink Reformat4c46d092018-04-07 15:32:371482 }
1483 }
1484
1485 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161486 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171487 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131488 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171489 });
Blink Reformat4c46d092018-04-07 15:32:371490 }
1491
1492 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131493 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1494 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371495 }
1496
1497 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131498 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371499 * @param {string} platform
1500 */
1501 async _copyCurlCommand(request, platform) {
1502 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131503 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371504 }
1505
1506 /**
1507 * @param {string} platform
1508 */
1509 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161510 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131511 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371512 }
1513
1514 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131515 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291516 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371517 */
Jan Scheffler7c50d1f2019-12-17 13:33:291518 async _copyFetchCall(request, includeCookies) {
1519 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131520 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371521 }
1522
Jan Scheffler7c50d1f2019-12-17 13:33:291523 /**
1524 * @param {boolean} includeCookies
1525 */
1526 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161527 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131528 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371529 }
1530
1531 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131532 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371533 */
1534 async _copyPowerShellCommand(request) {
1535 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131536 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371537 }
1538
1539 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161540 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131541 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371542 }
1543
Tim van der Lippe119690c2020-01-13 12:31:301544 /**
1545 * @override
1546 * @return {!Promise}
1547 */
Joey Arhar0e1093c2019-05-21 00:34:221548 async exportAll() {
Paul Lewisdaac1062020-03-05 14:37:101549 const url = SDK.SDKModel.TargetManager.instance().mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131550 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371551 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131552 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371553
Tim van der Lippe1d6e57a2019-09-30 11:55:341554 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371555 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341556 }
Blink Reformat4c46d092018-04-07 15:32:371557
Tim van der Lippe0ed1d2b2020-02-04 13:45:131558 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371559 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301560 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371561 progressIndicator.done();
1562 stream.close();
1563 }
1564
1565 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131566 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081567 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341568 }
Blink Reformat4c46d092018-04-07 15:32:371569 }
1570
1571 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081573 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341574 }
Blink Reformat4c46d092018-04-07 15:32:371575 }
1576
1577 _removeAllHighlights() {
1578 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341579 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131580 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341581 }
Blink Reformat4c46d092018-04-07 15:32:371582 this._highlightedSubstringChanges = [];
1583 }
1584
1585 /**
Tim van der Lippe119690c2020-01-13 12:31:301586 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371587 * @return {boolean}
1588 */
1589 _applyFilter(node) {
1590 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341591 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371592 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341593 }
Blink Reformat4c46d092018-04-07 15:32:371594 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341595 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371596 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341597 }
1598 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371599 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341600 }
Sigurd Schneider874023b2020-03-24 12:23:071601 if (this._onlyIssuesFilterUI.checked() && !SDK.RelatedIssue.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371602 return false;
1603 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131604 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1605 return false;
1606 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341607 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371608 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341609 }
Blink Reformat4c46d092018-04-07 15:32:371610 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341611 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371612 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341613 }
Blink Reformat4c46d092018-04-07 15:32:371614 }
1615 return true;
1616 }
1617
1618 /**
1619 * @param {string} query
1620 */
1621 _parseFilterQuery(query) {
1622 const descriptors = this._filterParser.parse(query);
1623 this._filters = descriptors.map(descriptor => {
1624 const key = descriptor.key;
1625 const text = descriptor.text || '';
1626 const regex = descriptor.regex;
1627 let filter;
1628 if (key) {
1629 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581630 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1631 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371632 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581633 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371634 } else {
Paul Lewis56509652019-12-06 12:51:581635 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371636 }
Paul Lewis56509652019-12-06 12:51:581637 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371638 });
1639 }
1640
1641 /**
Paul Lewis56509652019-12-06 12:51:581642 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371643 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161644 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371645 */
1646 _createSpecialFilter(type, value) {
1647 switch (type) {
Paul Lewis56509652019-12-06 12:51:581648 case FilterType.Domain:
1649 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371650
Paul Lewis56509652019-12-06 12:51:581651 case FilterType.HasResponseHeader:
1652 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371653
Paul Lewis56509652019-12-06 12:51:581654 case FilterType.Is:
1655 if (value.toLowerCase() === IsFilterType.Running) {
1656 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341657 }
Paul Lewis56509652019-12-06 12:51:581658 if (value.toLowerCase() === IsFilterType.FromCache) {
1659 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341660 }
Paul Lewis56509652019-12-06 12:51:581661 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1662 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 }
Paul Lewis56509652019-12-06 12:51:581664 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1665 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341666 }
Blink Reformat4c46d092018-04-07 15:32:371667 break;
1668
Paul Lewis56509652019-12-06 12:51:581669 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371670 return this._createSizeFilter(value.toLowerCase());
1671
Paul Lewis56509652019-12-06 12:51:581672 case FilterType.Method:
1673 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371674
Paul Lewis56509652019-12-06 12:51:581675 case FilterType.MimeType:
1676 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371677
Paul Lewis56509652019-12-06 12:51:581678 case FilterType.MixedContent:
1679 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371680
Paul Lewis56509652019-12-06 12:51:581681 case FilterType.Scheme:
1682 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371683
Paul Lewis56509652019-12-06 12:51:581684 case FilterType.SetCookieDomain:
1685 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371686
Paul Lewis56509652019-12-06 12:51:581687 case FilterType.SetCookieName:
1688 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371689
Paul Lewis56509652019-12-06 12:51:581690 case FilterType.SetCookieValue:
1691 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371692
Jan Scheffler341eea52019-12-12 09:08:411693 case FilterType.CookieDomain:
1694 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1695
1696 case FilterType.CookieName:
1697 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1698
Simon Zündc9759102020-03-25 11:24:541699 case FilterType.CookiePath:
1700 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1701
Jan Scheffler341eea52019-12-12 09:08:411702 case FilterType.CookieValue:
1703 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1704
Paul Lewis56509652019-12-06 12:51:581705 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501706 return NetworkLogView._requestPriorityFilter.bind(
1707 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371708
Paul Lewis56509652019-12-06 12:51:581709 case FilterType.StatusCode:
1710 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371711 }
1712 return null;
1713 }
1714
1715 /**
1716 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161717 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371718 */
1719 _createSizeFilter(value) {
1720 let multiplier = 1;
1721 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411722 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371723 value = value.substring(0, value.length - 1);
1724 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411725 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371726 value = value.substring(0, value.length - 1);
1727 }
1728 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341729 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371730 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 }
Paul Lewis56509652019-12-06 12:51:581732 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371733 }
1734
1735 _filterRequests() {
1736 this._removeAllHighlights();
1737 this._invalidateAllItems();
1738 }
1739
1740 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131741 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301742 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371743 */
1744 _reveal(request) {
1745 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581746 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341747 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371748 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341749 }
Blink Reformat4c46d092018-04-07 15:32:371750 node.reveal();
1751 return node;
1752 }
1753
1754 /**
Tim van der Lippe119690c2020-01-13 12:31:301755 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131756 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371757 */
1758 revealAndHighlightRequest(request) {
1759 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341760 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371761 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341762 }
Blink Reformat4c46d092018-04-07 15:32:371763 }
1764
1765 /**
Tim van der Lippe119690c2020-01-13 12:31:301766 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131767 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371768 */
1769 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141770 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371771 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341772 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371773 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341774 }
Blink Reformat4c46d092018-04-07 15:32:371775 }
1776
Tim van der Lippe119690c2020-01-13 12:31:301777 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371778 removeAllNodeHighlights() {
1779 if (this._highlightedNode) {
1780 this._highlightedNode.element().classList.remove('highlighted-row');
1781 this._highlightedNode = null;
1782 }
1783 }
1784
1785 /**
Tim van der Lippe119690c2020-01-13 12:31:301786 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371787 */
1788 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131789 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371790 this._highlightedNode = node;
1791 }
1792
1793 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131794 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1795 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131796 */
1797 _filterOutBlobRequests(requests) {
1798 return requests.filter(request => !request.isBlobRequest());
1799 }
1800
1801 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131802 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291803 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371804 * @return {!Promise<string>}
1805 */
Jan Scheffler7c50d1f2019-12-17 13:33:291806 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371807 const ignoredHeaders = {
1808 // Internal headers
1809 'method': 1,
1810 'path': 1,
1811 'scheme': 1,
1812 'version': 1,
1813
1814 // Unsafe headers
1815 // Keep this list synchronized with src/net/http/http_util.cc
1816 'accept-charset': 1,
1817 'accept-encoding': 1,
1818 'access-control-request-headers': 1,
1819 'access-control-request-method': 1,
1820 'connection': 1,
1821 'content-length': 1,
1822 'cookie': 1,
1823 'cookie2': 1,
1824 'date': 1,
1825 'dnt': 1,
1826 'expect': 1,
1827 'host': 1,
1828 'keep-alive': 1,
1829 'origin': 1,
1830 'referer': 1,
1831 'te': 1,
1832 'trailer': 1,
1833 'transfer-encoding': 1,
1834 'upgrade': 1,
1835 'via': 1,
1836 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1837 'user-agent': 1
1838 };
1839
1840 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1841
1842 const url = JSON.stringify(request.url());
1843
1844 const requestHeaders = request.requestHeaders();
1845 const headerData = requestHeaders.reduce((result, header) => {
1846 const name = header.name;
1847
Tim van der Lippe1d6e57a2019-09-30 11:55:341848 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371849 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341850 }
Blink Reformat4c46d092018-04-07 15:32:371851
1852 return result;
1853 }, new Headers());
1854
1855 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341856 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411857 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341858 }
Blink Reformat4c46d092018-04-07 15:32:371859
1860 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411861 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1862 'include' :
1863 'omit';
Blink Reformat4c46d092018-04-07 15:32:371864
1865 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1866
1867 const referrer = referrerHeader ? referrerHeader.value : void 0;
1868
1869 const referrerPolicy = request.referrerPolicy() || void 0;
1870
1871 const requestBody = await request.requestFormData();
1872
1873 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411874 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371875 referrer,
1876 referrerPolicy,
1877 body: requestBody,
1878 method: request.requestMethod,
1879 mode: 'cors'
1880 };
1881
Jan Scheffler7c50d1f2019-12-17 13:33:291882 if (includeCookies) {
1883 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1884 if (cookieHeader) {
1885 fetchOptions.headers = {
1886 ...headers,
1887 'cookie': cookieHeader.value,
1888 };
1889 }
1890 } else {
1891 fetchOptions.credentials = credentials;
1892 }
1893
Jan Scheffler172d5212020-01-02 14:42:561894 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371895 return `fetch(${url}, ${options});`;
1896 }
1897
1898 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131899 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291900 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131901 * @return {!Promise<string>}
1902 */
Jan Scheffler7c50d1f2019-12-17 13:33:291903 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131904 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291905 const commands =
1906 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131907 return commands.join(' ;\n');
1908 }
1909
1910 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131911 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371912 * @param {string} platform
1913 * @return {!Promise<string>}
1914 */
1915 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561916 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361917 // Most of these headers are derived from the URL and are automatically added by cURL.
1918 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1919 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371920
1921 function escapeStringWin(str) {
1922 /* If there are no new line characters do not escape the " characters
1923 since it only uglifies the command.
1924
1925 Because cmd.exe parser and MS Crt arguments parsers use some of the
1926 same escape characters, they can interact with each other in
1927 horrible ways, the order of operations is critical.
1928
1929 Replace \ with \\ first because it is an escape character for certain
1930 conditions in both parsers.
1931
1932 Replace all " with \" to ensure the first parser does not remove it.
1933
1934 Then escape all characters we are not sure about with ^ to ensure it
1935 gets to MS Crt parser safely.
1936
1937 The % character is special because MS Crt parser will try and look for
1938 ENV variables and fill them in it's place. We cannot escape them with %
1939 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1940 parser); So we can get cmd.exe parser to escape the character after it,
1941 if it is followed by a valid beginning character of an ENV variable.
1942 This ensures we do not try and double escape another ^ if it was placed
1943 by the previous replace.
1944
1945 Lastly we replace new lines with ^ and TWO new lines because the first
1946 new line is there to enact the escape command the second is the character
1947 to escape (in this case new line).
1948 */
1949 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1950 return encapsChars +
1951 str.replace(/\\/g, '\\\\')
1952 .replace(/"/g, '\\"')
1953 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1954 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1955 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1956 encapsChars;
1957 }
1958
1959 /**
1960 * @param {string} str
1961 * @return {string}
1962 */
1963 function escapeStringPosix(str) {
1964 /**
1965 * @param {string} x
1966 * @return {string}
1967 */
1968 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221969 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121970 let hexString = code.toString(16);
1971 // Zero pad to four digits to comply with ANSI-C Quoting:
1972 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341973 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121974 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341975 }
Joey Arhar2d21f712019-05-20 21:07:121976
1977 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371978 }
1979
Mathias Bynensf06e8c02020-02-28 13:58:281980 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371981 // Use ANSI-C quoting syntax.
1982 return '$\'' +
1983 str.replace(/\\/g, '\\\\')
1984 .replace(/\'/g, '\\\'')
1985 .replace(/\n/g, '\\n')
1986 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:281987 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371988 '\'';
Blink Reformat4c46d092018-04-07 15:32:371989 }
Mathias Bynensf06e8c02020-02-28 13:58:281990 // Use single quote syntax.
1991 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:371992 }
1993
1994 // cURL command expected to run on the same platform that DevTools run
1995 // (it may be different from the inspected page platform).
1996 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1997
1998 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1999
2000 let inferredMethod = 'GET';
2001 const data = [];
2002 const requestContentType = request.requestContentType();
2003 const formData = await request.requestFormData();
2004 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272005 // Note that formData is not necessarily urlencoded because it might for example
2006 // come from a fetch request made with an explicitly unencoded body.
2007 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372008 ignoredHeaders['content-length'] = true;
2009 inferredMethod = 'POST';
2010 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:562011 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372012 ignoredHeaders['content-length'] = true;
2013 inferredMethod = 'POST';
2014 }
2015
2016 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292017 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372018 }
2019
2020 const requestHeaders = request.requestHeaders();
2021 for (let i = 0; i < requestHeaders.length; i++) {
2022 const header = requestHeaders[i];
2023 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342024 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:372025 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342026 }
Jan Scheffler172d5212020-01-02 14:42:562027 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372028 }
2029 command = command.concat(data);
2030 command.push('--compressed');
2031
Tim van der Lippe1d6e57a2019-09-30 11:55:342032 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372033 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342034 }
Jan Scheffler172d5212020-01-02 14:42:562035 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372036 }
2037
2038 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132039 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132040 * @param {string} platform
2041 * @return {!Promise<string>}
2042 */
2043 async _generateAllCurlCommand(requests, platform) {
2044 const nonBlobRequests = this._filterOutBlobRequests(requests);
2045 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342046 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132047 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342048 }
Mathias Bynensf06e8c02020-02-28 13:58:282049 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132050 }
2051
2052 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132053 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372054 * @return {!Promise<string>}
2055 */
2056 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562057 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372058 const ignoredHeaders =
2059 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2060
2061 /**
2062 * @param {string} str
2063 * @return {string}
2064 */
2065 function escapeString(str) {
2066 return '"' +
2067 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2068 }
2069
Jan Scheffler172d5212020-01-02 14:42:562070 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372071
2072 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562073 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372074 }
2075
2076 const requestHeaders = request.requestHeaders();
2077 const headerNameValuePairs = [];
2078 for (const header of requestHeaders) {
2079 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342080 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372081 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342082 }
Blink Reformat4c46d092018-04-07 15:32:372083 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2084 }
2085 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562086 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372087 }
2088
2089 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2090 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562091 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372092 }
2093
2094 const formData = await request.requestFormData();
2095 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372096 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342097 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562098 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342099 } else {
Jan Scheffler172d5212020-01-02 14:42:562100 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342101 }
Blink Reformat4c46d092018-04-07 15:32:372102 }
2103
Jan Scheffler172d5212020-01-02 14:42:562104 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372105 }
Harley Libcf41f92018-09-10 18:01:132106
2107 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132108 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132109 * @return {!Promise<string>}
2110 */
2111 async _generateAllPowerShellCommand(requests) {
2112 const nonBlobRequests = this._filterOutBlobRequests(requests);
2113 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2114 return commands.join(';\r\n');
2115 }
Joey Arhara86c14e2019-03-12 03:20:502116
2117 /**
2118 * @return {string}
2119 */
2120 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552121 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502122 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342123 }
Joey Arhara86c14e2019-03-12 03:20:502124 return '#0867CB';
2125 }
2126
2127 /**
2128 * @return {string}
2129 */
2130 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132131 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502132 }
Paul Lewis56509652019-12-06 12:51:582133}
Blink Reformat4c46d092018-04-07 15:32:372134
Tim van der Lippe119690c2020-01-13 12:31:302135export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582136export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372137
Paul Lewis56509652019-12-06 12:51:582138export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372139 'http': true,
2140 'https': true,
2141 'ws': true,
2142 'wss': true
2143};
2144
Blink Reformat4c46d092018-04-07 15:32:372145/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582146export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372147 Domain: 'domain',
2148 HasResponseHeader: 'has-response-header',
2149 Is: 'is',
2150 LargerThan: 'larger-than',
2151 Method: 'method',
2152 MimeType: 'mime-type',
2153 MixedContent: 'mixed-content',
2154 Priority: 'priority',
2155 Scheme: 'scheme',
2156 SetCookieDomain: 'set-cookie-domain',
2157 SetCookieName: 'set-cookie-name',
2158 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412159 CookieDomain: 'cookie-domain',
2160 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542161 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412162 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372163 StatusCode: 'status-code'
2164};
2165
2166/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582167export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372168 All: 'all',
2169 Displayed: 'displayed',
2170 Blocked: 'blocked',
2171 BlockOverridden: 'block-overridden'
2172};
2173
2174/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582175export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372176 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052177 FromCache: 'from-cache',
2178 ServiceWorkerIntercepted: 'service-worker-intercepted',
2179 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372180};
2181
2182/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582183export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372184
2185/**
2186 * @interface
2187 */
Paul Lewis56509652019-12-06 12:51:582188export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372189 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132190 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302191 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372192 */
Paul Lewis56509652019-12-06 12:51:582193 groupNodeForRequest(request) {
2194 }
Blink Reformat4c46d092018-04-07 15:32:372195
Paul Lewis56509652019-12-06 12:51:582196 reset() {
2197 }
2198}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162199
2200/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2201export let Filter;