blob: 24c72411c138f57ad78b864c511914228d0500cb [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;
Paul Lewis56509652019-12-06 12:51:58353 } else if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37354 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58355 } else if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37356 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58357 } else if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37358 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34359 }
Blink Reformat4c46d092018-04-07 15:32:37360
361 return false;
362 }
363
364 /**
365 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13366 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37367 * @return {boolean}
368 */
369 static _requestSchemeFilter(value, request) {
370 return request.scheme === value;
371 }
372
373 /**
374 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13375 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37376 * @return {boolean}
377 */
Jan Scheffler341eea52019-12-12 09:08:41378 static _requestCookieDomainFilter(value, request) {
379 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
380 }
381
382 /**
383 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13384 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41385 * @return {boolean}
386 */
387 static _requestCookieNameFilter(value, request) {
388 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
389 }
390
391 /**
392 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13393 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41394 * @return {boolean}
395 */
396 static _requestCookieValueFilter(value, request) {
397 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
398 }
399
400 /**
401 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13402 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41403 * @return {boolean}
404 */
Blink Reformat4c46d092018-04-07 15:32:37405 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41406 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37407 }
408
409 /**
410 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13411 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37412 * @return {boolean}
413 */
414 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41415 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37416 }
417
418 /**
419 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13420 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37421 * @return {boolean}
422 */
423 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41424 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37425 }
426
427 /**
428 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13429 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37430 * @return {boolean}
431 */
432 static _requestSizeLargerThanFilter(value, request) {
433 return request.transferSize >= value;
434 }
435
436 /**
437 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13438 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37439 * @return {boolean}
440 */
441 static _statusCodeFilter(value, request) {
442 return ('' + request.statusCode) === value;
443 }
444
445 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13446 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37447 * @return {boolean}
448 */
449 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58450 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37451 }
452
453 /**
Blink Reformat4c46d092018-04-07 15:32:37454 * @param {number} windowStart
455 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13456 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37457 * @return {boolean}
458 */
459 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34460 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37461 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34462 }
463 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37464 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34465 }
Blink Reformat4c46d092018-04-07 15:32:37466 return true;
467 }
468
469 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13470 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37471 */
472 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13473 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37474 }
475
476 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13477 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37478 */
479 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13480 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37481 }
482
483 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13484 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37485 */
486 static async _copyResponse(request) {
487 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08488 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34489 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08490 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34491 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08492 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34493 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13494 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37495 }
496
497 /**
498 * @param {!DataTransfer} dataTransfer
499 */
500 _handleDrop(dataTransfer) {
501 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34502 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37503 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34504 }
Blink Reformat4c46d092018-04-07 15:32:37505 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34506 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37507 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34508 }
Blink Reformat4c46d092018-04-07 15:32:37509
Joey Arhar0e1093c2019-05-21 00:34:22510 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37511 }
512
513 /**
Tim van der Lippe119690c2020-01-13 12:31:30514 * @override
Blink Reformat4c46d092018-04-07 15:32:37515 * @param {!File} file
516 */
Joey Arhar0e1093c2019-05-21 00:34:22517 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13518 const outputStream = new Common.StringOutputStream.StringOutputStream();
519 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37520 const success = await reader.read(outputStream);
521 if (!success) {
522 this._harLoadFailed(reader.error().message);
523 return;
524 }
525 let harRoot;
526 try {
527 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13528 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37529 } catch (e) {
530 this._harLoadFailed(e);
531 return;
532 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13533 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37534 }
535
536 /**
537 * @param {string} message
538 */
539 _harLoadFailed(message) {
Paul Lewis04ccecc2020-01-22 17:15:14540 self.Common.console.error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37541 }
542
543 /**
544 * @param {?string} groupKey
545 */
546 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34547 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37548 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34549 }
Blink Reformat4c46d092018-04-07 15:32:37550 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
551 this._activeGroupLookup = groupLookup;
552 this._invalidateAllItems();
553 }
554
555 /**
556 * @return {number}
557 */
558 _computeRowHeight() {
559 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
560 }
561
562 /**
Tim van der Lippe119690c2020-01-13 12:31:30563 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13564 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30565 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37566 */
567 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58568 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37569 }
570
571 /**
Tim van der Lippe119690c2020-01-13 12:31:30572 * @override
Blink Reformat4c46d092018-04-07 15:32:37573 * @return {number}
574 */
575 headerHeight() {
576 return this._headerHeight;
577 }
578
579 /**
Tim van der Lippe119690c2020-01-13 12:31:30580 * @override
Blink Reformat4c46d092018-04-07 15:32:37581 * @param {boolean} recording
582 */
583 setRecording(recording) {
584 this._recording = recording;
585 this._updateSummaryBar();
586 }
587
588 /**
589 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13590 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37591 */
592 modelAdded(networkManager) {
593 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34594 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37595 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34596 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13597 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37598 if (resourceTreeModel) {
599 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
600 resourceTreeModel.addEventListener(
601 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
602 }
603 }
604
605 /**
606 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13607 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37608 */
609 modelRemoved(networkManager) {
610 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13611 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37612 if (resourceTreeModel) {
613 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
614 resourceTreeModel.removeEventListener(
615 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
616 }
617 }
618 }
619
620 /**
Tim van der Lippe119690c2020-01-13 12:31:30621 * @override
Blink Reformat4c46d092018-04-07 15:32:37622 * @param {number} start
623 * @param {number} end
624 */
625 setWindow(start, end) {
626 if (!start && !end) {
627 this._timeFilter = null;
628 this._timeCalculator.setWindow(null);
629 } else {
Paul Lewis56509652019-12-06 12:51:58630 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30631 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37632 }
633 this._filterRequests();
634 }
635
Tim van der Lippe119690c2020-01-13 12:31:30636 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05637 resetFocus() {
638 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37639 }
640
641 _resetSuggestionBuilder() {
642 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58643 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
644 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
645 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
646 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
647 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
648 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
649 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37650 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
651 }
652
653 /**
Tim van der Lippec02a97c2020-02-14 14:39:27654 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37655 */
656 _filterChanged(event) {
657 this.removeAllNodeHighlights();
658 this._parseFilterQuery(this._textFilterUI.value());
659 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37660 }
661
Rajasekar Murugan3ad369e2020-02-19 18:20:12662 async resetFilter() {
663 this._textFilterUI.clear();
664 }
665
Blink Reformat4c46d092018-04-07 15:32:37666 _showRecordingHint() {
667 this._hideRecordingHint();
668 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
669 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18670
671 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40672 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18673 if (reloadShortcutDescriptor) {
674 reloadShortcutNode = this._recordingHint.createChild('b');
675 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
676 }
Blink Reformat4c46d092018-04-07 15:32:37677
678 if (this._recording) {
679 const recordingText = hintText.createChild('span');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13680 recordingText.textContent = Common.UIString.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18681 if (reloadShortcutNode) {
682 hintText.createChild('br');
683 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13684 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18685 }
Blink Reformat4c46d092018-04-07 15:32:37686 } else {
687 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40688 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18689 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13690 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18691 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
692 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13693 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18694 }
Blink Reformat4c46d092018-04-07 15:32:37695 }
Kayce Basques5444c1b2019-02-15 20:32:53696 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13697 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53698 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
699 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11700
701 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57702 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37703 }
704
705 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11706 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34707 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37708 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34709 }
Brandon Goddardc992d522020-01-08 21:44:57710 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37711 this._recordingHint = null;
712 }
713
714 /**
Amanda Baker6761aae2019-11-05 18:59:11715 * @param {boolean} value
716 */
717 _setHidden(value) {
718 this._columns.setHidden(value);
719 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
720 }
721
722 /**
Blink Reformat4c46d092018-04-07 15:32:37723 * @override
724 * @return {!Array.<!Element>}
725 */
726 elementsToRestoreScrollPositionsFor() {
727 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34728 {
Blink Reformat4c46d092018-04-07 15:32:37729 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34730 }
Blink Reformat4c46d092018-04-07 15:32:37731 return [this._dataGrid.scrollContainer];
732 }
733
Tim van der Lippe119690c2020-01-13 12:31:30734 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37735 columnExtensionResolved() {
736 this._invalidateAllItems(true);
737 }
738
739 _setupDataGrid() {
740 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
741 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34742 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37743 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34744 }
Blink Reformat4c46d092018-04-07 15:32:37745 });
746 this._dataGrid.setStickToBottom(true);
747 this._dataGrid.setName('networkLog');
748 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
749 this._dataGrid.element.classList.add('network-log-grid');
750 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
751 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
752 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05753 this._dataGrid.element.addEventListener('keydown', event => {
754 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58755 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05756 event.consume(true);
757 }
758 });
759 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
760 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37761 return this._dataGrid;
762 }
763
764 /**
765 * @param {!Event} event
766 */
767 _dataGridMouseMove(event) {
768 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
769 const highlightInitiatorChain = event.shiftKey;
770 this._setHoveredNode(node, highlightInitiatorChain);
771 }
772
773 /**
Tim van der Lippe119690c2020-01-13 12:31:30774 * @override
775 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37776 */
777 hoveredNode() {
778 return this._hoveredNode;
779 }
780
781 /**
Tim van der Lippe119690c2020-01-13 12:31:30782 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37783 * @param {boolean=} highlightInitiatorChain
784 */
785 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34786 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37787 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34788 }
Blink Reformat4c46d092018-04-07 15:32:37789 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34790 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37791 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34792 }
Blink Reformat4c46d092018-04-07 15:32:37793 }
794
795 /**
796 * @param {!Event} event
797 */
798 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34799 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37800 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34801 }
Blink Reformat4c46d092018-04-07 15:32:37802 }
803
804 _updateSummaryBar() {
805 this._hideRecordingHint();
806
807 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20808 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37809 let selectedNodeNumber = 0;
810 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20811 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37812 let baseTime = -1;
813 let maxTime = -1;
814
815 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16816 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58817 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34818 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37819 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34820 }
Blink Reformat4c46d092018-04-07 15:32:37821 nodeCount++;
822 const requestTransferSize = request.transferSize;
823 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20824 const requestResourceSize = request.resourceSize;
825 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30826 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37827 selectedNodeNumber++;
828 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20829 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37830 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13831 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37832 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
833 // inspected url.
834 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13835 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
836 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37837 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34838 }
839 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37840 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34841 }
Blink Reformat4c46d092018-04-07 15:32:37842 }
843
844 if (!nodeCount) {
845 this._showRecordingHint();
846 return;
847 }
848
Joey Arhara86c14e2019-03-12 03:20:50849 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37850 /**
851 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50852 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37853 * @return {!Element}
854 */
Joey Arhara86c14e2019-03-12 03:20:50855 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13856 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50857 toolbarText.setTitle(title ? title : chunk);
858 this._summaryToolbar.appendToolbarItem(toolbarText);
859 return toolbarText.element;
860 };
Blink Reformat4c46d092018-04-07 15:32:37861
862 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50863 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
864 this._summaryToolbar.appendSeparator();
865 appendChunk(
866 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25867 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50868 this._summaryToolbar.appendSeparator();
869 appendChunk(
870 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25871 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37872 } else {
Joey Arhara86c14e2019-03-12 03:20:50873 appendChunk(ls`${nodeCount} requests`);
874 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25875 appendChunk(
876 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50877 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25878 appendChunk(
879 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37880 }
Dan Beam87466b52018-12-01 18:41:20881
Blink Reformat4c46d092018-04-07 15:32:37882 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50883 this._summaryToolbar.appendSeparator();
884 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37885 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50886 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30887 const domContentLoadedText =
888 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58889 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37890 }
891 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50892 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30893 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58894 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37895 }
896 }
Blink Reformat4c46d092018-04-07 15:32:37897 }
898
Tim van der Lippe119690c2020-01-13 12:31:30899 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37900 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34901 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37902 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34903 }
Blink Reformat4c46d092018-04-07 15:32:37904
905 this._needsRefresh = true;
906
Tim van der Lippe1d6e57a2019-09-30 11:55:34907 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37908 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34909 }
Blink Reformat4c46d092018-04-07 15:32:37910 }
911
912 /**
Tim van der Lippe119690c2020-01-13 12:31:30913 * @override
Blink Reformat4c46d092018-04-07 15:32:37914 * @param {!Array<number>} times
915 */
916 addFilmStripFrames(times) {
917 this._columns.addEventDividers(times, 'network-frame-divider');
918 }
919
920 /**
Tim van der Lippe119690c2020-01-13 12:31:30921 * @override
Blink Reformat4c46d092018-04-07 15:32:37922 * @param {number} time
923 */
924 selectFilmStripFrame(time) {
925 this._columns.selectFilmStripFrame(time);
926 }
927
Tim van der Lippe119690c2020-01-13 12:31:30928 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37929 clearFilmStripFrame() {
930 this._columns.clearFilmStripFrame();
931 }
932
933 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34934 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37935 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34936 }
Blink Reformat4c46d092018-04-07 15:32:37937 }
938
939 /**
940 * @param {boolean=} deferUpdate
941 */
942 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16943 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34944 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37945 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34946 } else {
Blink Reformat4c46d092018-04-07 15:32:37947 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34948 }
Blink Reformat4c46d092018-04-07 15:32:37949 }
950
951 /**
Tim van der Lippe119690c2020-01-13 12:31:30952 * @override
953 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37954 */
955 timeCalculator() {
956 return this._timeCalculator;
957 }
958
959 /**
Tim van der Lippe119690c2020-01-13 12:31:30960 * @override
961 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37962 */
963 calculator() {
964 return this._calculator;
965 }
966
967 /**
Tim van der Lippe119690c2020-01-13 12:31:30968 * @override
969 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37970 */
971 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34972 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37973 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34974 }
Blink Reformat4c46d092018-04-07 15:32:37975
976 if (this._calculator !== x) {
977 this._calculator = x;
978 this._columns.setCalculator(this._calculator);
979 }
980 this._calculator.reset();
981
Tim van der Lippe1d6e57a2019-09-30 11:55:34982 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37983 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34984 } else {
Blink Reformat4c46d092018-04-07 15:32:37985 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34986 }
Blink Reformat4c46d092018-04-07 15:32:37987
988 this._invalidateAllItems();
989 }
990
991 /**
Tim van der Lippec02a97c2020-02-14 14:39:27992 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37993 */
994 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34995 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37996 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34997 }
Blink Reformat4c46d092018-04-07 15:32:37998
999 const time = /** @type {number} */ (event.data.loadTime);
1000 if (time) {
1001 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301002 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371003 }
1004 }
1005
1006 /**
Tim van der Lippec02a97c2020-02-14 14:39:271007 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371008 */
1009 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341010 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371011 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341012 }
Blink Reformat4c46d092018-04-07 15:32:371013 const data = /** @type {number} */ (event.data);
1014 if (data) {
1015 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301016 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371017 }
1018 }
1019
1020 /**
1021 * @override
1022 */
1023 wasShown() {
1024 this._refreshIfNeeded();
1025 this._columns.wasShown();
1026 }
1027
1028 /**
1029 * @override
1030 */
1031 willHide() {
1032 this._columns.willHide();
1033 }
1034
1035 /**
1036 * @override
1037 */
1038 onResize() {
1039 this._rowHeight = this._computeRowHeight();
1040 }
1041
1042 /**
Tim van der Lippe119690c2020-01-13 12:31:301043 * @override
1044 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371045 */
1046 flatNodesList() {
1047 return this._dataGrid.rootNode().flatChildren();
1048 }
1049
Tim van der Lippe119690c2020-01-13 12:31:301050 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051051 updateNodeBackground() {
1052 if (this._dataGrid.selectedNode) {
1053 this._dataGrid.selectedNode.updateBackgroundColor();
1054 }
1055 }
1056
1057 /**
Tim van der Lippe119690c2020-01-13 12:31:301058 * @override
Brandon Goddard88d885a2019-10-31 16:11:051059 * @param {boolean} isSelected
1060 */
1061 updateNodeSelectedClass(isSelected) {
1062 if (isSelected) {
1063 this.element.classList.remove('no-node-selected');
1064 } else {
1065 this.element.classList.add('no-node-selected');
1066 }
1067 }
1068
Tim van der Lippe119690c2020-01-13 12:31:301069 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371070 stylesChanged() {
1071 this._columns.scheduleRefresh();
1072 }
1073
1074 _refresh() {
1075 this._needsRefresh = false;
1076
1077 if (this._refreshRequestId) {
1078 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1079 this._refreshRequestId = null;
1080 }
1081
1082 this.removeAllNodeHighlights();
1083
1084 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1085 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1086 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1087 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1088
Tim van der Lippe119690c2020-01-13 12:31:301089 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371090 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301091 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371092 const nodesToRefresh = [];
1093
Tim van der Lippe119690c2020-01-13 12:31:301094 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371095 const staleNodes = new Set();
1096
1097 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1098 // node so we loop until we have no more stale requests.
1099 while (this._staleRequests.size) {
1100 const request = this._staleRequests.firstValue();
1101 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581102 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341103 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371104 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341105 }
Blink Reformat4c46d092018-04-07 15:32:371106 staleNodes.add(node);
1107 }
1108
1109 for (const node of staleNodes) {
1110 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341111 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371112 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341113 }
Blink Reformat4c46d092018-04-07 15:32:371114
Tim van der Lippe1d6e57a2019-09-30 11:55:341115 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371116 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341117 }
Blink Reformat4c46d092018-04-07 15:32:371118 const request = node.request();
1119 this._timeCalculator.updateBoundaries(request);
1120 this._durationCalculator.updateBoundaries(request);
1121 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301122 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371123 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341124 }
Tim van der Lippe119690c2020-01-13 12:31:301125 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371126 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1127 if (removeFromParent) {
1128 let parent = node.parent;
1129 parent.removeChild(node);
1130 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1131 const grandparent = parent.parent;
1132 grandparent.removeChild(parent);
1133 parent = grandparent;
1134 }
1135 }
1136
Tim van der Lippe1d6e57a2019-09-30 11:55:341137 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371138 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341139 }
Blink Reformat4c46d092018-04-07 15:32:371140
1141 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1142 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1143 nodesToRefresh.push(newParent);
1144 }
1145 nodesToInsert.set(node, newParent);
1146 }
1147
Tim van der Lippe1d6e57a2019-09-30 11:55:341148 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371149 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 }
Blink Reformat4c46d092018-04-07 15:32:371151
Tim van der Lippe1d6e57a2019-09-30 11:55:341152 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371153 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341154 }
Blink Reformat4c46d092018-04-07 15:32:371155
1156 this._updateSummaryBar();
1157
Tim van der Lippe1d6e57a2019-09-30 11:55:341158 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371159 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341160 }
Blink Reformat4c46d092018-04-07 15:32:371161
1162 this._dataGrid.updateInstantly();
1163 this._didRefreshForTest();
1164 }
1165
1166 _didRefreshForTest() {
1167 }
1168
1169 /**
Tim van der Lippe119690c2020-01-13 12:31:301170 * @param {!NetworkRequestNode} node
1171 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371172 */
1173 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341174 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371175 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341176 }
Blink Reformat4c46d092018-04-07 15:32:371177
1178 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341179 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371180 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341181 }
Blink Reformat4c46d092018-04-07 15:32:371182 return groupNode;
1183 }
1184
1185 _reset() {
Paul Lewis56509652019-12-06 12:51:581186 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371187
1188 this._setHoveredNode(null);
1189 this._columns.reset();
1190
1191 this._timeFilter = null;
1192 this._calculator.reset();
1193
1194 this._timeCalculator.setWindow(null);
1195 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371196
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371198 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341199 }
Blink Reformat4c46d092018-04-07 15:32:371200 this._staleRequests.clear();
1201 this._resetSuggestionBuilder();
1202
1203 this._mainRequestLoadTime = -1;
1204 this._mainRequestDOMContentLoadedTime = -1;
1205
1206 this._dataGrid.rootNode().removeChildren();
1207 this._updateSummaryBar();
1208 this._dataGrid.setStickToBottom(true);
1209 this.scheduleRefresh();
1210 }
1211
1212 /**
Tim van der Lippe119690c2020-01-13 12:31:301213 * @override
Blink Reformat4c46d092018-04-07 15:32:371214 * @param {string} filterString
1215 */
1216 setTextFilterValue(filterString) {
1217 this._textFilterUI.setValue(filterString);
1218 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371219 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371220 this._resourceCategoryFilterUI.reset();
1221 }
1222
1223 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131224 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371225 */
1226 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301227 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581228 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301229 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371230
Tim van der Lippe1d6e57a2019-09-30 11:55:341231 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371232 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341233 }
Blink Reformat4c46d092018-04-07 15:32:371234 return node;
1235 }
1236
1237 /**
Tim van der Lippec02a97c2020-02-14 14:39:271238 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371239 */
1240 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131241 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371242 this._refreshRequest(request);
1243 }
1244
1245 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131246 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371247 */
1248 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581249 NetworkLogView._subdomains(request.domain)
1250 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1251 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1252 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1253 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1254 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371255
1256 const priority = request.priority();
1257 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501258 this._suggestionBuilder.addItem(
1259 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371260 }
1261
1262 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581263 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371264 }
1265
1266 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581267 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371268 }
1269
1270 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581271 const suggestion =
1272 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1273 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371274 }
1275
1276 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341277 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581278 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341279 }
Jan Scheffler341eea52019-12-12 09:08:411280
1281 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581282 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1283 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1284 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371285 }
1286
Jan Scheffler341eea52019-12-12 09:08:411287 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1288 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1289 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1290 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1291 }
1292
Blink Reformat4c46d092018-04-07 15:32:371293 this._staleRequests.add(request);
1294 this.scheduleRefresh();
1295 }
1296
1297 /**
Tim van der Lippe119690c2020-01-13 12:31:301298 * @override
Blink Reformat4c46d092018-04-07 15:32:371299 * @return {number}
1300 */
1301 rowHeight() {
1302 return this._rowHeight;
1303 }
1304
1305 /**
Tim van der Lippe119690c2020-01-13 12:31:301306 * @override
Blink Reformat4c46d092018-04-07 15:32:371307 * @param {boolean} gridMode
1308 */
1309 switchViewMode(gridMode) {
1310 this._columns.switchViewMode(gridMode);
1311 }
1312
1313 /**
Tim van der Lippe119690c2020-01-13 12:31:301314 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131315 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1316 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371317 */
1318 handleContextMenuForRequest(contextMenu, request) {
1319 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131320 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371321 const footerSection = copyMenu.footerSection();
1322 if (request) {
1323 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131324 UI.UIUtils.copyLinkAddressLabel(),
1325 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1326 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371327 if (request.requestHeadersText()) {
1328 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131329 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371330 }
1331
1332 if (request.responseHeadersText) {
1333 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131334 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371335 }
1336
1337 if (request.finished) {
1338 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131339 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371340 }
1341
Harley Libcf41f92018-09-10 18:01:131342 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131343 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371344 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131345 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1346 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371347 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131348 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291349 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131350 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1351 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371352 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131353 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1354 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131355 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131356 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1357 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371358 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131359 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1360 footerSection.appendItem(
1361 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1362 footerSection.appendItem(
1363 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1364 footerSection.appendItem(
1365 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1366 footerSection.appendItem(
1367 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371368 } else {
Harley Libcf41f92018-09-10 18:01:131369 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131370 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291371 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131372 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1373 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131374 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131375 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1376 footerSection.appendItem(
1377 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1378 footerSection.appendItem(
1379 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1380 footerSection.appendItem(
1381 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371382 }
1383 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131384 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371385 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131386 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371387
Joey Arhar0e1093c2019-05-21 00:34:221388 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371389
Blink Reformat4c46d092018-04-07 15:32:371390 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131391 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1392 contextMenu.editSection().appendItem(
1393 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371394
1395 if (request) {
1396 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081397 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371398 let patterns = manager.blockedPatterns();
1399
Tim van der Lippeffa78622019-09-16 12:07:121400 /**
1401 * @param {string} url
1402 */
1403 function addBlockedURL(url) {
1404 patterns.push({enabled: true, url: url});
1405 manager.setBlockedPatterns(patterns);
1406 manager.setBlockingEnabled(true);
Paul Lewis50993692020-01-23 15:22:261407 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121408 }
1409
1410 /**
1411 * @param {string} url
1412 */
1413 function removeBlockedURL(url) {
1414 patterns = patterns.filter(pattern => pattern.url !== url);
1415 manager.setBlockedPatterns(patterns);
Paul Lewis50993692020-01-23 15:22:261416 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121417 }
1418
Blink Reformat4c46d092018-04-07 15:32:371419 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1420 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1421 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371423 } else if (urlWithoutScheme) {
1424 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1425 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131426 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371427 }
1428
1429 const domain = request.parsedURL.domain();
1430 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1431 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131432 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371433 } else if (domain) {
1434 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1435 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131436 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371437 }
1438
Tim van der Lippe0ed1d2b2020-02-04 13:45:131439 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371440 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131441 Common.UIString.UIString('Replay XHR'),
1442 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371443 }
Blink Reformat4c46d092018-04-07 15:32:371444 }
1445 }
1446
1447 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161448 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171449 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131450 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171451 });
Blink Reformat4c46d092018-04-07 15:32:371452 }
1453
1454 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131455 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1456 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371457 }
1458
1459 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131460 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371461 * @param {string} platform
1462 */
1463 async _copyCurlCommand(request, platform) {
1464 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131465 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371466 }
1467
1468 /**
1469 * @param {string} platform
1470 */
1471 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161472 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131473 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371474 }
1475
1476 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131477 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291478 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371479 */
Jan Scheffler7c50d1f2019-12-17 13:33:291480 async _copyFetchCall(request, includeCookies) {
1481 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131482 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371483 }
1484
Jan Scheffler7c50d1f2019-12-17 13:33:291485 /**
1486 * @param {boolean} includeCookies
1487 */
1488 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161489 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131490 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371491 }
1492
1493 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371495 */
1496 async _copyPowerShellCommand(request) {
1497 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131498 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371499 }
1500
1501 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161502 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131503 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371504 }
1505
Tim van der Lippe119690c2020-01-13 12:31:301506 /**
1507 * @override
1508 * @return {!Promise}
1509 */
Joey Arhar0e1093c2019-05-21 00:34:221510 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331511 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131512 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371513 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131514 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371515
Tim van der Lippe1d6e57a2019-09-30 11:55:341516 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371517 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341518 }
Blink Reformat4c46d092018-04-07 15:32:371519
Tim van der Lippe0ed1d2b2020-02-04 13:45:131520 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371521 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301522 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371523 progressIndicator.done();
1524 stream.close();
1525 }
1526
1527 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131528 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081529 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341530 }
Blink Reformat4c46d092018-04-07 15:32:371531 }
1532
1533 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131534 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081535 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341536 }
Blink Reformat4c46d092018-04-07 15:32:371537 }
1538
1539 _removeAllHighlights() {
1540 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341541 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131542 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341543 }
Blink Reformat4c46d092018-04-07 15:32:371544 this._highlightedSubstringChanges = [];
1545 }
1546
1547 /**
Tim van der Lippe119690c2020-01-13 12:31:301548 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371549 * @return {boolean}
1550 */
1551 _applyFilter(node) {
1552 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341553 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371554 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341555 }
Blink Reformat4c46d092018-04-07 15:32:371556 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341557 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371558 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341559 }
1560 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371561 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341562 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131563 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.IssuesModel.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371564 return false;
1565 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341566 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371567 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341568 }
Blink Reformat4c46d092018-04-07 15:32:371569 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341570 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371571 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341572 }
Blink Reformat4c46d092018-04-07 15:32:371573 }
1574 return true;
1575 }
1576
1577 /**
1578 * @param {string} query
1579 */
1580 _parseFilterQuery(query) {
1581 const descriptors = this._filterParser.parse(query);
1582 this._filters = descriptors.map(descriptor => {
1583 const key = descriptor.key;
1584 const text = descriptor.text || '';
1585 const regex = descriptor.regex;
1586 let filter;
1587 if (key) {
1588 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581589 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1590 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371591 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581592 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371593 } else {
Paul Lewis56509652019-12-06 12:51:581594 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371595 }
Paul Lewis56509652019-12-06 12:51:581596 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371597 });
1598 }
1599
1600 /**
Paul Lewis56509652019-12-06 12:51:581601 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371602 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161603 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371604 */
1605 _createSpecialFilter(type, value) {
1606 switch (type) {
Paul Lewis56509652019-12-06 12:51:581607 case FilterType.Domain:
1608 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371609
Paul Lewis56509652019-12-06 12:51:581610 case FilterType.HasResponseHeader:
1611 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371612
Paul Lewis56509652019-12-06 12:51:581613 case FilterType.Is:
1614 if (value.toLowerCase() === IsFilterType.Running) {
1615 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341616 }
Paul Lewis56509652019-12-06 12:51:581617 if (value.toLowerCase() === IsFilterType.FromCache) {
1618 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341619 }
Paul Lewis56509652019-12-06 12:51:581620 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1621 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341622 }
Paul Lewis56509652019-12-06 12:51:581623 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1624 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341625 }
Blink Reformat4c46d092018-04-07 15:32:371626 break;
1627
Paul Lewis56509652019-12-06 12:51:581628 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371629 return this._createSizeFilter(value.toLowerCase());
1630
Paul Lewis56509652019-12-06 12:51:581631 case FilterType.Method:
1632 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371633
Paul Lewis56509652019-12-06 12:51:581634 case FilterType.MimeType:
1635 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371636
Paul Lewis56509652019-12-06 12:51:581637 case FilterType.MixedContent:
1638 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371639
Paul Lewis56509652019-12-06 12:51:581640 case FilterType.Scheme:
1641 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371642
Paul Lewis56509652019-12-06 12:51:581643 case FilterType.SetCookieDomain:
1644 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371645
Paul Lewis56509652019-12-06 12:51:581646 case FilterType.SetCookieName:
1647 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371648
Paul Lewis56509652019-12-06 12:51:581649 case FilterType.SetCookieValue:
1650 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371651
Jan Scheffler341eea52019-12-12 09:08:411652 case FilterType.CookieDomain:
1653 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1654
1655 case FilterType.CookieName:
1656 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1657
1658 case FilterType.CookieValue:
1659 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1660
Paul Lewis56509652019-12-06 12:51:581661 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501662 return NetworkLogView._requestPriorityFilter.bind(
1663 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371664
Paul Lewis56509652019-12-06 12:51:581665 case FilterType.StatusCode:
1666 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371667 }
1668 return null;
1669 }
1670
1671 /**
1672 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161673 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371674 */
1675 _createSizeFilter(value) {
1676 let multiplier = 1;
1677 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411678 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371679 value = value.substring(0, value.length - 1);
1680 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411681 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371682 value = value.substring(0, value.length - 1);
1683 }
1684 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341685 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371686 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341687 }
Paul Lewis56509652019-12-06 12:51:581688 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371689 }
1690
1691 _filterRequests() {
1692 this._removeAllHighlights();
1693 this._invalidateAllItems();
1694 }
1695
1696 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131697 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301698 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371699 */
1700 _reveal(request) {
1701 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581702 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341703 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371704 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341705 }
Blink Reformat4c46d092018-04-07 15:32:371706 node.reveal();
1707 return node;
1708 }
1709
1710 /**
Tim van der Lippe119690c2020-01-13 12:31:301711 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131712 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371713 */
1714 revealAndHighlightRequest(request) {
1715 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341716 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371717 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341718 }
Blink Reformat4c46d092018-04-07 15:32:371719 }
1720
1721 /**
Tim van der Lippe119690c2020-01-13 12:31:301722 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131723 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371724 */
1725 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141726 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371727 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341728 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371729 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341730 }
Blink Reformat4c46d092018-04-07 15:32:371731 }
1732
Tim van der Lippe119690c2020-01-13 12:31:301733 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371734 removeAllNodeHighlights() {
1735 if (this._highlightedNode) {
1736 this._highlightedNode.element().classList.remove('highlighted-row');
1737 this._highlightedNode = null;
1738 }
1739 }
1740
1741 /**
Tim van der Lippe119690c2020-01-13 12:31:301742 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371743 */
1744 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131745 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371746 this._highlightedNode = node;
1747 }
1748
1749 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131750 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1751 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131752 */
1753 _filterOutBlobRequests(requests) {
1754 return requests.filter(request => !request.isBlobRequest());
1755 }
1756
1757 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131758 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291759 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371760 * @return {!Promise<string>}
1761 */
Jan Scheffler7c50d1f2019-12-17 13:33:291762 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371763 const ignoredHeaders = {
1764 // Internal headers
1765 'method': 1,
1766 'path': 1,
1767 'scheme': 1,
1768 'version': 1,
1769
1770 // Unsafe headers
1771 // Keep this list synchronized with src/net/http/http_util.cc
1772 'accept-charset': 1,
1773 'accept-encoding': 1,
1774 'access-control-request-headers': 1,
1775 'access-control-request-method': 1,
1776 'connection': 1,
1777 'content-length': 1,
1778 'cookie': 1,
1779 'cookie2': 1,
1780 'date': 1,
1781 'dnt': 1,
1782 'expect': 1,
1783 'host': 1,
1784 'keep-alive': 1,
1785 'origin': 1,
1786 'referer': 1,
1787 'te': 1,
1788 'trailer': 1,
1789 'transfer-encoding': 1,
1790 'upgrade': 1,
1791 'via': 1,
1792 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1793 'user-agent': 1
1794 };
1795
1796 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1797
1798 const url = JSON.stringify(request.url());
1799
1800 const requestHeaders = request.requestHeaders();
1801 const headerData = requestHeaders.reduce((result, header) => {
1802 const name = header.name;
1803
Tim van der Lippe1d6e57a2019-09-30 11:55:341804 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371805 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341806 }
Blink Reformat4c46d092018-04-07 15:32:371807
1808 return result;
1809 }, new Headers());
1810
1811 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341812 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411813 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341814 }
Blink Reformat4c46d092018-04-07 15:32:371815
1816 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411817 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1818 'include' :
1819 'omit';
Blink Reformat4c46d092018-04-07 15:32:371820
1821 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1822
1823 const referrer = referrerHeader ? referrerHeader.value : void 0;
1824
1825 const referrerPolicy = request.referrerPolicy() || void 0;
1826
1827 const requestBody = await request.requestFormData();
1828
1829 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411830 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371831 referrer,
1832 referrerPolicy,
1833 body: requestBody,
1834 method: request.requestMethod,
1835 mode: 'cors'
1836 };
1837
Jan Scheffler7c50d1f2019-12-17 13:33:291838 if (includeCookies) {
1839 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1840 if (cookieHeader) {
1841 fetchOptions.headers = {
1842 ...headers,
1843 'cookie': cookieHeader.value,
1844 };
1845 }
1846 } else {
1847 fetchOptions.credentials = credentials;
1848 }
1849
Jan Scheffler172d5212020-01-02 14:42:561850 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371851 return `fetch(${url}, ${options});`;
1852 }
1853
1854 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131855 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291856 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131857 * @return {!Promise<string>}
1858 */
Jan Scheffler7c50d1f2019-12-17 13:33:291859 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131860 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291861 const commands =
1862 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131863 return commands.join(' ;\n');
1864 }
1865
1866 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131867 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371868 * @param {string} platform
1869 * @return {!Promise<string>}
1870 */
1871 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561872 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361873 // Most of these headers are derived from the URL and are automatically added by cURL.
1874 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1875 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371876
1877 function escapeStringWin(str) {
1878 /* If there are no new line characters do not escape the " characters
1879 since it only uglifies the command.
1880
1881 Because cmd.exe parser and MS Crt arguments parsers use some of the
1882 same escape characters, they can interact with each other in
1883 horrible ways, the order of operations is critical.
1884
1885 Replace \ with \\ first because it is an escape character for certain
1886 conditions in both parsers.
1887
1888 Replace all " with \" to ensure the first parser does not remove it.
1889
1890 Then escape all characters we are not sure about with ^ to ensure it
1891 gets to MS Crt parser safely.
1892
1893 The % character is special because MS Crt parser will try and look for
1894 ENV variables and fill them in it's place. We cannot escape them with %
1895 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1896 parser); So we can get cmd.exe parser to escape the character after it,
1897 if it is followed by a valid beginning character of an ENV variable.
1898 This ensures we do not try and double escape another ^ if it was placed
1899 by the previous replace.
1900
1901 Lastly we replace new lines with ^ and TWO new lines because the first
1902 new line is there to enact the escape command the second is the character
1903 to escape (in this case new line).
1904 */
1905 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1906 return encapsChars +
1907 str.replace(/\\/g, '\\\\')
1908 .replace(/"/g, '\\"')
1909 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1910 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1911 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1912 encapsChars;
1913 }
1914
1915 /**
1916 * @param {string} str
1917 * @return {string}
1918 */
1919 function escapeStringPosix(str) {
1920 /**
1921 * @param {string} x
1922 * @return {string}
1923 */
1924 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221925 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121926 let hexString = code.toString(16);
1927 // Zero pad to four digits to comply with ANSI-C Quoting:
1928 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341929 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121930 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341931 }
Joey Arhar2d21f712019-05-20 21:07:121932
1933 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371934 }
1935
Joey Arhar512e3742019-01-25 21:33:541936 if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371937 // Use ANSI-C quoting syntax.
1938 return '$\'' +
1939 str.replace(/\\/g, '\\\\')
1940 .replace(/\'/g, '\\\'')
1941 .replace(/\n/g, '\\n')
1942 .replace(/\r/g, '\\r')
Joey Arhar512e3742019-01-25 21:33:541943 .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371944 '\'';
1945 } else {
1946 // Use single quote syntax.
1947 return '\'' + str + '\'';
1948 }
1949 }
1950
1951 // cURL command expected to run on the same platform that DevTools run
1952 // (it may be different from the inspected page platform).
1953 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1954
1955 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1956
1957 let inferredMethod = 'GET';
1958 const data = [];
1959 const requestContentType = request.requestContentType();
1960 const formData = await request.requestFormData();
1961 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:271962 // Note that formData is not necessarily urlencoded because it might for example
1963 // come from a fetch request made with an explicitly unencoded body.
1964 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371965 ignoredHeaders['content-length'] = true;
1966 inferredMethod = 'POST';
1967 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561968 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371969 ignoredHeaders['content-length'] = true;
1970 inferredMethod = 'POST';
1971 }
1972
1973 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291974 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371975 }
1976
1977 const requestHeaders = request.requestHeaders();
1978 for (let i = 0; i < requestHeaders.length; i++) {
1979 const header = requestHeaders[i];
1980 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341981 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371982 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341983 }
Jan Scheffler172d5212020-01-02 14:42:561984 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371985 }
1986 command = command.concat(data);
1987 command.push('--compressed');
1988
Tim van der Lippe1d6e57a2019-09-30 11:55:341989 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371990 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341991 }
Jan Scheffler172d5212020-01-02 14:42:561992 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:371993 }
1994
1995 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131996 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:131997 * @param {string} platform
1998 * @return {!Promise<string>}
1999 */
2000 async _generateAllCurlCommand(requests, platform) {
2001 const nonBlobRequests = this._filterOutBlobRequests(requests);
2002 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342003 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132004 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342005 } else {
Harley Libcf41f92018-09-10 18:01:132006 return commands.join(' ;\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342007 }
Harley Libcf41f92018-09-10 18:01:132008 }
2009
2010 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132011 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372012 * @return {!Promise<string>}
2013 */
2014 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562015 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372016 const ignoredHeaders =
2017 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2018
2019 /**
2020 * @param {string} str
2021 * @return {string}
2022 */
2023 function escapeString(str) {
2024 return '"' +
2025 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2026 }
2027
Jan Scheffler172d5212020-01-02 14:42:562028 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372029
2030 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562031 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372032 }
2033
2034 const requestHeaders = request.requestHeaders();
2035 const headerNameValuePairs = [];
2036 for (const header of requestHeaders) {
2037 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342038 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372039 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342040 }
Blink Reformat4c46d092018-04-07 15:32:372041 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2042 }
2043 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562044 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372045 }
2046
2047 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2048 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562049 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372050 }
2051
2052 const formData = await request.requestFormData();
2053 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372054 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342055 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562056 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342057 } else {
Jan Scheffler172d5212020-01-02 14:42:562058 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342059 }
Blink Reformat4c46d092018-04-07 15:32:372060 }
2061
Jan Scheffler172d5212020-01-02 14:42:562062 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372063 }
Harley Libcf41f92018-09-10 18:01:132064
2065 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132066 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132067 * @return {!Promise<string>}
2068 */
2069 async _generateAllPowerShellCommand(requests) {
2070 const nonBlobRequests = this._filterOutBlobRequests(requests);
2071 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2072 return commands.join(';\r\n');
2073 }
Joey Arhara86c14e2019-03-12 03:20:502074
2075 /**
2076 * @return {string}
2077 */
2078 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552079 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502080 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342081 }
Joey Arhara86c14e2019-03-12 03:20:502082 return '#0867CB';
2083 }
2084
2085 /**
2086 * @return {string}
2087 */
2088 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132089 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502090 }
Paul Lewis56509652019-12-06 12:51:582091}
Blink Reformat4c46d092018-04-07 15:32:372092
Tim van der Lippe119690c2020-01-13 12:31:302093export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582094export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372095
Paul Lewis56509652019-12-06 12:51:582096export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372097 'http': true,
2098 'https': true,
2099 'ws': true,
2100 'wss': true
2101};
2102
Blink Reformat4c46d092018-04-07 15:32:372103/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582104export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372105 Domain: 'domain',
2106 HasResponseHeader: 'has-response-header',
2107 Is: 'is',
2108 LargerThan: 'larger-than',
2109 Method: 'method',
2110 MimeType: 'mime-type',
2111 MixedContent: 'mixed-content',
2112 Priority: 'priority',
2113 Scheme: 'scheme',
2114 SetCookieDomain: 'set-cookie-domain',
2115 SetCookieName: 'set-cookie-name',
2116 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412117 CookieDomain: 'cookie-domain',
2118 CookieName: 'cookie-name',
2119 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372120 StatusCode: 'status-code'
2121};
2122
2123/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582124export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372125 All: 'all',
2126 Displayed: 'displayed',
2127 Blocked: 'blocked',
2128 BlockOverridden: 'block-overridden'
2129};
2130
2131/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582132export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372133 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052134 FromCache: 'from-cache',
2135 ServiceWorkerIntercepted: 'service-worker-intercepted',
2136 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372137};
2138
2139/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582140export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372141
2142/**
2143 * @interface
2144 */
Paul Lewis56509652019-12-06 12:51:582145export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372146 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132147 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302148 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372149 */
Paul Lewis56509652019-12-06 12:51:582150 groupNodeForRequest(request) {
2151 }
Blink Reformat4c46d092018-04-07 15:32:372152
Paul Lewis56509652019-12-06 12:51:582153 reset() {
2154 }
2155}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162156
2157/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2158export let Filter;