blob: 3495e03c83c6be459b5690a7bb2344943fe68045 [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';
Sigurd Schneiderba818512020-04-29 10:54:3732import * as BrowserSDK from '../browser_sdk/browser_sdk.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1333import * as Common from '../common/common.js';
34import * as Components from '../components/components.js';
35import * as DataGrid from '../data_grid/data_grid.js';
36import * as HARImporter from '../har_importer/har_importer.js';
37import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5038import * as PerfUI from '../perf_ui/perf_ui.js';
Jack Franklin9c225ca2020-04-29 09:55:1739import * as Platform from '../platform/platform.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1340import * as SDK from '../sdk/sdk.js';
41import * as TextUtils from '../text_utils/text_utils.js';
42import * as UI from '../ui/ui.js';
43
Tim van der Lippe119690c2020-01-13 12:31:3044import {HARWriter} from './HARWriter.js';
45import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
46import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
47import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
48import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
49
Blink Reformat4c46d092018-04-07 15:32:3750/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1351 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3052 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3753 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3755 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3757 * @param {!Element} progressBarContainer
Tim van der Lippe0ed1d2b2020-02-04 13:45:1358 * @param {!Common.Settings.Setting} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3759 */
60 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
61 super();
62 this.setMinimumSize(50, 64);
63 this.registerRequiredCSS('network/networkLogView.css');
64
65 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0566 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3767
Paul Lewis2d7d65c2020-03-16 17:26:3068 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
69 this._networkShowIssuesOnlySetting =
70 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
71 this._networkOnlyBlockedRequestsSetting =
72 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
73 this._networkResourceTypeFiltersSetting =
74 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3775
76 this._rawRowHeight = 0;
77 this._progressBarContainer = progressBarContainer;
78 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
79 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
80
81 /**
Paul Lewis56509652019-12-06 12:51:5882 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3783 */
84 function updateRowHeight() {
85 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
86 this._rowHeight = this._computeRowHeight();
87 }
88 this._rawRowHeight = 0;
89 this._rowHeight = 0;
90 updateRowHeight.call(this);
91
Tim van der Lippe119690c2020-01-13 12:31:3092 /** @type {!NetworkTransferTimeCalculator} */
93 this._timeCalculator = new NetworkTransferTimeCalculator();
94 /** @type {!NetworkTransferDurationCalculator} */
95 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3796 this._calculator = this._timeCalculator;
97
Tim van der Lippe119690c2020-01-13 12:31:3098 this._columns =
99 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37100 this._columns.show(this.element);
101
Tim van der Lippe0ed1d2b2020-02-04 13:45:13102 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37103 this._staleRequests = new Set();
104 /** @type {number} */
105 this._mainRequestLoadTime = -1;
106 /** @type {number} */
107 this._mainRequestDOMContentLoadedTime = -1;
108 this._highlightedSubstringChanges = [];
109
Tim van der Lippeb1f2b6c2020-02-17 13:00:16110 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16112 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37113 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30114 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37115 this._hoveredNode = null;
116 /** @type {?Element} */
117 this._recordingHint = null;
118 /** @type {?number} */
119 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30120 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37121 this._highlightedNode = null;
122
Tim van der Lippe0ed1d2b2020-02-04 13:45:13123 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37124
125 this._recording = false;
126 this._needsRefresh = false;
127
128 this._headerHeight = 0;
129
Paul Lewis56509652019-12-06 12:51:58130 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37131 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30132 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37133
Paul Lewis56509652019-12-06 12:51:58134 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37135 this._activeGroupLookup = null;
136
Tim van der Lippe0ed1d2b2020-02-04 13:45:13137 this._textFilterUI = new UI.FilterBar.TextFilterUI();
138 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37139 filterBar.addFilter(this._textFilterUI);
140
Tim van der Lippe0ed1d2b2020-02-04 13:45:13141 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
142 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
143 this._dataURLFilterUI.addEventListener(
144 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48145 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37146 filterBar.addFilter(this._dataURLFilterUI);
147
148 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13149 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37150 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13151 this._resourceCategoryFilterUI =
152 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20153 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37154 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13155 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37156 filterBar.addFilter(this._resourceCategoryFilterUI);
157
Tim van der Lippe0ed1d2b2020-02-04 13:45:13158 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
159 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
160 this._onlyIssuesFilterUI.addEventListener(
161 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41162 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37163 filterBar.addFilter(this._onlyIssuesFilterUI);
164
Sigurd Schneidera2afe0b2020-03-03 15:27:13165 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
166 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
167 this._onlyBlockedRequestsUI.addEventListener(
168 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
169 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
170 filterBar.addFilter(this._onlyBlockedRequestsUI);
171
Jan Scheffler1ae7c9e2019-12-03 15:48:37172
Tim van der Lippe0ed1d2b2020-02-04 13:45:13173 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
174 this._suggestionBuilder =
175 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37176 this._resetSuggestionBuilder();
177
178 this._dataGrid = this._columns.dataGrid();
179 this._setupDataGrid();
180 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49181 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13182 UI.Toolbar.ToolbarButton.Events.Click,
183 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37184
Tim van der Lippe0ed1d2b2020-02-04 13:45:13185 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37186
Tim van der Lippe0ed1d2b2020-02-04 13:45:13187 new UI.DropTarget.DropTarget(
188 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
189 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37190
Paul Lewis2d7d65c2020-03-16 17:26:30191 Common.Settings.Settings.instance()
192 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37193 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
194
Paul Lewisdaac1062020-03-05 14:37:10195 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Paul Lewisca3665d2020-01-24 13:31:16196 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
197 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
198 self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37199
200 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30201 Common.Settings.Settings.instance()
202 .moduleSetting('network.group-by-frame')
203 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37204
205 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37206 }
207
Blink Reformat4c46d092018-04-07 15:32:37208 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30209 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37210 this._setGrouping(value ? 'Frame' : null);
211 }
212
213 /**
214 * @param {string} key
215 * @param {!Array<string>} values
216 */
217 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58218 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37219 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50220 const aPriority =
221 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
222 const bPriority =
223 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
224 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
225 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37226 });
227 } else {
228 values.sort();
229 }
230 }
231
232 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16233 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13234 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37235 * @return {boolean}
236 */
237 static _negativeFilter(filter, request) {
238 return !filter(request);
239 }
240
241 /**
242 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13243 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37244 * @return {boolean}
245 */
246 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34247 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37248 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34249 }
Blink Reformat4c46d092018-04-07 15:32:37250
251 return regex.test(request.path() + '/' + request.name());
252 }
253
254 /**
255 * @param {string} domain
256 * @return {!Array.<string>}
257 */
258 static _subdomains(domain) {
259 const result = [domain];
260 let indexOfPeriod = domain.indexOf('.');
261 while (indexOfPeriod !== -1) {
262 result.push('*' + domain.substring(indexOfPeriod));
263 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
264 }
265 return result;
266 }
267
268 /**
269 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16270 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37271 */
272 static _createRequestDomainFilter(value) {
273 /**
274 * @param {string} string
275 * @return {string}
276 */
277 function escapeForRegExp(string) {
278 return string.escapeForRegExp();
279 }
280 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58281 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37282 }
283
284 /**
285 * @param {!RegExp} regex
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 _requestDomainFilter(regex, request) {
290 return regex.test(request.domain);
291 }
292
293 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13294 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37295 * @return {boolean}
296 */
297 static _runningRequestFilter(request) {
298 return !request.finished;
299 }
300
301 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13302 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37303 * @return {boolean}
304 */
305 static _fromCacheRequestFilter(request) {
306 return request.cached();
307 }
308
309 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13310 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05311 * @return {boolean}
312 */
313 static _interceptedByServiceWorkerFilter(request) {
314 return request.fetchedViaServiceWorker;
315 }
316
317 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13318 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05319 * @return {boolean}
320 */
321 static _initiatedByServiceWorkerFilter(request) {
322 return request.initiatedByServiceWorker();
323 }
324
325 /**
Blink Reformat4c46d092018-04-07 15:32:37326 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13327 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37328 * @return {boolean}
329 */
330 static _requestResponseHeaderFilter(value, request) {
331 return request.responseHeaderValue(value) !== undefined;
332 }
333
334 /**
335 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13336 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37337 * @return {boolean}
338 */
339 static _requestMethodFilter(value, request) {
340 return request.requestMethod === value;
341 }
342
343 /**
344 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13345 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37346 * @return {boolean}
347 */
348 static _requestPriorityFilter(value, request) {
349 return request.priority() === value;
350 }
351
352 /**
353 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13354 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37355 * @return {boolean}
356 */
357 static _requestMimeTypeFilter(value, request) {
358 return request.mimeType === value;
359 }
360
361 /**
Paul Lewis56509652019-12-06 12:51:58362 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13363 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37364 * @return {boolean}
365 */
366 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58367 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37368 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28369 }
370 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37371 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28372 }
373 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37374 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28375 }
376 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37377 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34378 }
Blink Reformat4c46d092018-04-07 15:32:37379
380 return false;
381 }
382
383 /**
384 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13385 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37386 * @return {boolean}
387 */
388 static _requestSchemeFilter(value, request) {
389 return request.scheme === value;
390 }
391
392 /**
393 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13394 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37395 * @return {boolean}
396 */
Jan Scheffler341eea52019-12-12 09:08:41397 static _requestCookieDomainFilter(value, request) {
398 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
399 }
400
401 /**
402 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13403 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41404 * @return {boolean}
405 */
406 static _requestCookieNameFilter(value, request) {
407 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
408 }
409
410 /**
411 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13412 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41413 * @return {boolean}
414 */
Simon Zündc9759102020-03-25 11:24:54415 static _requestCookiePathFilter(value, request) {
416 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
417 }
418
419 /**
420 * @param {string} value
421 * @param {!SDK.NetworkRequest.NetworkRequest} request
422 * @return {boolean}
423 */
Jan Scheffler341eea52019-12-12 09:08:41424 static _requestCookieValueFilter(value, request) {
425 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
426 }
427
428 /**
429 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13430 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41431 * @return {boolean}
432 */
Blink Reformat4c46d092018-04-07 15:32:37433 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41434 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37435 }
436
437 /**
438 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13439 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37440 * @return {boolean}
441 */
442 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41443 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37444 }
445
446 /**
447 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13448 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37449 * @return {boolean}
450 */
451 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41452 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37453 }
454
455 /**
456 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13457 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37458 * @return {boolean}
459 */
460 static _requestSizeLargerThanFilter(value, request) {
461 return request.transferSize >= value;
462 }
463
464 /**
465 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13466 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37467 * @return {boolean}
468 */
469 static _statusCodeFilter(value, request) {
470 return ('' + request.statusCode) === value;
471 }
472
473 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13474 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37475 * @return {boolean}
476 */
477 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58478 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37479 }
480
481 /**
Blink Reformat4c46d092018-04-07 15:32:37482 * @param {number} windowStart
483 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13484 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37485 * @return {boolean}
486 */
487 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34488 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37489 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34490 }
491 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37492 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34493 }
Blink Reformat4c46d092018-04-07 15:32:37494 return true;
495 }
496
497 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13498 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37499 */
500 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13501 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37502 }
503
504 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13505 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37506 */
507 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13508 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37509 }
510
511 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13512 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37513 */
514 static async _copyResponse(request) {
515 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08516 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34517 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40518 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08520 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34521 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13522 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37523 }
524
525 /**
526 * @param {!DataTransfer} dataTransfer
527 */
528 _handleDrop(dataTransfer) {
529 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34530 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37531 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34532 }
Blink Reformat4c46d092018-04-07 15:32:37533 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34534 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37535 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34536 }
Blink Reformat4c46d092018-04-07 15:32:37537
Joey Arhar0e1093c2019-05-21 00:34:22538 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37539 }
540
541 /**
Tim van der Lippe119690c2020-01-13 12:31:30542 * @override
Blink Reformat4c46d092018-04-07 15:32:37543 * @param {!File} file
544 */
Joey Arhar0e1093c2019-05-21 00:34:22545 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13546 const outputStream = new Common.StringOutputStream.StringOutputStream();
547 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37548 const success = await reader.read(outputStream);
549 if (!success) {
550 this._harLoadFailed(reader.error().message);
551 return;
552 }
553 let harRoot;
554 try {
555 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13556 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37557 } catch (e) {
558 this._harLoadFailed(e);
559 return;
560 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13561 self.SDK.networkLog.importRequests(HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37562 }
563
564 /**
565 * @param {string} message
566 */
567 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36568 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37569 }
570
571 /**
572 * @param {?string} groupKey
573 */
574 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34575 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37576 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34577 }
Blink Reformat4c46d092018-04-07 15:32:37578 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
579 this._activeGroupLookup = groupLookup;
580 this._invalidateAllItems();
581 }
582
583 /**
584 * @return {number}
585 */
586 _computeRowHeight() {
587 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
588 }
589
590 /**
Tim van der Lippe119690c2020-01-13 12:31:30591 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13592 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30593 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37594 */
595 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58596 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37597 }
598
599 /**
Tim van der Lippe119690c2020-01-13 12:31:30600 * @override
Blink Reformat4c46d092018-04-07 15:32:37601 * @return {number}
602 */
603 headerHeight() {
604 return this._headerHeight;
605 }
606
607 /**
Tim van der Lippe119690c2020-01-13 12:31:30608 * @override
Blink Reformat4c46d092018-04-07 15:32:37609 * @param {boolean} recording
610 */
611 setRecording(recording) {
612 this._recording = recording;
613 this._updateSummaryBar();
614 }
615
616 /**
617 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13618 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37619 */
620 modelAdded(networkManager) {
621 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34622 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37623 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34624 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13625 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37626 if (resourceTreeModel) {
627 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
628 resourceTreeModel.addEventListener(
629 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
630 }
631 }
632
633 /**
634 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13635 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37636 */
637 modelRemoved(networkManager) {
638 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13639 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37640 if (resourceTreeModel) {
641 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
642 resourceTreeModel.removeEventListener(
643 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
644 }
645 }
646 }
647
648 /**
Tim van der Lippe119690c2020-01-13 12:31:30649 * @override
Blink Reformat4c46d092018-04-07 15:32:37650 * @param {number} start
651 * @param {number} end
652 */
653 setWindow(start, end) {
654 if (!start && !end) {
655 this._timeFilter = null;
656 this._timeCalculator.setWindow(null);
657 } else {
Paul Lewis56509652019-12-06 12:51:58658 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30659 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37660 }
661 this._filterRequests();
662 }
663
Tim van der Lippe119690c2020-01-13 12:31:30664 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05665 resetFocus() {
666 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37667 }
668
669 _resetSuggestionBuilder() {
670 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58671 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
672 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
673 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
674 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
675 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
676 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
677 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37678 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
679 }
680
681 /**
Tim van der Lippec02a97c2020-02-14 14:39:27682 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37683 */
684 _filterChanged(event) {
685 this.removeAllNodeHighlights();
686 this._parseFilterQuery(this._textFilterUI.value());
687 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37688 }
689
Rajasekar Murugan3ad369e2020-02-19 18:20:12690 async resetFilter() {
691 this._textFilterUI.clear();
692 }
693
Blink Reformat4c46d092018-04-07 15:32:37694 _showRecordingHint() {
695 this._hideRecordingHint();
696 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
697 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18698
699 let reloadShortcutNode = null;
Jack Lynchb8fb3c72020-04-21 05:36:16700 const reloadShortcut = self.UI.shortcutRegistry.shortcutsForAction('inspector_main.reload')[0];
701 if (reloadShortcut) {
Joey Arhar0585e6f2018-10-30 23:11:18702 reloadShortcutNode = this._recordingHint.createChild('b');
Jack Lynchb8fb3c72020-04-21 05:36:16703 reloadShortcutNode.textContent = reloadShortcut.title();
Joey Arhar0585e6f2018-10-30 23:11:18704 }
Blink Reformat4c46d092018-04-07 15:32:37705
706 if (this._recording) {
707 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38708 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18709 if (reloadShortcutNode) {
710 hintText.createChild('br');
711 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13712 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18713 }
Blink Reformat4c46d092018-04-07 15:32:37714 } else {
715 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40716 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18717 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13718 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18719 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
720 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13721 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18722 }
Blink Reformat4c46d092018-04-07 15:32:37723 }
Kayce Basques5444c1b2019-02-15 20:32:53724 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13725 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53726 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
727 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11728
729 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57730 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37731 }
732
733 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11734 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34735 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37736 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34737 }
Brandon Goddardc992d522020-01-08 21:44:57738 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37739 this._recordingHint = null;
740 }
741
742 /**
Amanda Baker6761aae2019-11-05 18:59:11743 * @param {boolean} value
744 */
745 _setHidden(value) {
746 this._columns.setHidden(value);
747 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
748 }
749
750 /**
Blink Reformat4c46d092018-04-07 15:32:37751 * @override
752 * @return {!Array.<!Element>}
753 */
754 elementsToRestoreScrollPositionsFor() {
755 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34756 {
Blink Reformat4c46d092018-04-07 15:32:37757 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34758 }
Blink Reformat4c46d092018-04-07 15:32:37759 return [this._dataGrid.scrollContainer];
760 }
761
Tim van der Lippe119690c2020-01-13 12:31:30762 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37763 columnExtensionResolved() {
764 this._invalidateAllItems(true);
765 }
766
767 _setupDataGrid() {
768 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
769 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34770 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37771 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34772 }
Blink Reformat4c46d092018-04-07 15:32:37773 });
774 this._dataGrid.setStickToBottom(true);
775 this._dataGrid.setName('networkLog');
776 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
777 this._dataGrid.element.classList.add('network-log-grid');
778 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
779 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
780 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05781 this._dataGrid.element.addEventListener('keydown', event => {
782 if (isEnterOrSpaceKey(event)) {
Simon Zünd98419832020-03-12 06:18:15783 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true});
Brandon Goddard88d885a2019-10-31 16:11:05784 event.consume(true);
785 }
786 });
Brandon Goddard44934902020-03-25 16:03:18787 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
788 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37789 return this._dataGrid;
790 }
791
792 /**
793 * @param {!Event} event
794 */
795 _dataGridMouseMove(event) {
796 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
797 const highlightInitiatorChain = event.shiftKey;
798 this._setHoveredNode(node, highlightInitiatorChain);
799 }
800
801 /**
Tim van der Lippe119690c2020-01-13 12:31:30802 * @override
803 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37804 */
805 hoveredNode() {
806 return this._hoveredNode;
807 }
808
809 /**
Tim van der Lippe119690c2020-01-13 12:31:30810 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37811 * @param {boolean=} highlightInitiatorChain
812 */
813 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34814 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37815 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34816 }
Blink Reformat4c46d092018-04-07 15:32:37817 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34818 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37819 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34820 }
Blink Reformat4c46d092018-04-07 15:32:37821 }
822
823 /**
824 * @param {!Event} event
825 */
826 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34827 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37828 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34829 }
Blink Reformat4c46d092018-04-07 15:32:37830 }
831
832 _updateSummaryBar() {
833 this._hideRecordingHint();
834
835 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20836 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37837 let selectedNodeNumber = 0;
838 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20839 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37840 let baseTime = -1;
841 let maxTime = -1;
842
843 let nodeCount = 0;
Paul Lewisca3665d2020-01-24 13:31:16844 for (const request of self.SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58845 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34846 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37847 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34848 }
Blink Reformat4c46d092018-04-07 15:32:37849 nodeCount++;
850 const requestTransferSize = request.transferSize;
851 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20852 const requestResourceSize = request.resourceSize;
853 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30854 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37855 selectedNodeNumber++;
856 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20857 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37858 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13859 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37860 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
861 // inspected url.
862 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13863 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
864 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37865 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34866 }
867 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37868 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34869 }
Blink Reformat4c46d092018-04-07 15:32:37870 }
871
872 if (!nodeCount) {
873 this._showRecordingHint();
874 return;
875 }
876
Joey Arhara86c14e2019-03-12 03:20:50877 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37878 /**
879 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50880 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37881 * @return {!Element}
882 */
Joey Arhara86c14e2019-03-12 03:20:50883 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13884 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50885 toolbarText.setTitle(title ? title : chunk);
886 this._summaryToolbar.appendToolbarItem(toolbarText);
887 return toolbarText.element;
888 };
Blink Reformat4c46d092018-04-07 15:32:37889
890 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50891 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
892 this._summaryToolbar.appendSeparator();
893 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17894 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
895 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25896 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50897 this._summaryToolbar.appendSeparator();
898 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17899 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
900 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25901 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37902 } else {
Joey Arhara86c14e2019-03-12 03:20:50903 appendChunk(ls`${nodeCount} requests`);
904 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25905 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17906 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
907 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50908 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25909 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17910 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
911 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37912 }
Dan Beam87466b52018-12-01 18:41:20913
Blink Reformat4c46d092018-04-07 15:32:37914 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50915 this._summaryToolbar.appendSeparator();
916 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37917 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50918 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30919 const domContentLoadedText =
920 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58921 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37922 }
923 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50924 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30925 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58926 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37927 }
928 }
Blink Reformat4c46d092018-04-07 15:32:37929 }
930
Tim van der Lippe119690c2020-01-13 12:31:30931 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37932 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34933 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37934 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34935 }
Blink Reformat4c46d092018-04-07 15:32:37936
937 this._needsRefresh = true;
938
Tim van der Lippe1d6e57a2019-09-30 11:55:34939 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37940 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34941 }
Blink Reformat4c46d092018-04-07 15:32:37942 }
943
944 /**
Tim van der Lippe119690c2020-01-13 12:31:30945 * @override
Blink Reformat4c46d092018-04-07 15:32:37946 * @param {!Array<number>} times
947 */
948 addFilmStripFrames(times) {
949 this._columns.addEventDividers(times, 'network-frame-divider');
950 }
951
952 /**
Tim van der Lippe119690c2020-01-13 12:31:30953 * @override
Blink Reformat4c46d092018-04-07 15:32:37954 * @param {number} time
955 */
956 selectFilmStripFrame(time) {
957 this._columns.selectFilmStripFrame(time);
958 }
959
Tim van der Lippe119690c2020-01-13 12:31:30960 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37961 clearFilmStripFrame() {
962 this._columns.clearFilmStripFrame();
963 }
964
965 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34966 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37967 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34968 }
Blink Reformat4c46d092018-04-07 15:32:37969 }
970
971 /**
972 * @param {boolean=} deferUpdate
973 */
974 _invalidateAllItems(deferUpdate) {
Paul Lewisca3665d2020-01-24 13:31:16975 this._staleRequests = new Set(self.SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34976 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37977 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34978 } else {
Blink Reformat4c46d092018-04-07 15:32:37979 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34980 }
Blink Reformat4c46d092018-04-07 15:32:37981 }
982
983 /**
Tim van der Lippe119690c2020-01-13 12:31:30984 * @override
985 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37986 */
987 timeCalculator() {
988 return this._timeCalculator;
989 }
990
991 /**
Tim van der Lippe119690c2020-01-13 12:31:30992 * @override
993 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37994 */
995 calculator() {
996 return this._calculator;
997 }
998
999 /**
Tim van der Lippe119690c2020-01-13 12:31:301000 * @override
1001 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371002 */
1003 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341004 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371005 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 }
Blink Reformat4c46d092018-04-07 15:32:371007
1008 if (this._calculator !== x) {
1009 this._calculator = x;
1010 this._columns.setCalculator(this._calculator);
1011 }
1012 this._calculator.reset();
1013
Tim van der Lippe1d6e57a2019-09-30 11:55:341014 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371015 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341016 } else {
Blink Reformat4c46d092018-04-07 15:32:371017 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341018 }
Blink Reformat4c46d092018-04-07 15:32:371019
1020 this._invalidateAllItems();
1021 }
1022
1023 /**
Tim van der Lippec02a97c2020-02-14 14:39:271024 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371025 */
1026 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341027 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371028 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341029 }
Blink Reformat4c46d092018-04-07 15:32:371030
1031 const time = /** @type {number} */ (event.data.loadTime);
1032 if (time) {
1033 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301034 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371035 }
1036 }
1037
1038 /**
Tim van der Lippec02a97c2020-02-14 14:39:271039 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371040 */
1041 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341042 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371043 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341044 }
Blink Reformat4c46d092018-04-07 15:32:371045 const data = /** @type {number} */ (event.data);
1046 if (data) {
1047 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301048 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371049 }
1050 }
1051
1052 /**
1053 * @override
1054 */
1055 wasShown() {
1056 this._refreshIfNeeded();
1057 this._columns.wasShown();
1058 }
1059
1060 /**
1061 * @override
1062 */
1063 willHide() {
1064 this._columns.willHide();
1065 }
1066
1067 /**
1068 * @override
1069 */
1070 onResize() {
1071 this._rowHeight = this._computeRowHeight();
1072 }
1073
1074 /**
Tim van der Lippe119690c2020-01-13 12:31:301075 * @override
1076 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371077 */
1078 flatNodesList() {
1079 return this._dataGrid.rootNode().flatChildren();
1080 }
1081
Brandon Goddard44934902020-03-25 16:03:181082 _onDataGridFocus() {
1083 this.element.classList.add('grid-focused');
1084 this.updateNodeBackground();
1085 }
1086
1087 _onDataGridBlur() {
1088 this.element.classList.remove('grid-focused');
1089 this.updateNodeBackground();
1090 }
1091
Tim van der Lippe119690c2020-01-13 12:31:301092 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051093 updateNodeBackground() {
1094 if (this._dataGrid.selectedNode) {
1095 this._dataGrid.selectedNode.updateBackgroundColor();
1096 }
1097 }
1098
1099 /**
Tim van der Lippe119690c2020-01-13 12:31:301100 * @override
Brandon Goddard88d885a2019-10-31 16:11:051101 * @param {boolean} isSelected
1102 */
1103 updateNodeSelectedClass(isSelected) {
1104 if (isSelected) {
1105 this.element.classList.remove('no-node-selected');
1106 } else {
1107 this.element.classList.add('no-node-selected');
1108 }
1109 }
1110
Tim van der Lippe119690c2020-01-13 12:31:301111 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371112 stylesChanged() {
1113 this._columns.scheduleRefresh();
1114 }
1115
1116 _refresh() {
1117 this._needsRefresh = false;
1118
1119 if (this._refreshRequestId) {
1120 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1121 this._refreshRequestId = null;
1122 }
1123
1124 this.removeAllNodeHighlights();
1125
1126 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1127 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1128 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1129 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1130
Tim van der Lippe119690c2020-01-13 12:31:301131 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371132 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301133 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371134 const nodesToRefresh = [];
1135
Tim van der Lippe119690c2020-01-13 12:31:301136 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371137 const staleNodes = new Set();
1138
1139 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1140 // node so we loop until we have no more stale requests.
1141 while (this._staleRequests.size) {
1142 const request = this._staleRequests.firstValue();
1143 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581144 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341145 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371146 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341147 }
Blink Reformat4c46d092018-04-07 15:32:371148 staleNodes.add(node);
1149 }
1150
1151 for (const node of staleNodes) {
1152 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341153 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371154 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341155 }
Blink Reformat4c46d092018-04-07 15:32:371156
Tim van der Lippe1d6e57a2019-09-30 11:55:341157 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371158 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341159 }
Blink Reformat4c46d092018-04-07 15:32:371160 const request = node.request();
1161 this._timeCalculator.updateBoundaries(request);
1162 this._durationCalculator.updateBoundaries(request);
1163 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301164 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371165 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341166 }
Tim van der Lippe119690c2020-01-13 12:31:301167 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371168 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1169 if (removeFromParent) {
1170 let parent = node.parent;
1171 parent.removeChild(node);
1172 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1173 const grandparent = parent.parent;
1174 grandparent.removeChild(parent);
1175 parent = grandparent;
1176 }
1177 }
1178
Tim van der Lippe1d6e57a2019-09-30 11:55:341179 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371180 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341181 }
Blink Reformat4c46d092018-04-07 15:32:371182
1183 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1184 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1185 nodesToRefresh.push(newParent);
1186 }
1187 nodesToInsert.set(node, newParent);
1188 }
1189
Tim van der Lippe1d6e57a2019-09-30 11:55:341190 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371191 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341192 }
Blink Reformat4c46d092018-04-07 15:32:371193
Tim van der Lippe1d6e57a2019-09-30 11:55:341194 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371195 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341196 }
Blink Reformat4c46d092018-04-07 15:32:371197
1198 this._updateSummaryBar();
1199
Tim van der Lippe1d6e57a2019-09-30 11:55:341200 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371201 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341202 }
Blink Reformat4c46d092018-04-07 15:32:371203
1204 this._dataGrid.updateInstantly();
1205 this._didRefreshForTest();
1206 }
1207
1208 _didRefreshForTest() {
1209 }
1210
1211 /**
Tim van der Lippe119690c2020-01-13 12:31:301212 * @param {!NetworkRequestNode} node
1213 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371214 */
1215 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341216 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371217 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341218 }
Blink Reformat4c46d092018-04-07 15:32:371219
1220 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341221 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371222 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341223 }
Blink Reformat4c46d092018-04-07 15:32:371224 return groupNode;
1225 }
1226
1227 _reset() {
Simon Zünd98419832020-03-12 06:18:151228 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371229
1230 this._setHoveredNode(null);
1231 this._columns.reset();
1232
1233 this._timeFilter = null;
1234 this._calculator.reset();
1235
1236 this._timeCalculator.setWindow(null);
1237 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371238
Tim van der Lippe1d6e57a2019-09-30 11:55:341239 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371240 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341241 }
Blink Reformat4c46d092018-04-07 15:32:371242 this._staleRequests.clear();
1243 this._resetSuggestionBuilder();
1244
1245 this._mainRequestLoadTime = -1;
1246 this._mainRequestDOMContentLoadedTime = -1;
1247
1248 this._dataGrid.rootNode().removeChildren();
1249 this._updateSummaryBar();
1250 this._dataGrid.setStickToBottom(true);
1251 this.scheduleRefresh();
1252 }
1253
1254 /**
Tim van der Lippe119690c2020-01-13 12:31:301255 * @override
Blink Reformat4c46d092018-04-07 15:32:371256 * @param {string} filterString
1257 */
1258 setTextFilterValue(filterString) {
1259 this._textFilterUI.setValue(filterString);
1260 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371261 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131262 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371263 this._resourceCategoryFilterUI.reset();
1264 }
1265
1266 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131267 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371268 */
1269 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301270 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581271 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301272 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371273
Tim van der Lippe1d6e57a2019-09-30 11:55:341274 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371275 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 }
Blink Reformat4c46d092018-04-07 15:32:371277 return node;
1278 }
1279
1280 /**
Tim van der Lippec02a97c2020-02-14 14:39:271281 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371282 */
1283 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131284 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371285 this._refreshRequest(request);
1286 }
1287
1288 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131289 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371290 */
1291 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581292 NetworkLogView._subdomains(request.domain)
1293 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1294 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1295 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1296 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1297 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371298
1299 const priority = request.priority();
1300 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501301 this._suggestionBuilder.addItem(
1302 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371303 }
1304
1305 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581306 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371307 }
1308
1309 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581310 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371311 }
1312
1313 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581314 const suggestion =
1315 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1316 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371317 }
1318
1319 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341320 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581321 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341322 }
Jan Scheffler341eea52019-12-12 09:08:411323
1324 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581325 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1326 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1327 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371328 }
1329
Jan Scheffler341eea52019-12-12 09:08:411330 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1331 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1332 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541333 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411334 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1335 }
1336
Blink Reformat4c46d092018-04-07 15:32:371337 this._staleRequests.add(request);
1338 this.scheduleRefresh();
1339 }
1340
1341 /**
Tim van der Lippe119690c2020-01-13 12:31:301342 * @override
Blink Reformat4c46d092018-04-07 15:32:371343 * @return {number}
1344 */
1345 rowHeight() {
1346 return this._rowHeight;
1347 }
1348
1349 /**
Tim van der Lippe119690c2020-01-13 12:31:301350 * @override
Blink Reformat4c46d092018-04-07 15:32:371351 * @param {boolean} gridMode
1352 */
1353 switchViewMode(gridMode) {
1354 this._columns.switchViewMode(gridMode);
1355 }
1356
1357 /**
Tim van der Lippe119690c2020-01-13 12:31:301358 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131359 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1360 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371361 */
1362 handleContextMenuForRequest(contextMenu, request) {
1363 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131364 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371365 const footerSection = copyMenu.footerSection();
1366 if (request) {
1367 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131368 UI.UIUtils.copyLinkAddressLabel(),
1369 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1370 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371371 if (request.requestHeadersText()) {
1372 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131373 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371374 }
1375
1376 if (request.responseHeadersText) {
1377 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131378 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371379 }
1380
1381 if (request.finished) {
1382 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131383 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371384 }
1385
Harley Libcf41f92018-09-10 18:01:131386 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131387 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371388 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131389 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1390 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371391 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131392 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291393 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131394 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1395 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371396 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131397 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1398 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131399 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131400 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1401 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371402 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131403 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1404 footerSection.appendItem(
1405 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1406 footerSection.appendItem(
1407 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1408 footerSection.appendItem(
1409 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1410 footerSection.appendItem(
1411 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371412 } else {
Harley Libcf41f92018-09-10 18:01:131413 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131414 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291415 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131416 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1417 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131418 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131419 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1420 footerSection.appendItem(
1421 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1422 footerSection.appendItem(
1423 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1424 footerSection.appendItem(
1425 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371426 }
1427 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131428 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371429 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131430 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371431
Joey Arhar0e1093c2019-05-21 00:34:221432 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371433
Blink Reformat4c46d092018-04-07 15:32:371434 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131435 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1436 contextMenu.editSection().appendItem(
1437 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371438
1439 if (request) {
1440 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211441 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371442 let patterns = manager.blockedPatterns();
1443
Tim van der Lippeffa78622019-09-16 12:07:121444 /**
1445 * @param {string} url
1446 */
1447 function addBlockedURL(url) {
1448 patterns.push({enabled: true, url: url});
1449 manager.setBlockedPatterns(patterns);
1450 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261451 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121452 }
1453
1454 /**
1455 * @param {string} url
1456 */
1457 function removeBlockedURL(url) {
1458 patterns = patterns.filter(pattern => pattern.url !== url);
1459 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261460 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121461 }
1462
Blink Reformat4c46d092018-04-07 15:32:371463 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1464 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1465 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131466 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371467 } else if (urlWithoutScheme) {
1468 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1469 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131470 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371471 }
1472
1473 const domain = request.parsedURL.domain();
1474 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1475 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371477 } else if (domain) {
1478 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1479 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131480 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371481 }
1482
Tim van der Lippe0ed1d2b2020-02-04 13:45:131483 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371484 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131485 Common.UIString.UIString('Replay XHR'),
1486 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371487 }
Blink Reformat4c46d092018-04-07 15:32:371488 }
1489 }
1490
1491 _harRequests() {
Paul Lewisca3665d2020-01-24 13:31:161492 return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171493 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131494 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171495 });
Blink Reformat4c46d092018-04-07 15:32:371496 }
1497
1498 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131499 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1500 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371501 }
1502
1503 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131504 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371505 * @param {string} platform
1506 */
1507 async _copyCurlCommand(request, platform) {
1508 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131509 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371510 }
1511
1512 /**
1513 * @param {string} platform
1514 */
1515 async _copyAllCurlCommand(platform) {
Paul Lewisca3665d2020-01-24 13:31:161516 const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131517 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371518 }
1519
1520 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131521 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291522 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371523 */
Jan Scheffler7c50d1f2019-12-17 13:33:291524 async _copyFetchCall(request, includeCookies) {
1525 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131526 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371527 }
1528
Jan Scheffler7c50d1f2019-12-17 13:33:291529 /**
1530 * @param {boolean} includeCookies
1531 */
1532 async _copyAllFetchCall(includeCookies) {
Paul Lewisca3665d2020-01-24 13:31:161533 const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131534 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371535 }
1536
1537 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131538 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371539 */
1540 async _copyPowerShellCommand(request) {
1541 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131542 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371543 }
1544
1545 async _copyAllPowerShellCommand() {
Paul Lewisca3665d2020-01-24 13:31:161546 const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131547 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371548 }
1549
Tim van der Lippe119690c2020-01-13 12:31:301550 /**
1551 * @override
1552 * @return {!Promise}
1553 */
Joey Arhar0e1093c2019-05-21 00:34:221554 async exportAll() {
Paul Lewisdaac1062020-03-05 14:37:101555 const url = SDK.SDKModel.TargetManager.instance().mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131556 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371557 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131558 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371559
Tim van der Lippe1d6e57a2019-09-30 11:55:341560 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371561 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341562 }
Blink Reformat4c46d092018-04-07 15:32:371563
Tim van der Lippe0ed1d2b2020-02-04 13:45:131564 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371565 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301566 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371567 progressIndicator.done();
1568 stream.close();
1569 }
1570
1571 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211573 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341574 }
Blink Reformat4c46d092018-04-07 15:32:371575 }
1576
1577 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131578 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211579 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341580 }
Blink Reformat4c46d092018-04-07 15:32:371581 }
1582
1583 _removeAllHighlights() {
1584 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341585 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131586 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341587 }
Blink Reformat4c46d092018-04-07 15:32:371588 this._highlightedSubstringChanges = [];
1589 }
1590
1591 /**
Tim van der Lippe119690c2020-01-13 12:31:301592 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371593 * @return {boolean}
1594 */
1595 _applyFilter(node) {
1596 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341597 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371598 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341599 }
Blink Reformat4c46d092018-04-07 15:32:371600 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341601 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371602 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341603 }
1604 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371605 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341606 }
Sigurd Schneiderba818512020-04-29 10:54:371607 if (this._onlyIssuesFilterUI.checked() && !BrowserSDK.RelatedIssue.hasIssues(request)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371608 return false;
1609 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131610 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1611 return false;
1612 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341613 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371614 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341615 }
Blink Reformat4c46d092018-04-07 15:32:371616 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341617 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371618 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341619 }
Blink Reformat4c46d092018-04-07 15:32:371620 }
1621 return true;
1622 }
1623
1624 /**
1625 * @param {string} query
1626 */
1627 _parseFilterQuery(query) {
1628 const descriptors = this._filterParser.parse(query);
1629 this._filters = descriptors.map(descriptor => {
1630 const key = descriptor.key;
1631 const text = descriptor.text || '';
1632 const regex = descriptor.regex;
1633 let filter;
1634 if (key) {
1635 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581636 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1637 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371638 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581639 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371640 } else {
Paul Lewis56509652019-12-06 12:51:581641 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371642 }
Paul Lewis56509652019-12-06 12:51:581643 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371644 });
1645 }
1646
1647 /**
Paul Lewis56509652019-12-06 12:51:581648 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371649 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161650 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371651 */
1652 _createSpecialFilter(type, value) {
1653 switch (type) {
Paul Lewis56509652019-12-06 12:51:581654 case FilterType.Domain:
1655 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371656
Paul Lewis56509652019-12-06 12:51:581657 case FilterType.HasResponseHeader:
1658 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371659
Paul Lewis56509652019-12-06 12:51:581660 case FilterType.Is:
1661 if (value.toLowerCase() === IsFilterType.Running) {
1662 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 }
Paul Lewis56509652019-12-06 12:51:581664 if (value.toLowerCase() === IsFilterType.FromCache) {
1665 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341666 }
Paul Lewis56509652019-12-06 12:51:581667 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1668 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341669 }
Paul Lewis56509652019-12-06 12:51:581670 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1671 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341672 }
Blink Reformat4c46d092018-04-07 15:32:371673 break;
1674
Paul Lewis56509652019-12-06 12:51:581675 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371676 return this._createSizeFilter(value.toLowerCase());
1677
Paul Lewis56509652019-12-06 12:51:581678 case FilterType.Method:
1679 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371680
Paul Lewis56509652019-12-06 12:51:581681 case FilterType.MimeType:
1682 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371683
Paul Lewis56509652019-12-06 12:51:581684 case FilterType.MixedContent:
1685 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371686
Paul Lewis56509652019-12-06 12:51:581687 case FilterType.Scheme:
1688 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371689
Paul Lewis56509652019-12-06 12:51:581690 case FilterType.SetCookieDomain:
1691 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371692
Paul Lewis56509652019-12-06 12:51:581693 case FilterType.SetCookieName:
1694 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371695
Paul Lewis56509652019-12-06 12:51:581696 case FilterType.SetCookieValue:
1697 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371698
Jan Scheffler341eea52019-12-12 09:08:411699 case FilterType.CookieDomain:
1700 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1701
1702 case FilterType.CookieName:
1703 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1704
Simon Zündc9759102020-03-25 11:24:541705 case FilterType.CookiePath:
1706 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1707
Jan Scheffler341eea52019-12-12 09:08:411708 case FilterType.CookieValue:
1709 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1710
Paul Lewis56509652019-12-06 12:51:581711 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501712 return NetworkLogView._requestPriorityFilter.bind(
1713 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371714
Paul Lewis56509652019-12-06 12:51:581715 case FilterType.StatusCode:
1716 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371717 }
1718 return null;
1719 }
1720
1721 /**
1722 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161723 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371724 */
1725 _createSizeFilter(value) {
1726 let multiplier = 1;
1727 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411728 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371729 value = value.substring(0, value.length - 1);
1730 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411731 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371732 value = value.substring(0, value.length - 1);
1733 }
1734 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341735 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371736 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341737 }
Paul Lewis56509652019-12-06 12:51:581738 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371739 }
1740
1741 _filterRequests() {
1742 this._removeAllHighlights();
1743 this._invalidateAllItems();
1744 }
1745
1746 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131747 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301748 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371749 */
1750 _reveal(request) {
1751 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581752 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341753 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371754 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341755 }
Brandon Goddard5e4244d2020-04-08 22:08:471756 // Viewport datagrid nodes do not reveal if not in the root node
1757 // list of flatChildren. For children of grouped frame nodes:
1758 // reveal and expand parent to ensure child is revealable.
1759 if (node.parent && node.parent instanceof NetworkGroupNode) {
1760 node.parent.reveal();
1761 node.parent.expand();
1762 }
Blink Reformat4c46d092018-04-07 15:32:371763 node.reveal();
1764 return node;
1765 }
1766
1767 /**
Tim van der Lippe119690c2020-01-13 12:31:301768 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131769 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371770 */
1771 revealAndHighlightRequest(request) {
1772 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341773 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371774 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341775 }
Blink Reformat4c46d092018-04-07 15:32:371776 }
1777
1778 /**
Tim van der Lippe119690c2020-01-13 12:31:301779 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131780 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371781 */
1782 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141783 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371784 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341785 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371786 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341787 }
Blink Reformat4c46d092018-04-07 15:32:371788 }
1789
Tim van der Lippe119690c2020-01-13 12:31:301790 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371791 removeAllNodeHighlights() {
1792 if (this._highlightedNode) {
1793 this._highlightedNode.element().classList.remove('highlighted-row');
1794 this._highlightedNode = null;
1795 }
1796 }
1797
1798 /**
Tim van der Lippe119690c2020-01-13 12:31:301799 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371800 */
1801 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131802 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371803 this._highlightedNode = node;
1804 }
1805
1806 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131807 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1808 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131809 */
1810 _filterOutBlobRequests(requests) {
1811 return requests.filter(request => !request.isBlobRequest());
1812 }
1813
1814 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131815 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291816 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371817 * @return {!Promise<string>}
1818 */
Jan Scheffler7c50d1f2019-12-17 13:33:291819 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371820 const ignoredHeaders = {
1821 // Internal headers
1822 'method': 1,
1823 'path': 1,
1824 'scheme': 1,
1825 'version': 1,
1826
1827 // Unsafe headers
1828 // Keep this list synchronized with src/net/http/http_util.cc
1829 'accept-charset': 1,
1830 'accept-encoding': 1,
1831 'access-control-request-headers': 1,
1832 'access-control-request-method': 1,
1833 'connection': 1,
1834 'content-length': 1,
1835 'cookie': 1,
1836 'cookie2': 1,
1837 'date': 1,
1838 'dnt': 1,
1839 'expect': 1,
1840 'host': 1,
1841 'keep-alive': 1,
1842 'origin': 1,
1843 'referer': 1,
1844 'te': 1,
1845 'trailer': 1,
1846 'transfer-encoding': 1,
1847 'upgrade': 1,
1848 'via': 1,
1849 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1850 'user-agent': 1
1851 };
1852
1853 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1854
1855 const url = JSON.stringify(request.url());
1856
1857 const requestHeaders = request.requestHeaders();
1858 const headerData = requestHeaders.reduce((result, header) => {
1859 const name = header.name;
1860
Tim van der Lippe1d6e57a2019-09-30 11:55:341861 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371862 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341863 }
Blink Reformat4c46d092018-04-07 15:32:371864
1865 return result;
1866 }, new Headers());
1867
1868 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341869 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411870 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341871 }
Blink Reformat4c46d092018-04-07 15:32:371872
1873 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411874 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1875 'include' :
1876 'omit';
Blink Reformat4c46d092018-04-07 15:32:371877
1878 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1879
1880 const referrer = referrerHeader ? referrerHeader.value : void 0;
1881
1882 const referrerPolicy = request.referrerPolicy() || void 0;
1883
1884 const requestBody = await request.requestFormData();
1885
1886 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411887 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371888 referrer,
1889 referrerPolicy,
1890 body: requestBody,
1891 method: request.requestMethod,
1892 mode: 'cors'
1893 };
1894
Jan Scheffler7c50d1f2019-12-17 13:33:291895 if (includeCookies) {
1896 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1897 if (cookieHeader) {
1898 fetchOptions.headers = {
1899 ...headers,
1900 'cookie': cookieHeader.value,
1901 };
1902 }
1903 } else {
1904 fetchOptions.credentials = credentials;
1905 }
1906
Jan Scheffler172d5212020-01-02 14:42:561907 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371908 return `fetch(${url}, ${options});`;
1909 }
1910
1911 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131912 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291913 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131914 * @return {!Promise<string>}
1915 */
Jan Scheffler7c50d1f2019-12-17 13:33:291916 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131917 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291918 const commands =
1919 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131920 return commands.join(' ;\n');
1921 }
1922
1923 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131924 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371925 * @param {string} platform
1926 * @return {!Promise<string>}
1927 */
1928 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561929 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361930 // Most of these headers are derived from the URL and are automatically added by cURL.
1931 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1932 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371933
1934 function escapeStringWin(str) {
1935 /* If there are no new line characters do not escape the " characters
1936 since it only uglifies the command.
1937
1938 Because cmd.exe parser and MS Crt arguments parsers use some of the
1939 same escape characters, they can interact with each other in
1940 horrible ways, the order of operations is critical.
1941
1942 Replace \ with \\ first because it is an escape character for certain
1943 conditions in both parsers.
1944
1945 Replace all " with \" to ensure the first parser does not remove it.
1946
1947 Then escape all characters we are not sure about with ^ to ensure it
1948 gets to MS Crt parser safely.
1949
1950 The % character is special because MS Crt parser will try and look for
1951 ENV variables and fill them in it's place. We cannot escape them with %
1952 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1953 parser); So we can get cmd.exe parser to escape the character after it,
1954 if it is followed by a valid beginning character of an ENV variable.
1955 This ensures we do not try and double escape another ^ if it was placed
1956 by the previous replace.
1957
1958 Lastly we replace new lines with ^ and TWO new lines because the first
1959 new line is there to enact the escape command the second is the character
1960 to escape (in this case new line).
1961 */
1962 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1963 return encapsChars +
1964 str.replace(/\\/g, '\\\\')
1965 .replace(/"/g, '\\"')
1966 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1967 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1968 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1969 encapsChars;
1970 }
1971
1972 /**
1973 * @param {string} str
1974 * @return {string}
1975 */
1976 function escapeStringPosix(str) {
1977 /**
1978 * @param {string} x
1979 * @return {string}
1980 */
1981 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221982 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121983 let hexString = code.toString(16);
1984 // Zero pad to four digits to comply with ANSI-C Quoting:
1985 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341986 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121987 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341988 }
Joey Arhar2d21f712019-05-20 21:07:121989
1990 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371991 }
1992
Mathias Bynensf06e8c02020-02-28 13:58:281993 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371994 // Use ANSI-C quoting syntax.
1995 return '$\'' +
1996 str.replace(/\\/g, '\\\\')
1997 .replace(/\'/g, '\\\'')
1998 .replace(/\n/g, '\\n')
1999 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282000 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372001 '\'';
Blink Reformat4c46d092018-04-07 15:32:372002 }
Mathias Bynensf06e8c02020-02-28 13:58:282003 // Use single quote syntax.
2004 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372005 }
2006
2007 // cURL command expected to run on the same platform that DevTools run
2008 // (it may be different from the inspected page platform).
2009 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2010
2011 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2012
2013 let inferredMethod = 'GET';
2014 const data = [];
2015 const requestContentType = request.requestContentType();
2016 const formData = await request.requestFormData();
2017 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272018 // Note that formData is not necessarily urlencoded because it might for example
2019 // come from a fetch request made with an explicitly unencoded body.
2020 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372021 ignoredHeaders['content-length'] = true;
2022 inferredMethod = 'POST';
2023 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:562024 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372025 ignoredHeaders['content-length'] = true;
2026 inferredMethod = 'POST';
2027 }
2028
2029 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292030 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372031 }
2032
2033 const requestHeaders = request.requestHeaders();
2034 for (let i = 0; i < requestHeaders.length; i++) {
2035 const header = requestHeaders[i];
2036 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342037 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:372038 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342039 }
Jan Scheffler172d5212020-01-02 14:42:562040 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372041 }
2042 command = command.concat(data);
2043 command.push('--compressed');
2044
Tim van der Lippe1d6e57a2019-09-30 11:55:342045 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372046 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342047 }
Jan Scheffler172d5212020-01-02 14:42:562048 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372049 }
2050
2051 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132052 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132053 * @param {string} platform
2054 * @return {!Promise<string>}
2055 */
2056 async _generateAllCurlCommand(requests, platform) {
2057 const nonBlobRequests = this._filterOutBlobRequests(requests);
2058 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342059 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132060 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342061 }
Mathias Bynensf06e8c02020-02-28 13:58:282062 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132063 }
2064
2065 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132066 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372067 * @return {!Promise<string>}
2068 */
2069 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562070 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372071 const ignoredHeaders =
2072 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2073
2074 /**
2075 * @param {string} str
2076 * @return {string}
2077 */
2078 function escapeString(str) {
2079 return '"' +
2080 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2081 }
2082
Jan Scheffler172d5212020-01-02 14:42:562083 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372084
2085 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562086 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372087 }
2088
2089 const requestHeaders = request.requestHeaders();
2090 const headerNameValuePairs = [];
2091 for (const header of requestHeaders) {
2092 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342093 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372094 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342095 }
Blink Reformat4c46d092018-04-07 15:32:372096 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2097 }
2098 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562099 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372100 }
2101
2102 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2103 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562104 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372105 }
2106
2107 const formData = await request.requestFormData();
2108 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372109 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342110 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562111 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342112 } else {
Jan Scheffler172d5212020-01-02 14:42:562113 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342114 }
Blink Reformat4c46d092018-04-07 15:32:372115 }
2116
Jan Scheffler172d5212020-01-02 14:42:562117 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372118 }
Harley Libcf41f92018-09-10 18:01:132119
2120 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132121 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132122 * @return {!Promise<string>}
2123 */
2124 async _generateAllPowerShellCommand(requests) {
2125 const nonBlobRequests = this._filterOutBlobRequests(requests);
2126 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2127 return commands.join(';\r\n');
2128 }
Joey Arhara86c14e2019-03-12 03:20:502129
2130 /**
2131 * @return {string}
2132 */
2133 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552134 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502135 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342136 }
Joey Arhara86c14e2019-03-12 03:20:502137 return '#0867CB';
2138 }
2139
2140 /**
2141 * @return {string}
2142 */
2143 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132144 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502145 }
Paul Lewis56509652019-12-06 12:51:582146}
Blink Reformat4c46d092018-04-07 15:32:372147
Tim van der Lippe119690c2020-01-13 12:31:302148export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582149export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372150
Paul Lewis56509652019-12-06 12:51:582151export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372152 'http': true,
2153 'https': true,
2154 'ws': true,
2155 'wss': true
2156};
2157
Blink Reformat4c46d092018-04-07 15:32:372158/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582159export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372160 Domain: 'domain',
2161 HasResponseHeader: 'has-response-header',
2162 Is: 'is',
2163 LargerThan: 'larger-than',
2164 Method: 'method',
2165 MimeType: 'mime-type',
2166 MixedContent: 'mixed-content',
2167 Priority: 'priority',
2168 Scheme: 'scheme',
2169 SetCookieDomain: 'set-cookie-domain',
2170 SetCookieName: 'set-cookie-name',
2171 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412172 CookieDomain: 'cookie-domain',
2173 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542174 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412175 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372176 StatusCode: 'status-code'
2177};
2178
2179/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582180export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372181 All: 'all',
2182 Displayed: 'displayed',
2183 Blocked: 'blocked',
2184 BlockOverridden: 'block-overridden'
2185};
2186
2187/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582188export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372189 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052190 FromCache: 'from-cache',
2191 ServiceWorkerIntercepted: 'service-worker-intercepted',
2192 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372193};
2194
2195/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582196export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372197
2198/**
2199 * @interface
2200 */
Paul Lewis56509652019-12-06 12:51:582201export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372202 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132203 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302204 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372205 */
Paul Lewis56509652019-12-06 12:51:582206 groupNodeForRequest(request) {
2207 }
Blink Reformat4c46d092018-04-07 15:32:372208
Paul Lewis56509652019-12-06 12:51:582209 reset() {
2210 }
2211}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162212
2213/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2214export let Filter;