blob: dcf7d9269344fe3aaf42439cf6b7f1d424f352d2 [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';
37import * as SDK from '../sdk/sdk.js';
38import * as TextUtils from '../text_utils/text_utils.js';
39import * as UI from '../ui/ui.js';
40
Tim van der Lippe119690c2020-01-13 12:31:3041import {HARWriter} from './HARWriter.js';
42import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
43import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
44import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
45import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
46
Blink Reformat4c46d092018-04-07 15:32:3747/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1348 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3049 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3750 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1351export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3752 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1353 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3754 * @param {!Element} progressBarContainer
Tim van der Lippe0ed1d2b2020-02-04 13:45:1355 * @param {!Common.Settings.Setting} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3756 */
57 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
58 super();
59 this.setMinimumSize(50, 64);
60 this.registerRequiredCSS('network/networkLogView.css');
61
62 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0563 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3764
Paul Lewis6bcdb182020-01-23 11:08:0565 this._networkHideDataURLSetting = self.Common.settings.createSetting('networkHideDataURL', false);
66 this._networkShowIssuesOnlySetting = self.Common.settings.createSetting('networkShowIssuesOnly', false);
67 this._networkResourceTypeFiltersSetting = self.Common.settings.createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3768
69 this._rawRowHeight = 0;
70 this._progressBarContainer = progressBarContainer;
71 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
72 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
73
74 /**
Paul Lewis56509652019-12-06 12:51:5875 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3776 */
77 function updateRowHeight() {
78 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
79 this._rowHeight = this._computeRowHeight();
80 }
81 this._rawRowHeight = 0;
82 this._rowHeight = 0;
83 updateRowHeight.call(this);
84
Tim van der Lippe119690c2020-01-13 12:31:3085 /** @type {!NetworkTransferTimeCalculator} */
86 this._timeCalculator = new NetworkTransferTimeCalculator();
87 /** @type {!NetworkTransferDurationCalculator} */
88 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3789 this._calculator = this._timeCalculator;
90
Tim van der Lippe119690c2020-01-13 12:31:3091 this._columns =
92 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:3793 this._columns.show(this.element);
94
Tim van der Lippe0ed1d2b2020-02-04 13:45:1395 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:3796 this._staleRequests = new Set();
97 /** @type {number} */
98 this._mainRequestLoadTime = -1;
99 /** @type {number} */
100 this._mainRequestDOMContentLoadedTime = -1;
101 this._highlightedSubstringChanges = [];
102
103 /** @type {!Array.<!Network.NetworkLogView.Filter>} */
104 this._filters = [];
105 /** @type {?Network.NetworkLogView.Filter} */
106 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30107 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37108 this._hoveredNode = null;
109 /** @type {?Element} */
110 this._recordingHint = null;
111 /** @type {?number} */
112 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30113 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._highlightedNode = null;
115
Tim van der Lippe0ed1d2b2020-02-04 13:45:13116 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37117
118 this._recording = false;
119 this._needsRefresh = false;
120
121 this._headerHeight = 0;
122
Paul Lewis56509652019-12-06 12:51:58123 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37124 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30125 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37126
Paul Lewis56509652019-12-06 12:51:58127 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37128 this._activeGroupLookup = null;
129
Tim van der Lippe0ed1d2b2020-02-04 13:45:13130 this._textFilterUI = new UI.FilterBar.TextFilterUI();
131 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37132 filterBar.addFilter(this._textFilterUI);
133
Tim van der Lippe0ed1d2b2020-02-04 13:45:13134 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
135 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
136 this._dataURLFilterUI.addEventListener(
137 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48138 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37139 filterBar.addFilter(this._dataURLFilterUI);
140
141 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13142 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37143 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 this._resourceCategoryFilterUI =
145 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20146 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37147 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13148 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37149 filterBar.addFilter(this._resourceCategoryFilterUI);
150
Tim van der Lippe0ed1d2b2020-02-04 13:45:13151 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
152 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
153 this._onlyIssuesFilterUI.addEventListener(
154 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41155 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37156 filterBar.addFilter(this._onlyIssuesFilterUI);
157
158
Tim van der Lippe0ed1d2b2020-02-04 13:45:13159 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
160 this._suggestionBuilder =
161 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37162 this._resetSuggestionBuilder();
163
164 this._dataGrid = this._columns.dataGrid();
165 this._setupDataGrid();
166 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49167 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13168 UI.Toolbar.ToolbarButton.Events.Click,
169 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37170
Tim van der Lippe0ed1d2b2020-02-04 13:45:13171 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37172
Tim van der Lippe0ed1d2b2020-02-04 13:45:13173 new UI.DropTarget.DropTarget(
174 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
175 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37176
Paul Lewis4b64b3f2020-01-23 11:41:20177 self.Common.settings.moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37178 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
179
Tim van der Lippe0ed1d2b2020-02-04 13:45:13180 self.SDK.targetManager.observeModels(SDK.NetworkManager.NetworkManager, this);
Paul Lewisca3665d2020-01-24 13:31:16181 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
182 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
183 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37184
185 this._updateGroupByFrame();
Paul Lewis4b64b3f2020-01-23 11:41:20186 self.Common.settings.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37187
188 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37189 }
190
Blink Reformat4c46d092018-04-07 15:32:37191 _updateGroupByFrame() {
Paul Lewis4b64b3f2020-01-23 11:41:20192 const value = self.Common.settings.moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37193 this._setGrouping(value ? 'Frame' : null);
194 }
195
196 /**
197 * @param {string} key
198 * @param {!Array<string>} values
199 */
200 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58201 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37202 values.sort((a, b) => {
203 const aPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(a));
204 const bPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(b));
205 return PerfUI.networkPriorityWeight(aPriority) - PerfUI.networkPriorityWeight(bPriority);
206 });
207 } else {
208 values.sort();
209 }
210 }
211
212 /**
213 * @param {!Network.NetworkLogView.Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13214 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37215 * @return {boolean}
216 */
217 static _negativeFilter(filter, request) {
218 return !filter(request);
219 }
220
221 /**
222 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13223 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37224 * @return {boolean}
225 */
226 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34227 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37228 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34229 }
Blink Reformat4c46d092018-04-07 15:32:37230
231 return regex.test(request.path() + '/' + request.name());
232 }
233
234 /**
235 * @param {string} domain
236 * @return {!Array.<string>}
237 */
238 static _subdomains(domain) {
239 const result = [domain];
240 let indexOfPeriod = domain.indexOf('.');
241 while (indexOfPeriod !== -1) {
242 result.push('*' + domain.substring(indexOfPeriod));
243 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
244 }
245 return result;
246 }
247
248 /**
249 * @param {string} value
250 * @return {!Network.NetworkLogView.Filter}
251 */
252 static _createRequestDomainFilter(value) {
253 /**
254 * @param {string} string
255 * @return {string}
256 */
257 function escapeForRegExp(string) {
258 return string.escapeForRegExp();
259 }
260 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58261 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37262 }
263
264 /**
265 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13266 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37267 * @return {boolean}
268 */
269 static _requestDomainFilter(regex, request) {
270 return regex.test(request.domain);
271 }
272
273 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13274 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37275 * @return {boolean}
276 */
277 static _runningRequestFilter(request) {
278 return !request.finished;
279 }
280
281 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13282 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37283 * @return {boolean}
284 */
285 static _fromCacheRequestFilter(request) {
286 return request.cached();
287 }
288
289 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13290 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05291 * @return {boolean}
292 */
293 static _interceptedByServiceWorkerFilter(request) {
294 return request.fetchedViaServiceWorker;
295 }
296
297 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13298 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05299 * @return {boolean}
300 */
301 static _initiatedByServiceWorkerFilter(request) {
302 return request.initiatedByServiceWorker();
303 }
304
305 /**
Blink Reformat4c46d092018-04-07 15:32:37306 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13307 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37308 * @return {boolean}
309 */
310 static _requestResponseHeaderFilter(value, request) {
311 return request.responseHeaderValue(value) !== undefined;
312 }
313
314 /**
315 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13316 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37317 * @return {boolean}
318 */
319 static _requestMethodFilter(value, request) {
320 return request.requestMethod === value;
321 }
322
323 /**
324 * @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 _requestPriorityFilter(value, request) {
329 return request.priority() === value;
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 _requestMimeTypeFilter(value, request) {
338 return request.mimeType === value;
339 }
340
341 /**
Paul Lewis56509652019-12-06 12:51:58342 * @param {!MixedContentFilterValues} 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 _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58347 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37348 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Paul Lewis56509652019-12-06 12:51:58349 } else if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37350 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58351 } else if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37352 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58353 } else if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37354 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34355 }
Blink Reformat4c46d092018-04-07 15:32:37356
357 return false;
358 }
359
360 /**
361 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13362 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37363 * @return {boolean}
364 */
365 static _requestSchemeFilter(value, request) {
366 return request.scheme === value;
367 }
368
369 /**
370 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13371 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37372 * @return {boolean}
373 */
Jan Scheffler341eea52019-12-12 09:08:41374 static _requestCookieDomainFilter(value, request) {
375 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
376 }
377
378 /**
379 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13380 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41381 * @return {boolean}
382 */
383 static _requestCookieNameFilter(value, request) {
384 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
385 }
386
387 /**
388 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13389 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41390 * @return {boolean}
391 */
392 static _requestCookieValueFilter(value, request) {
393 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
394 }
395
396 /**
397 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13398 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41399 * @return {boolean}
400 */
Blink Reformat4c46d092018-04-07 15:32:37401 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41402 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37403 }
404
405 /**
406 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13407 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37408 * @return {boolean}
409 */
410 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41411 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37412 }
413
414 /**
415 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13416 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37417 * @return {boolean}
418 */
419 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41420 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37421 }
422
423 /**
424 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13425 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37426 * @return {boolean}
427 */
428 static _requestSizeLargerThanFilter(value, request) {
429 return request.transferSize >= value;
430 }
431
432 /**
433 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13434 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37435 * @return {boolean}
436 */
437 static _statusCodeFilter(value, request) {
438 return ('' + request.statusCode) === value;
439 }
440
441 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13442 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37443 * @return {boolean}
444 */
445 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58446 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37447 }
448
449 /**
Blink Reformat4c46d092018-04-07 15:32:37450 * @param {number} windowStart
451 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13452 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37453 * @return {boolean}
454 */
455 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34456 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37457 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34458 }
459 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37460 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34461 }
Blink Reformat4c46d092018-04-07 15:32:37462 return true;
463 }
464
465 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13466 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37467 */
468 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13469 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37470 }
471
472 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13473 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37474 */
475 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13476 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37477 }
478
479 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13480 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37481 */
482 static async _copyResponse(request) {
483 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08484 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34485 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08486 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34487 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08488 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34489 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13490 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37491 }
492
493 /**
494 * @param {!DataTransfer} dataTransfer
495 */
496 _handleDrop(dataTransfer) {
497 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34498 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37499 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34500 }
Blink Reformat4c46d092018-04-07 15:32:37501 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34502 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37503 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34504 }
Blink Reformat4c46d092018-04-07 15:32:37505
Joey Arhar0e1093c2019-05-21 00:34:22506 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37507 }
508
509 /**
Tim van der Lippe119690c2020-01-13 12:31:30510 * @override
Blink Reformat4c46d092018-04-07 15:32:37511 * @param {!File} file
512 */
Joey Arhar0e1093c2019-05-21 00:34:22513 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13514 const outputStream = new Common.StringOutputStream.StringOutputStream();
515 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37516 const success = await reader.read(outputStream);
517 if (!success) {
518 this._harLoadFailed(reader.error().message);
519 return;
520 }
521 let harRoot;
522 try {
523 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13524 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37525 } catch (e) {
526 this._harLoadFailed(e);
527 return;
528 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13529 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37530 }
531
532 /**
533 * @param {string} message
534 */
535 _harLoadFailed(message) {
Paul Lewis04ccecc2020-01-22 17:15:14536 self.Common.console.error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37537 }
538
539 /**
540 * @param {?string} groupKey
541 */
542 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34543 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37544 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34545 }
Blink Reformat4c46d092018-04-07 15:32:37546 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
547 this._activeGroupLookup = groupLookup;
548 this._invalidateAllItems();
549 }
550
551 /**
552 * @return {number}
553 */
554 _computeRowHeight() {
555 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
556 }
557
558 /**
Tim van der Lippe119690c2020-01-13 12:31:30559 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13560 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30561 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37562 */
563 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58564 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37565 }
566
567 /**
Tim van der Lippe119690c2020-01-13 12:31:30568 * @override
Blink Reformat4c46d092018-04-07 15:32:37569 * @return {number}
570 */
571 headerHeight() {
572 return this._headerHeight;
573 }
574
575 /**
Tim van der Lippe119690c2020-01-13 12:31:30576 * @override
Blink Reformat4c46d092018-04-07 15:32:37577 * @param {boolean} recording
578 */
579 setRecording(recording) {
580 this._recording = recording;
581 this._updateSummaryBar();
582 }
583
584 /**
585 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13586 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37587 */
588 modelAdded(networkManager) {
589 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34590 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37591 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34592 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13593 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37594 if (resourceTreeModel) {
595 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
596 resourceTreeModel.addEventListener(
597 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
598 }
599 }
600
601 /**
602 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13603 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37604 */
605 modelRemoved(networkManager) {
606 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13607 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37608 if (resourceTreeModel) {
609 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
610 resourceTreeModel.removeEventListener(
611 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
612 }
613 }
614 }
615
616 /**
Tim van der Lippe119690c2020-01-13 12:31:30617 * @override
Blink Reformat4c46d092018-04-07 15:32:37618 * @param {number} start
619 * @param {number} end
620 */
621 setWindow(start, end) {
622 if (!start && !end) {
623 this._timeFilter = null;
624 this._timeCalculator.setWindow(null);
625 } else {
Paul Lewis56509652019-12-06 12:51:58626 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30627 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37628 }
629 this._filterRequests();
630 }
631
Tim van der Lippe119690c2020-01-13 12:31:30632 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05633 resetFocus() {
634 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37635 }
636
637 _resetSuggestionBuilder() {
638 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58639 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
640 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
641 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
642 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
643 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
644 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
645 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37646 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
647 }
648
649 /**
650 * @param {!Common.Event} event
651 */
652 _filterChanged(event) {
653 this.removeAllNodeHighlights();
654 this._parseFilterQuery(this._textFilterUI.value());
655 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37656 }
657
658 _showRecordingHint() {
659 this._hideRecordingHint();
660 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
661 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18662
663 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40664 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18665 if (reloadShortcutDescriptor) {
666 reloadShortcutNode = this._recordingHint.createChild('b');
667 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
668 }
Blink Reformat4c46d092018-04-07 15:32:37669
670 if (this._recording) {
671 const recordingText = hintText.createChild('span');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13672 recordingText.textContent = Common.UIString.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18673 if (reloadShortcutNode) {
674 hintText.createChild('br');
675 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13676 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18677 }
Blink Reformat4c46d092018-04-07 15:32:37678 } else {
679 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40680 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18681 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13682 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18683 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
684 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13685 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18686 }
Blink Reformat4c46d092018-04-07 15:32:37687 }
Kayce Basques5444c1b2019-02-15 20:32:53688 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13689 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53690 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
691 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11692
693 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57694 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37695 }
696
697 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11698 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34699 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37700 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34701 }
Brandon Goddardc992d522020-01-08 21:44:57702 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37703 this._recordingHint = null;
704 }
705
706 /**
Amanda Baker6761aae2019-11-05 18:59:11707 * @param {boolean} value
708 */
709 _setHidden(value) {
710 this._columns.setHidden(value);
711 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
712 }
713
714 /**
Blink Reformat4c46d092018-04-07 15:32:37715 * @override
716 * @return {!Array.<!Element>}
717 */
718 elementsToRestoreScrollPositionsFor() {
719 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34720 {
Blink Reformat4c46d092018-04-07 15:32:37721 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34722 }
Blink Reformat4c46d092018-04-07 15:32:37723 return [this._dataGrid.scrollContainer];
724 }
725
Tim van der Lippe119690c2020-01-13 12:31:30726 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37727 columnExtensionResolved() {
728 this._invalidateAllItems(true);
729 }
730
731 _setupDataGrid() {
732 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
733 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34734 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37735 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34736 }
Blink Reformat4c46d092018-04-07 15:32:37737 });
738 this._dataGrid.setStickToBottom(true);
739 this._dataGrid.setName('networkLog');
740 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
741 this._dataGrid.element.classList.add('network-log-grid');
742 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
743 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
744 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05745 this._dataGrid.element.addEventListener('keydown', event => {
746 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58747 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05748 event.consume(true);
749 }
750 });
751 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
752 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37753 return this._dataGrid;
754 }
755
756 /**
757 * @param {!Event} event
758 */
759 _dataGridMouseMove(event) {
760 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
761 const highlightInitiatorChain = event.shiftKey;
762 this._setHoveredNode(node, highlightInitiatorChain);
763 }
764
765 /**
Tim van der Lippe119690c2020-01-13 12:31:30766 * @override
767 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37768 */
769 hoveredNode() {
770 return this._hoveredNode;
771 }
772
773 /**
Tim van der Lippe119690c2020-01-13 12:31:30774 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37775 * @param {boolean=} highlightInitiatorChain
776 */
777 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34778 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37779 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34780 }
Blink Reformat4c46d092018-04-07 15:32:37781 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34782 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37783 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34784 }
Blink Reformat4c46d092018-04-07 15:32:37785 }
786
787 /**
788 * @param {!Event} event
789 */
790 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37792 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 }
Blink Reformat4c46d092018-04-07 15:32:37794 }
795
796 _updateSummaryBar() {
797 this._hideRecordingHint();
798
799 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20800 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37801 let selectedNodeNumber = 0;
802 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20803 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37804 let baseTime = -1;
805 let maxTime = -1;
806
807 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16808 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58809 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34810 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37811 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34812 }
Blink Reformat4c46d092018-04-07 15:32:37813 nodeCount++;
814 const requestTransferSize = request.transferSize;
815 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20816 const requestResourceSize = request.resourceSize;
817 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30818 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37819 selectedNodeNumber++;
820 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20821 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37822 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13823 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37824 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
825 // inspected url.
826 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13827 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
828 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37829 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34830 }
831 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37832 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34833 }
Blink Reformat4c46d092018-04-07 15:32:37834 }
835
836 if (!nodeCount) {
837 this._showRecordingHint();
838 return;
839 }
840
Joey Arhara86c14e2019-03-12 03:20:50841 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37842 /**
843 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50844 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37845 * @return {!Element}
846 */
Joey Arhara86c14e2019-03-12 03:20:50847 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13848 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50849 toolbarText.setTitle(title ? title : chunk);
850 this._summaryToolbar.appendToolbarItem(toolbarText);
851 return toolbarText.element;
852 };
Blink Reformat4c46d092018-04-07 15:32:37853
854 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50855 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
856 this._summaryToolbar.appendSeparator();
857 appendChunk(
858 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25859 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50860 this._summaryToolbar.appendSeparator();
861 appendChunk(
862 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25863 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37864 } else {
Joey Arhara86c14e2019-03-12 03:20:50865 appendChunk(ls`${nodeCount} requests`);
866 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25867 appendChunk(
868 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50869 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25870 appendChunk(
871 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37872 }
Dan Beam87466b52018-12-01 18:41:20873
Blink Reformat4c46d092018-04-07 15:32:37874 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50875 this._summaryToolbar.appendSeparator();
876 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37877 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50878 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30879 const domContentLoadedText =
880 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58881 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37882 }
883 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50884 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30885 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58886 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37887 }
888 }
Blink Reformat4c46d092018-04-07 15:32:37889 }
890
Tim van der Lippe119690c2020-01-13 12:31:30891 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37892 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34893 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37894 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34895 }
Blink Reformat4c46d092018-04-07 15:32:37896
897 this._needsRefresh = true;
898
Tim van der Lippe1d6e57a2019-09-30 11:55:34899 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37900 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34901 }
Blink Reformat4c46d092018-04-07 15:32:37902 }
903
904 /**
Tim van der Lippe119690c2020-01-13 12:31:30905 * @override
Blink Reformat4c46d092018-04-07 15:32:37906 * @param {!Array<number>} times
907 */
908 addFilmStripFrames(times) {
909 this._columns.addEventDividers(times, 'network-frame-divider');
910 }
911
912 /**
Tim van der Lippe119690c2020-01-13 12:31:30913 * @override
Blink Reformat4c46d092018-04-07 15:32:37914 * @param {number} time
915 */
916 selectFilmStripFrame(time) {
917 this._columns.selectFilmStripFrame(time);
918 }
919
Tim van der Lippe119690c2020-01-13 12:31:30920 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37921 clearFilmStripFrame() {
922 this._columns.clearFilmStripFrame();
923 }
924
925 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34926 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37927 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34928 }
Blink Reformat4c46d092018-04-07 15:32:37929 }
930
931 /**
932 * @param {boolean=} deferUpdate
933 */
934 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16935 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34936 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37937 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34938 } else {
Blink Reformat4c46d092018-04-07 15:32:37939 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34940 }
Blink Reformat4c46d092018-04-07 15:32:37941 }
942
943 /**
Tim van der Lippe119690c2020-01-13 12:31:30944 * @override
945 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37946 */
947 timeCalculator() {
948 return this._timeCalculator;
949 }
950
951 /**
Tim van der Lippe119690c2020-01-13 12:31:30952 * @override
953 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37954 */
955 calculator() {
956 return this._calculator;
957 }
958
959 /**
Tim van der Lippe119690c2020-01-13 12:31:30960 * @override
961 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37962 */
963 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34964 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37965 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34966 }
Blink Reformat4c46d092018-04-07 15:32:37967
968 if (this._calculator !== x) {
969 this._calculator = x;
970 this._columns.setCalculator(this._calculator);
971 }
972 this._calculator.reset();
973
Tim van der Lippe1d6e57a2019-09-30 11:55:34974 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37975 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34976 } else {
Blink Reformat4c46d092018-04-07 15:32:37977 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34978 }
Blink Reformat4c46d092018-04-07 15:32:37979
980 this._invalidateAllItems();
981 }
982
983 /**
984 * @param {!Common.Event} event
985 */
986 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34987 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37988 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34989 }
Blink Reformat4c46d092018-04-07 15:32:37990
991 const time = /** @type {number} */ (event.data.loadTime);
992 if (time) {
993 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:30994 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:37995 }
996 }
997
998 /**
999 * @param {!Common.Event} event
1000 */
1001 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341002 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371003 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341004 }
Blink Reformat4c46d092018-04-07 15:32:371005 const data = /** @type {number} */ (event.data);
1006 if (data) {
1007 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301008 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371009 }
1010 }
1011
1012 /**
1013 * @override
1014 */
1015 wasShown() {
1016 this._refreshIfNeeded();
1017 this._columns.wasShown();
1018 }
1019
1020 /**
1021 * @override
1022 */
1023 willHide() {
1024 this._columns.willHide();
1025 }
1026
1027 /**
1028 * @override
1029 */
1030 onResize() {
1031 this._rowHeight = this._computeRowHeight();
1032 }
1033
1034 /**
Tim van der Lippe119690c2020-01-13 12:31:301035 * @override
1036 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371037 */
1038 flatNodesList() {
1039 return this._dataGrid.rootNode().flatChildren();
1040 }
1041
Tim van der Lippe119690c2020-01-13 12:31:301042 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051043 updateNodeBackground() {
1044 if (this._dataGrid.selectedNode) {
1045 this._dataGrid.selectedNode.updateBackgroundColor();
1046 }
1047 }
1048
1049 /**
Tim van der Lippe119690c2020-01-13 12:31:301050 * @override
Brandon Goddard88d885a2019-10-31 16:11:051051 * @param {boolean} isSelected
1052 */
1053 updateNodeSelectedClass(isSelected) {
1054 if (isSelected) {
1055 this.element.classList.remove('no-node-selected');
1056 } else {
1057 this.element.classList.add('no-node-selected');
1058 }
1059 }
1060
Tim van der Lippe119690c2020-01-13 12:31:301061 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371062 stylesChanged() {
1063 this._columns.scheduleRefresh();
1064 }
1065
1066 _refresh() {
1067 this._needsRefresh = false;
1068
1069 if (this._refreshRequestId) {
1070 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1071 this._refreshRequestId = null;
1072 }
1073
1074 this.removeAllNodeHighlights();
1075
1076 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1077 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1078 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1079 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1080
Tim van der Lippe119690c2020-01-13 12:31:301081 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371082 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301083 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371084 const nodesToRefresh = [];
1085
Tim van der Lippe119690c2020-01-13 12:31:301086 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371087 const staleNodes = new Set();
1088
1089 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1090 // node so we loop until we have no more stale requests.
1091 while (this._staleRequests.size) {
1092 const request = this._staleRequests.firstValue();
1093 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581094 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341095 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371096 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341097 }
Blink Reformat4c46d092018-04-07 15:32:371098 staleNodes.add(node);
1099 }
1100
1101 for (const node of staleNodes) {
1102 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341103 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371104 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341105 }
Blink Reformat4c46d092018-04-07 15:32:371106
Tim van der Lippe1d6e57a2019-09-30 11:55:341107 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371108 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341109 }
Blink Reformat4c46d092018-04-07 15:32:371110 const request = node.request();
1111 this._timeCalculator.updateBoundaries(request);
1112 this._durationCalculator.updateBoundaries(request);
1113 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301114 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371115 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341116 }
Tim van der Lippe119690c2020-01-13 12:31:301117 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371118 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1119 if (removeFromParent) {
1120 let parent = node.parent;
1121 parent.removeChild(node);
1122 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1123 const grandparent = parent.parent;
1124 grandparent.removeChild(parent);
1125 parent = grandparent;
1126 }
1127 }
1128
Tim van der Lippe1d6e57a2019-09-30 11:55:341129 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371130 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341131 }
Blink Reformat4c46d092018-04-07 15:32:371132
1133 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1134 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1135 nodesToRefresh.push(newParent);
1136 }
1137 nodesToInsert.set(node, newParent);
1138 }
1139
Tim van der Lippe1d6e57a2019-09-30 11:55:341140 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371141 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341142 }
Blink Reformat4c46d092018-04-07 15:32:371143
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371145 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341146 }
Blink Reformat4c46d092018-04-07 15:32:371147
1148 this._updateSummaryBar();
1149
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371151 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341152 }
Blink Reformat4c46d092018-04-07 15:32:371153
1154 this._dataGrid.updateInstantly();
1155 this._didRefreshForTest();
1156 }
1157
1158 _didRefreshForTest() {
1159 }
1160
1161 /**
Tim van der Lippe119690c2020-01-13 12:31:301162 * @param {!NetworkRequestNode} node
1163 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371164 */
1165 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341166 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371167 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341168 }
Blink Reformat4c46d092018-04-07 15:32:371169
1170 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341171 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371172 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341173 }
Blink Reformat4c46d092018-04-07 15:32:371174 return groupNode;
1175 }
1176
1177 _reset() {
Paul Lewis56509652019-12-06 12:51:581178 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371179
1180 this._setHoveredNode(null);
1181 this._columns.reset();
1182
1183 this._timeFilter = null;
1184 this._calculator.reset();
1185
1186 this._timeCalculator.setWindow(null);
1187 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371188
Tim van der Lippe1d6e57a2019-09-30 11:55:341189 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371190 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341191 }
Blink Reformat4c46d092018-04-07 15:32:371192 this._staleRequests.clear();
1193 this._resetSuggestionBuilder();
1194
1195 this._mainRequestLoadTime = -1;
1196 this._mainRequestDOMContentLoadedTime = -1;
1197
1198 this._dataGrid.rootNode().removeChildren();
1199 this._updateSummaryBar();
1200 this._dataGrid.setStickToBottom(true);
1201 this.scheduleRefresh();
1202 }
1203
1204 /**
Tim van der Lippe119690c2020-01-13 12:31:301205 * @override
Blink Reformat4c46d092018-04-07 15:32:371206 * @param {string} filterString
1207 */
1208 setTextFilterValue(filterString) {
1209 this._textFilterUI.setValue(filterString);
1210 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371211 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371212 this._resourceCategoryFilterUI.reset();
1213 }
1214
1215 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131216 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371217 */
1218 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301219 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581220 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301221 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371222
Tim van der Lippe1d6e57a2019-09-30 11:55:341223 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371224 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341225 }
Blink Reformat4c46d092018-04-07 15:32:371226 return node;
1227 }
1228
1229 /**
1230 * @param {!Common.Event} event
1231 */
1232 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131233 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371234 this._refreshRequest(request);
1235 }
1236
1237 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131238 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371239 */
1240 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581241 NetworkLogView._subdomains(request.domain)
1242 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1243 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1244 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1245 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1246 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371247
1248 const priority = request.priority();
1249 if (priority) {
Paul Lewis56509652019-12-06 12:51:581250 this._suggestionBuilder.addItem(FilterType.Priority, PerfUI.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371251 }
1252
1253 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581254 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371255 }
1256
1257 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581258 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371259 }
1260
1261 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581262 const suggestion =
1263 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1264 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371265 }
1266
1267 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341268 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581269 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341270 }
Jan Scheffler341eea52019-12-12 09:08:411271
1272 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581273 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1274 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1275 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371276 }
1277
Jan Scheffler341eea52019-12-12 09:08:411278 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1279 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1280 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1281 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1282 }
1283
Blink Reformat4c46d092018-04-07 15:32:371284 this._staleRequests.add(request);
1285 this.scheduleRefresh();
1286 }
1287
1288 /**
Tim van der Lippe119690c2020-01-13 12:31:301289 * @override
Blink Reformat4c46d092018-04-07 15:32:371290 * @return {number}
1291 */
1292 rowHeight() {
1293 return this._rowHeight;
1294 }
1295
1296 /**
Tim van der Lippe119690c2020-01-13 12:31:301297 * @override
Blink Reformat4c46d092018-04-07 15:32:371298 * @param {boolean} gridMode
1299 */
1300 switchViewMode(gridMode) {
1301 this._columns.switchViewMode(gridMode);
1302 }
1303
1304 /**
Tim van der Lippe119690c2020-01-13 12:31:301305 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131306 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1307 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371308 */
1309 handleContextMenuForRequest(contextMenu, request) {
1310 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131311 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371312 const footerSection = copyMenu.footerSection();
1313 if (request) {
1314 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131315 UI.UIUtils.copyLinkAddressLabel(),
1316 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1317 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371318 if (request.requestHeadersText()) {
1319 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131320 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371321 }
1322
1323 if (request.responseHeadersText) {
1324 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131325 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371326 }
1327
1328 if (request.finished) {
1329 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131330 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371331 }
1332
Harley Libcf41f92018-09-10 18:01:131333 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131334 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371335 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131336 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1337 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371338 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131339 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291340 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131341 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1342 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371343 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131344 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1345 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131346 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131347 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1348 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371349 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131350 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1351 footerSection.appendItem(
1352 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1353 footerSection.appendItem(
1354 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1355 footerSection.appendItem(
1356 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1357 footerSection.appendItem(
1358 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371359 } else {
Harley Libcf41f92018-09-10 18:01:131360 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131361 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291362 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131363 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1364 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131365 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131366 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1367 footerSection.appendItem(
1368 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1369 footerSection.appendItem(
1370 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1371 footerSection.appendItem(
1372 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371373 }
1374 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131375 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371376 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131377 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371378
Joey Arhar0e1093c2019-05-21 00:34:221379 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371380
Blink Reformat4c46d092018-04-07 15:32:371381 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131382 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1383 contextMenu.editSection().appendItem(
1384 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371385
1386 if (request) {
1387 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081388 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371389 let patterns = manager.blockedPatterns();
1390
Tim van der Lippeffa78622019-09-16 12:07:121391 /**
1392 * @param {string} url
1393 */
1394 function addBlockedURL(url) {
1395 patterns.push({enabled: true, url: url});
1396 manager.setBlockedPatterns(patterns);
1397 manager.setBlockingEnabled(true);
Paul Lewis50993692020-01-23 15:22:261398 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121399 }
1400
1401 /**
1402 * @param {string} url
1403 */
1404 function removeBlockedURL(url) {
1405 patterns = patterns.filter(pattern => pattern.url !== url);
1406 manager.setBlockedPatterns(patterns);
Paul Lewis50993692020-01-23 15:22:261407 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121408 }
1409
Blink Reformat4c46d092018-04-07 15:32:371410 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1411 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1412 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131413 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371414 } else if (urlWithoutScheme) {
1415 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1416 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131417 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371418 }
1419
1420 const domain = request.parsedURL.domain();
1421 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1422 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131423 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371424 } else if (domain) {
1425 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1426 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131427 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371428 }
1429
Tim van der Lippe0ed1d2b2020-02-04 13:45:131430 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371431 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131432 Common.UIString.UIString('Replay XHR'),
1433 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371434 }
Blink Reformat4c46d092018-04-07 15:32:371435 }
1436 }
1437
1438 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161439 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171440 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131441 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171442 });
Blink Reformat4c46d092018-04-07 15:32:371443 }
1444
1445 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131446 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1447 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371448 }
1449
1450 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131451 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371452 * @param {string} platform
1453 */
1454 async _copyCurlCommand(request, platform) {
1455 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131456 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371457 }
1458
1459 /**
1460 * @param {string} platform
1461 */
1462 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161463 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131464 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371465 }
1466
1467 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131468 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291469 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371470 */
Jan Scheffler7c50d1f2019-12-17 13:33:291471 async _copyFetchCall(request, includeCookies) {
1472 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131473 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371474 }
1475
Jan Scheffler7c50d1f2019-12-17 13:33:291476 /**
1477 * @param {boolean} includeCookies
1478 */
1479 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161480 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131481 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371482 }
1483
1484 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131485 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371486 */
1487 async _copyPowerShellCommand(request) {
1488 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131489 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371490 }
1491
1492 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161493 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371495 }
1496
Tim van der Lippe119690c2020-01-13 12:31:301497 /**
1498 * @override
1499 * @return {!Promise}
1500 */
Joey Arhar0e1093c2019-05-21 00:34:221501 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331502 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131503 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371504 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131505 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371506
Tim van der Lippe1d6e57a2019-09-30 11:55:341507 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371508 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341509 }
Blink Reformat4c46d092018-04-07 15:32:371510
Tim van der Lippe0ed1d2b2020-02-04 13:45:131511 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371512 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301513 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371514 progressIndicator.done();
1515 stream.close();
1516 }
1517
1518 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131519 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081520 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341521 }
Blink Reformat4c46d092018-04-07 15:32:371522 }
1523
1524 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131525 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081526 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341527 }
Blink Reformat4c46d092018-04-07 15:32:371528 }
1529
1530 _removeAllHighlights() {
1531 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341532 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131533 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341534 }
Blink Reformat4c46d092018-04-07 15:32:371535 this._highlightedSubstringChanges = [];
1536 }
1537
1538 /**
Tim van der Lippe119690c2020-01-13 12:31:301539 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371540 * @return {boolean}
1541 */
1542 _applyFilter(node) {
1543 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341544 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371545 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341546 }
Blink Reformat4c46d092018-04-07 15:32:371547 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341548 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371549 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341550 }
1551 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371552 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341553 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131554 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.IssuesModel.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371555 return false;
1556 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341557 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371558 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341559 }
Blink Reformat4c46d092018-04-07 15:32:371560 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341561 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371562 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341563 }
Blink Reformat4c46d092018-04-07 15:32:371564 }
1565 return true;
1566 }
1567
1568 /**
1569 * @param {string} query
1570 */
1571 _parseFilterQuery(query) {
1572 const descriptors = this._filterParser.parse(query);
1573 this._filters = descriptors.map(descriptor => {
1574 const key = descriptor.key;
1575 const text = descriptor.text || '';
1576 const regex = descriptor.regex;
1577 let filter;
1578 if (key) {
1579 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581580 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1581 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371582 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581583 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371584 } else {
Paul Lewis56509652019-12-06 12:51:581585 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371586 }
Paul Lewis56509652019-12-06 12:51:581587 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371588 });
1589 }
1590
1591 /**
Paul Lewis56509652019-12-06 12:51:581592 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371593 * @param {string} value
1594 * @return {?Network.NetworkLogView.Filter}
1595 */
1596 _createSpecialFilter(type, value) {
1597 switch (type) {
Paul Lewis56509652019-12-06 12:51:581598 case FilterType.Domain:
1599 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371600
Paul Lewis56509652019-12-06 12:51:581601 case FilterType.HasResponseHeader:
1602 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371603
Paul Lewis56509652019-12-06 12:51:581604 case FilterType.Is:
1605 if (value.toLowerCase() === IsFilterType.Running) {
1606 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341607 }
Paul Lewis56509652019-12-06 12:51:581608 if (value.toLowerCase() === IsFilterType.FromCache) {
1609 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341610 }
Paul Lewis56509652019-12-06 12:51:581611 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1612 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341613 }
Paul Lewis56509652019-12-06 12:51:581614 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1615 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341616 }
Blink Reformat4c46d092018-04-07 15:32:371617 break;
1618
Paul Lewis56509652019-12-06 12:51:581619 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371620 return this._createSizeFilter(value.toLowerCase());
1621
Paul Lewis56509652019-12-06 12:51:581622 case FilterType.Method:
1623 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371624
Paul Lewis56509652019-12-06 12:51:581625 case FilterType.MimeType:
1626 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371627
Paul Lewis56509652019-12-06 12:51:581628 case FilterType.MixedContent:
1629 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371630
Paul Lewis56509652019-12-06 12:51:581631 case FilterType.Scheme:
1632 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371633
Paul Lewis56509652019-12-06 12:51:581634 case FilterType.SetCookieDomain:
1635 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371636
Paul Lewis56509652019-12-06 12:51:581637 case FilterType.SetCookieName:
1638 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371639
Paul Lewis56509652019-12-06 12:51:581640 case FilterType.SetCookieValue:
1641 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371642
Jan Scheffler341eea52019-12-12 09:08:411643 case FilterType.CookieDomain:
1644 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1645
1646 case FilterType.CookieName:
1647 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1648
1649 case FilterType.CookieValue:
1650 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1651
Paul Lewis56509652019-12-06 12:51:581652 case FilterType.Priority:
1653 return NetworkLogView._requestPriorityFilter.bind(null, PerfUI.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371654
Paul Lewis56509652019-12-06 12:51:581655 case FilterType.StatusCode:
1656 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371657 }
1658 return null;
1659 }
1660
1661 /**
1662 * @param {string} value
1663 * @return {?Network.NetworkLogView.Filter}
1664 */
1665 _createSizeFilter(value) {
1666 let multiplier = 1;
1667 if (value.endsWith('k')) {
1668 multiplier = 1024;
1669 value = value.substring(0, value.length - 1);
1670 } else if (value.endsWith('m')) {
1671 multiplier = 1024 * 1024;
1672 value = value.substring(0, value.length - 1);
1673 }
1674 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341675 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371676 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341677 }
Paul Lewis56509652019-12-06 12:51:581678 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371679 }
1680
1681 _filterRequests() {
1682 this._removeAllHighlights();
1683 this._invalidateAllItems();
1684 }
1685
1686 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131687 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301688 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371689 */
1690 _reveal(request) {
1691 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581692 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341693 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371694 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341695 }
Blink Reformat4c46d092018-04-07 15:32:371696 node.reveal();
1697 return node;
1698 }
1699
1700 /**
Tim van der Lippe119690c2020-01-13 12:31:301701 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131702 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371703 */
1704 revealAndHighlightRequest(request) {
1705 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341706 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371707 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341708 }
Blink Reformat4c46d092018-04-07 15:32:371709 }
1710
1711 /**
Tim van der Lippe119690c2020-01-13 12:31:301712 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131713 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371714 */
1715 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141716 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371717 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341718 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371719 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341720 }
Blink Reformat4c46d092018-04-07 15:32:371721 }
1722
Tim van der Lippe119690c2020-01-13 12:31:301723 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371724 removeAllNodeHighlights() {
1725 if (this._highlightedNode) {
1726 this._highlightedNode.element().classList.remove('highlighted-row');
1727 this._highlightedNode = null;
1728 }
1729 }
1730
1731 /**
Tim van der Lippe119690c2020-01-13 12:31:301732 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371733 */
1734 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131735 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371736 this._highlightedNode = node;
1737 }
1738
1739 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131740 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1741 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131742 */
1743 _filterOutBlobRequests(requests) {
1744 return requests.filter(request => !request.isBlobRequest());
1745 }
1746
1747 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131748 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291749 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371750 * @return {!Promise<string>}
1751 */
Jan Scheffler7c50d1f2019-12-17 13:33:291752 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371753 const ignoredHeaders = {
1754 // Internal headers
1755 'method': 1,
1756 'path': 1,
1757 'scheme': 1,
1758 'version': 1,
1759
1760 // Unsafe headers
1761 // Keep this list synchronized with src/net/http/http_util.cc
1762 'accept-charset': 1,
1763 'accept-encoding': 1,
1764 'access-control-request-headers': 1,
1765 'access-control-request-method': 1,
1766 'connection': 1,
1767 'content-length': 1,
1768 'cookie': 1,
1769 'cookie2': 1,
1770 'date': 1,
1771 'dnt': 1,
1772 'expect': 1,
1773 'host': 1,
1774 'keep-alive': 1,
1775 'origin': 1,
1776 'referer': 1,
1777 'te': 1,
1778 'trailer': 1,
1779 'transfer-encoding': 1,
1780 'upgrade': 1,
1781 'via': 1,
1782 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1783 'user-agent': 1
1784 };
1785
1786 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1787
1788 const url = JSON.stringify(request.url());
1789
1790 const requestHeaders = request.requestHeaders();
1791 const headerData = requestHeaders.reduce((result, header) => {
1792 const name = header.name;
1793
Tim van der Lippe1d6e57a2019-09-30 11:55:341794 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371795 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341796 }
Blink Reformat4c46d092018-04-07 15:32:371797
1798 return result;
1799 }, new Headers());
1800
1801 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341802 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411803 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341804 }
Blink Reformat4c46d092018-04-07 15:32:371805
1806 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411807 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1808 'include' :
1809 'omit';
Blink Reformat4c46d092018-04-07 15:32:371810
1811 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1812
1813 const referrer = referrerHeader ? referrerHeader.value : void 0;
1814
1815 const referrerPolicy = request.referrerPolicy() || void 0;
1816
1817 const requestBody = await request.requestFormData();
1818
1819 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411820 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371821 referrer,
1822 referrerPolicy,
1823 body: requestBody,
1824 method: request.requestMethod,
1825 mode: 'cors'
1826 };
1827
Jan Scheffler7c50d1f2019-12-17 13:33:291828 if (includeCookies) {
1829 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1830 if (cookieHeader) {
1831 fetchOptions.headers = {
1832 ...headers,
1833 'cookie': cookieHeader.value,
1834 };
1835 }
1836 } else {
1837 fetchOptions.credentials = credentials;
1838 }
1839
Jan Scheffler172d5212020-01-02 14:42:561840 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371841 return `fetch(${url}, ${options});`;
1842 }
1843
1844 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131845 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291846 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131847 * @return {!Promise<string>}
1848 */
Jan Scheffler7c50d1f2019-12-17 13:33:291849 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131850 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291851 const commands =
1852 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131853 return commands.join(' ;\n');
1854 }
1855
1856 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131857 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371858 * @param {string} platform
1859 * @return {!Promise<string>}
1860 */
1861 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561862 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361863 // Most of these headers are derived from the URL and are automatically added by cURL.
1864 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1865 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371866
1867 function escapeStringWin(str) {
1868 /* If there are no new line characters do not escape the " characters
1869 since it only uglifies the command.
1870
1871 Because cmd.exe parser and MS Crt arguments parsers use some of the
1872 same escape characters, they can interact with each other in
1873 horrible ways, the order of operations is critical.
1874
1875 Replace \ with \\ first because it is an escape character for certain
1876 conditions in both parsers.
1877
1878 Replace all " with \" to ensure the first parser does not remove it.
1879
1880 Then escape all characters we are not sure about with ^ to ensure it
1881 gets to MS Crt parser safely.
1882
1883 The % character is special because MS Crt parser will try and look for
1884 ENV variables and fill them in it's place. We cannot escape them with %
1885 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1886 parser); So we can get cmd.exe parser to escape the character after it,
1887 if it is followed by a valid beginning character of an ENV variable.
1888 This ensures we do not try and double escape another ^ if it was placed
1889 by the previous replace.
1890
1891 Lastly we replace new lines with ^ and TWO new lines because the first
1892 new line is there to enact the escape command the second is the character
1893 to escape (in this case new line).
1894 */
1895 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1896 return encapsChars +
1897 str.replace(/\\/g, '\\\\')
1898 .replace(/"/g, '\\"')
1899 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1900 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1901 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1902 encapsChars;
1903 }
1904
1905 /**
1906 * @param {string} str
1907 * @return {string}
1908 */
1909 function escapeStringPosix(str) {
1910 /**
1911 * @param {string} x
1912 * @return {string}
1913 */
1914 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221915 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121916 let hexString = code.toString(16);
1917 // Zero pad to four digits to comply with ANSI-C Quoting:
1918 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341919 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121920 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341921 }
Joey Arhar2d21f712019-05-20 21:07:121922
1923 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371924 }
1925
Joey Arhar512e3742019-01-25 21:33:541926 if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371927 // Use ANSI-C quoting syntax.
1928 return '$\'' +
1929 str.replace(/\\/g, '\\\\')
1930 .replace(/\'/g, '\\\'')
1931 .replace(/\n/g, '\\n')
1932 .replace(/\r/g, '\\r')
Joey Arhar512e3742019-01-25 21:33:541933 .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371934 '\'';
1935 } else {
1936 // Use single quote syntax.
1937 return '\'' + str + '\'';
1938 }
1939 }
1940
1941 // cURL command expected to run on the same platform that DevTools run
1942 // (it may be different from the inspected page platform).
1943 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1944
1945 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1946
1947 let inferredMethod = 'GET';
1948 const data = [];
1949 const requestContentType = request.requestContentType();
1950 const formData = await request.requestFormData();
1951 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:271952 // Note that formData is not necessarily urlencoded because it might for example
1953 // come from a fetch request made with an explicitly unencoded body.
1954 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371955 ignoredHeaders['content-length'] = true;
1956 inferredMethod = 'POST';
1957 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561958 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371959 ignoredHeaders['content-length'] = true;
1960 inferredMethod = 'POST';
1961 }
1962
1963 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291964 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371965 }
1966
1967 const requestHeaders = request.requestHeaders();
1968 for (let i = 0; i < requestHeaders.length; i++) {
1969 const header = requestHeaders[i];
1970 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341971 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371972 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341973 }
Jan Scheffler172d5212020-01-02 14:42:561974 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371975 }
1976 command = command.concat(data);
1977 command.push('--compressed');
1978
Tim van der Lippe1d6e57a2019-09-30 11:55:341979 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371980 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341981 }
Jan Scheffler172d5212020-01-02 14:42:561982 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:371983 }
1984
1985 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131986 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:131987 * @param {string} platform
1988 * @return {!Promise<string>}
1989 */
1990 async _generateAllCurlCommand(requests, platform) {
1991 const nonBlobRequests = this._filterOutBlobRequests(requests);
1992 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:131994 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341995 } else {
Harley Libcf41f92018-09-10 18:01:131996 return commands.join(' ;\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341997 }
Harley Libcf41f92018-09-10 18:01:131998 }
1999
2000 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132001 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372002 * @return {!Promise<string>}
2003 */
2004 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562005 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372006 const ignoredHeaders =
2007 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2008
2009 /**
2010 * @param {string} str
2011 * @return {string}
2012 */
2013 function escapeString(str) {
2014 return '"' +
2015 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2016 }
2017
Jan Scheffler172d5212020-01-02 14:42:562018 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372019
2020 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562021 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372022 }
2023
2024 const requestHeaders = request.requestHeaders();
2025 const headerNameValuePairs = [];
2026 for (const header of requestHeaders) {
2027 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342028 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372029 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342030 }
Blink Reformat4c46d092018-04-07 15:32:372031 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2032 }
2033 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562034 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372035 }
2036
2037 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2038 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562039 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372040 }
2041
2042 const formData = await request.requestFormData();
2043 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372044 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342045 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562046 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342047 } else {
Jan Scheffler172d5212020-01-02 14:42:562048 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342049 }
Blink Reformat4c46d092018-04-07 15:32:372050 }
2051
Jan Scheffler172d5212020-01-02 14:42:562052 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372053 }
Harley Libcf41f92018-09-10 18:01:132054
2055 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132056 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132057 * @return {!Promise<string>}
2058 */
2059 async _generateAllPowerShellCommand(requests) {
2060 const nonBlobRequests = this._filterOutBlobRequests(requests);
2061 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2062 return commands.join(';\r\n');
2063 }
Joey Arhara86c14e2019-03-12 03:20:502064
2065 /**
2066 * @return {string}
2067 */
2068 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552069 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502070 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342071 }
Joey Arhara86c14e2019-03-12 03:20:502072 return '#0867CB';
2073 }
2074
2075 /**
2076 * @return {string}
2077 */
2078 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132079 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502080 }
Paul Lewis56509652019-12-06 12:51:582081}
Blink Reformat4c46d092018-04-07 15:32:372082
Tim van der Lippe119690c2020-01-13 12:31:302083export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582084export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372085
Paul Lewis56509652019-12-06 12:51:582086export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372087 'http': true,
2088 'https': true,
2089 'ws': true,
2090 'wss': true
2091};
2092
Blink Reformat4c46d092018-04-07 15:32:372093/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582094export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372095 Domain: 'domain',
2096 HasResponseHeader: 'has-response-header',
2097 Is: 'is',
2098 LargerThan: 'larger-than',
2099 Method: 'method',
2100 MimeType: 'mime-type',
2101 MixedContent: 'mixed-content',
2102 Priority: 'priority',
2103 Scheme: 'scheme',
2104 SetCookieDomain: 'set-cookie-domain',
2105 SetCookieName: 'set-cookie-name',
2106 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412107 CookieDomain: 'cookie-domain',
2108 CookieName: 'cookie-name',
2109 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372110 StatusCode: 'status-code'
2111};
2112
2113/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582114export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372115 All: 'all',
2116 Displayed: 'displayed',
2117 Blocked: 'blocked',
2118 BlockOverridden: 'block-overridden'
2119};
2120
2121/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582122export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372123 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052124 FromCache: 'from-cache',
2125 ServiceWorkerIntercepted: 'service-worker-intercepted',
2126 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372127};
2128
2129/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582130export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372131
2132/**
2133 * @interface
2134 */
Paul Lewis56509652019-12-06 12:51:582135export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372136 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132137 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302138 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372139 */
Paul Lewis56509652019-12-06 12:51:582140 groupNodeForRequest(request) {
2141 }
Blink Reformat4c46d092018-04-07 15:32:372142
Paul Lewis56509652019-12-06 12:51:582143 reset() {
2144 }
2145}