blob: 9763f8f24d129ed98b2d421b28680c61e2fe3735 [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);
68 this._networkResourceTypeFiltersSetting = self.Common.settings.createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3769
70 this._rawRowHeight = 0;
71 this._progressBarContainer = progressBarContainer;
72 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
73 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
74
75 /**
Paul Lewis56509652019-12-06 12:51:5876 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3777 */
78 function updateRowHeight() {
79 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
80 this._rowHeight = this._computeRowHeight();
81 }
82 this._rawRowHeight = 0;
83 this._rowHeight = 0;
84 updateRowHeight.call(this);
85
Tim van der Lippe119690c2020-01-13 12:31:3086 /** @type {!NetworkTransferTimeCalculator} */
87 this._timeCalculator = new NetworkTransferTimeCalculator();
88 /** @type {!NetworkTransferDurationCalculator} */
89 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3790 this._calculator = this._timeCalculator;
91
Tim van der Lippe119690c2020-01-13 12:31:3092 this._columns =
93 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:3794 this._columns.show(this.element);
95
Tim van der Lippe0ed1d2b2020-02-04 13:45:1396 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:3797 this._staleRequests = new Set();
98 /** @type {number} */
99 this._mainRequestLoadTime = -1;
100 /** @type {number} */
101 this._mainRequestDOMContentLoadedTime = -1;
102 this._highlightedSubstringChanges = [];
103
Tim van der Lippeb1f2b6c2020-02-17 13:00:16104 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37105 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16106 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37107 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30108 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37109 this._hoveredNode = null;
110 /** @type {?Element} */
111 this._recordingHint = null;
112 /** @type {?number} */
113 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30114 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37115 this._highlightedNode = null;
116
Tim van der Lippe0ed1d2b2020-02-04 13:45:13117 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37118
119 this._recording = false;
120 this._needsRefresh = false;
121
122 this._headerHeight = 0;
123
Paul Lewis56509652019-12-06 12:51:58124 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37125 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30126 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37127
Paul Lewis56509652019-12-06 12:51:58128 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37129 this._activeGroupLookup = null;
130
Tim van der Lippe0ed1d2b2020-02-04 13:45:13131 this._textFilterUI = new UI.FilterBar.TextFilterUI();
132 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37133 filterBar.addFilter(this._textFilterUI);
134
Tim van der Lippe0ed1d2b2020-02-04 13:45:13135 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
136 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
137 this._dataURLFilterUI.addEventListener(
138 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48139 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37140 filterBar.addFilter(this._dataURLFilterUI);
141
142 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13143 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37144 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13145 this._resourceCategoryFilterUI =
146 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20147 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37148 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13149 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37150 filterBar.addFilter(this._resourceCategoryFilterUI);
151
Tim van der Lippe0ed1d2b2020-02-04 13:45:13152 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
153 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
154 this._onlyIssuesFilterUI.addEventListener(
155 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41156 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37157 filterBar.addFilter(this._onlyIssuesFilterUI);
158
159
Tim van der Lippe0ed1d2b2020-02-04 13:45:13160 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
161 this._suggestionBuilder =
162 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37163 this._resetSuggestionBuilder();
164
165 this._dataGrid = this._columns.dataGrid();
166 this._setupDataGrid();
167 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49168 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13169 UI.Toolbar.ToolbarButton.Events.Click,
170 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37171
Tim van der Lippe0ed1d2b2020-02-04 13:45:13172 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37173
Tim van der Lippe0ed1d2b2020-02-04 13:45:13174 new UI.DropTarget.DropTarget(
175 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
176 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37177
Paul Lewis4b64b3f2020-01-23 11:41:20178 self.Common.settings.moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37179 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
180
Tim van der Lippe0ed1d2b2020-02-04 13:45:13181 self.SDK.targetManager.observeModels(SDK.NetworkManager.NetworkManager, this);
Paul Lewisca3665d2020-01-24 13:31:16182 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
183 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
184 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37185
186 this._updateGroupByFrame();
Paul Lewis4b64b3f2020-01-23 11:41:20187 self.Common.settings.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37188
189 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37190 }
191
Blink Reformat4c46d092018-04-07 15:32:37192 _updateGroupByFrame() {
Paul Lewis4b64b3f2020-01-23 11:41:20193 const value = self.Common.settings.moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37194 this._setGrouping(value ? 'Frame' : null);
195 }
196
197 /**
198 * @param {string} key
199 * @param {!Array<string>} values
200 */
201 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58202 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37203 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50204 const aPriority =
205 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
206 const bPriority =
207 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
208 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
209 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37210 });
211 } else {
212 values.sort();
213 }
214 }
215
216 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16217 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13218 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37219 * @return {boolean}
220 */
221 static _negativeFilter(filter, request) {
222 return !filter(request);
223 }
224
225 /**
226 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13227 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37228 * @return {boolean}
229 */
230 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34231 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37232 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34233 }
Blink Reformat4c46d092018-04-07 15:32:37234
235 return regex.test(request.path() + '/' + request.name());
236 }
237
238 /**
239 * @param {string} domain
240 * @return {!Array.<string>}
241 */
242 static _subdomains(domain) {
243 const result = [domain];
244 let indexOfPeriod = domain.indexOf('.');
245 while (indexOfPeriod !== -1) {
246 result.push('*' + domain.substring(indexOfPeriod));
247 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
248 }
249 return result;
250 }
251
252 /**
253 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16254 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37255 */
256 static _createRequestDomainFilter(value) {
257 /**
258 * @param {string} string
259 * @return {string}
260 */
261 function escapeForRegExp(string) {
262 return string.escapeForRegExp();
263 }
264 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58265 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37266 }
267
268 /**
269 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13270 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37271 * @return {boolean}
272 */
273 static _requestDomainFilter(regex, request) {
274 return regex.test(request.domain);
275 }
276
277 /**
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 _runningRequestFilter(request) {
282 return !request.finished;
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 _fromCacheRequestFilter(request) {
290 return request.cached();
291 }
292
293 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13294 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05295 * @return {boolean}
296 */
297 static _interceptedByServiceWorkerFilter(request) {
298 return request.fetchedViaServiceWorker;
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 _initiatedByServiceWorkerFilter(request) {
306 return request.initiatedByServiceWorker();
307 }
308
309 /**
Blink Reformat4c46d092018-04-07 15:32:37310 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13311 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37312 * @return {boolean}
313 */
314 static _requestResponseHeaderFilter(value, request) {
315 return request.responseHeaderValue(value) !== undefined;
316 }
317
318 /**
319 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13320 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37321 * @return {boolean}
322 */
323 static _requestMethodFilter(value, request) {
324 return request.requestMethod === value;
325 }
326
327 /**
328 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13329 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37330 * @return {boolean}
331 */
332 static _requestPriorityFilter(value, request) {
333 return request.priority() === value;
334 }
335
336 /**
337 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13338 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37339 * @return {boolean}
340 */
341 static _requestMimeTypeFilter(value, request) {
342 return request.mimeType === value;
343 }
344
345 /**
Paul Lewis56509652019-12-06 12:51:58346 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13347 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37348 * @return {boolean}
349 */
350 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58351 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37352 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28353 }
354 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37355 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28356 }
357 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37358 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28359 }
360 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37361 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34362 }
Blink Reformat4c46d092018-04-07 15:32:37363
364 return false;
365 }
366
367 /**
368 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13369 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37370 * @return {boolean}
371 */
372 static _requestSchemeFilter(value, request) {
373 return request.scheme === value;
374 }
375
376 /**
377 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13378 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37379 * @return {boolean}
380 */
Jan Scheffler341eea52019-12-12 09:08:41381 static _requestCookieDomainFilter(value, request) {
382 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
383 }
384
385 /**
386 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13387 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41388 * @return {boolean}
389 */
390 static _requestCookieNameFilter(value, request) {
391 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
392 }
393
394 /**
395 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13396 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41397 * @return {boolean}
398 */
399 static _requestCookieValueFilter(value, request) {
400 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
401 }
402
403 /**
404 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13405 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41406 * @return {boolean}
407 */
Blink Reformat4c46d092018-04-07 15:32:37408 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41409 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37410 }
411
412 /**
413 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13414 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37415 * @return {boolean}
416 */
417 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41418 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37419 }
420
421 /**
422 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13423 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37424 * @return {boolean}
425 */
426 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41427 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37428 }
429
430 /**
431 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13432 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37433 * @return {boolean}
434 */
435 static _requestSizeLargerThanFilter(value, request) {
436 return request.transferSize >= value;
437 }
438
439 /**
440 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13441 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37442 * @return {boolean}
443 */
444 static _statusCodeFilter(value, request) {
445 return ('' + request.statusCode) === value;
446 }
447
448 /**
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 HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58453 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37454 }
455
456 /**
Blink Reformat4c46d092018-04-07 15:32:37457 * @param {number} windowStart
458 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13459 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37460 * @return {boolean}
461 */
462 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34463 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37464 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34465 }
466 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37467 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34468 }
Blink Reformat4c46d092018-04-07 15:32:37469 return true;
470 }
471
472 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13473 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37474 */
475 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13476 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37477 }
478
479 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13480 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37481 */
482 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13483 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37484 }
485
486 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13487 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37488 */
489 static async _copyResponse(request) {
490 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08491 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34492 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08493 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34494 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08495 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34496 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13497 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37498 }
499
500 /**
501 * @param {!DataTransfer} dataTransfer
502 */
503 _handleDrop(dataTransfer) {
504 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34505 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37506 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34507 }
Blink Reformat4c46d092018-04-07 15:32:37508 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34509 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37510 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34511 }
Blink Reformat4c46d092018-04-07 15:32:37512
Joey Arhar0e1093c2019-05-21 00:34:22513 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37514 }
515
516 /**
Tim van der Lippe119690c2020-01-13 12:31:30517 * @override
Blink Reformat4c46d092018-04-07 15:32:37518 * @param {!File} file
519 */
Joey Arhar0e1093c2019-05-21 00:34:22520 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13521 const outputStream = new Common.StringOutputStream.StringOutputStream();
522 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37523 const success = await reader.read(outputStream);
524 if (!success) {
525 this._harLoadFailed(reader.error().message);
526 return;
527 }
528 let harRoot;
529 try {
530 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13531 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37532 } catch (e) {
533 this._harLoadFailed(e);
534 return;
535 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13536 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37537 }
538
539 /**
540 * @param {string} message
541 */
542 _harLoadFailed(message) {
Paul Lewis04ccecc2020-01-22 17:15:14543 self.Common.console.error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37544 }
545
546 /**
547 * @param {?string} groupKey
548 */
549 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34550 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37551 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34552 }
Blink Reformat4c46d092018-04-07 15:32:37553 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
554 this._activeGroupLookup = groupLookup;
555 this._invalidateAllItems();
556 }
557
558 /**
559 * @return {number}
560 */
561 _computeRowHeight() {
562 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
563 }
564
565 /**
Tim van der Lippe119690c2020-01-13 12:31:30566 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13567 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30568 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37569 */
570 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58571 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37572 }
573
574 /**
Tim van der Lippe119690c2020-01-13 12:31:30575 * @override
Blink Reformat4c46d092018-04-07 15:32:37576 * @return {number}
577 */
578 headerHeight() {
579 return this._headerHeight;
580 }
581
582 /**
Tim van der Lippe119690c2020-01-13 12:31:30583 * @override
Blink Reformat4c46d092018-04-07 15:32:37584 * @param {boolean} recording
585 */
586 setRecording(recording) {
587 this._recording = recording;
588 this._updateSummaryBar();
589 }
590
591 /**
592 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13593 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37594 */
595 modelAdded(networkManager) {
596 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34597 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37598 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34599 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13600 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37601 if (resourceTreeModel) {
602 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
603 resourceTreeModel.addEventListener(
604 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
605 }
606 }
607
608 /**
609 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13610 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37611 */
612 modelRemoved(networkManager) {
613 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13614 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37615 if (resourceTreeModel) {
616 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
617 resourceTreeModel.removeEventListener(
618 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
619 }
620 }
621 }
622
623 /**
Tim van der Lippe119690c2020-01-13 12:31:30624 * @override
Blink Reformat4c46d092018-04-07 15:32:37625 * @param {number} start
626 * @param {number} end
627 */
628 setWindow(start, end) {
629 if (!start && !end) {
630 this._timeFilter = null;
631 this._timeCalculator.setWindow(null);
632 } else {
Paul Lewis56509652019-12-06 12:51:58633 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30634 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37635 }
636 this._filterRequests();
637 }
638
Tim van der Lippe119690c2020-01-13 12:31:30639 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05640 resetFocus() {
641 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37642 }
643
644 _resetSuggestionBuilder() {
645 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58646 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
647 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
648 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
649 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
650 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
651 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
652 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37653 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
654 }
655
656 /**
Tim van der Lippec02a97c2020-02-14 14:39:27657 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37658 */
659 _filterChanged(event) {
660 this.removeAllNodeHighlights();
661 this._parseFilterQuery(this._textFilterUI.value());
662 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37663 }
664
Rajasekar Murugan3ad369e2020-02-19 18:20:12665 async resetFilter() {
666 this._textFilterUI.clear();
667 }
668
Blink Reformat4c46d092018-04-07 15:32:37669 _showRecordingHint() {
670 this._hideRecordingHint();
671 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
672 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18673
674 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40675 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18676 if (reloadShortcutDescriptor) {
677 reloadShortcutNode = this._recordingHint.createChild('b');
678 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
679 }
Blink Reformat4c46d092018-04-07 15:32:37680
681 if (this._recording) {
682 const recordingText = hintText.createChild('span');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13683 recordingText.textContent = Common.UIString.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18684 if (reloadShortcutNode) {
685 hintText.createChild('br');
686 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13687 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18688 }
Blink Reformat4c46d092018-04-07 15:32:37689 } else {
690 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40691 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18692 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13693 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18694 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
695 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13696 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18697 }
Blink Reformat4c46d092018-04-07 15:32:37698 }
Kayce Basques5444c1b2019-02-15 20:32:53699 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13700 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53701 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
702 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11703
704 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57705 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37706 }
707
708 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11709 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34710 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37711 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34712 }
Brandon Goddardc992d522020-01-08 21:44:57713 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37714 this._recordingHint = null;
715 }
716
717 /**
Amanda Baker6761aae2019-11-05 18:59:11718 * @param {boolean} value
719 */
720 _setHidden(value) {
721 this._columns.setHidden(value);
722 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
723 }
724
725 /**
Blink Reformat4c46d092018-04-07 15:32:37726 * @override
727 * @return {!Array.<!Element>}
728 */
729 elementsToRestoreScrollPositionsFor() {
730 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34731 {
Blink Reformat4c46d092018-04-07 15:32:37732 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34733 }
Blink Reformat4c46d092018-04-07 15:32:37734 return [this._dataGrid.scrollContainer];
735 }
736
Tim van der Lippe119690c2020-01-13 12:31:30737 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37738 columnExtensionResolved() {
739 this._invalidateAllItems(true);
740 }
741
742 _setupDataGrid() {
743 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
744 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34745 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37746 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34747 }
Blink Reformat4c46d092018-04-07 15:32:37748 });
749 this._dataGrid.setStickToBottom(true);
750 this._dataGrid.setName('networkLog');
751 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
752 this._dataGrid.element.classList.add('network-log-grid');
753 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
754 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
755 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05756 this._dataGrid.element.addEventListener('keydown', event => {
757 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58758 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05759 event.consume(true);
760 }
761 });
762 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
763 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37764 return this._dataGrid;
765 }
766
767 /**
768 * @param {!Event} event
769 */
770 _dataGridMouseMove(event) {
771 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
772 const highlightInitiatorChain = event.shiftKey;
773 this._setHoveredNode(node, highlightInitiatorChain);
774 }
775
776 /**
Tim van der Lippe119690c2020-01-13 12:31:30777 * @override
778 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37779 */
780 hoveredNode() {
781 return this._hoveredNode;
782 }
783
784 /**
Tim van der Lippe119690c2020-01-13 12:31:30785 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37786 * @param {boolean=} highlightInitiatorChain
787 */
788 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34789 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37790 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 }
Blink Reformat4c46d092018-04-07 15:32:37792 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34793 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37794 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34795 }
Blink Reformat4c46d092018-04-07 15:32:37796 }
797
798 /**
799 * @param {!Event} event
800 */
801 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34802 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37803 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34804 }
Blink Reformat4c46d092018-04-07 15:32:37805 }
806
807 _updateSummaryBar() {
808 this._hideRecordingHint();
809
810 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20811 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37812 let selectedNodeNumber = 0;
813 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20814 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37815 let baseTime = -1;
816 let maxTime = -1;
817
818 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16819 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58820 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34821 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37822 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34823 }
Blink Reformat4c46d092018-04-07 15:32:37824 nodeCount++;
825 const requestTransferSize = request.transferSize;
826 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20827 const requestResourceSize = request.resourceSize;
828 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30829 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37830 selectedNodeNumber++;
831 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20832 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37833 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13834 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37835 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
836 // inspected url.
837 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13838 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
839 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37840 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34841 }
842 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37843 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34844 }
Blink Reformat4c46d092018-04-07 15:32:37845 }
846
847 if (!nodeCount) {
848 this._showRecordingHint();
849 return;
850 }
851
Joey Arhara86c14e2019-03-12 03:20:50852 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37853 /**
854 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50855 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37856 * @return {!Element}
857 */
Joey Arhara86c14e2019-03-12 03:20:50858 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13859 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50860 toolbarText.setTitle(title ? title : chunk);
861 this._summaryToolbar.appendToolbarItem(toolbarText);
862 return toolbarText.element;
863 };
Blink Reformat4c46d092018-04-07 15:32:37864
865 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50866 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
867 this._summaryToolbar.appendSeparator();
868 appendChunk(
869 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25870 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50871 this._summaryToolbar.appendSeparator();
872 appendChunk(
873 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25874 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37875 } else {
Joey Arhara86c14e2019-03-12 03:20:50876 appendChunk(ls`${nodeCount} requests`);
877 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25878 appendChunk(
879 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50880 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25881 appendChunk(
882 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37883 }
Dan Beam87466b52018-12-01 18:41:20884
Blink Reformat4c46d092018-04-07 15:32:37885 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50886 this._summaryToolbar.appendSeparator();
887 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37888 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50889 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30890 const domContentLoadedText =
891 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58892 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37893 }
894 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50895 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30896 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58897 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37898 }
899 }
Blink Reformat4c46d092018-04-07 15:32:37900 }
901
Tim van der Lippe119690c2020-01-13 12:31:30902 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37903 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34904 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37905 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34906 }
Blink Reformat4c46d092018-04-07 15:32:37907
908 this._needsRefresh = true;
909
Tim van der Lippe1d6e57a2019-09-30 11:55:34910 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37911 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34912 }
Blink Reformat4c46d092018-04-07 15:32:37913 }
914
915 /**
Tim van der Lippe119690c2020-01-13 12:31:30916 * @override
Blink Reformat4c46d092018-04-07 15:32:37917 * @param {!Array<number>} times
918 */
919 addFilmStripFrames(times) {
920 this._columns.addEventDividers(times, 'network-frame-divider');
921 }
922
923 /**
Tim van der Lippe119690c2020-01-13 12:31:30924 * @override
Blink Reformat4c46d092018-04-07 15:32:37925 * @param {number} time
926 */
927 selectFilmStripFrame(time) {
928 this._columns.selectFilmStripFrame(time);
929 }
930
Tim van der Lippe119690c2020-01-13 12:31:30931 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37932 clearFilmStripFrame() {
933 this._columns.clearFilmStripFrame();
934 }
935
936 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34937 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37938 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34939 }
Blink Reformat4c46d092018-04-07 15:32:37940 }
941
942 /**
943 * @param {boolean=} deferUpdate
944 */
945 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16946 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34947 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37948 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34949 } else {
Blink Reformat4c46d092018-04-07 15:32:37950 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34951 }
Blink Reformat4c46d092018-04-07 15:32:37952 }
953
954 /**
Tim van der Lippe119690c2020-01-13 12:31:30955 * @override
956 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37957 */
958 timeCalculator() {
959 return this._timeCalculator;
960 }
961
962 /**
Tim van der Lippe119690c2020-01-13 12:31:30963 * @override
964 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37965 */
966 calculator() {
967 return this._calculator;
968 }
969
970 /**
Tim van der Lippe119690c2020-01-13 12:31:30971 * @override
972 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37973 */
974 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34975 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37976 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34977 }
Blink Reformat4c46d092018-04-07 15:32:37978
979 if (this._calculator !== x) {
980 this._calculator = x;
981 this._columns.setCalculator(this._calculator);
982 }
983 this._calculator.reset();
984
Tim van der Lippe1d6e57a2019-09-30 11:55:34985 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37986 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34987 } else {
Blink Reformat4c46d092018-04-07 15:32:37988 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34989 }
Blink Reformat4c46d092018-04-07 15:32:37990
991 this._invalidateAllItems();
992 }
993
994 /**
Tim van der Lippec02a97c2020-02-14 14:39:27995 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37996 */
997 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34998 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37999 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341000 }
Blink Reformat4c46d092018-04-07 15:32:371001
1002 const time = /** @type {number} */ (event.data.loadTime);
1003 if (time) {
1004 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301005 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371006 }
1007 }
1008
1009 /**
Tim van der Lippec02a97c2020-02-14 14:39:271010 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371011 */
1012 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341013 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371014 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341015 }
Blink Reformat4c46d092018-04-07 15:32:371016 const data = /** @type {number} */ (event.data);
1017 if (data) {
1018 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301019 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371020 }
1021 }
1022
1023 /**
1024 * @override
1025 */
1026 wasShown() {
1027 this._refreshIfNeeded();
1028 this._columns.wasShown();
1029 }
1030
1031 /**
1032 * @override
1033 */
1034 willHide() {
1035 this._columns.willHide();
1036 }
1037
1038 /**
1039 * @override
1040 */
1041 onResize() {
1042 this._rowHeight = this._computeRowHeight();
1043 }
1044
1045 /**
Tim van der Lippe119690c2020-01-13 12:31:301046 * @override
1047 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371048 */
1049 flatNodesList() {
1050 return this._dataGrid.rootNode().flatChildren();
1051 }
1052
Tim van der Lippe119690c2020-01-13 12:31:301053 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051054 updateNodeBackground() {
1055 if (this._dataGrid.selectedNode) {
1056 this._dataGrid.selectedNode.updateBackgroundColor();
1057 }
1058 }
1059
1060 /**
Tim van der Lippe119690c2020-01-13 12:31:301061 * @override
Brandon Goddard88d885a2019-10-31 16:11:051062 * @param {boolean} isSelected
1063 */
1064 updateNodeSelectedClass(isSelected) {
1065 if (isSelected) {
1066 this.element.classList.remove('no-node-selected');
1067 } else {
1068 this.element.classList.add('no-node-selected');
1069 }
1070 }
1071
Tim van der Lippe119690c2020-01-13 12:31:301072 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371073 stylesChanged() {
1074 this._columns.scheduleRefresh();
1075 }
1076
1077 _refresh() {
1078 this._needsRefresh = false;
1079
1080 if (this._refreshRequestId) {
1081 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1082 this._refreshRequestId = null;
1083 }
1084
1085 this.removeAllNodeHighlights();
1086
1087 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1088 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1089 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1090 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1091
Tim van der Lippe119690c2020-01-13 12:31:301092 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371093 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301094 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371095 const nodesToRefresh = [];
1096
Tim van der Lippe119690c2020-01-13 12:31:301097 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371098 const staleNodes = new Set();
1099
1100 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1101 // node so we loop until we have no more stale requests.
1102 while (this._staleRequests.size) {
1103 const request = this._staleRequests.firstValue();
1104 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581105 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341106 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371107 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341108 }
Blink Reformat4c46d092018-04-07 15:32:371109 staleNodes.add(node);
1110 }
1111
1112 for (const node of staleNodes) {
1113 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341114 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371115 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341116 }
Blink Reformat4c46d092018-04-07 15:32:371117
Tim van der Lippe1d6e57a2019-09-30 11:55:341118 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371119 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341120 }
Blink Reformat4c46d092018-04-07 15:32:371121 const request = node.request();
1122 this._timeCalculator.updateBoundaries(request);
1123 this._durationCalculator.updateBoundaries(request);
1124 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301125 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371126 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341127 }
Tim van der Lippe119690c2020-01-13 12:31:301128 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371129 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1130 if (removeFromParent) {
1131 let parent = node.parent;
1132 parent.removeChild(node);
1133 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1134 const grandparent = parent.parent;
1135 grandparent.removeChild(parent);
1136 parent = grandparent;
1137 }
1138 }
1139
Tim van der Lippe1d6e57a2019-09-30 11:55:341140 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371141 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341142 }
Blink Reformat4c46d092018-04-07 15:32:371143
1144 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1145 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1146 nodesToRefresh.push(newParent);
1147 }
1148 nodesToInsert.set(node, newParent);
1149 }
1150
Tim van der Lippe1d6e57a2019-09-30 11:55:341151 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371152 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341153 }
Blink Reformat4c46d092018-04-07 15:32:371154
Tim van der Lippe1d6e57a2019-09-30 11:55:341155 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371156 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341157 }
Blink Reformat4c46d092018-04-07 15:32:371158
1159 this._updateSummaryBar();
1160
Tim van der Lippe1d6e57a2019-09-30 11:55:341161 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371162 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341163 }
Blink Reformat4c46d092018-04-07 15:32:371164
1165 this._dataGrid.updateInstantly();
1166 this._didRefreshForTest();
1167 }
1168
1169 _didRefreshForTest() {
1170 }
1171
1172 /**
Tim van der Lippe119690c2020-01-13 12:31:301173 * @param {!NetworkRequestNode} node
1174 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371175 */
1176 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341177 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371178 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341179 }
Blink Reformat4c46d092018-04-07 15:32:371180
1181 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341182 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371183 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341184 }
Blink Reformat4c46d092018-04-07 15:32:371185 return groupNode;
1186 }
1187
1188 _reset() {
Paul Lewis56509652019-12-06 12:51:581189 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371190
1191 this._setHoveredNode(null);
1192 this._columns.reset();
1193
1194 this._timeFilter = null;
1195 this._calculator.reset();
1196
1197 this._timeCalculator.setWindow(null);
1198 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371199
Tim van der Lippe1d6e57a2019-09-30 11:55:341200 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371201 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341202 }
Blink Reformat4c46d092018-04-07 15:32:371203 this._staleRequests.clear();
1204 this._resetSuggestionBuilder();
1205
1206 this._mainRequestLoadTime = -1;
1207 this._mainRequestDOMContentLoadedTime = -1;
1208
1209 this._dataGrid.rootNode().removeChildren();
1210 this._updateSummaryBar();
1211 this._dataGrid.setStickToBottom(true);
1212 this.scheduleRefresh();
1213 }
1214
1215 /**
Tim van der Lippe119690c2020-01-13 12:31:301216 * @override
Blink Reformat4c46d092018-04-07 15:32:371217 * @param {string} filterString
1218 */
1219 setTextFilterValue(filterString) {
1220 this._textFilterUI.setValue(filterString);
1221 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371222 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371223 this._resourceCategoryFilterUI.reset();
1224 }
1225
1226 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131227 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371228 */
1229 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301230 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581231 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301232 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371233
Tim van der Lippe1d6e57a2019-09-30 11:55:341234 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371235 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341236 }
Blink Reformat4c46d092018-04-07 15:32:371237 return node;
1238 }
1239
1240 /**
Tim van der Lippec02a97c2020-02-14 14:39:271241 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371242 */
1243 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131244 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371245 this._refreshRequest(request);
1246 }
1247
1248 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131249 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371250 */
1251 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581252 NetworkLogView._subdomains(request.domain)
1253 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1254 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1255 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1256 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1257 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371258
1259 const priority = request.priority();
1260 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501261 this._suggestionBuilder.addItem(
1262 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371263 }
1264
1265 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581266 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371267 }
1268
1269 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581270 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371271 }
1272
1273 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581274 const suggestion =
1275 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1276 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371277 }
1278
1279 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341280 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581281 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341282 }
Jan Scheffler341eea52019-12-12 09:08:411283
1284 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581285 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1286 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1287 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371288 }
1289
Jan Scheffler341eea52019-12-12 09:08:411290 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1291 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1292 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1293 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1294 }
1295
Blink Reformat4c46d092018-04-07 15:32:371296 this._staleRequests.add(request);
1297 this.scheduleRefresh();
1298 }
1299
1300 /**
Tim van der Lippe119690c2020-01-13 12:31:301301 * @override
Blink Reformat4c46d092018-04-07 15:32:371302 * @return {number}
1303 */
1304 rowHeight() {
1305 return this._rowHeight;
1306 }
1307
1308 /**
Tim van der Lippe119690c2020-01-13 12:31:301309 * @override
Blink Reformat4c46d092018-04-07 15:32:371310 * @param {boolean} gridMode
1311 */
1312 switchViewMode(gridMode) {
1313 this._columns.switchViewMode(gridMode);
1314 }
1315
1316 /**
Tim van der Lippe119690c2020-01-13 12:31:301317 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131318 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1319 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371320 */
1321 handleContextMenuForRequest(contextMenu, request) {
1322 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131323 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371324 const footerSection = copyMenu.footerSection();
1325 if (request) {
1326 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131327 UI.UIUtils.copyLinkAddressLabel(),
1328 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1329 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371330 if (request.requestHeadersText()) {
1331 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131332 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371333 }
1334
1335 if (request.responseHeadersText) {
1336 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131337 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371338 }
1339
1340 if (request.finished) {
1341 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131342 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371343 }
1344
Harley Libcf41f92018-09-10 18:01:131345 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131346 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371347 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131348 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1349 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371350 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131351 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291352 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131353 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1354 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371355 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131356 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1357 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131358 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131359 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1360 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371361 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131362 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1363 footerSection.appendItem(
1364 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1365 footerSection.appendItem(
1366 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1367 footerSection.appendItem(
1368 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1369 footerSection.appendItem(
1370 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371371 } else {
Harley Libcf41f92018-09-10 18:01:131372 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131373 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291374 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131375 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1376 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131377 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131378 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1379 footerSection.appendItem(
1380 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1381 footerSection.appendItem(
1382 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1383 footerSection.appendItem(
1384 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371385 }
1386 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131387 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371388 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131389 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371390
Joey Arhar0e1093c2019-05-21 00:34:221391 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371392
Blink Reformat4c46d092018-04-07 15:32:371393 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131394 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1395 contextMenu.editSection().appendItem(
1396 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371397
1398 if (request) {
1399 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081400 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371401 let patterns = manager.blockedPatterns();
1402
Tim van der Lippeffa78622019-09-16 12:07:121403 /**
1404 * @param {string} url
1405 */
1406 function addBlockedURL(url) {
1407 patterns.push({enabled: true, url: url});
1408 manager.setBlockedPatterns(patterns);
1409 manager.setBlockingEnabled(true);
Paul Lewis50993692020-01-23 15:22:261410 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121411 }
1412
1413 /**
1414 * @param {string} url
1415 */
1416 function removeBlockedURL(url) {
1417 patterns = patterns.filter(pattern => pattern.url !== url);
1418 manager.setBlockedPatterns(patterns);
Paul Lewis50993692020-01-23 15:22:261419 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121420 }
1421
Blink Reformat4c46d092018-04-07 15:32:371422 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1423 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1424 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131425 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371426 } else if (urlWithoutScheme) {
1427 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1428 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131429 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371430 }
1431
1432 const domain = request.parsedURL.domain();
1433 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1434 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371436 } else if (domain) {
1437 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1438 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131439 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371440 }
1441
Tim van der Lippe0ed1d2b2020-02-04 13:45:131442 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371443 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131444 Common.UIString.UIString('Replay XHR'),
1445 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371446 }
Blink Reformat4c46d092018-04-07 15:32:371447 }
1448 }
1449
1450 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161451 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171452 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131453 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171454 });
Blink Reformat4c46d092018-04-07 15:32:371455 }
1456
1457 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131458 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1459 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371460 }
1461
1462 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131463 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371464 * @param {string} platform
1465 */
1466 async _copyCurlCommand(request, platform) {
1467 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131468 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371469 }
1470
1471 /**
1472 * @param {string} platform
1473 */
1474 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161475 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371477 }
1478
1479 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131480 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291481 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371482 */
Jan Scheffler7c50d1f2019-12-17 13:33:291483 async _copyFetchCall(request, includeCookies) {
1484 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131485 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371486 }
1487
Jan Scheffler7c50d1f2019-12-17 13:33:291488 /**
1489 * @param {boolean} includeCookies
1490 */
1491 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161492 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131493 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371494 }
1495
1496 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131497 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371498 */
1499 async _copyPowerShellCommand(request) {
1500 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131501 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371502 }
1503
1504 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161505 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131506 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371507 }
1508
Tim van der Lippe119690c2020-01-13 12:31:301509 /**
1510 * @override
1511 * @return {!Promise}
1512 */
Joey Arhar0e1093c2019-05-21 00:34:221513 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331514 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131515 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371516 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131517 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371518
Tim van der Lippe1d6e57a2019-09-30 11:55:341519 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371520 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341521 }
Blink Reformat4c46d092018-04-07 15:32:371522
Tim van der Lippe0ed1d2b2020-02-04 13:45:131523 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371524 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301525 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371526 progressIndicator.done();
1527 stream.close();
1528 }
1529
1530 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131531 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081532 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341533 }
Blink Reformat4c46d092018-04-07 15:32:371534 }
1535
1536 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131537 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081538 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341539 }
Blink Reformat4c46d092018-04-07 15:32:371540 }
1541
1542 _removeAllHighlights() {
1543 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341544 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131545 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341546 }
Blink Reformat4c46d092018-04-07 15:32:371547 this._highlightedSubstringChanges = [];
1548 }
1549
1550 /**
Tim van der Lippe119690c2020-01-13 12:31:301551 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371552 * @return {boolean}
1553 */
1554 _applyFilter(node) {
1555 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341556 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371557 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341558 }
Blink Reformat4c46d092018-04-07 15:32:371559 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341560 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371561 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341562 }
1563 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371564 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341565 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131566 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.IssuesModel.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371567 return false;
1568 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341569 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371570 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341571 }
Blink Reformat4c46d092018-04-07 15:32:371572 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341573 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371574 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341575 }
Blink Reformat4c46d092018-04-07 15:32:371576 }
1577 return true;
1578 }
1579
1580 /**
1581 * @param {string} query
1582 */
1583 _parseFilterQuery(query) {
1584 const descriptors = this._filterParser.parse(query);
1585 this._filters = descriptors.map(descriptor => {
1586 const key = descriptor.key;
1587 const text = descriptor.text || '';
1588 const regex = descriptor.regex;
1589 let filter;
1590 if (key) {
1591 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581592 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1593 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371594 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581595 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371596 } else {
Paul Lewis56509652019-12-06 12:51:581597 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371598 }
Paul Lewis56509652019-12-06 12:51:581599 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371600 });
1601 }
1602
1603 /**
Paul Lewis56509652019-12-06 12:51:581604 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371605 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161606 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371607 */
1608 _createSpecialFilter(type, value) {
1609 switch (type) {
Paul Lewis56509652019-12-06 12:51:581610 case FilterType.Domain:
1611 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371612
Paul Lewis56509652019-12-06 12:51:581613 case FilterType.HasResponseHeader:
1614 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371615
Paul Lewis56509652019-12-06 12:51:581616 case FilterType.Is:
1617 if (value.toLowerCase() === IsFilterType.Running) {
1618 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341619 }
Paul Lewis56509652019-12-06 12:51:581620 if (value.toLowerCase() === IsFilterType.FromCache) {
1621 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341622 }
Paul Lewis56509652019-12-06 12:51:581623 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1624 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341625 }
Paul Lewis56509652019-12-06 12:51:581626 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1627 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341628 }
Blink Reformat4c46d092018-04-07 15:32:371629 break;
1630
Paul Lewis56509652019-12-06 12:51:581631 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371632 return this._createSizeFilter(value.toLowerCase());
1633
Paul Lewis56509652019-12-06 12:51:581634 case FilterType.Method:
1635 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371636
Paul Lewis56509652019-12-06 12:51:581637 case FilterType.MimeType:
1638 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371639
Paul Lewis56509652019-12-06 12:51:581640 case FilterType.MixedContent:
1641 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371642
Paul Lewis56509652019-12-06 12:51:581643 case FilterType.Scheme:
1644 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371645
Paul Lewis56509652019-12-06 12:51:581646 case FilterType.SetCookieDomain:
1647 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371648
Paul Lewis56509652019-12-06 12:51:581649 case FilterType.SetCookieName:
1650 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371651
Paul Lewis56509652019-12-06 12:51:581652 case FilterType.SetCookieValue:
1653 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371654
Jan Scheffler341eea52019-12-12 09:08:411655 case FilterType.CookieDomain:
1656 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1657
1658 case FilterType.CookieName:
1659 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1660
1661 case FilterType.CookieValue:
1662 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1663
Paul Lewis56509652019-12-06 12:51:581664 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501665 return NetworkLogView._requestPriorityFilter.bind(
1666 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371667
Paul Lewis56509652019-12-06 12:51:581668 case FilterType.StatusCode:
1669 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371670 }
1671 return null;
1672 }
1673
1674 /**
1675 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161676 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371677 */
1678 _createSizeFilter(value) {
1679 let multiplier = 1;
1680 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411681 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371682 value = value.substring(0, value.length - 1);
1683 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411684 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371685 value = value.substring(0, value.length - 1);
1686 }
1687 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341688 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371689 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341690 }
Paul Lewis56509652019-12-06 12:51:581691 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371692 }
1693
1694 _filterRequests() {
1695 this._removeAllHighlights();
1696 this._invalidateAllItems();
1697 }
1698
1699 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131700 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301701 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371702 */
1703 _reveal(request) {
1704 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581705 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341706 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371707 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341708 }
Blink Reformat4c46d092018-04-07 15:32:371709 node.reveal();
1710 return node;
1711 }
1712
1713 /**
Tim van der Lippe119690c2020-01-13 12:31:301714 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131715 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371716 */
1717 revealAndHighlightRequest(request) {
1718 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341719 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371720 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341721 }
Blink Reformat4c46d092018-04-07 15:32:371722 }
1723
1724 /**
Tim van der Lippe119690c2020-01-13 12:31:301725 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131726 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371727 */
1728 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141729 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371730 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341731 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371732 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341733 }
Blink Reformat4c46d092018-04-07 15:32:371734 }
1735
Tim van der Lippe119690c2020-01-13 12:31:301736 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371737 removeAllNodeHighlights() {
1738 if (this._highlightedNode) {
1739 this._highlightedNode.element().classList.remove('highlighted-row');
1740 this._highlightedNode = null;
1741 }
1742 }
1743
1744 /**
Tim van der Lippe119690c2020-01-13 12:31:301745 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371746 */
1747 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131748 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371749 this._highlightedNode = node;
1750 }
1751
1752 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131753 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1754 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131755 */
1756 _filterOutBlobRequests(requests) {
1757 return requests.filter(request => !request.isBlobRequest());
1758 }
1759
1760 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131761 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291762 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371763 * @return {!Promise<string>}
1764 */
Jan Scheffler7c50d1f2019-12-17 13:33:291765 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371766 const ignoredHeaders = {
1767 // Internal headers
1768 'method': 1,
1769 'path': 1,
1770 'scheme': 1,
1771 'version': 1,
1772
1773 // Unsafe headers
1774 // Keep this list synchronized with src/net/http/http_util.cc
1775 'accept-charset': 1,
1776 'accept-encoding': 1,
1777 'access-control-request-headers': 1,
1778 'access-control-request-method': 1,
1779 'connection': 1,
1780 'content-length': 1,
1781 'cookie': 1,
1782 'cookie2': 1,
1783 'date': 1,
1784 'dnt': 1,
1785 'expect': 1,
1786 'host': 1,
1787 'keep-alive': 1,
1788 'origin': 1,
1789 'referer': 1,
1790 'te': 1,
1791 'trailer': 1,
1792 'transfer-encoding': 1,
1793 'upgrade': 1,
1794 'via': 1,
1795 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1796 'user-agent': 1
1797 };
1798
1799 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1800
1801 const url = JSON.stringify(request.url());
1802
1803 const requestHeaders = request.requestHeaders();
1804 const headerData = requestHeaders.reduce((result, header) => {
1805 const name = header.name;
1806
Tim van der Lippe1d6e57a2019-09-30 11:55:341807 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371808 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341809 }
Blink Reformat4c46d092018-04-07 15:32:371810
1811 return result;
1812 }, new Headers());
1813
1814 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341815 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411816 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341817 }
Blink Reformat4c46d092018-04-07 15:32:371818
1819 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411820 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1821 'include' :
1822 'omit';
Blink Reformat4c46d092018-04-07 15:32:371823
1824 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1825
1826 const referrer = referrerHeader ? referrerHeader.value : void 0;
1827
1828 const referrerPolicy = request.referrerPolicy() || void 0;
1829
1830 const requestBody = await request.requestFormData();
1831
1832 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411833 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371834 referrer,
1835 referrerPolicy,
1836 body: requestBody,
1837 method: request.requestMethod,
1838 mode: 'cors'
1839 };
1840
Jan Scheffler7c50d1f2019-12-17 13:33:291841 if (includeCookies) {
1842 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1843 if (cookieHeader) {
1844 fetchOptions.headers = {
1845 ...headers,
1846 'cookie': cookieHeader.value,
1847 };
1848 }
1849 } else {
1850 fetchOptions.credentials = credentials;
1851 }
1852
Jan Scheffler172d5212020-01-02 14:42:561853 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371854 return `fetch(${url}, ${options});`;
1855 }
1856
1857 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131858 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291859 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131860 * @return {!Promise<string>}
1861 */
Jan Scheffler7c50d1f2019-12-17 13:33:291862 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131863 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291864 const commands =
1865 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131866 return commands.join(' ;\n');
1867 }
1868
1869 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131870 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371871 * @param {string} platform
1872 * @return {!Promise<string>}
1873 */
1874 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561875 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361876 // Most of these headers are derived from the URL and are automatically added by cURL.
1877 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1878 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371879
1880 function escapeStringWin(str) {
1881 /* If there are no new line characters do not escape the " characters
1882 since it only uglifies the command.
1883
1884 Because cmd.exe parser and MS Crt arguments parsers use some of the
1885 same escape characters, they can interact with each other in
1886 horrible ways, the order of operations is critical.
1887
1888 Replace \ with \\ first because it is an escape character for certain
1889 conditions in both parsers.
1890
1891 Replace all " with \" to ensure the first parser does not remove it.
1892
1893 Then escape all characters we are not sure about with ^ to ensure it
1894 gets to MS Crt parser safely.
1895
1896 The % character is special because MS Crt parser will try and look for
1897 ENV variables and fill them in it's place. We cannot escape them with %
1898 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1899 parser); So we can get cmd.exe parser to escape the character after it,
1900 if it is followed by a valid beginning character of an ENV variable.
1901 This ensures we do not try and double escape another ^ if it was placed
1902 by the previous replace.
1903
1904 Lastly we replace new lines with ^ and TWO new lines because the first
1905 new line is there to enact the escape command the second is the character
1906 to escape (in this case new line).
1907 */
1908 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1909 return encapsChars +
1910 str.replace(/\\/g, '\\\\')
1911 .replace(/"/g, '\\"')
1912 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1913 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1914 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1915 encapsChars;
1916 }
1917
1918 /**
1919 * @param {string} str
1920 * @return {string}
1921 */
1922 function escapeStringPosix(str) {
1923 /**
1924 * @param {string} x
1925 * @return {string}
1926 */
1927 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221928 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121929 let hexString = code.toString(16);
1930 // Zero pad to four digits to comply with ANSI-C Quoting:
1931 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341932 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121933 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341934 }
Joey Arhar2d21f712019-05-20 21:07:121935
1936 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371937 }
1938
Mathias Bynensf06e8c02020-02-28 13:58:281939 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371940 // Use ANSI-C quoting syntax.
1941 return '$\'' +
1942 str.replace(/\\/g, '\\\\')
1943 .replace(/\'/g, '\\\'')
1944 .replace(/\n/g, '\\n')
1945 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:281946 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371947 '\'';
Blink Reformat4c46d092018-04-07 15:32:371948 }
Mathias Bynensf06e8c02020-02-28 13:58:281949 // Use single quote syntax.
1950 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:371951 }
1952
1953 // cURL command expected to run on the same platform that DevTools run
1954 // (it may be different from the inspected page platform).
1955 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1956
1957 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1958
1959 let inferredMethod = 'GET';
1960 const data = [];
1961 const requestContentType = request.requestContentType();
1962 const formData = await request.requestFormData();
1963 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:271964 // Note that formData is not necessarily urlencoded because it might for example
1965 // come from a fetch request made with an explicitly unencoded body.
1966 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371967 ignoredHeaders['content-length'] = true;
1968 inferredMethod = 'POST';
1969 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561970 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371971 ignoredHeaders['content-length'] = true;
1972 inferredMethod = 'POST';
1973 }
1974
1975 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291976 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371977 }
1978
1979 const requestHeaders = request.requestHeaders();
1980 for (let i = 0; i < requestHeaders.length; i++) {
1981 const header = requestHeaders[i];
1982 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341983 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371984 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341985 }
Jan Scheffler172d5212020-01-02 14:42:561986 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371987 }
1988 command = command.concat(data);
1989 command.push('--compressed');
1990
Tim van der Lippe1d6e57a2019-09-30 11:55:341991 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371992 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 }
Jan Scheffler172d5212020-01-02 14:42:561994 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:371995 }
1996
1997 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131998 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:131999 * @param {string} platform
2000 * @return {!Promise<string>}
2001 */
2002 async _generateAllCurlCommand(requests, platform) {
2003 const nonBlobRequests = this._filterOutBlobRequests(requests);
2004 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342005 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132006 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342007 }
Mathias Bynensf06e8c02020-02-28 13:58:282008 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132009 }
2010
2011 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132012 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372013 * @return {!Promise<string>}
2014 */
2015 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562016 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372017 const ignoredHeaders =
2018 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2019
2020 /**
2021 * @param {string} str
2022 * @return {string}
2023 */
2024 function escapeString(str) {
2025 return '"' +
2026 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2027 }
2028
Jan Scheffler172d5212020-01-02 14:42:562029 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372030
2031 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562032 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372033 }
2034
2035 const requestHeaders = request.requestHeaders();
2036 const headerNameValuePairs = [];
2037 for (const header of requestHeaders) {
2038 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342039 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372040 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342041 }
Blink Reformat4c46d092018-04-07 15:32:372042 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2043 }
2044 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562045 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372046 }
2047
2048 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2049 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562050 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372051 }
2052
2053 const formData = await request.requestFormData();
2054 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372055 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342056 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562057 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342058 } else {
Jan Scheffler172d5212020-01-02 14:42:562059 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342060 }
Blink Reformat4c46d092018-04-07 15:32:372061 }
2062
Jan Scheffler172d5212020-01-02 14:42:562063 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372064 }
Harley Libcf41f92018-09-10 18:01:132065
2066 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132067 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132068 * @return {!Promise<string>}
2069 */
2070 async _generateAllPowerShellCommand(requests) {
2071 const nonBlobRequests = this._filterOutBlobRequests(requests);
2072 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2073 return commands.join(';\r\n');
2074 }
Joey Arhara86c14e2019-03-12 03:20:502075
2076 /**
2077 * @return {string}
2078 */
2079 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552080 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502081 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342082 }
Joey Arhara86c14e2019-03-12 03:20:502083 return '#0867CB';
2084 }
2085
2086 /**
2087 * @return {string}
2088 */
2089 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132090 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502091 }
Paul Lewis56509652019-12-06 12:51:582092}
Blink Reformat4c46d092018-04-07 15:32:372093
Tim van der Lippe119690c2020-01-13 12:31:302094export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582095export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372096
Paul Lewis56509652019-12-06 12:51:582097export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372098 'http': true,
2099 'https': true,
2100 'ws': true,
2101 'wss': true
2102};
2103
Blink Reformat4c46d092018-04-07 15:32:372104/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582105export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372106 Domain: 'domain',
2107 HasResponseHeader: 'has-response-header',
2108 Is: 'is',
2109 LargerThan: 'larger-than',
2110 Method: 'method',
2111 MimeType: 'mime-type',
2112 MixedContent: 'mixed-content',
2113 Priority: 'priority',
2114 Scheme: 'scheme',
2115 SetCookieDomain: 'set-cookie-domain',
2116 SetCookieName: 'set-cookie-name',
2117 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412118 CookieDomain: 'cookie-domain',
2119 CookieName: 'cookie-name',
2120 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372121 StatusCode: 'status-code'
2122};
2123
2124/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582125export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372126 All: 'all',
2127 Displayed: 'displayed',
2128 Blocked: 'blocked',
2129 BlockOverridden: 'block-overridden'
2130};
2131
2132/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582133export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372134 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052135 FromCache: 'from-cache',
2136 ServiceWorkerIntercepted: 'service-worker-intercepted',
2137 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372138};
2139
2140/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582141export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372142
2143/**
2144 * @interface
2145 */
Paul Lewis56509652019-12-06 12:51:582146export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372147 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132148 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302149 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372150 */
Paul Lewis56509652019-12-06 12:51:582151 groupNodeForRequest(request) {
2152 }
Blink Reformat4c46d092018-04-07 15:32:372153
Paul Lewis56509652019-12-06 12:51:582154 reset() {
2155 }
2156}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162157
2158/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2159export let Filter;