blob: c53b2c6bc05e5b8681e7221aeca3e21820abac14 [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
Jan Scheffler6c0cc692020-07-31 14:26:2231// @ts-nocheck
32// TODO(crbug.com/1011811): Enable TypeScript compiler checks
33
Tim van der Lippe0ed1d2b2020-02-04 13:45:1334import * as Bindings from '../bindings/bindings.js';
Sigurd Schneiderba818512020-04-29 10:54:3735import * as BrowserSDK from '../browser_sdk/browser_sdk.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1336import * as Common from '../common/common.js';
37import * as Components from '../components/components.js';
38import * as DataGrid from '../data_grid/data_grid.js';
39import * as HARImporter from '../har_importer/har_importer.js';
40import * as Host from '../host/host.js';
Tim van der Lippeded23fb2020-02-13 13:33:5041import * as PerfUI from '../perf_ui/perf_ui.js';
Jack Franklin9c225ca2020-04-29 09:55:1742import * as Platform from '../platform/platform.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1343import * as SDK from '../sdk/sdk.js';
44import * as TextUtils from '../text_utils/text_utils.js';
45import * as UI from '../ui/ui.js';
46
Tim van der Lippe119690c2020-01-13 12:31:3047import {HARWriter} from './HARWriter.js';
48import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
49import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
50import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
51import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
52
Blink Reformat4c46d092018-04-07 15:32:3753/**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354 * @implements {SDK.SDKModel.SDKModelObserver<!SDK.NetworkManager.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3055 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3756 */
Tim van der Lippe0ed1d2b2020-02-04 13:45:1357export class NetworkLogView extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3758 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:1359 * @param {!UI.FilterBar.FilterBar} filterBar
Blink Reformat4c46d092018-04-07 15:32:3760 * @param {!Element} progressBarContainer
Tim van der Lippe0ed1d2b2020-02-04 13:45:1361 * @param {!Common.Settings.Setting} networkLogLargeRowsSetting
Blink Reformat4c46d092018-04-07 15:32:3762 */
63 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
64 super();
65 this.setMinimumSize(50, 64);
66 this.registerRequiredCSS('network/networkLogView.css');
67
68 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0569 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3770
Paul Lewis2d7d65c2020-03-16 17:26:3071 this._networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
72 this._networkShowIssuesOnlySetting =
73 Common.Settings.Settings.instance().createSetting('networkShowIssuesOnly', false);
74 this._networkOnlyBlockedRequestsSetting =
75 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
76 this._networkResourceTypeFiltersSetting =
77 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:3778
79 this._rawRowHeight = 0;
80 this._progressBarContainer = progressBarContainer;
81 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
82 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
83
84 /**
Paul Lewis56509652019-12-06 12:51:5885 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3786 */
87 function updateRowHeight() {
88 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
89 this._rowHeight = this._computeRowHeight();
90 }
91 this._rawRowHeight = 0;
92 this._rowHeight = 0;
93 updateRowHeight.call(this);
94
Tim van der Lippe119690c2020-01-13 12:31:3095 /** @type {!NetworkTransferTimeCalculator} */
96 this._timeCalculator = new NetworkTransferTimeCalculator();
97 /** @type {!NetworkTransferDurationCalculator} */
98 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3799 this._calculator = this._timeCalculator;
100
Tim van der Lippe119690c2020-01-13 12:31:30101 this._columns =
102 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:37103 this._columns.show(this.element);
104
Tim van der Lippe0ed1d2b2020-02-04 13:45:13105 /** @type {!Set<!SDK.NetworkRequest.NetworkRequest>} */
Blink Reformat4c46d092018-04-07 15:32:37106 this._staleRequests = new Set();
107 /** @type {number} */
108 this._mainRequestLoadTime = -1;
109 /** @type {number} */
110 this._mainRequestDOMContentLoadedTime = -1;
111 this._highlightedSubstringChanges = [];
112
Tim van der Lippeb1f2b6c2020-02-17 13:00:16113 /** @type {!Array.<!Filter>} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._filters = [];
Tim van der Lippeb1f2b6c2020-02-17 13:00:16115 /** @type {?Filter} */
Blink Reformat4c46d092018-04-07 15:32:37116 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:30117 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:37118 this._hoveredNode = null;
119 /** @type {?Element} */
120 this._recordingHint = null;
121 /** @type {?number} */
122 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30123 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37124 this._highlightedNode = null;
125
Tim van der Lippe0ed1d2b2020-02-04 13:45:13126 this.linkifier = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37127
128 this._recording = false;
129 this._needsRefresh = false;
130
131 this._headerHeight = 0;
132
Paul Lewis56509652019-12-06 12:51:58133 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37134 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30135 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37136
Paul Lewis56509652019-12-06 12:51:58137 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37138 this._activeGroupLookup = null;
139
Tim van der Lippe0ed1d2b2020-02-04 13:45:13140 this._textFilterUI = new UI.FilterBar.TextFilterUI();
141 this._textFilterUI.addEventListener(UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged, this);
Blink Reformat4c46d092018-04-07 15:32:37142 filterBar.addFilter(this._textFilterUI);
143
Tim van der Lippe0ed1d2b2020-02-04 13:45:13144 this._dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
145 'hide-data-url', Common.UIString.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
146 this._dataURLFilterUI.addEventListener(
147 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48148 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37149 filterBar.addFilter(this._dataURLFilterUI);
150
151 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13152 Object.values(Common.ResourceType.resourceCategories)
Blink Reformat4c46d092018-04-07 15:32:37153 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
Tim van der Lippe0ed1d2b2020-02-04 13:45:13154 this._resourceCategoryFilterUI =
155 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20156 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37157 this._resourceCategoryFilterUI.addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13158 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37159 filterBar.addFilter(this._resourceCategoryFilterUI);
160
Tim van der Lippe0ed1d2b2020-02-04 13:45:13161 this._onlyIssuesFilterUI = new UI.FilterBar.CheckboxFilterUI(
162 'only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
163 this._onlyIssuesFilterUI.addEventListener(
164 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41165 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37166 filterBar.addFilter(this._onlyIssuesFilterUI);
167
Sigurd Schneidera2afe0b2020-03-03 15:27:13168 this._onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
169 'only-show-blocked-requests', ls`Blocked Requests`, true, this._networkOnlyBlockedRequestsSetting);
170 this._onlyBlockedRequestsUI.addEventListener(
171 UI.FilterBar.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
172 this._onlyBlockedRequestsUI.element().title = ls`Only show blocked requests`;
173 filterBar.addFilter(this._onlyBlockedRequestsUI);
174
Jan Scheffler1ae7c9e2019-12-03 15:48:37175
Tim van der Lippe0ed1d2b2020-02-04 13:45:13176 this._filterParser = new TextUtils.TextUtils.FilterParser(_searchKeys);
177 this._suggestionBuilder =
178 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37179 this._resetSuggestionBuilder();
180
181 this._dataGrid = this._columns.dataGrid();
182 this._setupDataGrid();
183 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49184 filterBar.filterButton().addEventListener(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13185 UI.Toolbar.ToolbarButton.Events.Click,
186 this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37187
Tim van der Lippe0ed1d2b2020-02-04 13:45:13188 this._summaryToolbar = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37189
Tim van der Lippe0ed1d2b2020-02-04 13:45:13190 new UI.DropTarget.DropTarget(
191 this.element, [UI.DropTarget.Type.File], Common.UIString.UIString('Drop HAR files here'),
192 this._handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37193
Paul Lewis2d7d65c2020-03-16 17:26:30194 Common.Settings.Settings.instance()
195 .moduleSetting('networkColorCodeResourceTypes')
Blink Reformat4c46d092018-04-07 15:32:37196 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
197
Paul Lewisdaac1062020-03-05 14:37:10198 SDK.SDKModel.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this);
Wolfgang Beyerd81fad62020-05-27 12:30:27199 SDK.NetworkLog.NetworkLog.instance().addEventListener(
200 SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
201 SDK.NetworkLog.NetworkLog.instance().addEventListener(
202 SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
203 SDK.NetworkLog.NetworkLog.instance().addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37204
205 this._updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30206 Common.Settings.Settings.instance()
207 .moduleSetting('network.group-by-frame')
208 .addChangeListener(() => this._updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37209
210 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37211 }
212
Blink Reformat4c46d092018-04-07 15:32:37213 _updateGroupByFrame() {
Paul Lewis2d7d65c2020-03-16 17:26:30214 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Blink Reformat4c46d092018-04-07 15:32:37215 this._setGrouping(value ? 'Frame' : null);
216 }
217
218 /**
219 * @param {string} key
220 * @param {!Array<string>} values
221 */
222 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58223 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37224 values.sort((a, b) => {
Tim van der Lippeded23fb2020-02-13 13:33:50225 const aPriority =
226 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a));
227 const bPriority =
228 /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b));
229 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
230 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37231 });
232 } else {
233 values.sort();
234 }
235 }
236
237 /**
Tim van der Lippeb1f2b6c2020-02-17 13:00:16238 * @param {!Filter} filter
Tim van der Lippe0ed1d2b2020-02-04 13:45:13239 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37240 * @return {boolean}
241 */
242 static _negativeFilter(filter, request) {
243 return !filter(request);
244 }
245
246 /**
247 * @param {?RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13248 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37249 * @return {boolean}
250 */
251 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34252 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37253 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34254 }
Blink Reformat4c46d092018-04-07 15:32:37255
256 return regex.test(request.path() + '/' + request.name());
257 }
258
259 /**
260 * @param {string} domain
261 * @return {!Array.<string>}
262 */
263 static _subdomains(domain) {
264 const result = [domain];
265 let indexOfPeriod = domain.indexOf('.');
266 while (indexOfPeriod !== -1) {
267 result.push('*' + domain.substring(indexOfPeriod));
268 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
269 }
270 return result;
271 }
272
273 /**
274 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:16275 * @return {!Filter}
Blink Reformat4c46d092018-04-07 15:32:37276 */
277 static _createRequestDomainFilter(value) {
278 /**
279 * @param {string} string
280 * @return {string}
281 */
282 function escapeForRegExp(string) {
283 return string.escapeForRegExp();
284 }
285 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58286 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37287 }
288
289 /**
290 * @param {!RegExp} regex
Tim van der Lippe0ed1d2b2020-02-04 13:45:13291 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37292 * @return {boolean}
293 */
294 static _requestDomainFilter(regex, request) {
295 return regex.test(request.domain);
296 }
297
298 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13299 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37300 * @return {boolean}
301 */
302 static _runningRequestFilter(request) {
303 return !request.finished;
304 }
305
306 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13307 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37308 * @return {boolean}
309 */
310 static _fromCacheRequestFilter(request) {
311 return request.cached();
312 }
313
314 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13315 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05316 * @return {boolean}
317 */
318 static _interceptedByServiceWorkerFilter(request) {
319 return request.fetchedViaServiceWorker;
320 }
321
322 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13323 * @param {!SDK.NetworkRequest.NetworkRequest} request
Joey Arhard183e7e2019-02-28 03:37:05324 * @return {boolean}
325 */
326 static _initiatedByServiceWorkerFilter(request) {
327 return request.initiatedByServiceWorker();
328 }
329
330 /**
Blink Reformat4c46d092018-04-07 15:32:37331 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13332 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37333 * @return {boolean}
334 */
335 static _requestResponseHeaderFilter(value, request) {
336 return request.responseHeaderValue(value) !== undefined;
337 }
338
339 /**
340 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13341 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37342 * @return {boolean}
343 */
344 static _requestMethodFilter(value, request) {
345 return request.requestMethod === value;
346 }
347
348 /**
349 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13350 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37351 * @return {boolean}
352 */
353 static _requestPriorityFilter(value, request) {
354 return request.priority() === value;
355 }
356
357 /**
358 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13359 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37360 * @return {boolean}
361 */
362 static _requestMimeTypeFilter(value, request) {
363 return request.mimeType === value;
364 }
365
366 /**
Paul Lewis56509652019-12-06 12:51:58367 * @param {!MixedContentFilterValues} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13368 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37369 * @return {boolean}
370 */
371 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58372 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37373 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28374 }
375 if (value === MixedContentFilterValues.Blocked) {
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.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37379 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28380 }
381 if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37382 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34383 }
Blink Reformat4c46d092018-04-07 15:32:37384
385 return false;
386 }
387
388 /**
389 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13390 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37391 * @return {boolean}
392 */
393 static _requestSchemeFilter(value, request) {
394 return request.scheme === value;
395 }
396
397 /**
398 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13399 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37400 * @return {boolean}
401 */
Jan Scheffler341eea52019-12-12 09:08:41402 static _requestCookieDomainFilter(value, request) {
403 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
404 }
405
406 /**
407 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13408 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41409 * @return {boolean}
410 */
411 static _requestCookieNameFilter(value, request) {
412 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
413 }
414
415 /**
416 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13417 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41418 * @return {boolean}
419 */
Simon Zündc9759102020-03-25 11:24:54420 static _requestCookiePathFilter(value, request) {
421 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
422 }
423
424 /**
425 * @param {string} value
426 * @param {!SDK.NetworkRequest.NetworkRequest} request
427 * @return {boolean}
428 */
Jan Scheffler341eea52019-12-12 09:08:41429 static _requestCookieValueFilter(value, request) {
430 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
431 }
432
433 /**
434 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13435 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler341eea52019-12-12 09:08:41436 * @return {boolean}
437 */
Blink Reformat4c46d092018-04-07 15:32:37438 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41439 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37440 }
441
442 /**
443 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13444 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37445 * @return {boolean}
446 */
447 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41448 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37449 }
450
451 /**
452 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13453 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37454 * @return {boolean}
455 */
456 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41457 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37458 }
459
460 /**
461 * @param {number} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13462 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37463 * @return {boolean}
464 */
465 static _requestSizeLargerThanFilter(value, request) {
466 return request.transferSize >= value;
467 }
468
469 /**
470 * @param {string} value
Tim van der Lippe0ed1d2b2020-02-04 13:45:13471 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37472 * @return {boolean}
473 */
474 static _statusCodeFilter(value, request) {
475 return ('' + request.statusCode) === value;
476 }
477
478 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13479 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37480 * @return {boolean}
481 */
482 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58483 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37484 }
485
Sigurd Schneider464838b2020-08-24 13:53:03486
487 /**
488 * @param {string} value
489 * @param {!SDK.NetworkRequest.NetworkRequest} request
490 * @return {boolean}
491 */
492 static _resourceTypeFilter(value, request) {
493 return request.resourceType().name() === value;
494 }
495
Blink Reformat4c46d092018-04-07 15:32:37496 /**
Julian Geppertf8ce40c2020-09-01 18:02:03497 * @param {string} value
498 * @param {!SDK.NetworkRequest.NetworkRequest} request
499 * @return {boolean}
500 */
501 static _requestUrlFilter(value, request) {
502 const regex = new RegExp(value.escapeForRegExp(), 'i');
503 return regex.test(request.url());
504 }
505
506 /**
Blink Reformat4c46d092018-04-07 15:32:37507 * @param {number} windowStart
508 * @param {number} windowEnd
Tim van der Lippe0ed1d2b2020-02-04 13:45:13509 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37510 * @return {boolean}
511 */
512 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34513 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37514 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34515 }
516 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37517 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34518 }
Blink Reformat4c46d092018-04-07 15:32:37519 return true;
520 }
521
522 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13523 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37524 */
525 static _copyRequestHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13526 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37527 }
528
529 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13530 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37531 */
532 static _copyResponseHeaders(request) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13533 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37534 }
535
536 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:13537 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:37538 */
539 static async _copyResponse(request) {
540 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08541 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34542 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40543 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34544 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08545 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34546 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13547 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37548 }
549
550 /**
551 * @param {!DataTransfer} dataTransfer
552 */
553 _handleDrop(dataTransfer) {
554 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34555 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37556 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34557 }
Blink Reformat4c46d092018-04-07 15:32:37558 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34559 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37560 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34561 }
Blink Reformat4c46d092018-04-07 15:32:37562
Joey Arhar0e1093c2019-05-21 00:34:22563 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37564 }
565
566 /**
Tim van der Lippe119690c2020-01-13 12:31:30567 * @override
Blink Reformat4c46d092018-04-07 15:32:37568 * @param {!File} file
569 */
Joey Arhar0e1093c2019-05-21 00:34:22570 async onLoadFromFile(file) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13571 const outputStream = new Common.StringOutputStream.StringOutputStream();
572 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37573 const success = await reader.read(outputStream);
574 if (!success) {
575 this._harLoadFailed(reader.error().message);
576 return;
577 }
578 let harRoot;
579 try {
580 // HARRoot and JSON.parse might throw.
Tim van der Lippe0ed1d2b2020-02-04 13:45:13581 harRoot = new HARImporter.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37582 } catch (e) {
583 this._harLoadFailed(e);
584 return;
585 }
Wolfgang Beyerd81fad62020-05-27 12:30:27586 SDK.NetworkLog.NetworkLog.instance().importRequests(
587 HARImporter.HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37588 }
589
590 /**
591 * @param {string} message
592 */
593 _harLoadFailed(message) {
Paul Lewisa83ea612020-03-04 13:01:36594 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37595 }
596
597 /**
598 * @param {?string} groupKey
599 */
600 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34601 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37602 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34603 }
Blink Reformat4c46d092018-04-07 15:32:37604 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
605 this._activeGroupLookup = groupLookup;
606 this._invalidateAllItems();
607 }
608
609 /**
610 * @return {number}
611 */
612 _computeRowHeight() {
613 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
614 }
615
616 /**
Tim van der Lippe119690c2020-01-13 12:31:30617 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13618 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30619 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37620 */
621 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58622 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37623 }
624
625 /**
Tim van der Lippe119690c2020-01-13 12:31:30626 * @override
Blink Reformat4c46d092018-04-07 15:32:37627 * @return {number}
628 */
629 headerHeight() {
630 return this._headerHeight;
631 }
632
633 /**
Tim van der Lippe119690c2020-01-13 12:31:30634 * @override
Blink Reformat4c46d092018-04-07 15:32:37635 * @param {boolean} recording
636 */
637 setRecording(recording) {
638 this._recording = recording;
639 this._updateSummaryBar();
640 }
641
642 /**
643 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13644 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37645 */
646 modelAdded(networkManager) {
647 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34648 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37649 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34650 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13651 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37652 if (resourceTreeModel) {
653 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
654 resourceTreeModel.addEventListener(
655 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
656 }
657 }
658
659 /**
660 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:13661 * @param {!SDK.NetworkManager.NetworkManager} networkManager
Blink Reformat4c46d092018-04-07 15:32:37662 */
663 modelRemoved(networkManager) {
664 if (!networkManager.target().parentTarget()) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13665 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37666 if (resourceTreeModel) {
667 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
668 resourceTreeModel.removeEventListener(
669 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
670 }
671 }
672 }
673
674 /**
Tim van der Lippe119690c2020-01-13 12:31:30675 * @override
Blink Reformat4c46d092018-04-07 15:32:37676 * @param {number} start
677 * @param {number} end
678 */
679 setWindow(start, end) {
680 if (!start && !end) {
681 this._timeFilter = null;
682 this._timeCalculator.setWindow(null);
683 } else {
Paul Lewis56509652019-12-06 12:51:58684 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30685 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37686 }
687 this._filterRequests();
688 }
689
Tim van der Lippe119690c2020-01-13 12:31:30690 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05691 resetFocus() {
692 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37693 }
694
695 _resetSuggestionBuilder() {
696 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58697 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
698 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
699 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
700 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
701 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
702 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
703 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37704 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
705 }
706
707 /**
Tim van der Lippec02a97c2020-02-14 14:39:27708 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:37709 */
710 _filterChanged(event) {
711 this.removeAllNodeHighlights();
712 this._parseFilterQuery(this._textFilterUI.value());
713 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37714 }
715
Rajasekar Murugan3ad369e2020-02-19 18:20:12716 async resetFilter() {
717 this._textFilterUI.clear();
718 }
719
Blink Reformat4c46d092018-04-07 15:32:37720 _showRecordingHint() {
721 this._hideRecordingHint();
722 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
723 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18724
725 let reloadShortcutNode = null;
Jack Lynchb8fb3c72020-04-21 05:36:16726 const reloadShortcut = self.UI.shortcutRegistry.shortcutsForAction('inspector_main.reload')[0];
727 if (reloadShortcut) {
Joey Arhar0585e6f2018-10-30 23:11:18728 reloadShortcutNode = this._recordingHint.createChild('b');
Jack Lynchb8fb3c72020-04-21 05:36:16729 reloadShortcutNode.textContent = reloadShortcut.title();
Joey Arhar0585e6f2018-10-30 23:11:18730 }
Blink Reformat4c46d092018-04-07 15:32:37731
732 if (this._recording) {
733 const recordingText = hintText.createChild('span');
Mathias Bynens23ee1aa2020-03-02 12:06:38734 recordingText.textContent = Common.UIString.UIString('Recording network activity…');
Joey Arhar0585e6f2018-10-30 23:11:18735 if (reloadShortcutNode) {
736 hintText.createChild('br');
737 hintText.appendChild(
Tim van der Lippe0ed1d2b2020-02-04 13:45:13738 UI.UIUtils.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
Joey Arhar0585e6f2018-10-30 23:11:18739 }
Blink Reformat4c46d092018-04-07 15:32:37740 } else {
741 const recordNode = hintText.createChild('b');
Paul Lewis05eb37f2020-01-24 14:31:40742 recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18743 if (reloadShortcutNode) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13744 hintText.appendChild(UI.UIUtils.formatLocalized(
Joey Arhar0585e6f2018-10-30 23:11:18745 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
746 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13747 hintText.appendChild(UI.UIUtils.formatLocalized('Record (%s) to display network activity.', [recordNode]));
Joey Arhar0585e6f2018-10-30 23:11:18748 }
Blink Reformat4c46d092018-04-07 15:32:37749 }
Kayce Basques5444c1b2019-02-15 20:32:53750 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13751 hintText.appendChild(UI.XLink.XLink.create(
Kayce Basques5444c1b2019-02-15 20:32:53752 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Peter Marshall90bf6602020-08-04 13:50:43753 ls`Learn more`));
Amanda Baker6761aae2019-11-05 18:59:11754
755 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57756 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37757 }
758
759 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11760 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34761 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37762 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34763 }
Brandon Goddardc992d522020-01-08 21:44:57764 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37765 this._recordingHint = null;
766 }
767
768 /**
Amanda Baker6761aae2019-11-05 18:59:11769 * @param {boolean} value
770 */
771 _setHidden(value) {
772 this._columns.setHidden(value);
773 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
774 }
775
776 /**
Blink Reformat4c46d092018-04-07 15:32:37777 * @override
778 * @return {!Array.<!Element>}
779 */
780 elementsToRestoreScrollPositionsFor() {
781 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34782 {
Blink Reformat4c46d092018-04-07 15:32:37783 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34784 }
Blink Reformat4c46d092018-04-07 15:32:37785 return [this._dataGrid.scrollContainer];
786 }
787
Tim van der Lippe119690c2020-01-13 12:31:30788 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37789 columnExtensionResolved() {
790 this._invalidateAllItems(true);
791 }
792
793 _setupDataGrid() {
794 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
795 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34796 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37797 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34798 }
Blink Reformat4c46d092018-04-07 15:32:37799 });
800 this._dataGrid.setStickToBottom(true);
801 this._dataGrid.setName('networkLog');
802 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
803 this._dataGrid.element.classList.add('network-log-grid');
804 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
805 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
806 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05807 this._dataGrid.element.addEventListener('keydown', event => {
808 if (isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:05809 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:05810 event.consume(true);
811 }
812 });
Brandon Goddard44934902020-03-25 16:03:18813 this._dataGrid.element.addEventListener('focus', this._onDataGridFocus.bind(this), true);
814 this._dataGrid.element.addEventListener('blur', this._onDataGridBlur.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37815 return this._dataGrid;
816 }
817
818 /**
819 * @param {!Event} event
820 */
821 _dataGridMouseMove(event) {
822 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
823 const highlightInitiatorChain = event.shiftKey;
824 this._setHoveredNode(node, highlightInitiatorChain);
825 }
826
827 /**
Tim van der Lippe119690c2020-01-13 12:31:30828 * @override
829 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37830 */
831 hoveredNode() {
832 return this._hoveredNode;
833 }
834
835 /**
Tim van der Lippe119690c2020-01-13 12:31:30836 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37837 * @param {boolean=} highlightInitiatorChain
838 */
839 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34840 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37841 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 }
Blink Reformat4c46d092018-04-07 15:32:37843 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34844 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37845 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34846 }
Blink Reformat4c46d092018-04-07 15:32:37847 }
848
849 /**
850 * @param {!Event} event
851 */
852 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34853 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37854 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34855 }
Blink Reformat4c46d092018-04-07 15:32:37856 }
857
858 _updateSummaryBar() {
859 this._hideRecordingHint();
860
861 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20862 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37863 let selectedNodeNumber = 0;
864 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20865 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37866 let baseTime = -1;
867 let maxTime = -1;
868
869 let nodeCount = 0;
Wolfgang Beyerd81fad62020-05-27 12:30:27870 for (const request of SDK.NetworkLog.NetworkLog.instance().requests()) {
Paul Lewis56509652019-12-06 12:51:58871 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34872 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37873 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34874 }
Blink Reformat4c46d092018-04-07 15:32:37875 nodeCount++;
876 const requestTransferSize = request.transferSize;
877 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20878 const requestResourceSize = request.resourceSize;
879 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30880 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37881 selectedNodeNumber++;
882 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20883 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37884 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13885 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:37886 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
887 // inspected url.
888 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:13889 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
890 !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37891 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34892 }
893 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37894 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34895 }
Blink Reformat4c46d092018-04-07 15:32:37896 }
897
898 if (!nodeCount) {
899 this._showRecordingHint();
900 return;
901 }
902
Joey Arhara86c14e2019-03-12 03:20:50903 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37904 /**
905 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50906 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37907 * @return {!Element}
908 */
Joey Arhara86c14e2019-03-12 03:20:50909 const appendChunk = (chunk, title) => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13910 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:50911 toolbarText.setTitle(title ? title : chunk);
912 this._summaryToolbar.appendToolbarItem(toolbarText);
913 return toolbarText.element;
914 };
Blink Reformat4c46d092018-04-07 15:32:37915
916 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50917 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
918 this._summaryToolbar.appendSeparator();
919 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17920 ls`${Platform.NumberUtilities.bytesToString(selectedTransferSize)} / ${
921 Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25922 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50923 this._summaryToolbar.appendSeparator();
924 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17925 ls`${Platform.NumberUtilities.bytesToString(selectedResourceSize)} / ${
926 Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25927 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37928 } else {
Joey Arhara86c14e2019-03-12 03:20:50929 appendChunk(ls`${nodeCount} requests`);
930 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25931 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17932 ls`${Platform.NumberUtilities.bytesToString(transferSize)} transferred`,
933 ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50934 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25935 appendChunk(
Jack Franklin9c225ca2020-04-29 09:55:17936 ls`${Platform.NumberUtilities.bytesToString(resourceSize)} resources`,
937 ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37938 }
Dan Beam87466b52018-12-01 18:41:20939
Blink Reformat4c46d092018-04-07 15:32:37940 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50941 this._summaryToolbar.appendSeparator();
942 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37943 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50944 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30945 const domContentLoadedText =
946 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58947 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37948 }
949 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50950 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30951 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58952 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37953 }
954 }
Blink Reformat4c46d092018-04-07 15:32:37955 }
956
Tim van der Lippe119690c2020-01-13 12:31:30957 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37958 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37960 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34961 }
Blink Reformat4c46d092018-04-07 15:32:37962
963 this._needsRefresh = true;
964
Tim van der Lippe1d6e57a2019-09-30 11:55:34965 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37966 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34967 }
Blink Reformat4c46d092018-04-07 15:32:37968 }
969
970 /**
Tim van der Lippe119690c2020-01-13 12:31:30971 * @override
Blink Reformat4c46d092018-04-07 15:32:37972 * @param {!Array<number>} times
973 */
974 addFilmStripFrames(times) {
975 this._columns.addEventDividers(times, 'network-frame-divider');
976 }
977
978 /**
Tim van der Lippe119690c2020-01-13 12:31:30979 * @override
Blink Reformat4c46d092018-04-07 15:32:37980 * @param {number} time
981 */
982 selectFilmStripFrame(time) {
983 this._columns.selectFilmStripFrame(time);
984 }
985
Tim van der Lippe119690c2020-01-13 12:31:30986 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37987 clearFilmStripFrame() {
988 this._columns.clearFilmStripFrame();
989 }
990
991 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34992 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37993 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34994 }
Blink Reformat4c46d092018-04-07 15:32:37995 }
996
997 /**
998 * @param {boolean=} deferUpdate
999 */
1000 _invalidateAllItems(deferUpdate) {
Wolfgang Beyerd81fad62020-05-27 12:30:271001 this._staleRequests = new Set(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:341002 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371003 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341004 } else {
Blink Reformat4c46d092018-04-07 15:32:371005 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341006 }
Blink Reformat4c46d092018-04-07 15:32:371007 }
1008
1009 /**
Tim van der Lippe119690c2020-01-13 12:31:301010 * @override
1011 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371012 */
1013 timeCalculator() {
1014 return this._timeCalculator;
1015 }
1016
1017 /**
Tim van der Lippe119690c2020-01-13 12:31:301018 * @override
1019 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:371020 */
1021 calculator() {
1022 return this._calculator;
1023 }
1024
1025 /**
Tim van der Lippe119690c2020-01-13 12:31:301026 * @override
1027 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:371028 */
1029 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341030 if (!x || this._calculator === x) {
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 if (this._calculator !== x) {
1035 this._calculator = x;
1036 this._columns.setCalculator(this._calculator);
1037 }
1038 this._calculator.reset();
1039
Tim van der Lippe1d6e57a2019-09-30 11:55:341040 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:371041 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341042 } else {
Blink Reformat4c46d092018-04-07 15:32:371043 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341044 }
Blink Reformat4c46d092018-04-07 15:32:371045
1046 this._invalidateAllItems();
1047 }
1048
1049 /**
Tim van der Lippec02a97c2020-02-14 14:39:271050 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371051 */
1052 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341053 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371054 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341055 }
Blink Reformat4c46d092018-04-07 15:32:371056
1057 const time = /** @type {number} */ (event.data.loadTime);
1058 if (time) {
1059 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:301060 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371061 }
1062 }
1063
1064 /**
Tim van der Lippec02a97c2020-02-14 14:39:271065 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371066 */
1067 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341068 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:371069 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341070 }
Blink Reformat4c46d092018-04-07 15:32:371071 const data = /** @type {number} */ (event.data);
1072 if (data) {
1073 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:301074 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371075 }
1076 }
1077
1078 /**
1079 * @override
1080 */
1081 wasShown() {
1082 this._refreshIfNeeded();
1083 this._columns.wasShown();
1084 }
1085
1086 /**
1087 * @override
1088 */
1089 willHide() {
1090 this._columns.willHide();
1091 }
1092
1093 /**
1094 * @override
1095 */
1096 onResize() {
1097 this._rowHeight = this._computeRowHeight();
1098 }
1099
1100 /**
Tim van der Lippe119690c2020-01-13 12:31:301101 * @override
1102 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371103 */
1104 flatNodesList() {
1105 return this._dataGrid.rootNode().flatChildren();
1106 }
1107
Brandon Goddard44934902020-03-25 16:03:181108 _onDataGridFocus() {
Peter Marshallde3fee72020-08-24 14:12:491109 if (this._dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351110 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381111 }
Brandon Goddard44934902020-03-25 16:03:181112 this.updateNodeBackground();
1113 }
1114
1115 _onDataGridBlur() {
1116 this.element.classList.remove('grid-focused');
1117 this.updateNodeBackground();
1118 }
1119
Tim van der Lippe119690c2020-01-13 12:31:301120 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051121 updateNodeBackground() {
1122 if (this._dataGrid.selectedNode) {
1123 this._dataGrid.selectedNode.updateBackgroundColor();
1124 }
1125 }
1126
1127 /**
Tim van der Lippe119690c2020-01-13 12:31:301128 * @override
Brandon Goddard88d885a2019-10-31 16:11:051129 * @param {boolean} isSelected
1130 */
1131 updateNodeSelectedClass(isSelected) {
1132 if (isSelected) {
1133 this.element.classList.remove('no-node-selected');
1134 } else {
1135 this.element.classList.add('no-node-selected');
1136 }
1137 }
1138
Tim van der Lippe119690c2020-01-13 12:31:301139 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371140 stylesChanged() {
1141 this._columns.scheduleRefresh();
1142 }
1143
1144 _refresh() {
1145 this._needsRefresh = false;
1146
1147 if (this._refreshRequestId) {
1148 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1149 this._refreshRequestId = null;
1150 }
1151
1152 this.removeAllNodeHighlights();
1153
1154 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1155 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1156 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1157 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1158
Tim van der Lippe119690c2020-01-13 12:31:301159 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371160 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301161 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371162 const nodesToRefresh = [];
1163
Tim van der Lippe119690c2020-01-13 12:31:301164 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371165 const staleNodes = new Set();
1166
1167 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1168 // node so we loop until we have no more stale requests.
1169 while (this._staleRequests.size) {
1170 const request = this._staleRequests.firstValue();
1171 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581172 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341173 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371174 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341175 }
Blink Reformat4c46d092018-04-07 15:32:371176 staleNodes.add(node);
1177 }
1178
1179 for (const node of staleNodes) {
1180 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341181 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371182 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341183 }
Blink Reformat4c46d092018-04-07 15:32:371184
Tim van der Lippe1d6e57a2019-09-30 11:55:341185 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371186 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341187 }
Blink Reformat4c46d092018-04-07 15:32:371188 const request = node.request();
1189 this._timeCalculator.updateBoundaries(request);
1190 this._durationCalculator.updateBoundaries(request);
1191 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301192 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371193 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341194 }
Tim van der Lippe119690c2020-01-13 12:31:301195 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371196 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1197 if (removeFromParent) {
1198 let parent = node.parent;
1199 parent.removeChild(node);
1200 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1201 const grandparent = parent.parent;
1202 grandparent.removeChild(parent);
1203 parent = grandparent;
1204 }
1205 }
1206
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371208 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341209 }
Blink Reformat4c46d092018-04-07 15:32:371210
1211 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1212 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1213 nodesToRefresh.push(newParent);
1214 }
1215 nodesToInsert.set(node, newParent);
1216 }
1217
Tim van der Lippe1d6e57a2019-09-30 11:55:341218 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371219 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341220 }
Blink Reformat4c46d092018-04-07 15:32:371221
Tim van der Lippe1d6e57a2019-09-30 11:55:341222 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371223 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341224 }
Blink Reformat4c46d092018-04-07 15:32:371225
1226 this._updateSummaryBar();
1227
Tim van der Lippe1d6e57a2019-09-30 11:55:341228 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371229 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341230 }
Blink Reformat4c46d092018-04-07 15:32:371231
1232 this._dataGrid.updateInstantly();
1233 this._didRefreshForTest();
1234 }
1235
1236 _didRefreshForTest() {
1237 }
1238
1239 /**
Tim van der Lippe119690c2020-01-13 12:31:301240 * @param {!NetworkRequestNode} node
1241 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371242 */
1243 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341244 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371245 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341246 }
Blink Reformat4c46d092018-04-07 15:32:371247
1248 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341249 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371250 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341251 }
Blink Reformat4c46d092018-04-07 15:32:371252 return groupNode;
1253 }
1254
1255 _reset() {
Simon Zünd98419832020-03-12 06:18:151256 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371257
1258 this._setHoveredNode(null);
1259 this._columns.reset();
1260
1261 this._timeFilter = null;
1262 this._calculator.reset();
1263
1264 this._timeCalculator.setWindow(null);
1265 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371266
Tim van der Lippe1d6e57a2019-09-30 11:55:341267 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371268 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341269 }
Blink Reformat4c46d092018-04-07 15:32:371270 this._staleRequests.clear();
1271 this._resetSuggestionBuilder();
1272
1273 this._mainRequestLoadTime = -1;
1274 this._mainRequestDOMContentLoadedTime = -1;
1275
1276 this._dataGrid.rootNode().removeChildren();
1277 this._updateSummaryBar();
1278 this._dataGrid.setStickToBottom(true);
1279 this.scheduleRefresh();
1280 }
1281
1282 /**
Tim van der Lippe119690c2020-01-13 12:31:301283 * @override
Blink Reformat4c46d092018-04-07 15:32:371284 * @param {string} filterString
1285 */
1286 setTextFilterValue(filterString) {
1287 this._textFilterUI.setValue(filterString);
1288 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371289 this._onlyIssuesFilterUI.setChecked(false);
Sigurd Schneidera2afe0b2020-03-03 15:27:131290 this._onlyBlockedRequestsUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371291 this._resourceCategoryFilterUI.reset();
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 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301298 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581299 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301300 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371301
Tim van der Lippe1d6e57a2019-09-30 11:55:341302 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371303 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341304 }
Blink Reformat4c46d092018-04-07 15:32:371305 return node;
1306 }
1307
1308 /**
Tim van der Lippec02a97c2020-02-14 14:39:271309 * @param {!Common.EventTarget.EventTargetEvent} event
Blink Reformat4c46d092018-04-07 15:32:371310 */
1311 _onRequestUpdated(event) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131312 const request = /** @type {!SDK.NetworkRequest.NetworkRequest} */ (event.data);
Blink Reformat4c46d092018-04-07 15:32:371313 this._refreshRequest(request);
1314 }
1315
1316 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131317 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371318 */
1319 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581320 NetworkLogView._subdomains(request.domain)
1321 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1322 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1323 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1324 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1325 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Sigurd Schneider464838b2020-08-24 13:53:031326 this._suggestionBuilder.addItem(FilterType.ResourceType, request.resourceType().name());
Julian Geppertf8ce40c2020-09-01 18:02:031327 this._suggestionBuilder.addItem(FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371328
1329 const priority = request.priority();
1330 if (priority) {
Tim van der Lippeded23fb2020-02-13 13:33:501331 this._suggestionBuilder.addItem(
1332 FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371333 }
1334
1335 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581336 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371337 }
1338
1339 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581340 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371341 }
1342
1343 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581344 const suggestion =
1345 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1346 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371347 }
1348
1349 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341350 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581351 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341352 }
Jan Scheffler341eea52019-12-12 09:08:411353
1354 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581355 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1356 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1357 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371358 }
1359
Jan Scheffler341eea52019-12-12 09:08:411360 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1361 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1362 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
Simon Zündc9759102020-03-25 11:24:541363 this._suggestionBuilder.addItem(FilterType.CookiePath, cookie.path());
Jan Scheffler341eea52019-12-12 09:08:411364 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1365 }
1366
Blink Reformat4c46d092018-04-07 15:32:371367 this._staleRequests.add(request);
1368 this.scheduleRefresh();
1369 }
1370
1371 /**
Tim van der Lippe119690c2020-01-13 12:31:301372 * @override
Blink Reformat4c46d092018-04-07 15:32:371373 * @return {number}
1374 */
1375 rowHeight() {
1376 return this._rowHeight;
1377 }
1378
1379 /**
Tim van der Lippe119690c2020-01-13 12:31:301380 * @override
Blink Reformat4c46d092018-04-07 15:32:371381 * @param {boolean} gridMode
1382 */
1383 switchViewMode(gridMode) {
1384 this._columns.switchViewMode(gridMode);
1385 }
1386
1387 /**
Tim van der Lippe119690c2020-01-13 12:31:301388 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131389 * @param {!UI.ContextMenu.ContextMenu} contextMenu
1390 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371391 */
1392 handleContextMenuForRequest(contextMenu, request) {
1393 contextMenu.appendApplicableItems(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131394 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371395 const footerSection = copyMenu.footerSection();
1396 if (request) {
1397 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131398 UI.UIUtils.copyLinkAddressLabel(),
1399 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1400 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371401 if (request.requestHeadersText()) {
1402 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131403 Common.UIString.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371404 }
1405
1406 if (request.responseHeadersText) {
1407 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131408 Common.UIString.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371409 }
1410
1411 if (request.finished) {
1412 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131413 Common.UIString.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371414 }
1415
Harley Libcf41f92018-09-10 18:01:131416 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131417 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371418 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131419 Common.UIString.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request),
1420 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371421 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131422 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291423 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131424 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1425 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371426 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131427 Common.UIString.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'),
1428 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131429 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131430 Common.UIString.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'),
1431 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371432 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131433 Common.UIString.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1434 footerSection.appendItem(
1435 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1436 footerSection.appendItem(
1437 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1438 footerSection.appendItem(
1439 Common.UIString.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1440 footerSection.appendItem(
1441 Common.UIString.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371442 } else {
Harley Libcf41f92018-09-10 18:01:131443 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131444 Common.UIString.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291445 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131446 Common.UIString.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true),
1447 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131448 footerSection.appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131449 Common.UIString.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1450 footerSection.appendItem(
1451 Common.UIString.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1452 footerSection.appendItem(
1453 Common.UIString.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
1454 footerSection.appendItem(
1455 Common.UIString.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371456 }
1457 } else {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131458 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString.UIString('Copy'));
Blink Reformat4c46d092018-04-07 15:32:371459 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131460 footerSection.appendItem(Common.UIString.UIString('Copy all as HAR'), this._copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371461
Joey Arhar0e1093c2019-05-21 00:34:221462 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371463
Blink Reformat4c46d092018-04-07 15:32:371464 contextMenu.editSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131465 Common.UIString.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1466 contextMenu.editSection().appendItem(
1467 Common.UIString.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371468
1469 if (request) {
1470 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211471 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371472 let patterns = manager.blockedPatterns();
1473
Tim van der Lippeffa78622019-09-16 12:07:121474 /**
1475 * @param {string} url
1476 */
1477 function addBlockedURL(url) {
1478 patterns.push({enabled: true, url: url});
1479 manager.setBlockedPatterns(patterns);
1480 manager.setBlockingEnabled(true);
Paul Lewis75c7d0d2020-03-19 12:17:261481 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121482 }
1483
1484 /**
1485 * @param {string} url
1486 */
1487 function removeBlockedURL(url) {
1488 patterns = patterns.filter(pattern => pattern.url !== url);
1489 manager.setBlockedPatterns(patterns);
Paul Lewis75c7d0d2020-03-19 12:17:261490 UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121491 }
1492
Blink Reformat4c46d092018-04-07 15:32:371493 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1494 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1495 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131496 Common.UIString.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371497 } else if (urlWithoutScheme) {
1498 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1499 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131500 Common.UIString.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371501 }
1502
1503 const domain = request.parsedURL.domain();
1504 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1505 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131506 Common.UIString.UIString('Block request domain'), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371507 } else if (domain) {
1508 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1509 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131510 Common.UIString.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371511 }
1512
Tim van der Lippe0ed1d2b2020-02-04 13:45:131513 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371514 contextMenu.debugSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131515 Common.UIString.UIString('Replay XHR'),
1516 SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371517 }
Blink Reformat4c46d092018-04-07 15:32:371518 }
1519 }
1520
1521 _harRequests() {
Wolfgang Beyerd81fad62020-05-27 12:30:271522 return SDK.NetworkLog.NetworkLog.instance().requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171523 return request.finished ||
Tim van der Lippe0ed1d2b2020-02-04 13:45:131524 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
Joey Arharb3d6de42019-04-23 21:26:171525 });
Blink Reformat4c46d092018-04-07 15:32:371526 }
1527
1528 async _copyAll() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131529 const harArchive = {log: await SDK.HARLog.HARLog.build(this._harRequests())};
1530 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371531 }
1532
1533 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131534 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371535 * @param {string} platform
1536 */
1537 async _copyCurlCommand(request, platform) {
1538 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131539 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371540 }
1541
1542 /**
1543 * @param {string} platform
1544 */
1545 async _copyAllCurlCommand(platform) {
Wolfgang Beyerd81fad62020-05-27 12:30:271546 const commands = await this._generateAllCurlCommand(SDK.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131547 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371548 }
1549
1550 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131551 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291552 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371553 */
Jan Scheffler7c50d1f2019-12-17 13:33:291554 async _copyFetchCall(request, includeCookies) {
1555 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131556 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371557 }
1558
Jan Scheffler7c50d1f2019-12-17 13:33:291559 /**
1560 * @param {boolean} includeCookies
1561 */
1562 async _copyAllFetchCall(includeCookies) {
Wolfgang Beyerd81fad62020-05-27 12:30:271563 const commands = await this._generateAllFetchCall(SDK.NetworkLog.NetworkLog.instance().requests(), includeCookies);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131564 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371565 }
1566
1567 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131568 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371569 */
1570 async _copyPowerShellCommand(request) {
1571 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371573 }
1574
1575 async _copyAllPowerShellCommand() {
Wolfgang Beyerd81fad62020-05-27 12:30:271576 const commands = await this._generateAllPowerShellCommand(SDK.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131577 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371578 }
1579
Tim van der Lippe119690c2020-01-13 12:31:301580 /**
1581 * @override
1582 * @return {!Promise}
1583 */
Joey Arhar0e1093c2019-05-21 00:34:221584 async exportAll() {
Paul Lewisdaac1062020-03-05 14:37:101585 const url = SDK.SDKModel.TargetManager.instance().mainTarget().inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131586 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371587 const filename = parsedURL ? parsedURL.host : 'network-log';
Tim van der Lippe0ed1d2b2020-02-04 13:45:131588 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371589
Tim van der Lippe1d6e57a2019-09-30 11:55:341590 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371591 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341592 }
Blink Reformat4c46d092018-04-07 15:32:371593
Tim van der Lippe0ed1d2b2020-02-04 13:45:131594 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Blink Reformat4c46d092018-04-07 15:32:371595 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301596 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371597 progressIndicator.done();
1598 stream.close();
1599 }
1600
1601 _clearBrowserCache() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131602 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cache?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211603 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341604 }
Blink Reformat4c46d092018-04-07 15:32:371605 }
1606
1607 _clearBrowserCookies() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131608 if (confirm(Common.UIString.UIString('Are you sure you want to clear browser cookies?'))) {
Tim van der Lippecd0bb372020-05-01 13:53:211609 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341610 }
Blink Reformat4c46d092018-04-07 15:32:371611 }
1612
1613 _removeAllHighlights() {
1614 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341615 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131616 UI.UIUtils.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341617 }
Blink Reformat4c46d092018-04-07 15:32:371618 this._highlightedSubstringChanges = [];
1619 }
1620
1621 /**
Tim van der Lippe119690c2020-01-13 12:31:301622 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371623 * @return {boolean}
1624 */
1625 _applyFilter(node) {
1626 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341627 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371628 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341629 }
Blink Reformat4c46d092018-04-07 15:32:371630 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341631 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371632 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341633 }
1634 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371635 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341636 }
Sigurd Schneiderc8c1e352020-05-08 14:33:221637 if (this._onlyIssuesFilterUI.checked() &&
1638 !BrowserSDK.RelatedIssue.hasIssueOfCategory(request, SDK.Issue.IssueCategory.SameSiteCookie)) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371639 return false;
1640 }
Sigurd Schneidera2afe0b2020-03-03 15:27:131641 if (this._onlyBlockedRequestsUI.checked() && !request.wasBlocked()) {
1642 return false;
1643 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341644 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371645 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341646 }
Blink Reformat4c46d092018-04-07 15:32:371647 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341648 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371649 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341650 }
Blink Reformat4c46d092018-04-07 15:32:371651 }
1652 return true;
1653 }
1654
1655 /**
1656 * @param {string} query
1657 */
1658 _parseFilterQuery(query) {
1659 const descriptors = this._filterParser.parse(query);
1660 this._filters = descriptors.map(descriptor => {
1661 const key = descriptor.key;
1662 const text = descriptor.text || '';
1663 const regex = descriptor.regex;
1664 let filter;
1665 if (key) {
1666 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581667 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1668 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371669 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581670 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371671 } else {
Paul Lewis56509652019-12-06 12:51:581672 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371673 }
Paul Lewis56509652019-12-06 12:51:581674 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371675 });
1676 }
1677
1678 /**
Paul Lewis56509652019-12-06 12:51:581679 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371680 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161681 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371682 */
1683 _createSpecialFilter(type, value) {
1684 switch (type) {
Paul Lewis56509652019-12-06 12:51:581685 case FilterType.Domain:
1686 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371687
Paul Lewis56509652019-12-06 12:51:581688 case FilterType.HasResponseHeader:
1689 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371690
Paul Lewis56509652019-12-06 12:51:581691 case FilterType.Is:
1692 if (value.toLowerCase() === IsFilterType.Running) {
1693 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341694 }
Paul Lewis56509652019-12-06 12:51:581695 if (value.toLowerCase() === IsFilterType.FromCache) {
1696 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341697 }
Paul Lewis56509652019-12-06 12:51:581698 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1699 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341700 }
Paul Lewis56509652019-12-06 12:51:581701 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1702 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341703 }
Blink Reformat4c46d092018-04-07 15:32:371704 break;
1705
Paul Lewis56509652019-12-06 12:51:581706 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371707 return this._createSizeFilter(value.toLowerCase());
1708
Paul Lewis56509652019-12-06 12:51:581709 case FilterType.Method:
1710 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371711
Paul Lewis56509652019-12-06 12:51:581712 case FilterType.MimeType:
1713 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371714
Paul Lewis56509652019-12-06 12:51:581715 case FilterType.MixedContent:
1716 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371717
Paul Lewis56509652019-12-06 12:51:581718 case FilterType.Scheme:
1719 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371720
Paul Lewis56509652019-12-06 12:51:581721 case FilterType.SetCookieDomain:
1722 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371723
Paul Lewis56509652019-12-06 12:51:581724 case FilterType.SetCookieName:
1725 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371726
Paul Lewis56509652019-12-06 12:51:581727 case FilterType.SetCookieValue:
1728 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371729
Jan Scheffler341eea52019-12-12 09:08:411730 case FilterType.CookieDomain:
1731 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1732
1733 case FilterType.CookieName:
1734 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1735
Simon Zündc9759102020-03-25 11:24:541736 case FilterType.CookiePath:
1737 return NetworkLogView._requestCookiePathFilter.bind(null, value);
1738
Jan Scheffler341eea52019-12-12 09:08:411739 case FilterType.CookieValue:
1740 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1741
Paul Lewis56509652019-12-06 12:51:581742 case FilterType.Priority:
Tim van der Lippeded23fb2020-02-13 13:33:501743 return NetworkLogView._requestPriorityFilter.bind(
1744 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371745
Paul Lewis56509652019-12-06 12:51:581746 case FilterType.StatusCode:
1747 return NetworkLogView._statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031748
1749 case FilterType.ResourceType:
1750 return NetworkLogView._resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031751
1752 case FilterType.Url:
1753 return NetworkLogView._requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371754 }
1755 return null;
1756 }
1757
1758 /**
1759 * @param {string} value
Tim van der Lippeb1f2b6c2020-02-17 13:00:161760 * @return {?Filter}
Blink Reformat4c46d092018-04-07 15:32:371761 */
1762 _createSizeFilter(value) {
1763 let multiplier = 1;
1764 if (value.endsWith('k')) {
Wolfgang Beyer585ded42020-02-25 08:42:411765 multiplier = 1024;
Blink Reformat4c46d092018-04-07 15:32:371766 value = value.substring(0, value.length - 1);
1767 } else if (value.endsWith('m')) {
Wolfgang Beyer585ded42020-02-25 08:42:411768 multiplier = 1024 * 1024;
Blink Reformat4c46d092018-04-07 15:32:371769 value = value.substring(0, value.length - 1);
1770 }
1771 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341772 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371773 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341774 }
Paul Lewis56509652019-12-06 12:51:581775 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371776 }
1777
1778 _filterRequests() {
1779 this._removeAllHighlights();
1780 this._invalidateAllItems();
1781 }
1782
1783 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131784 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301785 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371786 */
1787 _reveal(request) {
1788 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581789 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341790 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371791 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341792 }
Brandon Goddard5e4244d2020-04-08 22:08:471793 // Viewport datagrid nodes do not reveal if not in the root node
1794 // list of flatChildren. For children of grouped frame nodes:
1795 // reveal and expand parent to ensure child is revealable.
1796 if (node.parent && node.parent instanceof NetworkGroupNode) {
1797 node.parent.reveal();
1798 node.parent.expand();
1799 }
Blink Reformat4c46d092018-04-07 15:32:371800 node.reveal();
1801 return node;
1802 }
1803
1804 /**
Tim van der Lippe119690c2020-01-13 12:31:301805 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131806 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371807 */
1808 revealAndHighlightRequest(request) {
1809 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341810 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371811 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341812 }
Blink Reformat4c46d092018-04-07 15:32:371813 }
1814
1815 /**
Tim van der Lippe119690c2020-01-13 12:31:301816 * @override
Tim van der Lippe0ed1d2b2020-02-04 13:45:131817 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371818 */
1819 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141820 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371821 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341822 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371823 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341824 }
Blink Reformat4c46d092018-04-07 15:32:371825 }
1826
Tim van der Lippe119690c2020-01-13 12:31:301827 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371828 removeAllNodeHighlights() {
1829 if (this._highlightedNode) {
1830 this._highlightedNode.element().classList.remove('highlighted-row');
1831 this._highlightedNode = null;
1832 }
1833 }
1834
1835 /**
Tim van der Lippe119690c2020-01-13 12:31:301836 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371837 */
1838 _highlightNode(node) {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131839 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Blink Reformat4c46d092018-04-07 15:32:371840 this._highlightedNode = node;
1841 }
1842
1843 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131844 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
1845 * @return {!Array<!SDK.NetworkRequest.NetworkRequest>}
Harley Libcf41f92018-09-10 18:01:131846 */
1847 _filterOutBlobRequests(requests) {
1848 return requests.filter(request => !request.isBlobRequest());
1849 }
1850
1851 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131852 * @param {!SDK.NetworkRequest.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291853 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371854 * @return {!Promise<string>}
1855 */
Jan Scheffler7c50d1f2019-12-17 13:33:291856 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371857 const ignoredHeaders = {
1858 // Internal headers
1859 'method': 1,
1860 'path': 1,
1861 'scheme': 1,
1862 'version': 1,
1863
1864 // Unsafe headers
1865 // Keep this list synchronized with src/net/http/http_util.cc
1866 'accept-charset': 1,
1867 'accept-encoding': 1,
1868 'access-control-request-headers': 1,
1869 'access-control-request-method': 1,
1870 'connection': 1,
1871 'content-length': 1,
1872 'cookie': 1,
1873 'cookie2': 1,
1874 'date': 1,
1875 'dnt': 1,
1876 'expect': 1,
1877 'host': 1,
1878 'keep-alive': 1,
1879 'origin': 1,
1880 'referer': 1,
1881 'te': 1,
1882 'trailer': 1,
1883 'transfer-encoding': 1,
1884 'upgrade': 1,
1885 'via': 1,
1886 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1887 'user-agent': 1
1888 };
1889
1890 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1891
1892 const url = JSON.stringify(request.url());
1893
1894 const requestHeaders = request.requestHeaders();
1895 const headerData = requestHeaders.reduce((result, header) => {
1896 const name = header.name;
1897
Tim van der Lippe1d6e57a2019-09-30 11:55:341898 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371899 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341900 }
Blink Reformat4c46d092018-04-07 15:32:371901
1902 return result;
1903 }, new Headers());
1904
1905 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341906 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411907 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341908 }
Blink Reformat4c46d092018-04-07 15:32:371909
Sigurd Schneider0e88b912020-05-08 08:28:231910 const credentials = request.includedRequestCookies().length ||
1911 requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
Jan Scheffler341eea52019-12-12 09:08:411912 'include' :
1913 'omit';
Blink Reformat4c46d092018-04-07 15:32:371914
1915 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1916
1917 const referrer = referrerHeader ? referrerHeader.value : void 0;
1918
1919 const referrerPolicy = request.referrerPolicy() || void 0;
1920
1921 const requestBody = await request.requestFormData();
1922
1923 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411924 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371925 referrer,
1926 referrerPolicy,
1927 body: requestBody,
1928 method: request.requestMethod,
1929 mode: 'cors'
1930 };
1931
Jan Scheffler7c50d1f2019-12-17 13:33:291932 if (includeCookies) {
1933 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1934 if (cookieHeader) {
1935 fetchOptions.headers = {
1936 ...headers,
1937 'cookie': cookieHeader.value,
1938 };
1939 }
1940 } else {
1941 fetchOptions.credentials = credentials;
1942 }
1943
Jan Scheffler172d5212020-01-02 14:42:561944 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371945 return `fetch(${url}, ${options});`;
1946 }
1947
1948 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131949 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291950 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131951 * @return {!Promise<string>}
1952 */
Jan Scheffler7c50d1f2019-12-17 13:33:291953 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131954 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291955 const commands =
1956 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131957 return commands.join(' ;\n');
1958 }
1959
1960 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:131961 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:371962 * @param {string} platform
1963 * @return {!Promise<string>}
1964 */
1965 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561966 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361967 // Most of these headers are derived from the URL and are automatically added by cURL.
1968 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1969 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371970
1971 function escapeStringWin(str) {
1972 /* If there are no new line characters do not escape the " characters
1973 since it only uglifies the command.
1974
1975 Because cmd.exe parser and MS Crt arguments parsers use some of the
1976 same escape characters, they can interact with each other in
1977 horrible ways, the order of operations is critical.
1978
1979 Replace \ with \\ first because it is an escape character for certain
1980 conditions in both parsers.
1981
1982 Replace all " with \" to ensure the first parser does not remove it.
1983
1984 Then escape all characters we are not sure about with ^ to ensure it
1985 gets to MS Crt parser safely.
1986
1987 The % character is special because MS Crt parser will try and look for
1988 ENV variables and fill them in it's place. We cannot escape them with %
1989 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1990 parser); So we can get cmd.exe parser to escape the character after it,
1991 if it is followed by a valid beginning character of an ENV variable.
1992 This ensures we do not try and double escape another ^ if it was placed
1993 by the previous replace.
1994
1995 Lastly we replace new lines with ^ and TWO new lines because the first
1996 new line is there to enact the escape command the second is the character
1997 to escape (in this case new line).
1998 */
1999 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2000 return encapsChars +
2001 str.replace(/\\/g, '\\\\')
2002 .replace(/"/g, '\\"')
2003 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
2004 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
2005 .replace(/\r\n|[\n\r]/g, '^\n\n') +
2006 encapsChars;
2007 }
2008
2009 /**
2010 * @param {string} str
2011 * @return {string}
2012 */
2013 function escapeStringPosix(str) {
2014 /**
2015 * @param {string} x
2016 * @return {string}
2017 */
2018 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:222019 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122020 let hexString = code.toString(16);
2021 // Zero pad to four digits to comply with ANSI-C Quoting:
2022 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342023 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122024 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342025 }
Joey Arhar2d21f712019-05-20 21:07:122026
2027 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372028 }
2029
Mathias Bynensf06e8c02020-02-28 13:58:282030 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372031 // Use ANSI-C quoting syntax.
2032 return '$\'' +
2033 str.replace(/\\/g, '\\\\')
2034 .replace(/\'/g, '\\\'')
2035 .replace(/\n/g, '\\n')
2036 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282037 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372038 '\'';
Blink Reformat4c46d092018-04-07 15:32:372039 }
Mathias Bynensf06e8c02020-02-28 13:58:282040 // Use single quote syntax.
2041 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372042 }
2043
2044 // cURL command expected to run on the same platform that DevTools run
2045 // (it may be different from the inspected page platform).
2046 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2047
2048 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2049
2050 let inferredMethod = 'GET';
2051 const data = [];
2052 const requestContentType = request.requestContentType();
2053 const formData = await request.requestFormData();
2054 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272055 // Note that formData is not necessarily urlencoded because it might for example
2056 // come from a fetch request made with an explicitly unencoded body.
2057 data.push('--data-raw ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372058 ignoredHeaders['content-length'] = true;
2059 inferredMethod = 'POST';
2060 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:562061 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:372062 ignoredHeaders['content-length'] = true;
2063 inferredMethod = 'POST';
2064 }
2065
2066 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292067 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372068 }
2069
2070 const requestHeaders = request.requestHeaders();
2071 for (let i = 0; i < requestHeaders.length; i++) {
2072 const header = requestHeaders[i];
2073 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342074 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:372075 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342076 }
Jan Scheffler172d5212020-01-02 14:42:562077 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:372078 }
2079 command = command.concat(data);
2080 command.push('--compressed');
2081
Tim van der Lippe1d6e57a2019-09-30 11:55:342082 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372083 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342084 }
Jan Scheffler172d5212020-01-02 14:42:562085 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372086 }
2087
2088 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132089 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132090 * @param {string} platform
2091 * @return {!Promise<string>}
2092 */
2093 async _generateAllCurlCommand(requests, platform) {
2094 const nonBlobRequests = this._filterOutBlobRequests(requests);
2095 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342096 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132097 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342098 }
Mathias Bynensf06e8c02020-02-28 13:58:282099 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132100 }
2101
2102 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132103 * @param {!SDK.NetworkRequest.NetworkRequest} request
Blink Reformat4c46d092018-04-07 15:32:372104 * @return {!Promise<string>}
2105 */
2106 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:562107 const command = [];
Blink Reformat4c46d092018-04-07 15:32:372108 const ignoredHeaders =
2109 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
2110
2111 /**
2112 * @param {string} str
2113 * @return {string}
2114 */
2115 function escapeString(str) {
2116 return '"' +
2117 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2118 }
2119
Jan Scheffler172d5212020-01-02 14:42:562120 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372121
2122 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562123 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372124 }
2125
2126 const requestHeaders = request.requestHeaders();
2127 const headerNameValuePairs = [];
2128 for (const header of requestHeaders) {
2129 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342130 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372131 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342132 }
Blink Reformat4c46d092018-04-07 15:32:372133 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2134 }
2135 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562136 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372137 }
2138
2139 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2140 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562141 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372142 }
2143
2144 const formData = await request.requestFormData();
2145 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372146 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342147 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562148 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342149 } else {
Jan Scheffler172d5212020-01-02 14:42:562150 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342151 }
Blink Reformat4c46d092018-04-07 15:32:372152 }
2153
Jan Scheffler172d5212020-01-02 14:42:562154 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372155 }
Harley Libcf41f92018-09-10 18:01:132156
2157 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132158 * @param {!Array<!SDK.NetworkRequest.NetworkRequest>} requests
Harley Libcf41f92018-09-10 18:01:132159 * @return {!Promise<string>}
2160 */
2161 async _generateAllPowerShellCommand(requests) {
2162 const nonBlobRequests = this._filterOutBlobRequests(requests);
2163 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2164 return commands.join(';\r\n');
2165 }
Joey Arhara86c14e2019-03-12 03:20:502166
2167 /**
2168 * @return {string}
2169 */
2170 static getDCLEventColor() {
Paul Lewis93d8e2c2020-01-24 16:34:552171 if (self.UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502172 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342173 }
Joey Arhara86c14e2019-03-12 03:20:502174 return '#0867CB';
2175 }
2176
2177 /**
2178 * @return {string}
2179 */
2180 static getLoadEventColor() {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132181 return self.UI.themeSupport.patchColorText('#B31412', UI.UIUtils.ThemeSupport.ColorUsage.Foreground);
Joey Arhara86c14e2019-03-12 03:20:502182 }
Paul Lewis56509652019-12-06 12:51:582183}
Blink Reformat4c46d092018-04-07 15:32:372184
Tim van der Lippe119690c2020-01-13 12:31:302185export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582186export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372187
Paul Lewis56509652019-12-06 12:51:582188export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372189 'http': true,
2190 'https': true,
2191 'ws': true,
2192 'wss': true
2193};
2194
Blink Reformat4c46d092018-04-07 15:32:372195/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582196export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372197 Domain: 'domain',
2198 HasResponseHeader: 'has-response-header',
2199 Is: 'is',
2200 LargerThan: 'larger-than',
2201 Method: 'method',
2202 MimeType: 'mime-type',
2203 MixedContent: 'mixed-content',
2204 Priority: 'priority',
2205 Scheme: 'scheme',
2206 SetCookieDomain: 'set-cookie-domain',
2207 SetCookieName: 'set-cookie-name',
2208 SetCookieValue: 'set-cookie-value',
Sigurd Schneider464838b2020-08-24 13:53:032209 ResourceType: 'resource-type',
Jan Scheffler341eea52019-12-12 09:08:412210 CookieDomain: 'cookie-domain',
2211 CookieName: 'cookie-name',
Simon Zündc9759102020-03-25 11:24:542212 CookiePath: 'cookie-path',
Jan Scheffler341eea52019-12-12 09:08:412213 CookieValue: 'cookie-value',
Julian Geppertf8ce40c2020-09-01 18:02:032214 StatusCode: 'status-code',
2215 Url: 'url'
Blink Reformat4c46d092018-04-07 15:32:372216};
2217
2218/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582219export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372220 All: 'all',
2221 Displayed: 'displayed',
2222 Blocked: 'blocked',
2223 BlockOverridden: 'block-overridden'
2224};
2225
2226/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582227export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372228 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052229 FromCache: 'from-cache',
2230 ServiceWorkerIntercepted: 'service-worker-intercepted',
2231 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372232};
2233
2234/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582235export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372236
2237/**
2238 * @interface
2239 */
Paul Lewis56509652019-12-06 12:51:582240export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372241 /**
Tim van der Lippe0ed1d2b2020-02-04 13:45:132242 * @param {!SDK.NetworkRequest.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302243 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372244 */
Paul Lewis56509652019-12-06 12:51:582245 groupNodeForRequest(request) {
2246 }
Blink Reformat4c46d092018-04-07 15:32:372247
Paul Lewis56509652019-12-06 12:51:582248 reset() {
2249 }
2250}
Tim van der Lippeb1f2b6c2020-02-17 13:00:162251
2252/** @typedef {function(!SDK.NetworkRequest.NetworkRequest): boolean} */
2253export let Filter;