blob: a69857c6be26c622433da4b67e95352c0be7a915 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lippe0ed1d2b2020-02-04 13:45:1331import * as Bindings from '../bindings/bindings.js';
32import * as Common from '../common/common.js';
33import * as Components from '../components/components.js';
34import * as DataGrid from '../data_grid/data_grid.js';
35import * as HARImporter from '../har_importer/har_importer.js';
36import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5037import * as PerfUI from '../perf_ui/perf_ui.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1338import * as SDK from '../sdk/sdk.js';
39import * as TextUtils from '../text_utils/text_utils.js';
40import * as UI from '../ui/ui.js';
41
Tim van der Lippe119690c2020-01-13 12:31:3042import {HARWriter} from './HARWriter.js';
43import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
44import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
45import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
46import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
47
Blink Reformat4c46d092018-04-07 15:32:3748/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1349 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3050 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3751 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1352export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3753 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3755 * @param {!Element} progressBarContainer
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356 * @param {!Common.Settings.Setting} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3757 */
58 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
59 super();
60 this.setMinimumSize(50, 64);
61 this.registerRequiredCSS('network/networkLogView.css');
62
63 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0564 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3765
Paul Lewis6bcdb182020-01-23 11:08:0566 this._networkHideDataURLSetting = self.Common.settings.createSetting('networkHideDataURL', false);
67 this._networkShowIssuesOnlySetting = self.Common.settings.createSetting('networkShowIssuesOnly', false);
Sigurd Schneidera2afe0b2020-03-03 15:27:1368 this._networkOnlyBlockedRequestsSetting = self.Common.settings.createSetting('networkOnlyBlockedRequests', false);
Paul Lewis6bcdb182020-01-23 11:08:0569 this._networkResourceTypeFiltersSetting = self.Common.settings.createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3770
71 this._rawRowHeight = 0;
72 this._progressBarContainer = progressBarContainer;
73 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
74 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
75
76 /**
Paul Lewis56509652019-12-06 12:51:5877 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3778 */
79 function updateRowHeight() {
80 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
81 this._rowHeight = this._computeRowHeight();
82 }
83 this._rawRowHeight = 0;
84 this._rowHeight = 0;
85 updateRowHeight.call(this);
86
Tim van der Lippe119690c2020-01-13 12:31:3087 /** @type {!NetworkTransferTimeCalculator} */
88 this._timeCalculator = new NetworkTransferTimeCalculator();
89 /** @type {!NetworkTransferDurationCalculator} */
90 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3791 this._calculator = this._timeCalculator;
92
Tim van der Lippe119690c2020-01-13 12:31:3093 this._columns =
94 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:3795 this._columns.show(this.element);
96
Tim van der Lippe0ed1d2b2020-02-04 13:45:1397 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:3798 this._staleRequests = new Set();
99 /** @type {number} */
100 this._mainRequestLoadTime = -1;
101 /** @type {number} */
102 this._mainRequestDOMContentLoadedTime = -1;
103 this._highlightedSubstringChanges = [];
104
Tim van der Lippeb1f2b6c2020-02-17 13:00:16105 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37106 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16107 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37108 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30109 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37110 this._hoveredNode = null;
111 /** @type {?Element} */
112 this._recordingHint = null;
113 /** @type {?number} */
114 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30115 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37116 this._highlightedNode = null;
117
Tim van der Lippe0ed1d2b2020-02-04 13:45:13118 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37119
120 this._recording = false;
121 this._needsRefresh = false;
122
123 this._headerHeight = 0;
124
Paul Lewis56509652019-12-06 12:51:58125 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37126 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30127 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37128
Paul Lewis56509652019-12-06 12:51:58129 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37130 this._activeGroupLookup = null;
131
Tim van der Lippe0ed1d2b2020-02-04 13:45:13132 this._textFilterUI = new UI.FilterBar.TextFilterUI();
133 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37134 filterBar.addFilter(this._textFilterUI);
135
Tim van der Lippe0ed1d2b2020-02-04 13:45:13136 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
137 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
138 this._dataURLFilterUI.addEventListener(
139 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48140 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37141 filterBar.addFilter(this._dataURLFilterUI);
142
143 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37145 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13146 this._resourceCategoryFilterUI =
147 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20148 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37149 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13150 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37151 filterBar.addFilter(this._resourceCategoryFilterUI);
152
Tim van der Lippe0ed1d2b2020-02-04 13:45:13153 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
154 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
155 this._onlyIssuesFilterUI.addEventListener(
156 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41157 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37158 filterBar.addFilter(this._onlyIssuesFilterUI);
159
Sigurd Schneidera2afe0b2020-03-03 15:27:13160 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
161 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
162 this._onlyBlockedRequestsUI.addEventListener(
163 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
164 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
165 filterBar.addFilter(this._onlyBlockedRequestsUI);
166
Jan Scheffler1ae7c9e2019-12-03 15:48:37167
Tim van der Lippe0ed1d2b2020-02-04 13:45:13168 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
169 this._suggestionBuilder =
170 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37171 this._resetSuggestionBuilder();
172
173 this._dataGrid = this._columns.dataGrid();
174 this._setupDataGrid();
175 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49176 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13177 UI.Toolbar.ToolbarButton.Events.Click,
178 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37179
Tim van der Lippe0ed1d2b2020-02-04 13:45:13180 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37181
Tim van der Lippe0ed1d2b2020-02-04 13:45:13182 new UI.DropTarget.DropTarget(
183 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
184 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37185
Paul Lewis4b64b3f2020-01-23 11:41:20186 self.Common.settings.moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37187 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
188
Tim van der Lippe0ed1d2b2020-02-04 13:45:13189 self.SDK.targetManager.observeModels(SDK.NetworkManager.NetworkManager, this);
Paul Lewisca3665d2020-01-24 13:31:16190 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
191 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
192 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37193
194 this._updateGroupByFrame();
Paul Lewis4b64b3f2020-01-23 11:41:20195 self.Common.settings.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37196
197 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37198 }
199
Blink Reformat4c46d092018-04-07 15:32:37200 _updateGroupByFrame() {
Paul Lewis4b64b3f2020-01-23 11:41:20201 const value = self.Common.settings.moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37202 this._setGrouping(value ? 'Frame' : null);
203 }
204
205 /**
206 * @param {string} key
207 * @param {!Array<string>} values
208 */
209 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58210 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37211 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50212 const aPriority =
213 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
214 const bPriority =
215 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
216 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
217 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37218 });
219 } else {
220 values.sort();
221 }
222 }
223
224 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16225 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13226 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37227 * @return {boolean}
228 */
229 static _negativeFilter(filter, request) {
230 return !filter(request);
231 }
232
233 /**
234 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13235 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37236 * @return {boolean}
237 */
238 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34239 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37240 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34241 }
Blink Reformat4c46d092018-04-07 15:32:37242
243 return regex.test(request.path() + '/' + request.name());
244 }
245
246 /**
247 * @param {string} domain
248 * @return {!Array.<string>}
249 */
250 static _subdomains(domain) {
251 const result = [domain];
252 let indexOfPeriod = domain.indexOf('.');
253 while (indexOfPeriod !== -1) {
254 result.push('*' + domain.substring(indexOfPeriod));
255 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
256 }
257 return result;
258 }
259
260 /**
261 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16262 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37263 */
264 static _createRequestDomainFilter(value) {
265 /**
266 * @param {string} string
267 * @return {string}
268 */
269 function escapeForRegExp(string) {
270 return string.escapeForRegExp();
271 }
272 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58273 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37274 }
275
276 /**
277 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13278 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37279 * @return {boolean}
280 */
281 static _requestDomainFilter(regex, request) {
282 return regex.test(request.domain);
283 }
284
285 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13286 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37287 * @return {boolean}
288 */
289 static _runningRequestFilter(request) {
290 return !request.finished;
291 }
292
293 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13294 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37295 * @return {boolean}
296 */
297 static _fromCacheRequestFilter(request) {
298 return request.cached();
299 }
300
301 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13302 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05303 * @return {boolean}
304 */
305 static _interceptedByServiceWorkerFilter(request) {
306 return request.fetchedViaServiceWorker;
307 }
308
309 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13310 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05311 * @return {boolean}
312 */
313 static _initiatedByServiceWorkerFilter(request) {
314 return request.initiatedByServiceWorker();
315 }
316
317 /**
Blink Reformat4c46d092018-04-07 15:32:37318 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13319 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37320 * @return {boolean}
321 */
322 static _requestResponseHeaderFilter(value, request) {
323 return request.responseHeaderValue(value) !== undefined;
324 }
325
326 /**
327 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37329 * @return {boolean}
330 */
331 static _requestMethodFilter(value, request) {
332 return request.requestMethod === value;
333 }
334
335 /**
336 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13337 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37338 * @return {boolean}
339 */
340 static _requestPriorityFilter(value, request) {
341 return request.priority() === value;
342 }
343
344 /**
345 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13346 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37347 * @return {boolean}
348 */
349 static _requestMimeTypeFilter(value, request) {
350 return request.mimeType === value;
351 }
352
353 /**
Paul Lewis56509652019-12-06 12:51:58354 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13355 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37356 * @return {boolean}
357 */
358 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58359 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37360 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28361 }
362 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37363 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28364 }
365 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37366 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28367 }
368 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37369 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34370 }
Blink Reformat4c46d092018-04-07 15:32:37371
372 return false;
373 }
374
375 /**
376 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13377 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37378 * @return {boolean}
379 */
380 static _requestSchemeFilter(value, request) {
381 return request.scheme === value;
382 }
383
384 /**
385 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13386 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37387 * @return {boolean}
388 */
Jan Scheffler341eea52019-12-12 09:08:41389 static _requestCookieDomainFilter(value, request) {
390 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
391 }
392
393 /**
394 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13395 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41396 * @return {boolean}
397 */
398 static _requestCookieNameFilter(value, request) {
399 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
400 }
401
402 /**
403 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13404 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41405 * @return {boolean}
406 */
407 static _requestCookieValueFilter(value, request) {
408 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
409 }
410
411 /**
412 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13413 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41414 * @return {boolean}
415 */
Blink Reformat4c46d092018-04-07 15:32:37416 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41417 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37418 }
419
420 /**
421 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13422 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37423 * @return {boolean}
424 */
425 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41426 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37427 }
428
429 /**
430 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13431 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37432 * @return {boolean}
433 */
434 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41435 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37436 }
437
438 /**
439 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13440 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37441 * @return {boolean}
442 */
443 static _requestSizeLargerThanFilter(value, request) {
444 return request.transferSize >= value;
445 }
446
447 /**
448 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13449 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37450 * @return {boolean}
451 */
452 static _statusCodeFilter(value, request) {
453 return ('' + request.statusCode) === value;
454 }
455
456 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13457 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37458 * @return {boolean}
459 */
460 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58461 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37462 }
463
464 /**
Blink Reformat4c46d092018-04-07 15:32:37465 * @param {number} windowStart
466 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13467 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37468 * @return {boolean}
469 */
470 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34471 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37472 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34473 }
474 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37475 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34476 }
Blink Reformat4c46d092018-04-07 15:32:37477 return true;
478 }
479
480 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13481 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37482 */
483 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13484 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37485 }
486
487 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13488 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37489 */
490 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13491 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37492 }
493
494 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13495 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37496 */
497 static async _copyResponse(request) {
498 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08499 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34500 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08501 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34502 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08503 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34504 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13505 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37506 }
507
508 /**
509 * @param {!DataTransfer} dataTransfer
510 */
511 _handleDrop(dataTransfer) {
512 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34513 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37514 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34515 }
Blink Reformat4c46d092018-04-07 15:32:37516 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34517 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37518 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 }
Blink Reformat4c46d092018-04-07 15:32:37520
Joey Arhar0e1093c2019-05-21 00:34:22521 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37522 }
523
524 /**
Tim van der Lippe119690c2020-01-13 12:31:30525 * @override
Blink Reformat4c46d092018-04-07 15:32:37526 * @param {!File} file
527 */
Joey Arhar0e1093c2019-05-21 00:34:22528 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13529 const outputStream = new Common.StringOutputStream.StringOutputStream();
530 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37531 const success = await reader.read(outputStream);
532 if (!success) {
533 this._harLoadFailed(reader.error().message);
534 return;
535 }
536 let harRoot;
537 try {
538 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13539 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37540 } catch (e) {
541 this._harLoadFailed(e);
542 return;
543 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13544 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37545 }
546
547 /**
548 * @param {string} message
549 */
550 _harLoadFailed(message) {
Paul Lewis04ccecc2020-01-22 17:15:14551 self.Common.console.error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37552 }
553
554 /**
555 * @param {?string} groupKey
556 */
557 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34558 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37559 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34560 }
Blink Reformat4c46d092018-04-07 15:32:37561 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
562 this._activeGroupLookup = groupLookup;
563 this._invalidateAllItems();
564 }
565
566 /**
567 * @return {number}
568 */
569 _computeRowHeight() {
570 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
571 }
572
573 /**
Tim van der Lippe119690c2020-01-13 12:31:30574 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13575 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30576 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37577 */
578 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58579 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37580 }
581
582 /**
Tim van der Lippe119690c2020-01-13 12:31:30583 * @override
Blink Reformat4c46d092018-04-07 15:32:37584 * @return {number}
585 */
586 headerHeight() {
587 return this._headerHeight;
588 }
589
590 /**
Tim van der Lippe119690c2020-01-13 12:31:30591 * @override
Blink Reformat4c46d092018-04-07 15:32:37592 * @param {boolean} recording
593 */
594 setRecording(recording) {
595 this._recording = recording;
596 this._updateSummaryBar();
597 }
598
599 /**
600 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13601 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37602 */
603 modelAdded(networkManager) {
604 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34605 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37606 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34607 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13608 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37609 if (resourceTreeModel) {
610 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
611 resourceTreeModel.addEventListener(
612 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
613 }
614 }
615
616 /**
617 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13618 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37619 */
620 modelRemoved(networkManager) {
621 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13622 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37623 if (resourceTreeModel) {
624 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
625 resourceTreeModel.removeEventListener(
626 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
627 }
628 }
629 }
630
631 /**
Tim van der Lippe119690c2020-01-13 12:31:30632 * @override
Blink Reformat4c46d092018-04-07 15:32:37633 * @param {number} start
634 * @param {number} end
635 */
636 setWindow(start, end) {
637 if (!start && !end) {
638 this._timeFilter = null;
639 this._timeCalculator.setWindow(null);
640 } else {
Paul Lewis56509652019-12-06 12:51:58641 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30642 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37643 }
644 this._filterRequests();
645 }
646
Tim van der Lippe119690c2020-01-13 12:31:30647 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05648 resetFocus() {
649 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37650 }
651
652 _resetSuggestionBuilder() {
653 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58654 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
655 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
656 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
657 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
658 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
659 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
660 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37661 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
662 }
663
664 /**
Tim van der Lippec02a97c2020-02-14 14:39:27665 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37666 */
667 _filterChanged(event) {
668 this.removeAllNodeHighlights();
669 this._parseFilterQuery(this._textFilterUI.value());
670 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37671 }
672
Rajasekar Murugan3ad369e2020-02-19 18:20:12673 async resetFilter() {
674 this._textFilterUI.clear();
675 }
676
Blink Reformat4c46d092018-04-07 15:32:37677 _showRecordingHint() {
678 this._hideRecordingHint();
679 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
680 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18681
682 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40683 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18684 if (reloadShortcutDescriptor) {
685 reloadShortcutNode = this._recordingHint.createChild('b');
686 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
687 }
Blink Reformat4c46d092018-04-07 15:32:37688
689 if (this._recording) {
690 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38691 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18692 if (reloadShortcutNode) {
693 hintText.createChild('br');
694 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13695 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18696 }
Blink Reformat4c46d092018-04-07 15:32:37697 } else {
698 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40699 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18700 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13701 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18702 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
703 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13704 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18705 }
Blink Reformat4c46d092018-04-07 15:32:37706 }
Kayce Basques5444c1b2019-02-15 20:32:53707 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13708 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53709 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
710 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11711
712 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57713 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37714 }
715
716 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11717 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34718 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37719 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34720 }
Brandon Goddardc992d522020-01-08 21:44:57721 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37722 this._recordingHint = null;
723 }
724
725 /**
Amanda Baker6761aae2019-11-05 18:59:11726 * @param {boolean} value
727 */
728 _setHidden(value) {
729 this._columns.setHidden(value);
730 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
731 }
732
733 /**
Blink Reformat4c46d092018-04-07 15:32:37734 * @override
735 * @return {!Array.<!Element>}
736 */
737 elementsToRestoreScrollPositionsFor() {
738 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34739 {
Blink Reformat4c46d092018-04-07 15:32:37740 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34741 }
Blink Reformat4c46d092018-04-07 15:32:37742 return [this._dataGrid.scrollContainer];
743 }
744
Tim van der Lippe119690c2020-01-13 12:31:30745 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37746 columnExtensionResolved() {
747 this._invalidateAllItems(true);
748 }
749
750 _setupDataGrid() {
751 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
752 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34753 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37754 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34755 }
Blink Reformat4c46d092018-04-07 15:32:37756 });
757 this._dataGrid.setStickToBottom(true);
758 this._dataGrid.setName('networkLog');
759 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
760 this._dataGrid.element.classList.add('network-log-grid');
761 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
762 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
763 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05764 this._dataGrid.element.addEventListener('keydown', event => {
765 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58766 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05767 event.consume(true);
768 }
769 });
770 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
771 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37772 return this._dataGrid;
773 }
774
775 /**
776 * @param {!Event} event
777 */
778 _dataGridMouseMove(event) {
779 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
780 const highlightInitiatorChain = event.shiftKey;
781 this._setHoveredNode(node, highlightInitiatorChain);
782 }
783
784 /**
Tim van der Lippe119690c2020-01-13 12:31:30785 * @override
786 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37787 */
788 hoveredNode() {
789 return this._hoveredNode;
790 }
791
792 /**
Tim van der Lippe119690c2020-01-13 12:31:30793 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37794 * @param {boolean=} highlightInitiatorChain
795 */
796 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34797 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37798 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34799 }
Blink Reformat4c46d092018-04-07 15:32:37800 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34801 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37802 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34803 }
Blink Reformat4c46d092018-04-07 15:32:37804 }
805
806 /**
807 * @param {!Event} event
808 */
809 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34810 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37811 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34812 }
Blink Reformat4c46d092018-04-07 15:32:37813 }
814
815 _updateSummaryBar() {
816 this._hideRecordingHint();
817
818 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20819 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37820 let selectedNodeNumber = 0;
821 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20822 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37823 let baseTime = -1;
824 let maxTime = -1;
825
826 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16827 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58828 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34829 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37830 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34831 }
Blink Reformat4c46d092018-04-07 15:32:37832 nodeCount++;
833 const requestTransferSize = request.transferSize;
834 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20835 const requestResourceSize = request.resourceSize;
836 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30837 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37838 selectedNodeNumber++;
839 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20840 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37841 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13842 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37843 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
844 // inspected url.
845 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13846 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
847 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37848 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34849 }
850 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37851 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34852 }
Blink Reformat4c46d092018-04-07 15:32:37853 }
854
855 if (!nodeCount) {
856 this._showRecordingHint();
857 return;
858 }
859
Joey Arhara86c14e2019-03-12 03:20:50860 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37861 /**
862 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50863 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37864 * @return {!Element}
865 */
Joey Arhara86c14e2019-03-12 03:20:50866 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13867 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50868 toolbarText.setTitle(title ? title : chunk);
869 this._summaryToolbar.appendToolbarItem(toolbarText);
870 return toolbarText.element;
871 };
Blink Reformat4c46d092018-04-07 15:32:37872
873 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50874 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
875 this._summaryToolbar.appendSeparator();
876 appendChunk(
877 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25878 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50879 this._summaryToolbar.appendSeparator();
880 appendChunk(
881 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25882 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37883 } else {
Joey Arhara86c14e2019-03-12 03:20:50884 appendChunk(ls`${nodeCount} requests`);
885 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25886 appendChunk(
887 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50888 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25889 appendChunk(
890 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37891 }
Dan Beam87466b52018-12-01 18:41:20892
Blink Reformat4c46d092018-04-07 15:32:37893 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50894 this._summaryToolbar.appendSeparator();
895 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37896 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50897 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30898 const domContentLoadedText =
899 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58900 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37901 }
902 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50903 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30904 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58905 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37906 }
907 }
Blink Reformat4c46d092018-04-07 15:32:37908 }
909
Tim van der Lippe119690c2020-01-13 12:31:30910 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37911 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34912 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37913 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 }
Blink Reformat4c46d092018-04-07 15:32:37915
916 this._needsRefresh = true;
917
Tim van der Lippe1d6e57a2019-09-30 11:55:34918 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37919 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34920 }
Blink Reformat4c46d092018-04-07 15:32:37921 }
922
923 /**
Tim van der Lippe119690c2020-01-13 12:31:30924 * @override
Blink Reformat4c46d092018-04-07 15:32:37925 * @param {!Array<number>} times
926 */
927 addFilmStripFrames(times) {
928 this._columns.addEventDividers(times, 'network-frame-divider');
929 }
930
931 /**
Tim van der Lippe119690c2020-01-13 12:31:30932 * @override
Blink Reformat4c46d092018-04-07 15:32:37933 * @param {number} time
934 */
935 selectFilmStripFrame(time) {
936 this._columns.selectFilmStripFrame(time);
937 }
938
Tim van der Lippe119690c2020-01-13 12:31:30939 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37940 clearFilmStripFrame() {
941 this._columns.clearFilmStripFrame();
942 }
943
944 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34945 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37946 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34947 }
Blink Reformat4c46d092018-04-07 15:32:37948 }
949
950 /**
951 * @param {boolean=} deferUpdate
952 */
953 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16954 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34955 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37956 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34957 } else {
Blink Reformat4c46d092018-04-07 15:32:37958 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 }
Blink Reformat4c46d092018-04-07 15:32:37960 }
961
962 /**
Tim van der Lippe119690c2020-01-13 12:31:30963 * @override
964 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37965 */
966 timeCalculator() {
967 return this._timeCalculator;
968 }
969
970 /**
Tim van der Lippe119690c2020-01-13 12:31:30971 * @override
972 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37973 */
974 calculator() {
975 return this._calculator;
976 }
977
978 /**
Tim van der Lippe119690c2020-01-13 12:31:30979 * @override
980 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37981 */
982 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34983 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37984 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34985 }
Blink Reformat4c46d092018-04-07 15:32:37986
987 if (this._calculator !== x) {
988 this._calculator = x;
989 this._columns.setCalculator(this._calculator);
990 }
991 this._calculator.reset();
992
Tim van der Lippe1d6e57a2019-09-30 11:55:34993 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37994 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34995 } else {
Blink Reformat4c46d092018-04-07 15:32:37996 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34997 }
Blink Reformat4c46d092018-04-07 15:32:37998
999 this._invalidateAllItems();
1000 }
1001
1002 /**
Tim van der Lippec02a97c2020-02-14 14:39:271003 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371004 */
1005 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371007 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341008 }
Blink Reformat4c46d092018-04-07 15:32:371009
1010 const time = /** @type {number} */ (event.data.loadTime);
1011 if (time) {
1012 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301013 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371014 }
1015 }
1016
1017 /**
Tim van der Lippec02a97c2020-02-14 14:39:271018 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371019 */
1020 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341021 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371022 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341023 }
Blink Reformat4c46d092018-04-07 15:32:371024 const data = /** @type {number} */ (event.data);
1025 if (data) {
1026 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301027 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371028 }
1029 }
1030
1031 /**
1032 * @override
1033 */
1034 wasShown() {
1035 this._refreshIfNeeded();
1036 this._columns.wasShown();
1037 }
1038
1039 /**
1040 * @override
1041 */
1042 willHide() {
1043 this._columns.willHide();
1044 }
1045
1046 /**
1047 * @override
1048 */
1049 onResize() {
1050 this._rowHeight = this._computeRowHeight();
1051 }
1052
1053 /**
Tim van der Lippe119690c2020-01-13 12:31:301054 * @override
1055 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371056 */
1057 flatNodesList() {
1058 return this._dataGrid.rootNode().flatChildren();
1059 }
1060
Tim van der Lippe119690c2020-01-13 12:31:301061 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051062 updateNodeBackground() {
1063 if (this._dataGrid.selectedNode) {
1064 this._dataGrid.selectedNode.updateBackgroundColor();
1065 }
1066 }
1067
1068 /**
Tim van der Lippe119690c2020-01-13 12:31:301069 * @override
Brandon Goddard88d885a2019-10-31 16:11:051070 * @param {boolean} isSelected
1071 */
1072 updateNodeSelectedClass(isSelected) {
1073 if (isSelected) {
1074 this.element.classList.remove('no-node-selected');
1075 } else {
1076 this.element.classList.add('no-node-selected');
1077 }
1078 }
1079
Tim van der Lippe119690c2020-01-13 12:31:301080 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371081 stylesChanged() {
1082 this._columns.scheduleRefresh();
1083 }
1084
1085 _refresh() {
1086 this._needsRefresh = false;
1087
1088 if (this._refreshRequestId) {
1089 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1090 this._refreshRequestId = null;
1091 }
1092
1093 this.removeAllNodeHighlights();
1094
1095 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1096 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1097 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1098 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1099
Tim van der Lippe119690c2020-01-13 12:31:301100 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371101 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301102 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371103 const nodesToRefresh = [];
1104
Tim van der Lippe119690c2020-01-13 12:31:301105 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371106 const staleNodes = new Set();
1107
1108 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1109 // node so we loop until we have no more stale requests.
1110 while (this._staleRequests.size) {
1111 const request = this._staleRequests.firstValue();
1112 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581113 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341114 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371115 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341116 }
Blink Reformat4c46d092018-04-07 15:32:371117 staleNodes.add(node);
1118 }
1119
1120 for (const node of staleNodes) {
1121 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341122 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371123 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341124 }
Blink Reformat4c46d092018-04-07 15:32:371125
Tim van der Lippe1d6e57a2019-09-30 11:55:341126 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371127 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341128 }
Blink Reformat4c46d092018-04-07 15:32:371129 const request = node.request();
1130 this._timeCalculator.updateBoundaries(request);
1131 this._durationCalculator.updateBoundaries(request);
1132 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301133 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371134 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341135 }
Tim van der Lippe119690c2020-01-13 12:31:301136 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371137 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1138 if (removeFromParent) {
1139 let parent = node.parent;
1140 parent.removeChild(node);
1141 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1142 const grandparent = parent.parent;
1143 grandparent.removeChild(parent);
1144 parent = grandparent;
1145 }
1146 }
1147
Tim van der Lippe1d6e57a2019-09-30 11:55:341148 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371149 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 }
Blink Reformat4c46d092018-04-07 15:32:371151
1152 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1153 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1154 nodesToRefresh.push(newParent);
1155 }
1156 nodesToInsert.set(node, newParent);
1157 }
1158
Tim van der Lippe1d6e57a2019-09-30 11:55:341159 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371160 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341161 }
Blink Reformat4c46d092018-04-07 15:32:371162
Tim van der Lippe1d6e57a2019-09-30 11:55:341163 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371164 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341165 }
Blink Reformat4c46d092018-04-07 15:32:371166
1167 this._updateSummaryBar();
1168
Tim van der Lippe1d6e57a2019-09-30 11:55:341169 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371170 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341171 }
Blink Reformat4c46d092018-04-07 15:32:371172
1173 this._dataGrid.updateInstantly();
1174 this._didRefreshForTest();
1175 }
1176
1177 _didRefreshForTest() {
1178 }
1179
1180 /**
Tim van der Lippe119690c2020-01-13 12:31:301181 * @param {!NetworkRequestNode} node
1182 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371183 */
1184 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341185 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371186 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341187 }
Blink Reformat4c46d092018-04-07 15:32:371188
1189 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341190 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371191 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341192 }
Blink Reformat4c46d092018-04-07 15:32:371193 return groupNode;
1194 }
1195
1196 _reset() {
Paul Lewis56509652019-12-06 12:51:581197 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371198
1199 this._setHoveredNode(null);
1200 this._columns.reset();
1201
1202 this._timeFilter = null;
1203 this._calculator.reset();
1204
1205 this._timeCalculator.setWindow(null);
1206 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371207
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371209 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341210 }
Blink Reformat4c46d092018-04-07 15:32:371211 this._staleRequests.clear();
1212 this._resetSuggestionBuilder();
1213
1214 this._mainRequestLoadTime = -1;
1215 this._mainRequestDOMContentLoadedTime = -1;
1216
1217 this._dataGrid.rootNode().removeChildren();
1218 this._updateSummaryBar();
1219 this._dataGrid.setStickToBottom(true);
1220 this.scheduleRefresh();
1221 }
1222
1223 /**
Tim van der Lippe119690c2020-01-13 12:31:301224 * @override
Blink Reformat4c46d092018-04-07 15:32:371225 * @param {string} filterString
1226 */
1227 setTextFilterValue(filterString) {
1228 this._textFilterUI.setValue(filterString);
1229 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371230 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131231 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371232 this._resourceCategoryFilterUI.reset();
1233 }
1234
1235 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131236 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371237 */
1238 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301239 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581240 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301241 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371242
Tim van der Lippe1d6e57a2019-09-30 11:55:341243 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371244 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341245 }
Blink Reformat4c46d092018-04-07 15:32:371246 return node;
1247 }
1248
1249 /**
Tim van der Lippec02a97c2020-02-14 14:39:271250 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371251 */
1252 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131253 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371254 this._refreshRequest(request);
1255 }
1256
1257 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131258 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371259 */
1260 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581261 NetworkLogView._subdomains(request.domain)
1262 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1263 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1264 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1265 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1266 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371267
1268 const priority = request.priority();
1269 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501270 this._suggestionBuilder.addItem(
1271 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371272 }
1273
1274 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581275 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371276 }
1277
1278 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581279 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371280 }
1281
1282 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581283 const suggestion =
1284 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1285 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371286 }
1287
1288 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341289 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581290 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341291 }
Jan Scheffler341eea52019-12-12 09:08:411292
1293 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581294 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1295 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1296 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371297 }
1298
Jan Scheffler341eea52019-12-12 09:08:411299 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1300 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1301 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1302 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1303 }
1304
Blink Reformat4c46d092018-04-07 15:32:371305 this._staleRequests.add(request);
1306 this.scheduleRefresh();
1307 }
1308
1309 /**
Tim van der Lippe119690c2020-01-13 12:31:301310 * @override
Blink Reformat4c46d092018-04-07 15:32:371311 * @return {number}
1312 */
1313 rowHeight() {
1314 return this._rowHeight;
1315 }
1316
1317 /**
Tim van der Lippe119690c2020-01-13 12:31:301318 * @override
Blink Reformat4c46d092018-04-07 15:32:371319 * @param {boolean} gridMode
1320 */
1321 switchViewMode(gridMode) {
1322 this._columns.switchViewMode(gridMode);
1323 }
1324
1325 /**
Tim van der Lippe119690c2020-01-13 12:31:301326 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131327 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1328 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371329 */
1330 handleContextMenuForRequest(contextMenu, request) {
1331 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131332 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371333 const footerSection = copyMenu.footerSection();
1334 if (request) {
1335 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131336 UI.UIUtils.copyLinkAddressLabel(),
1337 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1338 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371339 if (request.requestHeadersText()) {
1340 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131341 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371342 }
1343
1344 if (request.responseHeadersText) {
1345 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131346 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371347 }
1348
1349 if (request.finished) {
1350 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131351 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371352 }
1353
Harley Libcf41f92018-09-10 18:01:131354 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131355 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371356 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131357 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1358 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371359 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131360 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291361 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131362 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1363 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371364 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131365 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1366 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131367 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131368 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1369 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371370 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131371 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1372 footerSection.appendItem(
1373 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1374 footerSection.appendItem(
1375 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1376 footerSection.appendItem(
1377 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1378 footerSection.appendItem(
1379 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371380 } else {
Harley Libcf41f92018-09-10 18:01:131381 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131382 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291383 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131384 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1385 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131386 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131387 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1388 footerSection.appendItem(
1389 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1390 footerSection.appendItem(
1391 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1392 footerSection.appendItem(
1393 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371394 }
1395 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131396 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371397 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131398 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371399
Joey Arhar0e1093c2019-05-21 00:34:221400 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371401
Blink Reformat4c46d092018-04-07 15:32:371402 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131403 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1404 contextMenu.editSection().appendItem(
1405 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371406
1407 if (request) {
1408 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081409 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371410 let patterns = manager.blockedPatterns();
1411
Tim van der Lippeffa78622019-09-16 12:07:121412 /**
1413 * @param {string} url
1414 */
1415 function addBlockedURL(url) {
1416 patterns.push({enabled: true, url: url});
1417 manager.setBlockedPatterns(patterns);
1418 manager.setBlockingEnabled(true);
Paul Lewis50993692020-01-23 15:22:261419 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121420 }
1421
1422 /**
1423 * @param {string} url
1424 */
1425 function removeBlockedURL(url) {
1426 patterns = patterns.filter(pattern => pattern.url !== url);
1427 manager.setBlockedPatterns(patterns);
Paul Lewis50993692020-01-23 15:22:261428 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121429 }
1430
Blink Reformat4c46d092018-04-07 15:32:371431 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1432 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1433 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131434 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371435 } else if (urlWithoutScheme) {
1436 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1437 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131438 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371439 }
1440
1441 const domain = request.parsedURL.domain();
1442 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1443 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131444 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371445 } else if (domain) {
1446 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1447 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131448 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371449 }
1450
Tim van der Lippe0ed1d2b2020-02-04 13:45:131451 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371452 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131453 Common.UIString.UIString('Replay XHR'),
1454 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371455 }
Blink Reformat4c46d092018-04-07 15:32:371456 }
1457 }
1458
1459 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161460 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171461 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131462 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171463 });
Blink Reformat4c46d092018-04-07 15:32:371464 }
1465
1466 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131467 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1468 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371469 }
1470
1471 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131472 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371473 * @param {string} platform
1474 */
1475 async _copyCurlCommand(request, platform) {
1476 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131477 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371478 }
1479
1480 /**
1481 * @param {string} platform
1482 */
1483 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161484 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131485 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371486 }
1487
1488 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131489 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291490 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371491 */
Jan Scheffler7c50d1f2019-12-17 13:33:291492 async _copyFetchCall(request, includeCookies) {
1493 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371495 }
1496
Jan Scheffler7c50d1f2019-12-17 13:33:291497 /**
1498 * @param {boolean} includeCookies
1499 */
1500 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161501 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131502 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371503 }
1504
1505 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131506 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371507 */
1508 async _copyPowerShellCommand(request) {
1509 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131510 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371511 }
1512
1513 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161514 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131515 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371516 }
1517
Tim van der Lippe119690c2020-01-13 12:31:301518 /**
1519 * @override
1520 * @return {!Promise}
1521 */
Joey Arhar0e1093c2019-05-21 00:34:221522 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331523 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131524 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371525 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131526 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371527
Tim van der Lippe1d6e57a2019-09-30 11:55:341528 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371529 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341530 }
Blink Reformat4c46d092018-04-07 15:32:371531
Tim van der Lippe0ed1d2b2020-02-04 13:45:131532 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371533 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301534 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371535 progressIndicator.done();
1536 stream.close();
1537 }
1538
1539 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131540 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081541 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341542 }
Blink Reformat4c46d092018-04-07 15:32:371543 }
1544
1545 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131546 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081547 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341548 }
Blink Reformat4c46d092018-04-07 15:32:371549 }
1550
1551 _removeAllHighlights() {
1552 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341553 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131554 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341555 }
Blink Reformat4c46d092018-04-07 15:32:371556 this._highlightedSubstringChanges = [];
1557 }
1558
1559 /**
Tim van der Lippe119690c2020-01-13 12:31:301560 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371561 * @return {boolean}
1562 */
1563 _applyFilter(node) {
1564 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341565 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371566 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341567 }
Blink Reformat4c46d092018-04-07 15:32:371568 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341569 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371570 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341571 }
1572 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371573 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341574 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131575 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.IssuesModel.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371576 return false;
1577 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131578 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1579 return false;
1580 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341581 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371582 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341583 }
Blink Reformat4c46d092018-04-07 15:32:371584 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341585 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371586 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341587 }
Blink Reformat4c46d092018-04-07 15:32:371588 }
1589 return true;
1590 }
1591
1592 /**
1593 * @param {string} query
1594 */
1595 _parseFilterQuery(query) {
1596 const descriptors = this._filterParser.parse(query);
1597 this._filters = descriptors.map(descriptor => {
1598 const key = descriptor.key;
1599 const text = descriptor.text || '';
1600 const regex = descriptor.regex;
1601 let filter;
1602 if (key) {
1603 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581604 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1605 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371606 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581607 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371608 } else {
Paul Lewis56509652019-12-06 12:51:581609 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371610 }
Paul Lewis56509652019-12-06 12:51:581611 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371612 });
1613 }
1614
1615 /**
Paul Lewis56509652019-12-06 12:51:581616 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371617 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161618 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371619 */
1620 _createSpecialFilter(type, value) {
1621 switch (type) {
Paul Lewis56509652019-12-06 12:51:581622 case FilterType.Domain:
1623 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371624
Paul Lewis56509652019-12-06 12:51:581625 case FilterType.HasResponseHeader:
1626 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371627
Paul Lewis56509652019-12-06 12:51:581628 case FilterType.Is:
1629 if (value.toLowerCase() === IsFilterType.Running) {
1630 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341631 }
Paul Lewis56509652019-12-06 12:51:581632 if (value.toLowerCase() === IsFilterType.FromCache) {
1633 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341634 }
Paul Lewis56509652019-12-06 12:51:581635 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1636 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341637 }
Paul Lewis56509652019-12-06 12:51:581638 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1639 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341640 }
Blink Reformat4c46d092018-04-07 15:32:371641 break;
1642
Paul Lewis56509652019-12-06 12:51:581643 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371644 return this._createSizeFilter(value.toLowerCase());
1645
Paul Lewis56509652019-12-06 12:51:581646 case FilterType.Method:
1647 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371648
Paul Lewis56509652019-12-06 12:51:581649 case FilterType.MimeType:
1650 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371651
Paul Lewis56509652019-12-06 12:51:581652 case FilterType.MixedContent:
1653 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371654
Paul Lewis56509652019-12-06 12:51:581655 case FilterType.Scheme:
1656 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371657
Paul Lewis56509652019-12-06 12:51:581658 case FilterType.SetCookieDomain:
1659 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371660
Paul Lewis56509652019-12-06 12:51:581661 case FilterType.SetCookieName:
1662 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371663
Paul Lewis56509652019-12-06 12:51:581664 case FilterType.SetCookieValue:
1665 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371666
Jan Scheffler341eea52019-12-12 09:08:411667 case FilterType.CookieDomain:
1668 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1669
1670 case FilterType.CookieName:
1671 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1672
1673 case FilterType.CookieValue:
1674 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1675
Paul Lewis56509652019-12-06 12:51:581676 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501677 return NetworkLogView._requestPriorityFilter.bind(
1678 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371679
Paul Lewis56509652019-12-06 12:51:581680 case FilterType.StatusCode:
1681 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371682 }
1683 return null;
1684 }
1685
1686 /**
1687 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161688 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371689 */
1690 _createSizeFilter(value) {
1691 let multiplier = 1;
1692 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411693 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371694 value = value.substring(0, value.length - 1);
1695 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411696 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371697 value = value.substring(0, value.length - 1);
1698 }
1699 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341700 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371701 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341702 }
Paul Lewis56509652019-12-06 12:51:581703 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371704 }
1705
1706 _filterRequests() {
1707 this._removeAllHighlights();
1708 this._invalidateAllItems();
1709 }
1710
1711 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131712 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301713 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371714 */
1715 _reveal(request) {
1716 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581717 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341718 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371719 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341720 }
Blink Reformat4c46d092018-04-07 15:32:371721 node.reveal();
1722 return node;
1723 }
1724
1725 /**
Tim van der Lippe119690c2020-01-13 12:31:301726 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131727 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371728 */
1729 revealAndHighlightRequest(request) {
1730 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371732 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341733 }
Blink Reformat4c46d092018-04-07 15:32:371734 }
1735
1736 /**
Tim van der Lippe119690c2020-01-13 12:31:301737 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131738 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371739 */
1740 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141741 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371742 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341743 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371744 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341745 }
Blink Reformat4c46d092018-04-07 15:32:371746 }
1747
Tim van der Lippe119690c2020-01-13 12:31:301748 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371749 removeAllNodeHighlights() {
1750 if (this._highlightedNode) {
1751 this._highlightedNode.element().classList.remove('highlighted-row');
1752 this._highlightedNode = null;
1753 }
1754 }
1755
1756 /**
Tim van der Lippe119690c2020-01-13 12:31:301757 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371758 */
1759 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131760 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371761 this._highlightedNode = node;
1762 }
1763
1764 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131765 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1766 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131767 */
1768 _filterOutBlobRequests(requests) {
1769 return requests.filter(request => !request.isBlobRequest());
1770 }
1771
1772 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131773 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291774 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371775 * @return {!Promise<string>}
1776 */
Jan Scheffler7c50d1f2019-12-17 13:33:291777 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371778 const ignoredHeaders = {
1779 // Internal headers
1780 'method': 1,
1781 'path': 1,
1782 'scheme': 1,
1783 'version': 1,
1784
1785 // Unsafe headers
1786 // Keep this list synchronized with src/net/http/http_util.cc
1787 'accept-charset': 1,
1788 'accept-encoding': 1,
1789 'access-control-request-headers': 1,
1790 'access-control-request-method': 1,
1791 'connection': 1,
1792 'content-length': 1,
1793 'cookie': 1,
1794 'cookie2': 1,
1795 'date': 1,
1796 'dnt': 1,
1797 'expect': 1,
1798 'host': 1,
1799 'keep-alive': 1,
1800 'origin': 1,
1801 'referer': 1,
1802 'te': 1,
1803 'trailer': 1,
1804 'transfer-encoding': 1,
1805 'upgrade': 1,
1806 'via': 1,
1807 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1808 'user-agent': 1
1809 };
1810
1811 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1812
1813 const url = JSON.stringify(request.url());
1814
1815 const requestHeaders = request.requestHeaders();
1816 const headerData = requestHeaders.reduce((result, header) => {
1817 const name = header.name;
1818
Tim van der Lippe1d6e57a2019-09-30 11:55:341819 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371820 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341821 }
Blink Reformat4c46d092018-04-07 15:32:371822
1823 return result;
1824 }, new Headers());
1825
1826 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341827 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411828 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341829 }
Blink Reformat4c46d092018-04-07 15:32:371830
1831 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411832 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1833 'include' :
1834 'omit';
Blink Reformat4c46d092018-04-07 15:32:371835
1836 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1837
1838 const referrer = referrerHeader ? referrerHeader.value : void 0;
1839
1840 const referrerPolicy = request.referrerPolicy() || void 0;
1841
1842 const requestBody = await request.requestFormData();
1843
1844 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411845 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371846 referrer,
1847 referrerPolicy,
1848 body: requestBody,
1849 method: request.requestMethod,
1850 mode: 'cors'
1851 };
1852
Jan Scheffler7c50d1f2019-12-17 13:33:291853 if (includeCookies) {
1854 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1855 if (cookieHeader) {
1856 fetchOptions.headers = {
1857 ...headers,
1858 'cookie': cookieHeader.value,
1859 };
1860 }
1861 } else {
1862 fetchOptions.credentials = credentials;
1863 }
1864
Jan Scheffler172d5212020-01-02 14:42:561865 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371866 return `fetch(${url}, ${options});`;
1867 }
1868
1869 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131870 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291871 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131872 * @return {!Promise<string>}
1873 */
Jan Scheffler7c50d1f2019-12-17 13:33:291874 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131875 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291876 const commands =
1877 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131878 return commands.join(' ;\n');
1879 }
1880
1881 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131882 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371883 * @param {string} platform
1884 * @return {!Promise<string>}
1885 */
1886 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561887 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361888 // Most of these headers are derived from the URL and are automatically added by cURL.
1889 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1890 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371891
1892 function escapeStringWin(str) {
1893 /* If there are no new line characters do not escape the " characters
1894 since it only uglifies the command.
1895
1896 Because cmd.exe parser and MS Crt arguments parsers use some of the
1897 same escape characters, they can interact with each other in
1898 horrible ways, the order of operations is critical.
1899
1900 Replace \ with \\ first because it is an escape character for certain
1901 conditions in both parsers.
1902
1903 Replace all " with \" to ensure the first parser does not remove it.
1904
1905 Then escape all characters we are not sure about with ^ to ensure it
1906 gets to MS Crt parser safely.
1907
1908 The % character is special because MS Crt parser will try and look for
1909 ENV variables and fill them in it's place. We cannot escape them with %
1910 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1911 parser); So we can get cmd.exe parser to escape the character after it,
1912 if it is followed by a valid beginning character of an ENV variable.
1913 This ensures we do not try and double escape another ^ if it was placed
1914 by the previous replace.
1915
1916 Lastly we replace new lines with ^ and TWO new lines because the first
1917 new line is there to enact the escape command the second is the character
1918 to escape (in this case new line).
1919 */
1920 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1921 return encapsChars +
1922 str.replace(/\\/g, '\\\\')
1923 .replace(/"/g, '\\"')
1924 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1925 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1926 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1927 encapsChars;
1928 }
1929
1930 /**
1931 * @param {string} str
1932 * @return {string}
1933 */
1934 function escapeStringPosix(str) {
1935 /**
1936 * @param {string} x
1937 * @return {string}
1938 */
1939 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221940 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121941 let hexString = code.toString(16);
1942 // Zero pad to four digits to comply with ANSI-C Quoting:
1943 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341944 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121945 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341946 }
Joey Arhar2d21f712019-05-20 21:07:121947
1948 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371949 }
1950
Mathias Bynensf06e8c02020-02-28 13:58:281951 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371952 // Use ANSI-C quoting syntax.
1953 return '$\'' +
1954 str.replace(/\\/g, '\\\\')
1955 .replace(/\'/g, '\\\'')
1956 .replace(/\n/g, '\\n')
1957 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:281958 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371959 '\'';
Blink Reformat4c46d092018-04-07 15:32:371960 }
Mathias Bynensf06e8c02020-02-28 13:58:281961 // Use single quote syntax.
1962 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:371963 }
1964
1965 // cURL command expected to run on the same platform that DevTools run
1966 // (it may be different from the inspected page platform).
1967 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1968
1969 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1970
1971 let inferredMethod = 'GET';
1972 const data = [];
1973 const requestContentType = request.requestContentType();
1974 const formData = await request.requestFormData();
1975 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:271976 // Note that formData is not necessarily urlencoded because it might for example
1977 // come from a fetch request made with an explicitly unencoded body.
1978 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371979 ignoredHeaders['content-length'] = true;
1980 inferredMethod = 'POST';
1981 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561982 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371983 ignoredHeaders['content-length'] = true;
1984 inferredMethod = 'POST';
1985 }
1986
1987 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291988 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371989 }
1990
1991 const requestHeaders = request.requestHeaders();
1992 for (let i = 0; i < requestHeaders.length; i++) {
1993 const header = requestHeaders[i];
1994 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341995 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371996 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341997 }
Jan Scheffler172d5212020-01-02 14:42:561998 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371999 }
2000 command = command.concat(data);
2001 command.push('--compressed');
2002
Tim van der Lippe1d6e57a2019-09-30 11:55:342003 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372004 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342005 }
Jan Scheffler172d5212020-01-02 14:42:562006 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372007 }
2008
2009 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132010 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132011 * @param {string} platform
2012 * @return {!Promise<string>}
2013 */
2014 async _generateAllCurlCommand(requests, platform) {
2015 const nonBlobRequests = this._filterOutBlobRequests(requests);
2016 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342017 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132018 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342019 }
Mathias Bynensf06e8c02020-02-28 13:58:282020 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132021 }
2022
2023 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132024 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372025 * @return {!Promise<string>}
2026 */
2027 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562028 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372029 const ignoredHeaders =
2030 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2031
2032 /**
2033 * @param {string} str
2034 * @return {string}
2035 */
2036 function escapeString(str) {
2037 return '"' +
2038 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2039 }
2040
Jan Scheffler172d5212020-01-02 14:42:562041 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372042
2043 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562044 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372045 }
2046
2047 const requestHeaders = request.requestHeaders();
2048 const headerNameValuePairs = [];
2049 for (const header of requestHeaders) {
2050 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342051 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372052 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342053 }
Blink Reformat4c46d092018-04-07 15:32:372054 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2055 }
2056 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562057 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372058 }
2059
2060 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2061 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562062 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372063 }
2064
2065 const formData = await request.requestFormData();
2066 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372067 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342068 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562069 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342070 } else {
Jan Scheffler172d5212020-01-02 14:42:562071 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342072 }
Blink Reformat4c46d092018-04-07 15:32:372073 }
2074
Jan Scheffler172d5212020-01-02 14:42:562075 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372076 }
Harley Libcf41f92018-09-10 18:01:132077
2078 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132079 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132080 * @return {!Promise<string>}
2081 */
2082 async _generateAllPowerShellCommand(requests) {
2083 const nonBlobRequests = this._filterOutBlobRequests(requests);
2084 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2085 return commands.join(';\r\n');
2086 }
Joey Arhara86c14e2019-03-12 03:20:502087
2088 /**
2089 * @return {string}
2090 */
2091 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552092 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502093 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342094 }
Joey Arhara86c14e2019-03-12 03:20:502095 return '#0867CB';
2096 }
2097
2098 /**
2099 * @return {string}
2100 */
2101 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132102 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502103 }
Paul Lewis56509652019-12-06 12:51:582104}
Blink Reformat4c46d092018-04-07 15:32:372105
Tim van der Lippe119690c2020-01-13 12:31:302106export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582107export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372108
Paul Lewis56509652019-12-06 12:51:582109export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372110 'http': true,
2111 'https': true,
2112 'ws': true,
2113 'wss': true
2114};
2115
Blink Reformat4c46d092018-04-07 15:32:372116/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582117export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372118 Domain: 'domain',
2119 HasResponseHeader: 'has-response-header',
2120 Is: 'is',
2121 LargerThan: 'larger-than',
2122 Method: 'method',
2123 MimeType: 'mime-type',
2124 MixedContent: 'mixed-content',
2125 Priority: 'priority',
2126 Scheme: 'scheme',
2127 SetCookieDomain: 'set-cookie-domain',
2128 SetCookieName: 'set-cookie-name',
2129 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412130 CookieDomain: 'cookie-domain',
2131 CookieName: 'cookie-name',
2132 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372133 StatusCode: 'status-code'
2134};
2135
2136/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582137export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372138 All: 'all',
2139 Displayed: 'displayed',
2140 Blocked: 'blocked',
2141 BlockOverridden: 'block-overridden'
2142};
2143
2144/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582145export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372146 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052147 FromCache: 'from-cache',
2148 ServiceWorkerIntercepted: 'service-worker-intercepted',
2149 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372150};
2151
2152/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582153export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372154
2155/**
2156 * @interface
2157 */
Paul Lewis56509652019-12-06 12:51:582158export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372159 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132160 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302161 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372162 */
Paul Lewis56509652019-12-06 12:51:582163 groupNodeForRequest(request) {
2164 }
Blink Reformat4c46d092018-04-07 15:32:372165
Paul Lewis56509652019-12-06 12:51:582166 reset() {
2167 }
2168}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162169
2170/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2171export let Filter;