blob: ea563af9a84785128a67fa22d48ac597f36c7fe5 [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);
Wolfgang Beyerd81fad62020-05-27 12:30:27196 SDK.NetworkLog.NetworkLog.instance().addEventListener(
197 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
198 SDK.NetworkLog.NetworkLog.instance().addEventListener(
199 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
200 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37201
202 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30203 Common.Settings.Settings.instance()
204 .moduleSetting('network.group-by-frame')
205 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37206
207 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37208 }
209
Blink Reformat4c46d092018-04-07 15:32:37210 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30211 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37212 this._setGrouping(value ? 'Frame' : null);
213 }
214
215 /**
216 * @param {string} key
217 * @param {!Array<string>} values
218 */
219 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58220 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37221 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50222 const aPriority =
223 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
224 const bPriority =
225 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
226 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
227 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37228 });
229 } else {
230 values.sort();
231 }
232 }
233
234 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16235 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13236 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37237 * @return {boolean}
238 */
239 static _negativeFilter(filter, request) {
240 return !filter(request);
241 }
242
243 /**
244 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13245 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37246 * @return {boolean}
247 */
248 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34249 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37250 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34251 }
Blink Reformat4c46d092018-04-07 15:32:37252
253 return regex.test(request.path() + '/' + request.name());
254 }
255
256 /**
257 * @param {string} domain
258 * @return {!Array.<string>}
259 */
260 static _subdomains(domain) {
261 const result = [domain];
262 let indexOfPeriod = domain.indexOf('.');
263 while (indexOfPeriod !== -1) {
264 result.push('*' + domain.substring(indexOfPeriod));
265 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
266 }
267 return result;
268 }
269
270 /**
271 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16272 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37273 */
274 static _createRequestDomainFilter(value) {
275 /**
276 * @param {string} string
277 * @return {string}
278 */
279 function escapeForRegExp(string) {
280 return string.escapeForRegExp();
281 }
282 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58283 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37284 }
285
286 /**
287 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13288 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37289 * @return {boolean}
290 */
291 static _requestDomainFilter(regex, request) {
292 return regex.test(request.domain);
293 }
294
295 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13296 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37297 * @return {boolean}
298 */
299 static _runningRequestFilter(request) {
300 return !request.finished;
301 }
302
303 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13304 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37305 * @return {boolean}
306 */
307 static _fromCacheRequestFilter(request) {
308 return request.cached();
309 }
310
311 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13312 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05313 * @return {boolean}
314 */
315 static _interceptedByServiceWorkerFilter(request) {
316 return request.fetchedViaServiceWorker;
317 }
318
319 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13320 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05321 * @return {boolean}
322 */
323 static _initiatedByServiceWorkerFilter(request) {
324 return request.initiatedByServiceWorker();
325 }
326
327 /**
Blink Reformat4c46d092018-04-07 15:32:37328 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13329 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37330 * @return {boolean}
331 */
332 static _requestResponseHeaderFilter(value, request) {
333 return request.responseHeaderValue(value) !== undefined;
334 }
335
336 /**
337 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13338 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37339 * @return {boolean}
340 */
341 static _requestMethodFilter(value, request) {
342 return request.requestMethod === value;
343 }
344
345 /**
346 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13347 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37348 * @return {boolean}
349 */
350 static _requestPriorityFilter(value, request) {
351 return request.priority() === value;
352 }
353
354 /**
355 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13356 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37357 * @return {boolean}
358 */
359 static _requestMimeTypeFilter(value, request) {
360 return request.mimeType === value;
361 }
362
363 /**
Paul Lewis56509652019-12-06 12:51:58364 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13365 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37366 * @return {boolean}
367 */
368 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58369 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37370 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28371 }
372 if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37373 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28374 }
375 if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37376 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28377 }
378 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37379 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34380 }
Blink Reformat4c46d092018-04-07 15:32:37381
382 return false;
383 }
384
385 /**
386 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13387 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37388 * @return {boolean}
389 */
390 static _requestSchemeFilter(value, request) {
391 return request.scheme === value;
392 }
393
394 /**
395 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13396 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37397 * @return {boolean}
398 */
Jan Scheffler341eea52019-12-12 09:08:41399 static _requestCookieDomainFilter(value, request) {
400 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
401 }
402
403 /**
404 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13405 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41406 * @return {boolean}
407 */
408 static _requestCookieNameFilter(value, request) {
409 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
410 }
411
412 /**
413 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13414 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41415 * @return {boolean}
416 */
Simon Zündc9759102020-03-25 11:24:54417 static _requestCookiePathFilter(value, request) {
418 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
419 }
420
421 /**
422 * @param {string} value
423 * @param {!SDK.NetworkRequest.NetworkRequest} request
424 * @return {boolean}
425 */
Jan Scheffler341eea52019-12-12 09:08:41426 static _requestCookieValueFilter(value, request) {
427 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
428 }
429
430 /**
431 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13432 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41433 * @return {boolean}
434 */
Blink Reformat4c46d092018-04-07 15:32:37435 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41436 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37437 }
438
439 /**
440 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13441 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37442 * @return {boolean}
443 */
444 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41445 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37446 }
447
448 /**
449 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13450 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37451 * @return {boolean}
452 */
453 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41454 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37455 }
456
457 /**
458 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13459 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37460 * @return {boolean}
461 */
462 static _requestSizeLargerThanFilter(value, request) {
463 return request.transferSize >= value;
464 }
465
466 /**
467 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13468 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37469 * @return {boolean}
470 */
471 static _statusCodeFilter(value, request) {
472 return ('' + request.statusCode) === value;
473 }
474
475 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13476 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37477 * @return {boolean}
478 */
479 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58480 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37481 }
482
483 /**
Blink Reformat4c46d092018-04-07 15:32:37484 * @param {number} windowStart
485 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13486 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37487 * @return {boolean}
488 */
489 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34490 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37491 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34492 }
493 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37494 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34495 }
Blink Reformat4c46d092018-04-07 15:32:37496 return true;
497 }
498
499 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13500 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37501 */
502 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13503 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37504 }
505
506 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13507 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37508 */
509 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13510 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37511 }
512
513 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13514 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37515 */
516 static async _copyResponse(request) {
517 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08518 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40520 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34521 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08522 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34523 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13524 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37525 }
526
527 /**
528 * @param {!DataTransfer} dataTransfer
529 */
530 _handleDrop(dataTransfer) {
531 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34532 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37533 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34534 }
Blink Reformat4c46d092018-04-07 15:32:37535 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34536 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37537 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34538 }
Blink Reformat4c46d092018-04-07 15:32:37539
Joey Arhar0e1093c2019-05-21 00:34:22540 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37541 }
542
543 /**
Tim van der Lippe119690c2020-01-13 12:31:30544 * @override
Blink Reformat4c46d092018-04-07 15:32:37545 * @param {!File} file
546 */
Joey Arhar0e1093c2019-05-21 00:34:22547 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13548 const outputStream = new Common.StringOutputStream.StringOutputStream();
549 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37550 const success = await reader.read(outputStream);
551 if (!success) {
552 this._harLoadFailed(reader.error().message);
553 return;
554 }
555 let harRoot;
556 try {
557 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13558 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37559 } catch (e) {
560 this._harLoadFailed(e);
561 return;
562 }
Wolfgang Beyerd81fad62020-05-27 12:30:27563 SDK.NetworkLog.NetworkLog.instance().importRequests(
564 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37565 }
566
567 /**
568 * @param {string} message
569 */
570 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36571 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37572 }
573
574 /**
575 * @param {?string} groupKey
576 */
577 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34578 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37579 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34580 }
Blink Reformat4c46d092018-04-07 15:32:37581 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
582 this._activeGroupLookup = groupLookup;
583 this._invalidateAllItems();
584 }
585
586 /**
587 * @return {number}
588 */
589 _computeRowHeight() {
590 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
591 }
592
593 /**
Tim van der Lippe119690c2020-01-13 12:31:30594 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13595 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30596 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37597 */
598 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58599 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37600 }
601
602 /**
Tim van der Lippe119690c2020-01-13 12:31:30603 * @override
Blink Reformat4c46d092018-04-07 15:32:37604 * @return {number}
605 */
606 headerHeight() {
607 return this._headerHeight;
608 }
609
610 /**
Tim van der Lippe119690c2020-01-13 12:31:30611 * @override
Blink Reformat4c46d092018-04-07 15:32:37612 * @param {boolean} recording
613 */
614 setRecording(recording) {
615 this._recording = recording;
616 this._updateSummaryBar();
617 }
618
619 /**
620 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13621 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37622 */
623 modelAdded(networkManager) {
624 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34625 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37626 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34627 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13628 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37629 if (resourceTreeModel) {
630 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
631 resourceTreeModel.addEventListener(
632 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
633 }
634 }
635
636 /**
637 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13638 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37639 */
640 modelRemoved(networkManager) {
641 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13642 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37643 if (resourceTreeModel) {
644 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
645 resourceTreeModel.removeEventListener(
646 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
647 }
648 }
649 }
650
651 /**
Tim van der Lippe119690c2020-01-13 12:31:30652 * @override
Blink Reformat4c46d092018-04-07 15:32:37653 * @param {number} start
654 * @param {number} end
655 */
656 setWindow(start, end) {
657 if (!start && !end) {
658 this._timeFilter = null;
659 this._timeCalculator.setWindow(null);
660 } else {
Paul Lewis56509652019-12-06 12:51:58661 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30662 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37663 }
664 this._filterRequests();
665 }
666
Tim van der Lippe119690c2020-01-13 12:31:30667 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05668 resetFocus() {
669 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37670 }
671
672 _resetSuggestionBuilder() {
673 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58674 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
675 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
676 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
677 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
678 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
679 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
680 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37681 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
682 }
683
684 /**
Tim van der Lippec02a97c2020-02-14 14:39:27685 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37686 */
687 _filterChanged(event) {
688 this.removeAllNodeHighlights();
689 this._parseFilterQuery(this._textFilterUI.value());
690 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37691 }
692
Rajasekar Murugan3ad369e2020-02-19 18:20:12693 async resetFilter() {
694 this._textFilterUI.clear();
695 }
696
Blink Reformat4c46d092018-04-07 15:32:37697 _showRecordingHint() {
698 this._hideRecordingHint();
699 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
700 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18701
702 let reloadShortcutNode = null;
Jack Lynchb8fb3c72020-04-21 05:36:16703 const reloadShortcut = self.UI.shortcutRegistry.shortcutsForAction('inspector_main.reload')[0];
704 if (reloadShortcut) {
Joey Arhar0585e6f2018-10-30 23:11:18705 reloadShortcutNode = this._recordingHint.createChild('b');
Jack Lynchb8fb3c72020-04-21 05:36:16706 reloadShortcutNode.textContent = reloadShortcut.title();
Joey Arhar0585e6f2018-10-30 23:11:18707 }
Blink Reformat4c46d092018-04-07 15:32:37708
709 if (this._recording) {
710 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38711 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18712 if (reloadShortcutNode) {
713 hintText.createChild('br');
714 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13715 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18716 }
Blink Reformat4c46d092018-04-07 15:32:37717 } else {
718 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40719 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18720 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13721 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18722 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
723 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13724 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18725 }
Blink Reformat4c46d092018-04-07 15:32:37726 }
Kayce Basques5444c1b2019-02-15 20:32:53727 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13728 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53729 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
730 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11731
732 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57733 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37734 }
735
736 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11737 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34738 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37739 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34740 }
Brandon Goddardc992d522020-01-08 21:44:57741 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37742 this._recordingHint = null;
743 }
744
745 /**
Amanda Baker6761aae2019-11-05 18:59:11746 * @param {boolean} value
747 */
748 _setHidden(value) {
749 this._columns.setHidden(value);
750 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
751 }
752
753 /**
Blink Reformat4c46d092018-04-07 15:32:37754 * @override
755 * @return {!Array.<!Element>}
756 */
757 elementsToRestoreScrollPositionsFor() {
758 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34759 {
Blink Reformat4c46d092018-04-07 15:32:37760 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34761 }
Blink Reformat4c46d092018-04-07 15:32:37762 return [this._dataGrid.scrollContainer];
763 }
764
Tim van der Lippe119690c2020-01-13 12:31:30765 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37766 columnExtensionResolved() {
767 this._invalidateAllItems(true);
768 }
769
770 _setupDataGrid() {
771 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
772 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34773 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37774 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34775 }
Blink Reformat4c46d092018-04-07 15:32:37776 });
777 this._dataGrid.setStickToBottom(true);
778 this._dataGrid.setName('networkLog');
779 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
780 this._dataGrid.element.classList.add('network-log-grid');
781 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
782 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
783 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05784 this._dataGrid.element.addEventListener('keydown', event => {
785 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05786 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05787 event.consume(true);
788 }
789 });
Brandon Goddard44934902020-03-25 16:03:18790 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
791 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37792 return this._dataGrid;
793 }
794
795 /**
796 * @param {!Event} event
797 */
798 _dataGridMouseMove(event) {
799 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
800 const highlightInitiatorChain = event.shiftKey;
801 this._setHoveredNode(node, highlightInitiatorChain);
802 }
803
804 /**
Tim van der Lippe119690c2020-01-13 12:31:30805 * @override
806 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37807 */
808 hoveredNode() {
809 return this._hoveredNode;
810 }
811
812 /**
Tim van der Lippe119690c2020-01-13 12:31:30813 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37814 * @param {boolean=} highlightInitiatorChain
815 */
816 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34817 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37818 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34819 }
Blink Reformat4c46d092018-04-07 15:32:37820 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34821 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37822 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34823 }
Blink Reformat4c46d092018-04-07 15:32:37824 }
825
826 /**
827 * @param {!Event} event
828 */
829 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34830 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37831 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34832 }
Blink Reformat4c46d092018-04-07 15:32:37833 }
834
835 _updateSummaryBar() {
836 this._hideRecordingHint();
837
838 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20839 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37840 let selectedNodeNumber = 0;
841 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20842 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37843 let baseTime = -1;
844 let maxTime = -1;
845
846 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27847 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Paul Lewis56509652019-12-06 12:51:58848 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34849 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37850 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34851 }
Blink Reformat4c46d092018-04-07 15:32:37852 nodeCount++;
853 const requestTransferSize = request.transferSize;
854 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20855 const requestResourceSize = request.resourceSize;
856 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30857 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37858 selectedNodeNumber++;
859 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20860 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37861 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13862 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37863 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
864 // inspected url.
865 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13866 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
867 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37868 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34869 }
870 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37871 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34872 }
Blink Reformat4c46d092018-04-07 15:32:37873 }
874
875 if (!nodeCount) {
876 this._showRecordingHint();
877 return;
878 }
879
Joey Arhara86c14e2019-03-12 03:20:50880 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37881 /**
882 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50883 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37884 * @return {!Element}
885 */
Joey Arhara86c14e2019-03-12 03:20:50886 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13887 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50888 toolbarText.setTitle(title ? title : chunk);
889 this._summaryToolbar.appendToolbarItem(toolbarText);
890 return toolbarText.element;
891 };
Blink Reformat4c46d092018-04-07 15:32:37892
893 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50894 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
895 this._summaryToolbar.appendSeparator();
896 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17897 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
898 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25899 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50900 this._summaryToolbar.appendSeparator();
901 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17902 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
903 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25904 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37905 } else {
Joey Arhara86c14e2019-03-12 03:20:50906 appendChunk(ls`${nodeCount} requests`);
907 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25908 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17909 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
910 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50911 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25912 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17913 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
914 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37915 }
Dan Beam87466b52018-12-01 18:41:20916
Blink Reformat4c46d092018-04-07 15:32:37917 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50918 this._summaryToolbar.appendSeparator();
919 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37920 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50921 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30922 const domContentLoadedText =
923 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58924 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37925 }
926 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50927 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30928 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58929 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37930 }
931 }
Blink Reformat4c46d092018-04-07 15:32:37932 }
933
Tim van der Lippe119690c2020-01-13 12:31:30934 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37935 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34936 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37937 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34938 }
Blink Reformat4c46d092018-04-07 15:32:37939
940 this._needsRefresh = true;
941
Tim van der Lippe1d6e57a2019-09-30 11:55:34942 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37943 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34944 }
Blink Reformat4c46d092018-04-07 15:32:37945 }
946
947 /**
Tim van der Lippe119690c2020-01-13 12:31:30948 * @override
Blink Reformat4c46d092018-04-07 15:32:37949 * @param {!Array<number>} times
950 */
951 addFilmStripFrames(times) {
952 this._columns.addEventDividers(times, 'network-frame-divider');
953 }
954
955 /**
Tim van der Lippe119690c2020-01-13 12:31:30956 * @override
Blink Reformat4c46d092018-04-07 15:32:37957 * @param {number} time
958 */
959 selectFilmStripFrame(time) {
960 this._columns.selectFilmStripFrame(time);
961 }
962
Tim van der Lippe119690c2020-01-13 12:31:30963 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37964 clearFilmStripFrame() {
965 this._columns.clearFilmStripFrame();
966 }
967
968 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34969 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37970 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34971 }
Blink Reformat4c46d092018-04-07 15:32:37972 }
973
974 /**
975 * @param {boolean=} deferUpdate
976 */
977 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:27978 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34979 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37980 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34981 } else {
Blink Reformat4c46d092018-04-07 15:32:37982 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34983 }
Blink Reformat4c46d092018-04-07 15:32:37984 }
985
986 /**
Tim van der Lippe119690c2020-01-13 12:31:30987 * @override
988 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37989 */
990 timeCalculator() {
991 return this._timeCalculator;
992 }
993
994 /**
Tim van der Lippe119690c2020-01-13 12:31:30995 * @override
996 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37997 */
998 calculator() {
999 return this._calculator;
1000 }
1001
1002 /**
Tim van der Lippe119690c2020-01-13 12:31:301003 * @override
1004 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371005 */
1006 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341007 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:371008 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341009 }
Blink Reformat4c46d092018-04-07 15:32:371010
1011 if (this._calculator !== x) {
1012 this._calculator = x;
1013 this._columns.setCalculator(this._calculator);
1014 }
1015 this._calculator.reset();
1016
Tim van der Lippe1d6e57a2019-09-30 11:55:341017 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371018 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341019 } else {
Blink Reformat4c46d092018-04-07 15:32:371020 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341021 }
Blink Reformat4c46d092018-04-07 15:32:371022
1023 this._invalidateAllItems();
1024 }
1025
1026 /**
Tim van der Lippec02a97c2020-02-14 14:39:271027 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371028 */
1029 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341030 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371031 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341032 }
Blink Reformat4c46d092018-04-07 15:32:371033
1034 const time = /** @type {number} */ (event.data.loadTime);
1035 if (time) {
1036 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301037 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371038 }
1039 }
1040
1041 /**
Tim van der Lippec02a97c2020-02-14 14:39:271042 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371043 */
1044 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341045 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371046 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341047 }
Blink Reformat4c46d092018-04-07 15:32:371048 const data = /** @type {number} */ (event.data);
1049 if (data) {
1050 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301051 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371052 }
1053 }
1054
1055 /**
1056 * @override
1057 */
1058 wasShown() {
1059 this._refreshIfNeeded();
1060 this._columns.wasShown();
1061 }
1062
1063 /**
1064 * @override
1065 */
1066 willHide() {
1067 this._columns.willHide();
1068 }
1069
1070 /**
1071 * @override
1072 */
1073 onResize() {
1074 this._rowHeight = this._computeRowHeight();
1075 }
1076
1077 /**
Tim van der Lippe119690c2020-01-13 12:31:301078 * @override
1079 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371080 */
1081 flatNodesList() {
1082 return this._dataGrid.rootNode().flatChildren();
1083 }
1084
Brandon Goddard44934902020-03-25 16:03:181085 _onDataGridFocus() {
Jack Lynchf3766732020-07-23 01:37:381086 if (!UI.UIUtils.elementIsFocusedByKeyboard(this._dataGrid.element)) {
1087 return;
1088 }
Brandon Goddard44934902020-03-25 16:03:181089 this.element.classList.add('grid-focused');
1090 this.updateNodeBackground();
1091 }
1092
1093 _onDataGridBlur() {
1094 this.element.classList.remove('grid-focused');
1095 this.updateNodeBackground();
1096 }
1097
Tim van der Lippe119690c2020-01-13 12:31:301098 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051099 updateNodeBackground() {
1100 if (this._dataGrid.selectedNode) {
1101 this._dataGrid.selectedNode.updateBackgroundColor();
1102 }
1103 }
1104
1105 /**
Tim van der Lippe119690c2020-01-13 12:31:301106 * @override
Brandon Goddard88d885a2019-10-31 16:11:051107 * @param {boolean} isSelected
1108 */
1109 updateNodeSelectedClass(isSelected) {
1110 if (isSelected) {
1111 this.element.classList.remove('no-node-selected');
1112 } else {
1113 this.element.classList.add('no-node-selected');
1114 }
1115 }
1116
Tim van der Lippe119690c2020-01-13 12:31:301117 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371118 stylesChanged() {
1119 this._columns.scheduleRefresh();
1120 }
1121
1122 _refresh() {
1123 this._needsRefresh = false;
1124
1125 if (this._refreshRequestId) {
1126 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1127 this._refreshRequestId = null;
1128 }
1129
1130 this.removeAllNodeHighlights();
1131
1132 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1133 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1134 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1135 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1136
Tim van der Lippe119690c2020-01-13 12:31:301137 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371138 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301139 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371140 const nodesToRefresh = [];
1141
Tim van der Lippe119690c2020-01-13 12:31:301142 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371143 const staleNodes = new Set();
1144
1145 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1146 // node so we loop until we have no more stale requests.
1147 while (this._staleRequests.size) {
1148 const request = this._staleRequests.firstValue();
1149 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581150 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341151 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371152 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341153 }
Blink Reformat4c46d092018-04-07 15:32:371154 staleNodes.add(node);
1155 }
1156
1157 for (const node of staleNodes) {
1158 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341159 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371160 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341161 }
Blink Reformat4c46d092018-04-07 15:32:371162
Tim van der Lippe1d6e57a2019-09-30 11:55:341163 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371164 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341165 }
Blink Reformat4c46d092018-04-07 15:32:371166 const request = node.request();
1167 this._timeCalculator.updateBoundaries(request);
1168 this._durationCalculator.updateBoundaries(request);
1169 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301170 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371171 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341172 }
Tim van der Lippe119690c2020-01-13 12:31:301173 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371174 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1175 if (removeFromParent) {
1176 let parent = node.parent;
1177 parent.removeChild(node);
1178 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1179 const grandparent = parent.parent;
1180 grandparent.removeChild(parent);
1181 parent = grandparent;
1182 }
1183 }
1184
Tim van der Lippe1d6e57a2019-09-30 11:55:341185 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371186 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341187 }
Blink Reformat4c46d092018-04-07 15:32:371188
1189 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1190 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1191 nodesToRefresh.push(newParent);
1192 }
1193 nodesToInsert.set(node, newParent);
1194 }
1195
Tim van der Lippe1d6e57a2019-09-30 11:55:341196 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371197 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341198 }
Blink Reformat4c46d092018-04-07 15:32:371199
Tim van der Lippe1d6e57a2019-09-30 11:55:341200 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371201 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341202 }
Blink Reformat4c46d092018-04-07 15:32:371203
1204 this._updateSummaryBar();
1205
Tim van der Lippe1d6e57a2019-09-30 11:55:341206 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371207 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 }
Blink Reformat4c46d092018-04-07 15:32:371209
1210 this._dataGrid.updateInstantly();
1211 this._didRefreshForTest();
1212 }
1213
1214 _didRefreshForTest() {
1215 }
1216
1217 /**
Tim van der Lippe119690c2020-01-13 12:31:301218 * @param {!NetworkRequestNode} node
1219 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371220 */
1221 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341222 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371223 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341224 }
Blink Reformat4c46d092018-04-07 15:32:371225
1226 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341227 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371228 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341229 }
Blink Reformat4c46d092018-04-07 15:32:371230 return groupNode;
1231 }
1232
1233 _reset() {
Simon Zünd98419832020-03-12 06:18:151234 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371235
1236 this._setHoveredNode(null);
1237 this._columns.reset();
1238
1239 this._timeFilter = null;
1240 this._calculator.reset();
1241
1242 this._timeCalculator.setWindow(null);
1243 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371244
Tim van der Lippe1d6e57a2019-09-30 11:55:341245 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371246 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341247 }
Blink Reformat4c46d092018-04-07 15:32:371248 this._staleRequests.clear();
1249 this._resetSuggestionBuilder();
1250
1251 this._mainRequestLoadTime = -1;
1252 this._mainRequestDOMContentLoadedTime = -1;
1253
1254 this._dataGrid.rootNode().removeChildren();
1255 this._updateSummaryBar();
1256 this._dataGrid.setStickToBottom(true);
1257 this.scheduleRefresh();
1258 }
1259
1260 /**
Tim van der Lippe119690c2020-01-13 12:31:301261 * @override
Blink Reformat4c46d092018-04-07 15:32:371262 * @param {string} filterString
1263 */
1264 setTextFilterValue(filterString) {
1265 this._textFilterUI.setValue(filterString);
1266 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371267 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131268 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371269 this._resourceCategoryFilterUI.reset();
1270 }
1271
1272 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131273 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371274 */
1275 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301276 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581277 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301278 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371279
Tim van der Lippe1d6e57a2019-09-30 11:55:341280 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371281 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341282 }
Blink Reformat4c46d092018-04-07 15:32:371283 return node;
1284 }
1285
1286 /**
Tim van der Lippec02a97c2020-02-14 14:39:271287 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371288 */
1289 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131290 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371291 this._refreshRequest(request);
1292 }
1293
1294 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131295 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371296 */
1297 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581298 NetworkLogView._subdomains(request.domain)
1299 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1300 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1301 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1302 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1303 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371304
1305 const priority = request.priority();
1306 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501307 this._suggestionBuilder.addItem(
1308 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371309 }
1310
1311 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581312 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371313 }
1314
1315 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581316 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371317 }
1318
1319 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581320 const suggestion =
1321 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1322 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371323 }
1324
1325 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341326 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581327 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341328 }
Jan Scheffler341eea52019-12-12 09:08:411329
1330 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581331 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1332 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1333 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371334 }
1335
Jan Scheffler341eea52019-12-12 09:08:411336 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1337 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1338 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541339 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411340 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1341 }
1342
Blink Reformat4c46d092018-04-07 15:32:371343 this._staleRequests.add(request);
1344 this.scheduleRefresh();
1345 }
1346
1347 /**
Tim van der Lippe119690c2020-01-13 12:31:301348 * @override
Blink Reformat4c46d092018-04-07 15:32:371349 * @return {number}
1350 */
1351 rowHeight() {
1352 return this._rowHeight;
1353 }
1354
1355 /**
Tim van der Lippe119690c2020-01-13 12:31:301356 * @override
Blink Reformat4c46d092018-04-07 15:32:371357 * @param {boolean} gridMode
1358 */
1359 switchViewMode(gridMode) {
1360 this._columns.switchViewMode(gridMode);
1361 }
1362
1363 /**
Tim van der Lippe119690c2020-01-13 12:31:301364 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131365 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1366 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371367 */
1368 handleContextMenuForRequest(contextMenu, request) {
1369 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131370 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371371 const footerSection = copyMenu.footerSection();
1372 if (request) {
1373 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131374 UI.UIUtils.copyLinkAddressLabel(),
1375 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1376 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371377 if (request.requestHeadersText()) {
1378 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131379 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381
1382 if (request.responseHeadersText) {
1383 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131384 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371385 }
1386
1387 if (request.finished) {
1388 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131389 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371390 }
1391
Harley Libcf41f92018-09-10 18:01:131392 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131393 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371394 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131395 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1396 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371397 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131398 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291399 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131400 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1401 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371402 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131403 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1404 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131405 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131406 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1407 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371408 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131409 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1410 footerSection.appendItem(
1411 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1412 footerSection.appendItem(
1413 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1414 footerSection.appendItem(
1415 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1416 footerSection.appendItem(
1417 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371418 } else {
Harley Libcf41f92018-09-10 18:01:131419 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131420 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291421 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1423 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131424 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131425 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1426 footerSection.appendItem(
1427 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1428 footerSection.appendItem(
1429 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1430 footerSection.appendItem(
1431 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371432 }
1433 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131434 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371435 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131436 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371437
Joey Arhar0e1093c2019-05-21 00:34:221438 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371439
Blink Reformat4c46d092018-04-07 15:32:371440 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131441 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1442 contextMenu.editSection().appendItem(
1443 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371444
1445 if (request) {
1446 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211447 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371448 let patterns = manager.blockedPatterns();
1449
Tim van der Lippeffa78622019-09-16 12:07:121450 /**
1451 * @param {string} url
1452 */
1453 function addBlockedURL(url) {
1454 patterns.push({enabled: true, url: url});
1455 manager.setBlockedPatterns(patterns);
1456 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261457 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121458 }
1459
1460 /**
1461 * @param {string} url
1462 */
1463 function removeBlockedURL(url) {
1464 patterns = patterns.filter(pattern => pattern.url !== url);
1465 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261466 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121467 }
1468
Blink Reformat4c46d092018-04-07 15:32:371469 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1470 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1471 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131472 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371473 } else if (urlWithoutScheme) {
1474 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1475 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131476 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371477 }
1478
1479 const domain = request.parsedURL.domain();
1480 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1481 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131482 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371483 } else if (domain) {
1484 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1485 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131486 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371487 }
1488
Tim van der Lippe0ed1d2b2020-02-04 13:45:131489 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371490 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131491 Common.UIString.UIString('Replay XHR'),
1492 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371493 }
Blink Reformat4c46d092018-04-07 15:32:371494 }
1495 }
1496
1497 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271498 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171499 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131500 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171501 });
Blink Reformat4c46d092018-04-07 15:32:371502 }
1503
1504 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131505 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1506 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371507 }
1508
1509 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131510 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371511 * @param {string} platform
1512 */
1513 async _copyCurlCommand(request, platform) {
1514 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131515 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371516 }
1517
1518 /**
1519 * @param {string} platform
1520 */
1521 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271522 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131523 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371524 }
1525
1526 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131527 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291528 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371529 */
Jan Scheffler7c50d1f2019-12-17 13:33:291530 async _copyFetchCall(request, includeCookies) {
1531 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131532 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371533 }
1534
Jan Scheffler7c50d1f2019-12-17 13:33:291535 /**
1536 * @param {boolean} includeCookies
1537 */
1538 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271539 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131540 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371541 }
1542
1543 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131544 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371545 */
1546 async _copyPowerShellCommand(request) {
1547 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131548 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371549 }
1550
1551 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271552 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131553 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371554 }
1555
Tim van der Lippe119690c2020-01-13 12:31:301556 /**
1557 * @override
1558 * @return {!Promise}
1559 */
Joey Arhar0e1093c2019-05-21 00:34:221560 async exportAll() {
Paul Lewisdaac1062020-03-05 14:37:101561 const url = SDK.SDKModel.TargetManager.instance().mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131562 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371563 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131564 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371565
Tim van der Lippe1d6e57a2019-09-30 11:55:341566 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371567 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341568 }
Blink Reformat4c46d092018-04-07 15:32:371569
Tim van der Lippe0ed1d2b2020-02-04 13:45:131570 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371571 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301572 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371573 progressIndicator.done();
1574 stream.close();
1575 }
1576
1577 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131578 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211579 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341580 }
Blink Reformat4c46d092018-04-07 15:32:371581 }
1582
1583 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131584 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211585 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341586 }
Blink Reformat4c46d092018-04-07 15:32:371587 }
1588
1589 _removeAllHighlights() {
1590 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341591 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131592 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341593 }
Blink Reformat4c46d092018-04-07 15:32:371594 this._highlightedSubstringChanges = [];
1595 }
1596
1597 /**
Tim van der Lippe119690c2020-01-13 12:31:301598 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371599 * @return {boolean}
1600 */
1601 _applyFilter(node) {
1602 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341603 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371604 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341605 }
Blink Reformat4c46d092018-04-07 15:32:371606 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341607 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371608 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341609 }
1610 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371611 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341612 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221613 if (this._onlyIssuesFilterUI.checked() &&
1614 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371615 return false;
1616 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131617 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1618 return false;
1619 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341620 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371621 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341622 }
Blink Reformat4c46d092018-04-07 15:32:371623 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341624 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371625 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341626 }
Blink Reformat4c46d092018-04-07 15:32:371627 }
1628 return true;
1629 }
1630
1631 /**
1632 * @param {string} query
1633 */
1634 _parseFilterQuery(query) {
1635 const descriptors = this._filterParser.parse(query);
1636 this._filters = descriptors.map(descriptor => {
1637 const key = descriptor.key;
1638 const text = descriptor.text || '';
1639 const regex = descriptor.regex;
1640 let filter;
1641 if (key) {
1642 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581643 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1644 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371645 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581646 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371647 } else {
Paul Lewis56509652019-12-06 12:51:581648 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371649 }
Paul Lewis56509652019-12-06 12:51:581650 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371651 });
1652 }
1653
1654 /**
Paul Lewis56509652019-12-06 12:51:581655 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371656 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161657 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371658 */
1659 _createSpecialFilter(type, value) {
1660 switch (type) {
Paul Lewis56509652019-12-06 12:51:581661 case FilterType.Domain:
1662 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371663
Paul Lewis56509652019-12-06 12:51:581664 case FilterType.HasResponseHeader:
1665 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371666
Paul Lewis56509652019-12-06 12:51:581667 case FilterType.Is:
1668 if (value.toLowerCase() === IsFilterType.Running) {
1669 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341670 }
Paul Lewis56509652019-12-06 12:51:581671 if (value.toLowerCase() === IsFilterType.FromCache) {
1672 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341673 }
Paul Lewis56509652019-12-06 12:51:581674 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1675 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341676 }
Paul Lewis56509652019-12-06 12:51:581677 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1678 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341679 }
Blink Reformat4c46d092018-04-07 15:32:371680 break;
1681
Paul Lewis56509652019-12-06 12:51:581682 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371683 return this._createSizeFilter(value.toLowerCase());
1684
Paul Lewis56509652019-12-06 12:51:581685 case FilterType.Method:
1686 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371687
Paul Lewis56509652019-12-06 12:51:581688 case FilterType.MimeType:
1689 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371690
Paul Lewis56509652019-12-06 12:51:581691 case FilterType.MixedContent:
1692 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371693
Paul Lewis56509652019-12-06 12:51:581694 case FilterType.Scheme:
1695 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371696
Paul Lewis56509652019-12-06 12:51:581697 case FilterType.SetCookieDomain:
1698 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371699
Paul Lewis56509652019-12-06 12:51:581700 case FilterType.SetCookieName:
1701 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371702
Paul Lewis56509652019-12-06 12:51:581703 case FilterType.SetCookieValue:
1704 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371705
Jan Scheffler341eea52019-12-12 09:08:411706 case FilterType.CookieDomain:
1707 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1708
1709 case FilterType.CookieName:
1710 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1711
Simon Zündc9759102020-03-25 11:24:541712 case FilterType.CookiePath:
1713 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1714
Jan Scheffler341eea52019-12-12 09:08:411715 case FilterType.CookieValue:
1716 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1717
Paul Lewis56509652019-12-06 12:51:581718 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501719 return NetworkLogView._requestPriorityFilter.bind(
1720 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371721
Paul Lewis56509652019-12-06 12:51:581722 case FilterType.StatusCode:
1723 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371724 }
1725 return null;
1726 }
1727
1728 /**
1729 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161730 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371731 */
1732 _createSizeFilter(value) {
1733 let multiplier = 1;
1734 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411735 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371736 value = value.substring(0, value.length - 1);
1737 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411738 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371739 value = value.substring(0, value.length - 1);
1740 }
1741 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341742 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371743 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341744 }
Paul Lewis56509652019-12-06 12:51:581745 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371746 }
1747
1748 _filterRequests() {
1749 this._removeAllHighlights();
1750 this._invalidateAllItems();
1751 }
1752
1753 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131754 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301755 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371756 */
1757 _reveal(request) {
1758 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581759 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341760 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371761 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341762 }
Brandon Goddard5e4244d2020-04-08 22:08:471763 // Viewport datagrid nodes do not reveal if not in the root node
1764 // list of flatChildren. For children of grouped frame nodes:
1765 // reveal and expand parent to ensure child is revealable.
1766 if (node.parent && node.parent instanceof NetworkGroupNode) {
1767 node.parent.reveal();
1768 node.parent.expand();
1769 }
Blink Reformat4c46d092018-04-07 15:32:371770 node.reveal();
1771 return node;
1772 }
1773
1774 /**
Tim van der Lippe119690c2020-01-13 12:31:301775 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131776 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371777 */
1778 revealAndHighlightRequest(request) {
1779 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341780 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371781 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341782 }
Blink Reformat4c46d092018-04-07 15:32:371783 }
1784
1785 /**
Tim van der Lippe119690c2020-01-13 12:31:301786 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131787 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371788 */
1789 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141790 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371791 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341792 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371793 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341794 }
Blink Reformat4c46d092018-04-07 15:32:371795 }
1796
Tim van der Lippe119690c2020-01-13 12:31:301797 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371798 removeAllNodeHighlights() {
1799 if (this._highlightedNode) {
1800 this._highlightedNode.element().classList.remove('highlighted-row');
1801 this._highlightedNode = null;
1802 }
1803 }
1804
1805 /**
Tim van der Lippe119690c2020-01-13 12:31:301806 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371807 */
1808 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131809 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371810 this._highlightedNode = node;
1811 }
1812
1813 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131814 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1815 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131816 */
1817 _filterOutBlobRequests(requests) {
1818 return requests.filter(request => !request.isBlobRequest());
1819 }
1820
1821 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131822 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291823 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371824 * @return {!Promise<string>}
1825 */
Jan Scheffler7c50d1f2019-12-17 13:33:291826 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371827 const ignoredHeaders = {
1828 // Internal headers
1829 'method': 1,
1830 'path': 1,
1831 'scheme': 1,
1832 'version': 1,
1833
1834 // Unsafe headers
1835 // Keep this list synchronized with src/net/http/http_util.cc
1836 'accept-charset': 1,
1837 'accept-encoding': 1,
1838 'access-control-request-headers': 1,
1839 'access-control-request-method': 1,
1840 'connection': 1,
1841 'content-length': 1,
1842 'cookie': 1,
1843 'cookie2': 1,
1844 'date': 1,
1845 'dnt': 1,
1846 'expect': 1,
1847 'host': 1,
1848 'keep-alive': 1,
1849 'origin': 1,
1850 'referer': 1,
1851 'te': 1,
1852 'trailer': 1,
1853 'transfer-encoding': 1,
1854 'upgrade': 1,
1855 'via': 1,
1856 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1857 'user-agent': 1
1858 };
1859
1860 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1861
1862 const url = JSON.stringify(request.url());
1863
1864 const requestHeaders = request.requestHeaders();
1865 const headerData = requestHeaders.reduce((result, header) => {
1866 const name = header.name;
1867
Tim van der Lippe1d6e57a2019-09-30 11:55:341868 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371869 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341870 }
Blink Reformat4c46d092018-04-07 15:32:371871
1872 return result;
1873 }, new Headers());
1874
1875 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341876 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411877 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341878 }
Blink Reformat4c46d092018-04-07 15:32:371879
Sigurd Schneider0e88b912020-05-08 08:28:231880 const credentials = request.includedRequestCookies().length ||
1881 requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
Jan Scheffler341eea52019-12-12 09:08:411882 'include' :
1883 'omit';
Blink Reformat4c46d092018-04-07 15:32:371884
1885 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1886
1887 const referrer = referrerHeader ? referrerHeader.value : void 0;
1888
1889 const referrerPolicy = request.referrerPolicy() || void 0;
1890
1891 const requestBody = await request.requestFormData();
1892
1893 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411894 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371895 referrer,
1896 referrerPolicy,
1897 body: requestBody,
1898 method: request.requestMethod,
1899 mode: 'cors'
1900 };
1901
Jan Scheffler7c50d1f2019-12-17 13:33:291902 if (includeCookies) {
1903 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1904 if (cookieHeader) {
1905 fetchOptions.headers = {
1906 ...headers,
1907 'cookie': cookieHeader.value,
1908 };
1909 }
1910 } else {
1911 fetchOptions.credentials = credentials;
1912 }
1913
Jan Scheffler172d5212020-01-02 14:42:561914 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371915 return `fetch(${url}, ${options});`;
1916 }
1917
1918 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131919 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291920 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131921 * @return {!Promise<string>}
1922 */
Jan Scheffler7c50d1f2019-12-17 13:33:291923 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131924 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291925 const commands =
1926 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131927 return commands.join(' ;\n');
1928 }
1929
1930 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131931 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371932 * @param {string} platform
1933 * @return {!Promise<string>}
1934 */
1935 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561936 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361937 // Most of these headers are derived from the URL and are automatically added by cURL.
1938 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1939 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371940
1941 function escapeStringWin(str) {
1942 /* If there are no new line characters do not escape the " characters
1943 since it only uglifies the command.
1944
1945 Because cmd.exe parser and MS Crt arguments parsers use some of the
1946 same escape characters, they can interact with each other in
1947 horrible ways, the order of operations is critical.
1948
1949 Replace \ with \\ first because it is an escape character for certain
1950 conditions in both parsers.
1951
1952 Replace all " with \" to ensure the first parser does not remove it.
1953
1954 Then escape all characters we are not sure about with ^ to ensure it
1955 gets to MS Crt parser safely.
1956
1957 The % character is special because MS Crt parser will try and look for
1958 ENV variables and fill them in it's place. We cannot escape them with %
1959 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1960 parser); So we can get cmd.exe parser to escape the character after it,
1961 if it is followed by a valid beginning character of an ENV variable.
1962 This ensures we do not try and double escape another ^ if it was placed
1963 by the previous replace.
1964
1965 Lastly we replace new lines with ^ and TWO new lines because the first
1966 new line is there to enact the escape command the second is the character
1967 to escape (in this case new line).
1968 */
1969 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1970 return encapsChars +
1971 str.replace(/\\/g, '\\\\')
1972 .replace(/"/g, '\\"')
1973 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1974 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1975 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1976 encapsChars;
1977 }
1978
1979 /**
1980 * @param {string} str
1981 * @return {string}
1982 */
1983 function escapeStringPosix(str) {
1984 /**
1985 * @param {string} x
1986 * @return {string}
1987 */
1988 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221989 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121990 let hexString = code.toString(16);
1991 // Zero pad to four digits to comply with ANSI-C Quoting:
1992 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121994 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341995 }
Joey Arhar2d21f712019-05-20 21:07:121996
1997 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371998 }
1999
Mathias Bynensf06e8c02020-02-28 13:58:282000 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372001 // Use ANSI-C quoting syntax.
2002 return '$\'' +
2003 str.replace(/\\/g, '\\\\')
2004 .replace(/\'/g, '\\\'')
2005 .replace(/\n/g, '\\n')
2006 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282007 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372008 '\'';
Blink Reformat4c46d092018-04-07 15:32:372009 }
Mathias Bynensf06e8c02020-02-28 13:58:282010 // Use single quote syntax.
2011 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372012 }
2013
2014 // cURL command expected to run on the same platform that DevTools run
2015 // (it may be different from the inspected page platform).
2016 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2017
2018 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2019
2020 let inferredMethod = 'GET';
2021 const data = [];
2022 const requestContentType = request.requestContentType();
2023 const formData = await request.requestFormData();
2024 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272025 // Note that formData is not necessarily urlencoded because it might for example
2026 // come from a fetch request made with an explicitly unencoded body.
2027 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372028 ignoredHeaders['content-length'] = true;
2029 inferredMethod = 'POST';
2030 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:562031 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372032 ignoredHeaders['content-length'] = true;
2033 inferredMethod = 'POST';
2034 }
2035
2036 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292037 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372038 }
2039
2040 const requestHeaders = request.requestHeaders();
2041 for (let i = 0; i < requestHeaders.length; i++) {
2042 const header = requestHeaders[i];
2043 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342044 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:372045 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342046 }
Jan Scheffler172d5212020-01-02 14:42:562047 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372048 }
2049 command = command.concat(data);
2050 command.push('--compressed');
2051
Tim van der Lippe1d6e57a2019-09-30 11:55:342052 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372053 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342054 }
Jan Scheffler172d5212020-01-02 14:42:562055 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372056 }
2057
2058 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132059 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132060 * @param {string} platform
2061 * @return {!Promise<string>}
2062 */
2063 async _generateAllCurlCommand(requests, platform) {
2064 const nonBlobRequests = this._filterOutBlobRequests(requests);
2065 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342066 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132067 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342068 }
Mathias Bynensf06e8c02020-02-28 13:58:282069 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132070 }
2071
2072 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132073 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372074 * @return {!Promise<string>}
2075 */
2076 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562077 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372078 const ignoredHeaders =
2079 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2080
2081 /**
2082 * @param {string} str
2083 * @return {string}
2084 */
2085 function escapeString(str) {
2086 return '"' +
2087 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2088 }
2089
Jan Scheffler172d5212020-01-02 14:42:562090 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372091
2092 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562093 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372094 }
2095
2096 const requestHeaders = request.requestHeaders();
2097 const headerNameValuePairs = [];
2098 for (const header of requestHeaders) {
2099 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342100 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372101 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342102 }
Blink Reformat4c46d092018-04-07 15:32:372103 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2104 }
2105 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562106 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372107 }
2108
2109 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2110 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562111 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372112 }
2113
2114 const formData = await request.requestFormData();
2115 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372116 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342117 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562118 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342119 } else {
Jan Scheffler172d5212020-01-02 14:42:562120 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342121 }
Blink Reformat4c46d092018-04-07 15:32:372122 }
2123
Jan Scheffler172d5212020-01-02 14:42:562124 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372125 }
Harley Libcf41f92018-09-10 18:01:132126
2127 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132128 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132129 * @return {!Promise<string>}
2130 */
2131 async _generateAllPowerShellCommand(requests) {
2132 const nonBlobRequests = this._filterOutBlobRequests(requests);
2133 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2134 return commands.join(';\r\n');
2135 }
Joey Arhara86c14e2019-03-12 03:20:502136
2137 /**
2138 * @return {string}
2139 */
2140 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552141 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502142 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342143 }
Joey Arhara86c14e2019-03-12 03:20:502144 return '#0867CB';
2145 }
2146
2147 /**
2148 * @return {string}
2149 */
2150 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132151 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502152 }
Paul Lewis56509652019-12-06 12:51:582153}
Blink Reformat4c46d092018-04-07 15:32:372154
Tim van der Lippe119690c2020-01-13 12:31:302155export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582156export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372157
Paul Lewis56509652019-12-06 12:51:582158export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372159 'http': true,
2160 'https': true,
2161 'ws': true,
2162 'wss': true
2163};
2164
Blink Reformat4c46d092018-04-07 15:32:372165/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582166export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372167 Domain: 'domain',
2168 HasResponseHeader: 'has-response-header',
2169 Is: 'is',
2170 LargerThan: 'larger-than',
2171 Method: 'method',
2172 MimeType: 'mime-type',
2173 MixedContent: 'mixed-content',
2174 Priority: 'priority',
2175 Scheme: 'scheme',
2176 SetCookieDomain: 'set-cookie-domain',
2177 SetCookieName: 'set-cookie-name',
2178 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412179 CookieDomain: 'cookie-domain',
2180 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542181 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412182 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372183 StatusCode: 'status-code'
2184};
2185
2186/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582187export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372188 All: 'all',
2189 Displayed: 'displayed',
2190 Blocked: 'blocked',
2191 BlockOverridden: 'block-overridden'
2192};
2193
2194/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582195export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372196 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052197 FromCache: 'from-cache',
2198 ServiceWorkerIntercepted: 'service-worker-intercepted',
2199 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372200};
2201
2202/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582203export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372204
2205/**
2206 * @interface
2207 */
Paul Lewis56509652019-12-06 12:51:582208export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372209 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132210 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302211 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372212 */
Paul Lewis56509652019-12-06 12:51:582213 groupNodeForRequest(request) {
2214 }
Blink Reformat4c46d092018-04-07 15:32:372215
Paul Lewis56509652019-12-06 12:51:582216 reset() {
2217 }
2218}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162219
2220/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2221export let Filter;