blob: 793404ba4dd5ed709f2cee121c5267b260abdbcd [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
104 /** @type {!Array.<!Network.NetworkLogView.Filter>} */
105 this._filters = [];
106 /** @type {?Network.NetworkLogView.Filter} */
107 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 /**
217 * @param {!Network.NetworkLogView.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
254 * @return {!Network.NetworkLogView.Filter}
255 */
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 /**
654 * @param {!Common.Event} event
655 */
656 _filterChanged(event) {
657 this.removeAllNodeHighlights();
658 this._parseFilterQuery(this._textFilterUI.value());
659 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37660 }
661
662 _showRecordingHint() {
663 this._hideRecordingHint();
664 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
665 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18666
667 let reloadShortcutNode = null;
Paul Lewis05eb37f2020-01-24 14:31:40668 const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
Joey Arhar0585e6f2018-10-30 23:11:18669 if (reloadShortcutDescriptor) {
670 reloadShortcutNode = this._recordingHint.createChild('b');
671 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
672 }
Blink Reformat4c46d092018-04-07 15:32:37673
674 if (this._recording) {
675 const recordingText = hintText.createChild('span');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13676 recordingText.textContent = Common.UIString.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18677 if (reloadShortcutNode) {
678 hintText.createChild('br');
679 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13680 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18681 }
Blink Reformat4c46d092018-04-07 15:32:37682 } else {
683 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40684 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18685 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13686 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18687 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
688 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13689 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18690 }
Blink Reformat4c46d092018-04-07 15:32:37691 }
Kayce Basques5444c1b2019-02-15 20:32:53692 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13693 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53694 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
695 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11696
697 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57698 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37699 }
700
701 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11702 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34703 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37704 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34705 }
Brandon Goddardc992d522020-01-08 21:44:57706 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37707 this._recordingHint = null;
708 }
709
710 /**
Amanda Baker6761aae2019-11-05 18:59:11711 * @param {boolean} value
712 */
713 _setHidden(value) {
714 this._columns.setHidden(value);
715 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
716 }
717
718 /**
Blink Reformat4c46d092018-04-07 15:32:37719 * @override
720 * @return {!Array.<!Element>}
721 */
722 elementsToRestoreScrollPositionsFor() {
723 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34724 {
Blink Reformat4c46d092018-04-07 15:32:37725 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34726 }
Blink Reformat4c46d092018-04-07 15:32:37727 return [this._dataGrid.scrollContainer];
728 }
729
Tim van der Lippe119690c2020-01-13 12:31:30730 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37731 columnExtensionResolved() {
732 this._invalidateAllItems(true);
733 }
734
735 _setupDataGrid() {
736 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
737 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34738 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37739 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34740 }
Blink Reformat4c46d092018-04-07 15:32:37741 });
742 this._dataGrid.setStickToBottom(true);
743 this._dataGrid.setName('networkLog');
744 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
745 this._dataGrid.element.classList.add('network-log-grid');
746 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
747 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
748 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05749 this._dataGrid.element.addEventListener('keydown', event => {
750 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58751 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05752 event.consume(true);
753 }
754 });
755 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
756 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37757 return this._dataGrid;
758 }
759
760 /**
761 * @param {!Event} event
762 */
763 _dataGridMouseMove(event) {
764 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
765 const highlightInitiatorChain = event.shiftKey;
766 this._setHoveredNode(node, highlightInitiatorChain);
767 }
768
769 /**
Tim van der Lippe119690c2020-01-13 12:31:30770 * @override
771 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37772 */
773 hoveredNode() {
774 return this._hoveredNode;
775 }
776
777 /**
Tim van der Lippe119690c2020-01-13 12:31:30778 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37779 * @param {boolean=} highlightInitiatorChain
780 */
781 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34782 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37783 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34784 }
Blink Reformat4c46d092018-04-07 15:32:37785 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34786 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37787 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34788 }
Blink Reformat4c46d092018-04-07 15:32:37789 }
790
791 /**
792 * @param {!Event} event
793 */
794 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34795 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37796 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34797 }
Blink Reformat4c46d092018-04-07 15:32:37798 }
799
800 _updateSummaryBar() {
801 this._hideRecordingHint();
802
803 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20804 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37805 let selectedNodeNumber = 0;
806 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20807 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37808 let baseTime = -1;
809 let maxTime = -1;
810
811 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16812 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58813 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34814 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37815 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34816 }
Blink Reformat4c46d092018-04-07 15:32:37817 nodeCount++;
818 const requestTransferSize = request.transferSize;
819 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20820 const requestResourceSize = request.resourceSize;
821 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30822 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37823 selectedNodeNumber++;
824 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20825 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37826 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13827 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37828 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
829 // inspected url.
830 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13831 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
832 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37833 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34834 }
835 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37836 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34837 }
Blink Reformat4c46d092018-04-07 15:32:37838 }
839
840 if (!nodeCount) {
841 this._showRecordingHint();
842 return;
843 }
844
Joey Arhara86c14e2019-03-12 03:20:50845 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37846 /**
847 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50848 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37849 * @return {!Element}
850 */
Joey Arhara86c14e2019-03-12 03:20:50851 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13852 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50853 toolbarText.setTitle(title ? title : chunk);
854 this._summaryToolbar.appendToolbarItem(toolbarText);
855 return toolbarText.element;
856 };
Blink Reformat4c46d092018-04-07 15:32:37857
858 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50859 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
860 this._summaryToolbar.appendSeparator();
861 appendChunk(
862 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25863 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50864 this._summaryToolbar.appendSeparator();
865 appendChunk(
866 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25867 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37868 } else {
Joey Arhara86c14e2019-03-12 03:20:50869 appendChunk(ls`${nodeCount} requests`);
870 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25871 appendChunk(
872 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50873 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25874 appendChunk(
875 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37876 }
Dan Beam87466b52018-12-01 18:41:20877
Blink Reformat4c46d092018-04-07 15:32:37878 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50879 this._summaryToolbar.appendSeparator();
880 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37881 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50882 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30883 const domContentLoadedText =
884 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58885 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37886 }
887 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50888 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30889 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58890 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37891 }
892 }
Blink Reformat4c46d092018-04-07 15:32:37893 }
894
Tim van der Lippe119690c2020-01-13 12:31:30895 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37896 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34897 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37898 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34899 }
Blink Reformat4c46d092018-04-07 15:32:37900
901 this._needsRefresh = true;
902
Tim van der Lippe1d6e57a2019-09-30 11:55:34903 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37904 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34905 }
Blink Reformat4c46d092018-04-07 15:32:37906 }
907
908 /**
Tim van der Lippe119690c2020-01-13 12:31:30909 * @override
Blink Reformat4c46d092018-04-07 15:32:37910 * @param {!Array<number>} times
911 */
912 addFilmStripFrames(times) {
913 this._columns.addEventDividers(times, 'network-frame-divider');
914 }
915
916 /**
Tim van der Lippe119690c2020-01-13 12:31:30917 * @override
Blink Reformat4c46d092018-04-07 15:32:37918 * @param {number} time
919 */
920 selectFilmStripFrame(time) {
921 this._columns.selectFilmStripFrame(time);
922 }
923
Tim van der Lippe119690c2020-01-13 12:31:30924 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37925 clearFilmStripFrame() {
926 this._columns.clearFilmStripFrame();
927 }
928
929 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34930 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37931 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34932 }
Blink Reformat4c46d092018-04-07 15:32:37933 }
934
935 /**
936 * @param {boolean=} deferUpdate
937 */
938 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16939 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34940 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37941 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34942 } else {
Blink Reformat4c46d092018-04-07 15:32:37943 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34944 }
Blink Reformat4c46d092018-04-07 15:32:37945 }
946
947 /**
Tim van der Lippe119690c2020-01-13 12:31:30948 * @override
949 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37950 */
951 timeCalculator() {
952 return this._timeCalculator;
953 }
954
955 /**
Tim van der Lippe119690c2020-01-13 12:31:30956 * @override
957 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37958 */
959 calculator() {
960 return this._calculator;
961 }
962
963 /**
Tim van der Lippe119690c2020-01-13 12:31:30964 * @override
965 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37966 */
967 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34968 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37969 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34970 }
Blink Reformat4c46d092018-04-07 15:32:37971
972 if (this._calculator !== x) {
973 this._calculator = x;
974 this._columns.setCalculator(this._calculator);
975 }
976 this._calculator.reset();
977
Tim van der Lippe1d6e57a2019-09-30 11:55:34978 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37979 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34980 } else {
Blink Reformat4c46d092018-04-07 15:32:37981 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34982 }
Blink Reformat4c46d092018-04-07 15:32:37983
984 this._invalidateAllItems();
985 }
986
987 /**
988 * @param {!Common.Event} event
989 */
990 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34991 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37992 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34993 }
Blink Reformat4c46d092018-04-07 15:32:37994
995 const time = /** @type {number} */ (event.data.loadTime);
996 if (time) {
997 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:30998 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:37999 }
1000 }
1001
1002 /**
1003 * @param {!Common.Event} event
1004 */
1005 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371007 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341008 }
Blink Reformat4c46d092018-04-07 15:32:371009 const data = /** @type {number} */ (event.data);
1010 if (data) {
1011 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301012 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371013 }
1014 }
1015
1016 /**
1017 * @override
1018 */
1019 wasShown() {
1020 this._refreshIfNeeded();
1021 this._columns.wasShown();
1022 }
1023
1024 /**
1025 * @override
1026 */
1027 willHide() {
1028 this._columns.willHide();
1029 }
1030
1031 /**
1032 * @override
1033 */
1034 onResize() {
1035 this._rowHeight = this._computeRowHeight();
1036 }
1037
1038 /**
Tim van der Lippe119690c2020-01-13 12:31:301039 * @override
1040 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371041 */
1042 flatNodesList() {
1043 return this._dataGrid.rootNode().flatChildren();
1044 }
1045
Tim van der Lippe119690c2020-01-13 12:31:301046 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051047 updateNodeBackground() {
1048 if (this._dataGrid.selectedNode) {
1049 this._dataGrid.selectedNode.updateBackgroundColor();
1050 }
1051 }
1052
1053 /**
Tim van der Lippe119690c2020-01-13 12:31:301054 * @override
Brandon Goddard88d885a2019-10-31 16:11:051055 * @param {boolean} isSelected
1056 */
1057 updateNodeSelectedClass(isSelected) {
1058 if (isSelected) {
1059 this.element.classList.remove('no-node-selected');
1060 } else {
1061 this.element.classList.add('no-node-selected');
1062 }
1063 }
1064
Tim van der Lippe119690c2020-01-13 12:31:301065 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371066 stylesChanged() {
1067 this._columns.scheduleRefresh();
1068 }
1069
1070 _refresh() {
1071 this._needsRefresh = false;
1072
1073 if (this._refreshRequestId) {
1074 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1075 this._refreshRequestId = null;
1076 }
1077
1078 this.removeAllNodeHighlights();
1079
1080 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1081 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1082 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1083 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1084
Tim van der Lippe119690c2020-01-13 12:31:301085 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371086 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301087 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371088 const nodesToRefresh = [];
1089
Tim van der Lippe119690c2020-01-13 12:31:301090 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371091 const staleNodes = new Set();
1092
1093 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1094 // node so we loop until we have no more stale requests.
1095 while (this._staleRequests.size) {
1096 const request = this._staleRequests.firstValue();
1097 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581098 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341099 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371100 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341101 }
Blink Reformat4c46d092018-04-07 15:32:371102 staleNodes.add(node);
1103 }
1104
1105 for (const node of staleNodes) {
1106 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341107 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371108 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341109 }
Blink Reformat4c46d092018-04-07 15:32:371110
Tim van der Lippe1d6e57a2019-09-30 11:55:341111 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371112 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341113 }
Blink Reformat4c46d092018-04-07 15:32:371114 const request = node.request();
1115 this._timeCalculator.updateBoundaries(request);
1116 this._durationCalculator.updateBoundaries(request);
1117 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301118 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371119 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341120 }
Tim van der Lippe119690c2020-01-13 12:31:301121 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371122 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1123 if (removeFromParent) {
1124 let parent = node.parent;
1125 parent.removeChild(node);
1126 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1127 const grandparent = parent.parent;
1128 grandparent.removeChild(parent);
1129 parent = grandparent;
1130 }
1131 }
1132
Tim van der Lippe1d6e57a2019-09-30 11:55:341133 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371134 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341135 }
Blink Reformat4c46d092018-04-07 15:32:371136
1137 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1138 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1139 nodesToRefresh.push(newParent);
1140 }
1141 nodesToInsert.set(node, newParent);
1142 }
1143
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371145 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341146 }
Blink Reformat4c46d092018-04-07 15:32:371147
Tim van der Lippe1d6e57a2019-09-30 11:55:341148 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371149 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 }
Blink Reformat4c46d092018-04-07 15:32:371151
1152 this._updateSummaryBar();
1153
Tim van der Lippe1d6e57a2019-09-30 11:55:341154 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371155 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341156 }
Blink Reformat4c46d092018-04-07 15:32:371157
1158 this._dataGrid.updateInstantly();
1159 this._didRefreshForTest();
1160 }
1161
1162 _didRefreshForTest() {
1163 }
1164
1165 /**
Tim van der Lippe119690c2020-01-13 12:31:301166 * @param {!NetworkRequestNode} node
1167 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371168 */
1169 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341170 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371171 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341172 }
Blink Reformat4c46d092018-04-07 15:32:371173
1174 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341175 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371176 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341177 }
Blink Reformat4c46d092018-04-07 15:32:371178 return groupNode;
1179 }
1180
1181 _reset() {
Paul Lewis56509652019-12-06 12:51:581182 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371183
1184 this._setHoveredNode(null);
1185 this._columns.reset();
1186
1187 this._timeFilter = null;
1188 this._calculator.reset();
1189
1190 this._timeCalculator.setWindow(null);
1191 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371192
Tim van der Lippe1d6e57a2019-09-30 11:55:341193 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371194 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 }
Blink Reformat4c46d092018-04-07 15:32:371196 this._staleRequests.clear();
1197 this._resetSuggestionBuilder();
1198
1199 this._mainRequestLoadTime = -1;
1200 this._mainRequestDOMContentLoadedTime = -1;
1201
1202 this._dataGrid.rootNode().removeChildren();
1203 this._updateSummaryBar();
1204 this._dataGrid.setStickToBottom(true);
1205 this.scheduleRefresh();
1206 }
1207
1208 /**
Tim van der Lippe119690c2020-01-13 12:31:301209 * @override
Blink Reformat4c46d092018-04-07 15:32:371210 * @param {string} filterString
1211 */
1212 setTextFilterValue(filterString) {
1213 this._textFilterUI.setValue(filterString);
1214 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371215 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371216 this._resourceCategoryFilterUI.reset();
1217 }
1218
1219 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131220 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371221 */
1222 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301223 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581224 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301225 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371226
Tim van der Lippe1d6e57a2019-09-30 11:55:341227 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371228 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341229 }
Blink Reformat4c46d092018-04-07 15:32:371230 return node;
1231 }
1232
1233 /**
1234 * @param {!Common.Event} event
1235 */
1236 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131237 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371238 this._refreshRequest(request);
1239 }
1240
1241 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131242 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371243 */
1244 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581245 NetworkLogView._subdomains(request.domain)
1246 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1247 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1248 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1249 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1250 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371251
1252 const priority = request.priority();
1253 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501254 this._suggestionBuilder.addItem(
1255 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371256 }
1257
1258 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581259 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371260 }
1261
1262 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581263 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371264 }
1265
1266 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581267 const suggestion =
1268 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1269 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371270 }
1271
1272 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341273 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581274 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341275 }
Jan Scheffler341eea52019-12-12 09:08:411276
1277 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581278 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1279 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1280 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371281 }
1282
Jan Scheffler341eea52019-12-12 09:08:411283 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1284 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1285 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1286 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1287 }
1288
Blink Reformat4c46d092018-04-07 15:32:371289 this._staleRequests.add(request);
1290 this.scheduleRefresh();
1291 }
1292
1293 /**
Tim van der Lippe119690c2020-01-13 12:31:301294 * @override
Blink Reformat4c46d092018-04-07 15:32:371295 * @return {number}
1296 */
1297 rowHeight() {
1298 return this._rowHeight;
1299 }
1300
1301 /**
Tim van der Lippe119690c2020-01-13 12:31:301302 * @override
Blink Reformat4c46d092018-04-07 15:32:371303 * @param {boolean} gridMode
1304 */
1305 switchViewMode(gridMode) {
1306 this._columns.switchViewMode(gridMode);
1307 }
1308
1309 /**
Tim van der Lippe119690c2020-01-13 12:31:301310 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131311 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1312 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371313 */
1314 handleContextMenuForRequest(contextMenu, request) {
1315 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131316 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371317 const footerSection = copyMenu.footerSection();
1318 if (request) {
1319 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131320 UI.UIUtils.copyLinkAddressLabel(),
1321 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1322 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371323 if (request.requestHeadersText()) {
1324 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131325 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371326 }
1327
1328 if (request.responseHeadersText) {
1329 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131330 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371331 }
1332
1333 if (request.finished) {
1334 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131335 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371336 }
1337
Harley Libcf41f92018-09-10 18:01:131338 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131339 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371340 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131341 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1342 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371343 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131344 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291345 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131346 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1347 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371348 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131349 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1350 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131351 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131352 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1353 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371354 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131355 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1356 footerSection.appendItem(
1357 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1358 footerSection.appendItem(
1359 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1360 footerSection.appendItem(
1361 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1362 footerSection.appendItem(
1363 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371364 } else {
Harley Libcf41f92018-09-10 18:01:131365 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131366 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291367 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131368 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1369 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131370 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131371 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1372 footerSection.appendItem(
1373 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1374 footerSection.appendItem(
1375 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1376 footerSection.appendItem(
1377 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371378 }
1379 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131380 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371381 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131382 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371383
Joey Arhar0e1093c2019-05-21 00:34:221384 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371385
Blink Reformat4c46d092018-04-07 15:32:371386 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131387 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1388 contextMenu.editSection().appendItem(
1389 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371390
1391 if (request) {
1392 const maxBlockedURLLength = 20;
Paul Lewis5a922e72020-01-24 11:58:081393 const manager = self.SDK.multitargetNetworkManager;
Blink Reformat4c46d092018-04-07 15:32:371394 let patterns = manager.blockedPatterns();
1395
Tim van der Lippeffa78622019-09-16 12:07:121396 /**
1397 * @param {string} url
1398 */
1399 function addBlockedURL(url) {
1400 patterns.push({enabled: true, url: url});
1401 manager.setBlockedPatterns(patterns);
1402 manager.setBlockingEnabled(true);
Paul Lewis50993692020-01-23 15:22:261403 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121404 }
1405
1406 /**
1407 * @param {string} url
1408 */
1409 function removeBlockedURL(url) {
1410 patterns = patterns.filter(pattern => pattern.url !== url);
1411 manager.setBlockedPatterns(patterns);
Paul Lewis50993692020-01-23 15:22:261412 self.UI.viewManager.showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121413 }
1414
Blink Reformat4c46d092018-04-07 15:32:371415 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1416 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1417 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131418 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371419 } else if (urlWithoutScheme) {
1420 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1421 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371423 }
1424
1425 const domain = request.parsedURL.domain();
1426 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1427 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131428 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371429 } else if (domain) {
1430 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1431 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131432 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371433 }
1434
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371436 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131437 Common.UIString.UIString('Replay XHR'),
1438 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371439 }
Blink Reformat4c46d092018-04-07 15:32:371440 }
1441 }
1442
1443 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161444 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171445 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131446 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171447 });
Blink Reformat4c46d092018-04-07 15:32:371448 }
1449
1450 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131451 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1452 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371453 }
1454
1455 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131456 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371457 * @param {string} platform
1458 */
1459 async _copyCurlCommand(request, platform) {
1460 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131461 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371462 }
1463
1464 /**
1465 * @param {string} platform
1466 */
1467 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161468 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131469 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371470 }
1471
1472 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131473 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291474 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371475 */
Jan Scheffler7c50d1f2019-12-17 13:33:291476 async _copyFetchCall(request, includeCookies) {
1477 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131478 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371479 }
1480
Jan Scheffler7c50d1f2019-12-17 13:33:291481 /**
1482 * @param {boolean} includeCookies
1483 */
1484 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161485 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131486 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371487 }
1488
1489 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131490 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371491 */
1492 async _copyPowerShellCommand(request) {
1493 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371495 }
1496
1497 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161498 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131499 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371500 }
1501
Tim van der Lippe119690c2020-01-13 12:31:301502 /**
1503 * @override
1504 * @return {!Promise}
1505 */
Joey Arhar0e1093c2019-05-21 00:34:221506 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331507 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131508 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371509 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131510 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371511
Tim van der Lippe1d6e57a2019-09-30 11:55:341512 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371513 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341514 }
Blink Reformat4c46d092018-04-07 15:32:371515
Tim van der Lippe0ed1d2b2020-02-04 13:45:131516 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371517 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301518 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371519 progressIndicator.done();
1520 stream.close();
1521 }
1522
1523 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131524 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Paul Lewis5a922e72020-01-24 11:58:081525 self.SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341526 }
Blink Reformat4c46d092018-04-07 15:32:371527 }
1528
1529 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131530 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Paul Lewis5a922e72020-01-24 11:58:081531 self.SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341532 }
Blink Reformat4c46d092018-04-07 15:32:371533 }
1534
1535 _removeAllHighlights() {
1536 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341537 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131538 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341539 }
Blink Reformat4c46d092018-04-07 15:32:371540 this._highlightedSubstringChanges = [];
1541 }
1542
1543 /**
Tim van der Lippe119690c2020-01-13 12:31:301544 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371545 * @return {boolean}
1546 */
1547 _applyFilter(node) {
1548 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341549 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371550 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341551 }
Blink Reformat4c46d092018-04-07 15:32:371552 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341553 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371554 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341555 }
1556 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371557 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341558 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131559 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.IssuesModel.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371560 return false;
1561 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341562 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371563 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341564 }
Blink Reformat4c46d092018-04-07 15:32:371565 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341566 if (!this._filters[i](request)) {
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 }
1570 return true;
1571 }
1572
1573 /**
1574 * @param {string} query
1575 */
1576 _parseFilterQuery(query) {
1577 const descriptors = this._filterParser.parse(query);
1578 this._filters = descriptors.map(descriptor => {
1579 const key = descriptor.key;
1580 const text = descriptor.text || '';
1581 const regex = descriptor.regex;
1582 let filter;
1583 if (key) {
1584 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581585 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1586 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371587 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581588 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371589 } else {
Paul Lewis56509652019-12-06 12:51:581590 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371591 }
Paul Lewis56509652019-12-06 12:51:581592 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371593 });
1594 }
1595
1596 /**
Paul Lewis56509652019-12-06 12:51:581597 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371598 * @param {string} value
1599 * @return {?Network.NetworkLogView.Filter}
1600 */
1601 _createSpecialFilter(type, value) {
1602 switch (type) {
Paul Lewis56509652019-12-06 12:51:581603 case FilterType.Domain:
1604 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371605
Paul Lewis56509652019-12-06 12:51:581606 case FilterType.HasResponseHeader:
1607 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371608
Paul Lewis56509652019-12-06 12:51:581609 case FilterType.Is:
1610 if (value.toLowerCase() === IsFilterType.Running) {
1611 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341612 }
Paul Lewis56509652019-12-06 12:51:581613 if (value.toLowerCase() === IsFilterType.FromCache) {
1614 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341615 }
Paul Lewis56509652019-12-06 12:51:581616 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1617 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341618 }
Paul Lewis56509652019-12-06 12:51:581619 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1620 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341621 }
Blink Reformat4c46d092018-04-07 15:32:371622 break;
1623
Paul Lewis56509652019-12-06 12:51:581624 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371625 return this._createSizeFilter(value.toLowerCase());
1626
Paul Lewis56509652019-12-06 12:51:581627 case FilterType.Method:
1628 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371629
Paul Lewis56509652019-12-06 12:51:581630 case FilterType.MimeType:
1631 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371632
Paul Lewis56509652019-12-06 12:51:581633 case FilterType.MixedContent:
1634 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371635
Paul Lewis56509652019-12-06 12:51:581636 case FilterType.Scheme:
1637 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371638
Paul Lewis56509652019-12-06 12:51:581639 case FilterType.SetCookieDomain:
1640 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371641
Paul Lewis56509652019-12-06 12:51:581642 case FilterType.SetCookieName:
1643 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371644
Paul Lewis56509652019-12-06 12:51:581645 case FilterType.SetCookieValue:
1646 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371647
Jan Scheffler341eea52019-12-12 09:08:411648 case FilterType.CookieDomain:
1649 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1650
1651 case FilterType.CookieName:
1652 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1653
1654 case FilterType.CookieValue:
1655 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1656
Paul Lewis56509652019-12-06 12:51:581657 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501658 return NetworkLogView._requestPriorityFilter.bind(
1659 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371660
Paul Lewis56509652019-12-06 12:51:581661 case FilterType.StatusCode:
1662 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371663 }
1664 return null;
1665 }
1666
1667 /**
1668 * @param {string} value
1669 * @return {?Network.NetworkLogView.Filter}
1670 */
1671 _createSizeFilter(value) {
1672 let multiplier = 1;
1673 if (value.endsWith('k')) {
1674 multiplier = 1024;
1675 value = value.substring(0, value.length - 1);
1676 } else if (value.endsWith('m')) {
1677 multiplier = 1024 * 1024;
1678 value = value.substring(0, value.length - 1);
1679 }
1680 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341681 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371682 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341683 }
Paul Lewis56509652019-12-06 12:51:581684 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371685 }
1686
1687 _filterRequests() {
1688 this._removeAllHighlights();
1689 this._invalidateAllItems();
1690 }
1691
1692 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131693 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301694 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371695 */
1696 _reveal(request) {
1697 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581698 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341699 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371700 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341701 }
Blink Reformat4c46d092018-04-07 15:32:371702 node.reveal();
1703 return node;
1704 }
1705
1706 /**
Tim van der Lippe119690c2020-01-13 12:31:301707 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131708 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371709 */
1710 revealAndHighlightRequest(request) {
1711 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341712 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371713 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341714 }
Blink Reformat4c46d092018-04-07 15:32:371715 }
1716
1717 /**
Tim van der Lippe119690c2020-01-13 12:31:301718 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131719 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371720 */
1721 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141722 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371723 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341724 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371725 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341726 }
Blink Reformat4c46d092018-04-07 15:32:371727 }
1728
Tim van der Lippe119690c2020-01-13 12:31:301729 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371730 removeAllNodeHighlights() {
1731 if (this._highlightedNode) {
1732 this._highlightedNode.element().classList.remove('highlighted-row');
1733 this._highlightedNode = null;
1734 }
1735 }
1736
1737 /**
Tim van der Lippe119690c2020-01-13 12:31:301738 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371739 */
1740 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131741 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371742 this._highlightedNode = node;
1743 }
1744
1745 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131746 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1747 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131748 */
1749 _filterOutBlobRequests(requests) {
1750 return requests.filter(request => !request.isBlobRequest());
1751 }
1752
1753 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131754 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291755 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371756 * @return {!Promise<string>}
1757 */
Jan Scheffler7c50d1f2019-12-17 13:33:291758 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371759 const ignoredHeaders = {
1760 // Internal headers
1761 'method': 1,
1762 'path': 1,
1763 'scheme': 1,
1764 'version': 1,
1765
1766 // Unsafe headers
1767 // Keep this list synchronized with src/net/http/http_util.cc
1768 'accept-charset': 1,
1769 'accept-encoding': 1,
1770 'access-control-request-headers': 1,
1771 'access-control-request-method': 1,
1772 'connection': 1,
1773 'content-length': 1,
1774 'cookie': 1,
1775 'cookie2': 1,
1776 'date': 1,
1777 'dnt': 1,
1778 'expect': 1,
1779 'host': 1,
1780 'keep-alive': 1,
1781 'origin': 1,
1782 'referer': 1,
1783 'te': 1,
1784 'trailer': 1,
1785 'transfer-encoding': 1,
1786 'upgrade': 1,
1787 'via': 1,
1788 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1789 'user-agent': 1
1790 };
1791
1792 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1793
1794 const url = JSON.stringify(request.url());
1795
1796 const requestHeaders = request.requestHeaders();
1797 const headerData = requestHeaders.reduce((result, header) => {
1798 const name = header.name;
1799
Tim van der Lippe1d6e57a2019-09-30 11:55:341800 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371801 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341802 }
Blink Reformat4c46d092018-04-07 15:32:371803
1804 return result;
1805 }, new Headers());
1806
1807 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341808 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411809 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341810 }
Blink Reformat4c46d092018-04-07 15:32:371811
1812 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411813 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1814 'include' :
1815 'omit';
Blink Reformat4c46d092018-04-07 15:32:371816
1817 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1818
1819 const referrer = referrerHeader ? referrerHeader.value : void 0;
1820
1821 const referrerPolicy = request.referrerPolicy() || void 0;
1822
1823 const requestBody = await request.requestFormData();
1824
1825 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411826 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371827 referrer,
1828 referrerPolicy,
1829 body: requestBody,
1830 method: request.requestMethod,
1831 mode: 'cors'
1832 };
1833
Jan Scheffler7c50d1f2019-12-17 13:33:291834 if (includeCookies) {
1835 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1836 if (cookieHeader) {
1837 fetchOptions.headers = {
1838 ...headers,
1839 'cookie': cookieHeader.value,
1840 };
1841 }
1842 } else {
1843 fetchOptions.credentials = credentials;
1844 }
1845
Jan Scheffler172d5212020-01-02 14:42:561846 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371847 return `fetch(${url}, ${options});`;
1848 }
1849
1850 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131851 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291852 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131853 * @return {!Promise<string>}
1854 */
Jan Scheffler7c50d1f2019-12-17 13:33:291855 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131856 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291857 const commands =
1858 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131859 return commands.join(' ;\n');
1860 }
1861
1862 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131863 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371864 * @param {string} platform
1865 * @return {!Promise<string>}
1866 */
1867 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561868 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361869 // Most of these headers are derived from the URL and are automatically added by cURL.
1870 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1871 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371872
1873 function escapeStringWin(str) {
1874 /* If there are no new line characters do not escape the " characters
1875 since it only uglifies the command.
1876
1877 Because cmd.exe parser and MS Crt arguments parsers use some of the
1878 same escape characters, they can interact with each other in
1879 horrible ways, the order of operations is critical.
1880
1881 Replace \ with \\ first because it is an escape character for certain
1882 conditions in both parsers.
1883
1884 Replace all " with \" to ensure the first parser does not remove it.
1885
1886 Then escape all characters we are not sure about with ^ to ensure it
1887 gets to MS Crt parser safely.
1888
1889 The % character is special because MS Crt parser will try and look for
1890 ENV variables and fill them in it's place. We cannot escape them with %
1891 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1892 parser); So we can get cmd.exe parser to escape the character after it,
1893 if it is followed by a valid beginning character of an ENV variable.
1894 This ensures we do not try and double escape another ^ if it was placed
1895 by the previous replace.
1896
1897 Lastly we replace new lines with ^ and TWO new lines because the first
1898 new line is there to enact the escape command the second is the character
1899 to escape (in this case new line).
1900 */
1901 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1902 return encapsChars +
1903 str.replace(/\\/g, '\\\\')
1904 .replace(/"/g, '\\"')
1905 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1906 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1907 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1908 encapsChars;
1909 }
1910
1911 /**
1912 * @param {string} str
1913 * @return {string}
1914 */
1915 function escapeStringPosix(str) {
1916 /**
1917 * @param {string} x
1918 * @return {string}
1919 */
1920 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221921 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121922 let hexString = code.toString(16);
1923 // Zero pad to four digits to comply with ANSI-C Quoting:
1924 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341925 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121926 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341927 }
Joey Arhar2d21f712019-05-20 21:07:121928
1929 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371930 }
1931
Joey Arhar512e3742019-01-25 21:33:541932 if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371933 // Use ANSI-C quoting syntax.
1934 return '$\'' +
1935 str.replace(/\\/g, '\\\\')
1936 .replace(/\'/g, '\\\'')
1937 .replace(/\n/g, '\\n')
1938 .replace(/\r/g, '\\r')
Joey Arhar512e3742019-01-25 21:33:541939 .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371940 '\'';
1941 } else {
1942 // Use single quote syntax.
1943 return '\'' + str + '\'';
1944 }
1945 }
1946
1947 // cURL command expected to run on the same platform that DevTools run
1948 // (it may be different from the inspected page platform).
1949 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1950
1951 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1952
1953 let inferredMethod = 'GET';
1954 const data = [];
1955 const requestContentType = request.requestContentType();
1956 const formData = await request.requestFormData();
1957 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:271958 // Note that formData is not necessarily urlencoded because it might for example
1959 // come from a fetch request made with an explicitly unencoded body.
1960 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371961 ignoredHeaders['content-length'] = true;
1962 inferredMethod = 'POST';
1963 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561964 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371965 ignoredHeaders['content-length'] = true;
1966 inferredMethod = 'POST';
1967 }
1968
1969 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291970 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371971 }
1972
1973 const requestHeaders = request.requestHeaders();
1974 for (let i = 0; i < requestHeaders.length; i++) {
1975 const header = requestHeaders[i];
1976 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341977 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371978 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341979 }
Jan Scheffler172d5212020-01-02 14:42:561980 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371981 }
1982 command = command.concat(data);
1983 command.push('--compressed');
1984
Tim van der Lippe1d6e57a2019-09-30 11:55:341985 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371986 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341987 }
Jan Scheffler172d5212020-01-02 14:42:561988 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:371989 }
1990
1991 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131992 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:131993 * @param {string} platform
1994 * @return {!Promise<string>}
1995 */
1996 async _generateAllCurlCommand(requests, platform) {
1997 const nonBlobRequests = this._filterOutBlobRequests(requests);
1998 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:341999 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132000 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342001 } else {
Harley Libcf41f92018-09-10 18:01:132002 return commands.join(' ;\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342003 }
Harley Libcf41f92018-09-10 18:01:132004 }
2005
2006 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132007 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372008 * @return {!Promise<string>}
2009 */
2010 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562011 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372012 const ignoredHeaders =
2013 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2014
2015 /**
2016 * @param {string} str
2017 * @return {string}
2018 */
2019 function escapeString(str) {
2020 return '"' +
2021 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2022 }
2023
Jan Scheffler172d5212020-01-02 14:42:562024 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372025
2026 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562027 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372028 }
2029
2030 const requestHeaders = request.requestHeaders();
2031 const headerNameValuePairs = [];
2032 for (const header of requestHeaders) {
2033 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342034 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372035 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342036 }
Blink Reformat4c46d092018-04-07 15:32:372037 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2038 }
2039 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562040 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372041 }
2042
2043 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2044 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562045 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372046 }
2047
2048 const formData = await request.requestFormData();
2049 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372050 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342051 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562052 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342053 } else {
Jan Scheffler172d5212020-01-02 14:42:562054 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342055 }
Blink Reformat4c46d092018-04-07 15:32:372056 }
2057
Jan Scheffler172d5212020-01-02 14:42:562058 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372059 }
Harley Libcf41f92018-09-10 18:01:132060
2061 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132062 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132063 * @return {!Promise<string>}
2064 */
2065 async _generateAllPowerShellCommand(requests) {
2066 const nonBlobRequests = this._filterOutBlobRequests(requests);
2067 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2068 return commands.join(';\r\n');
2069 }
Joey Arhara86c14e2019-03-12 03:20:502070
2071 /**
2072 * @return {string}
2073 */
2074 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552075 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502076 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342077 }
Joey Arhara86c14e2019-03-12 03:20:502078 return '#0867CB';
2079 }
2080
2081 /**
2082 * @return {string}
2083 */
2084 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132085 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502086 }
Paul Lewis56509652019-12-06 12:51:582087}
Blink Reformat4c46d092018-04-07 15:32:372088
Tim van der Lippe119690c2020-01-13 12:31:302089export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582090export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372091
Paul Lewis56509652019-12-06 12:51:582092export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372093 'http': true,
2094 'https': true,
2095 'ws': true,
2096 'wss': true
2097};
2098
Blink Reformat4c46d092018-04-07 15:32:372099/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582100export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372101 Domain: 'domain',
2102 HasResponseHeader: 'has-response-header',
2103 Is: 'is',
2104 LargerThan: 'larger-than',
2105 Method: 'method',
2106 MimeType: 'mime-type',
2107 MixedContent: 'mixed-content',
2108 Priority: 'priority',
2109 Scheme: 'scheme',
2110 SetCookieDomain: 'set-cookie-domain',
2111 SetCookieName: 'set-cookie-name',
2112 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412113 CookieDomain: 'cookie-domain',
2114 CookieName: 'cookie-name',
2115 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372116 StatusCode: 'status-code'
2117};
2118
2119/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582120export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372121 All: 'all',
2122 Displayed: 'displayed',
2123 Blocked: 'blocked',
2124 BlockOverridden: 'block-overridden'
2125};
2126
2127/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582128export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372129 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052130 FromCache: 'from-cache',
2131 ServiceWorkerIntercepted: 'service-worker-intercepted',
2132 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372133};
2134
2135/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582136export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372137
2138/**
2139 * @interface
2140 */
Paul Lewis56509652019-12-06 12:51:582141export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372142 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132143 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302144 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372145 */
Paul Lewis56509652019-12-06 12:51:582146 groupNodeForRequest(request) {
2147 }
Blink Reformat4c46d092018-04-07 15:32:372148
Paul Lewis56509652019-12-06 12:51:582149 reset() {
2150 }
2151}