blob: 71304f9819dc4e0fa676d5b0098c4cd54dba5aab [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lippe119690c2020-01-13 12:31:3031import {HARWriter} from './HARWriter.js';
32import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars
33import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
34import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
35import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars
36
Blink Reformat4c46d092018-04-07 15:32:3737/**
38 * @implements {SDK.SDKModelObserver<!SDK.NetworkManager>}
Tim van der Lippe119690c2020-01-13 12:31:3039 * @implements {NetworkLogViewInterface}
Blink Reformat4c46d092018-04-07 15:32:3740 */
Tim van der Lippe119690c2020-01-13 12:31:3041export class NetworkLogView extends UI.VBox {
Blink Reformat4c46d092018-04-07 15:32:3742 /**
43 * @param {!UI.FilterBar} filterBar
44 * @param {!Element} progressBarContainer
45 * @param {!Common.Setting} networkLogLargeRowsSetting
46 */
47 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
48 super();
49 this.setMinimumSize(50, 64);
50 this.registerRequiredCSS('network/networkLogView.css');
51
52 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0553 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3754
55 this._networkHideDataURLSetting = Common.settings.createSetting('networkHideDataURL', false);
Jan Scheffler1ae7c9e2019-12-03 15:48:3756 this._networkShowIssuesOnlySetting = Common.settings.createSetting('networkShowIssuesOnly', false);
Blink Reformat4c46d092018-04-07 15:32:3757 this._networkResourceTypeFiltersSetting = Common.settings.createSetting('networkResourceTypeFilters', {});
58
59 this._rawRowHeight = 0;
60 this._progressBarContainer = progressBarContainer;
61 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
62 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
63
64 /**
Paul Lewis56509652019-12-06 12:51:5865 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3766 */
67 function updateRowHeight() {
68 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
69 this._rowHeight = this._computeRowHeight();
70 }
71 this._rawRowHeight = 0;
72 this._rowHeight = 0;
73 updateRowHeight.call(this);
74
Tim van der Lippe119690c2020-01-13 12:31:3075 /** @type {!NetworkTransferTimeCalculator} */
76 this._timeCalculator = new NetworkTransferTimeCalculator();
77 /** @type {!NetworkTransferDurationCalculator} */
78 this._durationCalculator = new NetworkTransferDurationCalculator();
Blink Reformat4c46d092018-04-07 15:32:3779 this._calculator = this._timeCalculator;
80
Tim van der Lippe119690c2020-01-13 12:31:3081 this._columns =
82 new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
Blink Reformat4c46d092018-04-07 15:32:3783 this._columns.show(this.element);
84
85 /** @type {!Set<!SDK.NetworkRequest>} */
86 this._staleRequests = new Set();
87 /** @type {number} */
88 this._mainRequestLoadTime = -1;
89 /** @type {number} */
90 this._mainRequestDOMContentLoadedTime = -1;
91 this._highlightedSubstringChanges = [];
92
93 /** @type {!Array.<!Network.NetworkLogView.Filter>} */
94 this._filters = [];
95 /** @type {?Network.NetworkLogView.Filter} */
96 this._timeFilter = null;
Tim van der Lippe119690c2020-01-13 12:31:3097 /** @type {?NetworkNode} */
Blink Reformat4c46d092018-04-07 15:32:3798 this._hoveredNode = null;
99 /** @type {?Element} */
100 this._recordingHint = null;
101 /** @type {?number} */
102 this._refreshRequestId = null;
Tim van der Lippe119690c2020-01-13 12:31:30103 /** @type {?NetworkRequestNode} */
Blink Reformat4c46d092018-04-07 15:32:37104 this._highlightedNode = null;
105
106 this.linkifier = new Components.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37107
108 this._recording = false;
109 this._needsRefresh = false;
110
111 this._headerHeight = 0;
112
Paul Lewis56509652019-12-06 12:51:58113 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37114 this._groupLookups = new Map();
Tim van der Lippe119690c2020-01-13 12:31:30115 this._groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37116
Paul Lewis56509652019-12-06 12:51:58117 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37118 this._activeGroupLookup = null;
119
120 this._textFilterUI = new UI.TextFilterUI();
121 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged, this);
122 filterBar.addFilter(this._textFilterUI);
123
124 this._dataURLFilterUI = new UI.CheckboxFilterUI(
125 'hide-data-url', Common.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
126 this._dataURLFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48127 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37128 filterBar.addFilter(this._dataURLFilterUI);
129
130 const filterItems =
131 Object.values(Common.resourceCategories)
132 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
133 this._resourceCategoryFilterUI = new UI.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20134 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37135 this._resourceCategoryFilterUI.addEventListener(
136 UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
137 filterBar.addFilter(this._resourceCategoryFilterUI);
138
Jan Scheffler341eea52019-12-12 09:08:41139 this._onlyIssuesFilterUI =
140 new UI.CheckboxFilterUI('only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
Jan Scheffler1ae7c9e2019-12-03 15:48:37141 this._onlyIssuesFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41142 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37143 filterBar.addFilter(this._onlyIssuesFilterUI);
144
145
Paul Lewis56509652019-12-06 12:51:58146 this._filterParser = new TextUtils.FilterParser(_searchKeys);
147 this._suggestionBuilder = new UI.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37148 this._resetSuggestionBuilder();
149
150 this._dataGrid = this._columns.dataGrid();
151 this._setupDataGrid();
152 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49153 filterBar.filterButton().addEventListener(
154 UI.ToolbarButton.Events.Click, this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37155
Joey Arhara86c14e2019-03-12 03:20:50156 this._summaryToolbar = new UI.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37157
158 new UI.DropTarget(
159 this.element, [UI.DropTarget.Type.File], Common.UIString('Drop HAR files here'), this._handleDrop.bind(this));
160
161 Common.moduleSetting('networkColorCodeResourceTypes')
162 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
163
Paul Lewis4ae5f4f2020-01-23 10:19:33164 self.SDK.targetManager.observeModels(SDK.NetworkManager, this);
Pavel Feldman18d13562018-07-31 03:31:18165 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
166 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
167 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37168
169 this._updateGroupByFrame();
170 Common.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame());
171
172 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37173 }
174
Blink Reformat4c46d092018-04-07 15:32:37175 _updateGroupByFrame() {
176 const value = Common.moduleSetting('network.group-by-frame').get();
177 this._setGrouping(value ? 'Frame' : null);
178 }
179
180 /**
181 * @param {string} key
182 * @param {!Array<string>} values
183 */
184 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58185 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37186 values.sort((a, b) => {
187 const aPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(a));
188 const bPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(b));
189 return PerfUI.networkPriorityWeight(aPriority) - PerfUI.networkPriorityWeight(bPriority);
190 });
191 } else {
192 values.sort();
193 }
194 }
195
196 /**
197 * @param {!Network.NetworkLogView.Filter} filter
198 * @param {!SDK.NetworkRequest} request
199 * @return {boolean}
200 */
201 static _negativeFilter(filter, request) {
202 return !filter(request);
203 }
204
205 /**
206 * @param {?RegExp} regex
207 * @param {!SDK.NetworkRequest} request
208 * @return {boolean}
209 */
210 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34211 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37212 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34213 }
Blink Reformat4c46d092018-04-07 15:32:37214
215 return regex.test(request.path() + '/' + request.name());
216 }
217
218 /**
219 * @param {string} domain
220 * @return {!Array.<string>}
221 */
222 static _subdomains(domain) {
223 const result = [domain];
224 let indexOfPeriod = domain.indexOf('.');
225 while (indexOfPeriod !== -1) {
226 result.push('*' + domain.substring(indexOfPeriod));
227 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
228 }
229 return result;
230 }
231
232 /**
233 * @param {string} value
234 * @return {!Network.NetworkLogView.Filter}
235 */
236 static _createRequestDomainFilter(value) {
237 /**
238 * @param {string} string
239 * @return {string}
240 */
241 function escapeForRegExp(string) {
242 return string.escapeForRegExp();
243 }
244 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58245 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37246 }
247
248 /**
249 * @param {!RegExp} regex
250 * @param {!SDK.NetworkRequest} request
251 * @return {boolean}
252 */
253 static _requestDomainFilter(regex, request) {
254 return regex.test(request.domain);
255 }
256
257 /**
258 * @param {!SDK.NetworkRequest} request
259 * @return {boolean}
260 */
261 static _runningRequestFilter(request) {
262 return !request.finished;
263 }
264
265 /**
266 * @param {!SDK.NetworkRequest} request
267 * @return {boolean}
268 */
269 static _fromCacheRequestFilter(request) {
270 return request.cached();
271 }
272
273 /**
Joey Arhard183e7e2019-02-28 03:37:05274 * @param {!SDK.NetworkRequest} request
275 * @return {boolean}
276 */
277 static _interceptedByServiceWorkerFilter(request) {
278 return request.fetchedViaServiceWorker;
279 }
280
281 /**
282 * @param {!SDK.NetworkRequest} request
283 * @return {boolean}
284 */
285 static _initiatedByServiceWorkerFilter(request) {
286 return request.initiatedByServiceWorker();
287 }
288
289 /**
Blink Reformat4c46d092018-04-07 15:32:37290 * @param {string} value
291 * @param {!SDK.NetworkRequest} request
292 * @return {boolean}
293 */
294 static _requestResponseHeaderFilter(value, request) {
295 return request.responseHeaderValue(value) !== undefined;
296 }
297
298 /**
299 * @param {string} value
300 * @param {!SDK.NetworkRequest} request
301 * @return {boolean}
302 */
303 static _requestMethodFilter(value, request) {
304 return request.requestMethod === value;
305 }
306
307 /**
308 * @param {string} value
309 * @param {!SDK.NetworkRequest} request
310 * @return {boolean}
311 */
312 static _requestPriorityFilter(value, request) {
313 return request.priority() === value;
314 }
315
316 /**
317 * @param {string} value
318 * @param {!SDK.NetworkRequest} request
319 * @return {boolean}
320 */
321 static _requestMimeTypeFilter(value, request) {
322 return request.mimeType === value;
323 }
324
325 /**
Paul Lewis56509652019-12-06 12:51:58326 * @param {!MixedContentFilterValues} value
Blink Reformat4c46d092018-04-07 15:32:37327 * @param {!SDK.NetworkRequest} request
328 * @return {boolean}
329 */
330 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58331 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37332 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Paul Lewis56509652019-12-06 12:51:58333 } else if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37334 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58335 } else if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37336 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58337 } else if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37338 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34339 }
Blink Reformat4c46d092018-04-07 15:32:37340
341 return false;
342 }
343
344 /**
345 * @param {string} value
346 * @param {!SDK.NetworkRequest} request
347 * @return {boolean}
348 */
349 static _requestSchemeFilter(value, request) {
350 return request.scheme === value;
351 }
352
353 /**
354 * @param {string} value
355 * @param {!SDK.NetworkRequest} request
356 * @return {boolean}
357 */
Jan Scheffler341eea52019-12-12 09:08:41358 static _requestCookieDomainFilter(value, request) {
359 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
360 }
361
362 /**
363 * @param {string} value
364 * @param {!SDK.NetworkRequest} request
365 * @return {boolean}
366 */
367 static _requestCookieNameFilter(value, request) {
368 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
369 }
370
371 /**
372 * @param {string} value
373 * @param {!SDK.NetworkRequest} request
374 * @return {boolean}
375 */
376 static _requestCookieValueFilter(value, request) {
377 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
378 }
379
380 /**
381 * @param {string} value
382 * @param {!SDK.NetworkRequest} request
383 * @return {boolean}
384 */
Blink Reformat4c46d092018-04-07 15:32:37385 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41386 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37387 }
388
389 /**
390 * @param {string} value
391 * @param {!SDK.NetworkRequest} request
392 * @return {boolean}
393 */
394 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41395 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37396 }
397
398 /**
399 * @param {string} value
400 * @param {!SDK.NetworkRequest} request
401 * @return {boolean}
402 */
403 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41404 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37405 }
406
407 /**
408 * @param {number} value
409 * @param {!SDK.NetworkRequest} request
410 * @return {boolean}
411 */
412 static _requestSizeLargerThanFilter(value, request) {
413 return request.transferSize >= value;
414 }
415
416 /**
417 * @param {string} value
418 * @param {!SDK.NetworkRequest} request
419 * @return {boolean}
420 */
421 static _statusCodeFilter(value, request) {
422 return ('' + request.statusCode) === value;
423 }
424
425 /**
426 * @param {!SDK.NetworkRequest} request
427 * @return {boolean}
428 */
429 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58430 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37431 }
432
433 /**
Blink Reformat4c46d092018-04-07 15:32:37434 * @param {number} windowStart
435 * @param {number} windowEnd
436 * @param {!SDK.NetworkRequest} request
437 * @return {boolean}
438 */
439 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34440 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37441 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34442 }
443 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37444 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34445 }
Blink Reformat4c46d092018-04-07 15:32:37446 return true;
447 }
448
449 /**
450 * @param {!SDK.NetworkRequest} request
451 */
452 static _copyRequestHeaders(request) {
Tim van der Lippe50cfa9b2019-10-01 10:40:58453 Host.InspectorFrontendHost.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37454 }
455
456 /**
457 * @param {!SDK.NetworkRequest} request
458 */
459 static _copyResponseHeaders(request) {
Tim van der Lippe50cfa9b2019-10-01 10:40:58460 Host.InspectorFrontendHost.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37461 }
462
463 /**
464 * @param {!SDK.NetworkRequest} request
465 */
466 static async _copyResponse(request) {
467 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08468 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34469 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08470 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34471 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08472 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34473 }
Tim van der Lippe50cfa9b2019-10-01 10:40:58474 Host.InspectorFrontendHost.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37475 }
476
477 /**
478 * @param {!DataTransfer} dataTransfer
479 */
480 _handleDrop(dataTransfer) {
481 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34482 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37483 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34484 }
Blink Reformat4c46d092018-04-07 15:32:37485 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34486 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37487 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34488 }
Blink Reformat4c46d092018-04-07 15:32:37489
Joey Arhar0e1093c2019-05-21 00:34:22490 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37491 }
492
493 /**
Tim van der Lippe119690c2020-01-13 12:31:30494 * @override
Blink Reformat4c46d092018-04-07 15:32:37495 * @param {!File} file
496 */
Joey Arhar0e1093c2019-05-21 00:34:22497 async onLoadFromFile(file) {
Blink Reformat4c46d092018-04-07 15:32:37498 const outputStream = new Common.StringOutputStream();
499 const reader = new Bindings.ChunkedFileReader(file, /* chunkSize */ 10000000);
500 const success = await reader.read(outputStream);
501 if (!success) {
502 this._harLoadFailed(reader.error().message);
503 return;
504 }
505 let harRoot;
506 try {
507 // HARRoot and JSON.parse might throw.
508 harRoot = new HARImporter.HARRoot(JSON.parse(outputStream.data()));
509 } catch (e) {
510 this._harLoadFailed(e);
511 return;
512 }
Pavel Feldman18d13562018-07-31 03:31:18513 SDK.networkLog.importRequests(HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37514 }
515
516 /**
517 * @param {string} message
518 */
519 _harLoadFailed(message) {
Paul Lewis04ccecc2020-01-22 17:15:14520 self.Common.console.error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37521 }
522
523 /**
524 * @param {?string} groupKey
525 */
526 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34527 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37528 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34529 }
Blink Reformat4c46d092018-04-07 15:32:37530 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
531 this._activeGroupLookup = groupLookup;
532 this._invalidateAllItems();
533 }
534
535 /**
536 * @return {number}
537 */
538 _computeRowHeight() {
539 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
540 }
541
542 /**
Tim van der Lippe119690c2020-01-13 12:31:30543 * @override
Blink Reformat4c46d092018-04-07 15:32:37544 * @param {!SDK.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:30545 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:37546 */
547 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58548 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37549 }
550
551 /**
Tim van der Lippe119690c2020-01-13 12:31:30552 * @override
Blink Reformat4c46d092018-04-07 15:32:37553 * @return {number}
554 */
555 headerHeight() {
556 return this._headerHeight;
557 }
558
559 /**
Tim van der Lippe119690c2020-01-13 12:31:30560 * @override
Blink Reformat4c46d092018-04-07 15:32:37561 * @param {boolean} recording
562 */
563 setRecording(recording) {
564 this._recording = recording;
565 this._updateSummaryBar();
566 }
567
568 /**
569 * @override
570 * @param {!SDK.NetworkManager} networkManager
571 */
572 modelAdded(networkManager) {
573 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34574 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37575 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34576 }
Blink Reformat4c46d092018-04-07 15:32:37577 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel);
578 if (resourceTreeModel) {
579 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
580 resourceTreeModel.addEventListener(
581 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
582 }
583 }
584
585 /**
586 * @override
587 * @param {!SDK.NetworkManager} networkManager
588 */
589 modelRemoved(networkManager) {
590 if (!networkManager.target().parentTarget()) {
591 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel);
592 if (resourceTreeModel) {
593 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
594 resourceTreeModel.removeEventListener(
595 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
596 }
597 }
598 }
599
600 /**
Tim van der Lippe119690c2020-01-13 12:31:30601 * @override
Blink Reformat4c46d092018-04-07 15:32:37602 * @param {number} start
603 * @param {number} end
604 */
605 setWindow(start, end) {
606 if (!start && !end) {
607 this._timeFilter = null;
608 this._timeCalculator.setWindow(null);
609 } else {
Paul Lewis56509652019-12-06 12:51:58610 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Tim van der Lippe119690c2020-01-13 12:31:30611 this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37612 }
613 this._filterRequests();
614 }
615
Tim van der Lippe119690c2020-01-13 12:31:30616 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:05617 resetFocus() {
618 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37619 }
620
621 _resetSuggestionBuilder() {
622 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58623 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
624 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
625 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
626 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
627 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
628 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
629 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37630 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
631 }
632
633 /**
634 * @param {!Common.Event} event
635 */
636 _filterChanged(event) {
637 this.removeAllNodeHighlights();
638 this._parseFilterQuery(this._textFilterUI.value());
639 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37640 }
641
642 _showRecordingHint() {
643 this._hideRecordingHint();
644 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
645 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18646
647 let reloadShortcutNode = null;
648 const reloadShortcutDescriptor = UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
649 if (reloadShortcutDescriptor) {
650 reloadShortcutNode = this._recordingHint.createChild('b');
651 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
652 }
Blink Reformat4c46d092018-04-07 15:32:37653
654 if (this._recording) {
655 const recordingText = hintText.createChild('span');
656 recordingText.textContent = Common.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18657 if (reloadShortcutNode) {
658 hintText.createChild('br');
659 hintText.appendChild(
660 UI.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
661 }
Blink Reformat4c46d092018-04-07 15:32:37662 } else {
663 const recordNode = hintText.createChild('b');
664 recordNode.textContent = UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18665 if (reloadShortcutNode) {
666 hintText.appendChild(UI.formatLocalized(
667 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
668 } else {
669 hintText.appendChild(UI.formatLocalized('Record (%s) to display network activity.', [recordNode]));
670 }
Blink Reformat4c46d092018-04-07 15:32:37671 }
Kayce Basques5444c1b2019-02-15 20:32:53672 hintText.createChild('br');
673 hintText.appendChild(UI.XLink.create(
674 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
675 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11676
677 this._setHidden(true);
Brandon Goddardc992d522020-01-08 21:44:57678 this._dataGrid.updateGridAccessibleName('');
Blink Reformat4c46d092018-04-07 15:32:37679 }
680
681 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11682 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34683 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37684 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34685 }
Brandon Goddardc992d522020-01-08 21:44:57686 this._dataGrid.updateGridAccessibleName(ls`Network Data Available`);
Blink Reformat4c46d092018-04-07 15:32:37687 this._recordingHint = null;
688 }
689
690 /**
Amanda Baker6761aae2019-11-05 18:59:11691 * @param {boolean} value
692 */
693 _setHidden(value) {
694 this._columns.setHidden(value);
695 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
696 }
697
698 /**
Blink Reformat4c46d092018-04-07 15:32:37699 * @override
700 * @return {!Array.<!Element>}
701 */
702 elementsToRestoreScrollPositionsFor() {
703 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34704 {
Blink Reformat4c46d092018-04-07 15:32:37705 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34706 }
Blink Reformat4c46d092018-04-07 15:32:37707 return [this._dataGrid.scrollContainer];
708 }
709
Tim van der Lippe119690c2020-01-13 12:31:30710 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37711 columnExtensionResolved() {
712 this._invalidateAllItems(true);
713 }
714
715 _setupDataGrid() {
716 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
717 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34718 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37719 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34720 }
Blink Reformat4c46d092018-04-07 15:32:37721 });
722 this._dataGrid.setStickToBottom(true);
723 this._dataGrid.setName('networkLog');
724 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
725 this._dataGrid.element.classList.add('network-log-grid');
726 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
727 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
728 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05729 this._dataGrid.element.addEventListener('keydown', event => {
730 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58731 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05732 event.consume(true);
733 }
734 });
735 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
736 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37737 return this._dataGrid;
738 }
739
740 /**
741 * @param {!Event} event
742 */
743 _dataGridMouseMove(event) {
744 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
745 const highlightInitiatorChain = event.shiftKey;
746 this._setHoveredNode(node, highlightInitiatorChain);
747 }
748
749 /**
Tim van der Lippe119690c2020-01-13 12:31:30750 * @override
751 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:37752 */
753 hoveredNode() {
754 return this._hoveredNode;
755 }
756
757 /**
Tim van der Lippe119690c2020-01-13 12:31:30758 * @param {?NetworkNode} node
Blink Reformat4c46d092018-04-07 15:32:37759 * @param {boolean=} highlightInitiatorChain
760 */
761 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34762 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37763 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34764 }
Blink Reformat4c46d092018-04-07 15:32:37765 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34766 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37767 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34768 }
Blink Reformat4c46d092018-04-07 15:32:37769 }
770
771 /**
772 * @param {!Event} event
773 */
774 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34775 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37776 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34777 }
Blink Reformat4c46d092018-04-07 15:32:37778 }
779
780 _updateSummaryBar() {
781 this._hideRecordingHint();
782
783 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20784 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37785 let selectedNodeNumber = 0;
786 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20787 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37788 let baseTime = -1;
789 let maxTime = -1;
790
791 let nodeCount = 0;
Pavel Feldman18d13562018-07-31 03:31:18792 for (const request of SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58793 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34794 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37795 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34796 }
Blink Reformat4c46d092018-04-07 15:32:37797 nodeCount++;
798 const requestTransferSize = request.transferSize;
799 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20800 const requestResourceSize = request.resourceSize;
801 resourceSize += requestResourceSize;
Tim van der Lippe119690c2020-01-13 12:31:30802 if (!node[isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37803 selectedNodeNumber++;
804 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20805 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37806 }
807 const networkManager = SDK.NetworkManager.forRequest(request);
808 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
809 // inspected url.
810 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe1d6e57a2019-09-30 11:55:34811 request.resourceType() === Common.resourceTypes.Document && !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37812 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34813 }
814 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37815 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34816 }
Blink Reformat4c46d092018-04-07 15:32:37817 }
818
819 if (!nodeCount) {
820 this._showRecordingHint();
821 return;
822 }
823
Joey Arhara86c14e2019-03-12 03:20:50824 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37825 /**
826 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50827 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37828 * @return {!Element}
829 */
Joey Arhara86c14e2019-03-12 03:20:50830 const appendChunk = (chunk, title) => {
831 const toolbarText = new UI.ToolbarText(chunk);
832 toolbarText.setTitle(title ? title : chunk);
833 this._summaryToolbar.appendToolbarItem(toolbarText);
834 return toolbarText.element;
835 };
Blink Reformat4c46d092018-04-07 15:32:37836
837 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50838 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
839 this._summaryToolbar.appendSeparator();
840 appendChunk(
841 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25842 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50843 this._summaryToolbar.appendSeparator();
844 appendChunk(
845 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25846 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37847 } else {
Joey Arhara86c14e2019-03-12 03:20:50848 appendChunk(ls`${nodeCount} requests`);
849 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25850 appendChunk(
851 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50852 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25853 appendChunk(
854 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37855 }
Dan Beam87466b52018-12-01 18:41:20856
Blink Reformat4c46d092018-04-07 15:32:37857 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50858 this._summaryToolbar.appendSeparator();
859 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37860 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50861 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30862 const domContentLoadedText =
863 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58864 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37865 }
866 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50867 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30868 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58869 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37870 }
871 }
Blink Reformat4c46d092018-04-07 15:32:37872 }
873
Tim van der Lippe119690c2020-01-13 12:31:30874 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37875 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34876 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37877 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34878 }
Blink Reformat4c46d092018-04-07 15:32:37879
880 this._needsRefresh = true;
881
Tim van der Lippe1d6e57a2019-09-30 11:55:34882 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37883 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34884 }
Blink Reformat4c46d092018-04-07 15:32:37885 }
886
887 /**
Tim van der Lippe119690c2020-01-13 12:31:30888 * @override
Blink Reformat4c46d092018-04-07 15:32:37889 * @param {!Array<number>} times
890 */
891 addFilmStripFrames(times) {
892 this._columns.addEventDividers(times, 'network-frame-divider');
893 }
894
895 /**
Tim van der Lippe119690c2020-01-13 12:31:30896 * @override
Blink Reformat4c46d092018-04-07 15:32:37897 * @param {number} time
898 */
899 selectFilmStripFrame(time) {
900 this._columns.selectFilmStripFrame(time);
901 }
902
Tim van der Lippe119690c2020-01-13 12:31:30903 /** @override */
Blink Reformat4c46d092018-04-07 15:32:37904 clearFilmStripFrame() {
905 this._columns.clearFilmStripFrame();
906 }
907
908 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34909 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37910 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34911 }
Blink Reformat4c46d092018-04-07 15:32:37912 }
913
914 /**
915 * @param {boolean=} deferUpdate
916 */
917 _invalidateAllItems(deferUpdate) {
Pavel Feldman18d13562018-07-31 03:31:18918 this._staleRequests = new Set(SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34919 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37920 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34921 } else {
Blink Reformat4c46d092018-04-07 15:32:37922 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34923 }
Blink Reformat4c46d092018-04-07 15:32:37924 }
925
926 /**
Tim van der Lippe119690c2020-01-13 12:31:30927 * @override
928 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37929 */
930 timeCalculator() {
931 return this._timeCalculator;
932 }
933
934 /**
Tim van der Lippe119690c2020-01-13 12:31:30935 * @override
936 * @return {!NetworkTimeCalculator}
Blink Reformat4c46d092018-04-07 15:32:37937 */
938 calculator() {
939 return this._calculator;
940 }
941
942 /**
Tim van der Lippe119690c2020-01-13 12:31:30943 * @override
944 * @param {!NetworkTimeCalculator} x
Blink Reformat4c46d092018-04-07 15:32:37945 */
946 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34947 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37948 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34949 }
Blink Reformat4c46d092018-04-07 15:32:37950
951 if (this._calculator !== x) {
952 this._calculator = x;
953 this._columns.setCalculator(this._calculator);
954 }
955 this._calculator.reset();
956
Tim van der Lippe1d6e57a2019-09-30 11:55:34957 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37958 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34959 } else {
Blink Reformat4c46d092018-04-07 15:32:37960 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34961 }
Blink Reformat4c46d092018-04-07 15:32:37962
963 this._invalidateAllItems();
964 }
965
966 /**
967 * @param {!Common.Event} event
968 */
969 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34970 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37971 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34972 }
Blink Reformat4c46d092018-04-07 15:32:37973
974 const time = /** @type {number} */ (event.data.loadTime);
975 if (time) {
976 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:30977 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:37978 }
979 }
980
981 /**
982 * @param {!Common.Event} event
983 */
984 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34985 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37986 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34987 }
Blink Reformat4c46d092018-04-07 15:32:37988 const data = /** @type {number} */ (event.data);
989 if (data) {
990 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:30991 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:37992 }
993 }
994
995 /**
996 * @override
997 */
998 wasShown() {
999 this._refreshIfNeeded();
1000 this._columns.wasShown();
1001 }
1002
1003 /**
1004 * @override
1005 */
1006 willHide() {
1007 this._columns.willHide();
1008 }
1009
1010 /**
1011 * @override
1012 */
1013 onResize() {
1014 this._rowHeight = this._computeRowHeight();
1015 }
1016
1017 /**
Tim van der Lippe119690c2020-01-13 12:31:301018 * @override
1019 * @return {!Array<!NetworkNode>}
Blink Reformat4c46d092018-04-07 15:32:371020 */
1021 flatNodesList() {
1022 return this._dataGrid.rootNode().flatChildren();
1023 }
1024
Tim van der Lippe119690c2020-01-13 12:31:301025 /** @override */
Brandon Goddard88d885a2019-10-31 16:11:051026 updateNodeBackground() {
1027 if (this._dataGrid.selectedNode) {
1028 this._dataGrid.selectedNode.updateBackgroundColor();
1029 }
1030 }
1031
1032 /**
Tim van der Lippe119690c2020-01-13 12:31:301033 * @override
Brandon Goddard88d885a2019-10-31 16:11:051034 * @param {boolean} isSelected
1035 */
1036 updateNodeSelectedClass(isSelected) {
1037 if (isSelected) {
1038 this.element.classList.remove('no-node-selected');
1039 } else {
1040 this.element.classList.add('no-node-selected');
1041 }
1042 }
1043
Tim van der Lippe119690c2020-01-13 12:31:301044 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371045 stylesChanged() {
1046 this._columns.scheduleRefresh();
1047 }
1048
1049 _refresh() {
1050 this._needsRefresh = false;
1051
1052 if (this._refreshRequestId) {
1053 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1054 this._refreshRequestId = null;
1055 }
1056
1057 this.removeAllNodeHighlights();
1058
1059 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1060 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1061 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1062 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1063
Tim van der Lippe119690c2020-01-13 12:31:301064 /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371065 const nodesToInsert = new Map();
Tim van der Lippe119690c2020-01-13 12:31:301066 /** @type {!Array<!NetworkNode>} */
Blink Reformat4c46d092018-04-07 15:32:371067 const nodesToRefresh = [];
1068
Tim van der Lippe119690c2020-01-13 12:31:301069 /** @type {!Set<!NetworkRequestNode>} */
Blink Reformat4c46d092018-04-07 15:32:371070 const staleNodes = new Set();
1071
1072 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1073 // node so we loop until we have no more stale requests.
1074 while (this._staleRequests.size) {
1075 const request = this._staleRequests.firstValue();
1076 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581077 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341078 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371079 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341080 }
Blink Reformat4c46d092018-04-07 15:32:371081 staleNodes.add(node);
1082 }
1083
1084 for (const node of staleNodes) {
1085 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371087 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341088 }
Blink Reformat4c46d092018-04-07 15:32:371089
Tim van der Lippe1d6e57a2019-09-30 11:55:341090 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371091 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341092 }
Blink Reformat4c46d092018-04-07 15:32:371093 const request = node.request();
1094 this._timeCalculator.updateBoundaries(request);
1095 this._durationCalculator.updateBoundaries(request);
1096 const newParent = this._parentNodeForInsert(node);
Tim van der Lippe119690c2020-01-13 12:31:301097 if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371098 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341099 }
Tim van der Lippe119690c2020-01-13 12:31:301100 node[isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371101 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1102 if (removeFromParent) {
1103 let parent = node.parent;
1104 parent.removeChild(node);
1105 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1106 const grandparent = parent.parent;
1107 grandparent.removeChild(parent);
1108 parent = grandparent;
1109 }
1110 }
1111
Tim van der Lippe1d6e57a2019-09-30 11:55:341112 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371113 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341114 }
Blink Reformat4c46d092018-04-07 15:32:371115
1116 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1117 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1118 nodesToRefresh.push(newParent);
1119 }
1120 nodesToInsert.set(node, newParent);
1121 }
1122
Tim van der Lippe1d6e57a2019-09-30 11:55:341123 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371124 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341125 }
Blink Reformat4c46d092018-04-07 15:32:371126
Tim van der Lippe1d6e57a2019-09-30 11:55:341127 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371128 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341129 }
Blink Reformat4c46d092018-04-07 15:32:371130
1131 this._updateSummaryBar();
1132
Tim van der Lippe1d6e57a2019-09-30 11:55:341133 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371134 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341135 }
Blink Reformat4c46d092018-04-07 15:32:371136
1137 this._dataGrid.updateInstantly();
1138 this._didRefreshForTest();
1139 }
1140
1141 _didRefreshForTest() {
1142 }
1143
1144 /**
Tim van der Lippe119690c2020-01-13 12:31:301145 * @param {!NetworkRequestNode} node
1146 * @return {?NetworkNode}
Blink Reformat4c46d092018-04-07 15:32:371147 */
1148 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341149 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371150 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341151 }
Blink Reformat4c46d092018-04-07 15:32:371152
1153 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341154 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371155 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341156 }
Blink Reformat4c46d092018-04-07 15:32:371157 return groupNode;
1158 }
1159
1160 _reset() {
Paul Lewis56509652019-12-06 12:51:581161 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371162
1163 this._setHoveredNode(null);
1164 this._columns.reset();
1165
1166 this._timeFilter = null;
1167 this._calculator.reset();
1168
1169 this._timeCalculator.setWindow(null);
1170 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371171
Tim van der Lippe1d6e57a2019-09-30 11:55:341172 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371173 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341174 }
Blink Reformat4c46d092018-04-07 15:32:371175 this._staleRequests.clear();
1176 this._resetSuggestionBuilder();
1177
1178 this._mainRequestLoadTime = -1;
1179 this._mainRequestDOMContentLoadedTime = -1;
1180
1181 this._dataGrid.rootNode().removeChildren();
1182 this._updateSummaryBar();
1183 this._dataGrid.setStickToBottom(true);
1184 this.scheduleRefresh();
1185 }
1186
1187 /**
Tim van der Lippe119690c2020-01-13 12:31:301188 * @override
Blink Reformat4c46d092018-04-07 15:32:371189 * @param {string} filterString
1190 */
1191 setTextFilterValue(filterString) {
1192 this._textFilterUI.setValue(filterString);
1193 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371194 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371195 this._resourceCategoryFilterUI.reset();
1196 }
1197
1198 /**
1199 * @param {!SDK.NetworkRequest} request
1200 */
1201 _createNodeForRequest(request) {
Tim van der Lippe119690c2020-01-13 12:31:301202 const node = new NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581203 request[_networkNodeSymbol] = node;
Tim van der Lippe119690c2020-01-13 12:31:301204 node[isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371205
Tim van der Lippe1d6e57a2019-09-30 11:55:341206 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371207 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 }
Blink Reformat4c46d092018-04-07 15:32:371209 return node;
1210 }
1211
1212 /**
1213 * @param {!Common.Event} event
1214 */
1215 _onRequestUpdated(event) {
1216 const request = /** @type {!SDK.NetworkRequest} */ (event.data);
1217 this._refreshRequest(request);
1218 }
1219
1220 /**
1221 * @param {!SDK.NetworkRequest} request
1222 */
1223 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581224 NetworkLogView._subdomains(request.domain)
1225 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1226 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1227 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1228 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1229 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371230
1231 const priority = request.priority();
1232 if (priority) {
Paul Lewis56509652019-12-06 12:51:581233 this._suggestionBuilder.addItem(FilterType.Priority, PerfUI.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371234 }
1235
1236 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581237 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371238 }
1239
1240 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581241 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371242 }
1243
1244 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581245 const suggestion =
1246 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1247 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371248 }
1249
1250 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341251 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581252 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341253 }
Jan Scheffler341eea52019-12-12 09:08:411254
1255 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581256 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1257 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1258 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371259 }
1260
Jan Scheffler341eea52019-12-12 09:08:411261 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1262 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1263 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1264 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1265 }
1266
Blink Reformat4c46d092018-04-07 15:32:371267 this._staleRequests.add(request);
1268 this.scheduleRefresh();
1269 }
1270
1271 /**
Tim van der Lippe119690c2020-01-13 12:31:301272 * @override
Blink Reformat4c46d092018-04-07 15:32:371273 * @return {number}
1274 */
1275 rowHeight() {
1276 return this._rowHeight;
1277 }
1278
1279 /**
Tim van der Lippe119690c2020-01-13 12:31:301280 * @override
Blink Reformat4c46d092018-04-07 15:32:371281 * @param {boolean} gridMode
1282 */
1283 switchViewMode(gridMode) {
1284 this._columns.switchViewMode(gridMode);
1285 }
1286
1287 /**
Tim van der Lippe119690c2020-01-13 12:31:301288 * @override
Blink Reformat4c46d092018-04-07 15:32:371289 * @param {!UI.ContextMenu} contextMenu
1290 * @param {!SDK.NetworkRequest} request
1291 */
1292 handleContextMenuForRequest(contextMenu, request) {
1293 contextMenu.appendApplicableItems(request);
1294 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString('Copy'));
1295 const footerSection = copyMenu.footerSection();
1296 if (request) {
1297 copyMenu.defaultSection().appendItem(
Tim van der Lippe50cfa9b2019-10-01 10:40:581298 UI.copyLinkAddressLabel(),
1299 Host.InspectorFrontendHost.copyText.bind(Host.InspectorFrontendHost, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371300 if (request.requestHeadersText()) {
1301 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581302 Common.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371303 }
1304
1305 if (request.responseHeadersText) {
1306 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581307 Common.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371308 }
1309
1310 if (request.finished) {
1311 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581312 Common.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371313 }
1314
Harley Libcf41f92018-09-10 18:01:131315 const disableIfBlob = request.isBlobRequest();
Blink Reformat4c46d092018-04-07 15:32:371316 if (Host.isWin()) {
1317 footerSection.appendItem(
Harley Libcf41f92018-09-10 18:01:131318 Common.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371319 footerSection.appendItem(
Jan Scheffler7c50d1f2019-12-17 13:33:291320 Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
1321 footerSection.appendItem(
1322 Common.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371323 footerSection.appendItem(
Harley Libcf41f92018-09-10 18:01:131324 Common.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
1325 footerSection.appendItem(
1326 Common.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371327 footerSection.appendItem(Common.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
Jan Scheffler7c50d1f2019-12-17 13:33:291328 footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1329 footerSection.appendItem(Common.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
Blink Reformat4c46d092018-04-07 15:32:371330 footerSection.appendItem(Common.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1331 footerSection.appendItem(
1332 Common.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
1333 } else {
Harley Libcf41f92018-09-10 18:01:131334 footerSection.appendItem(
Jan Scheffler7c50d1f2019-12-17 13:33:291335 Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request, false), disableIfBlob);
1336 footerSection.appendItem(
1337 Common.UIString('Copy as Node.js fetch'), this._copyFetchCall.bind(this, request, true), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131338 footerSection.appendItem(
1339 Common.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291340 footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this, false));
1341 footerSection.appendItem(Common.UIString('Copy all as Node.js fetch'), this._copyAllFetchCall.bind(this, true));
Blink Reformat4c46d092018-04-07 15:32:371342 footerSection.appendItem(Common.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
1343 }
1344 } else {
1345 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString('Copy'));
1346 }
1347 footerSection.appendItem(Common.UIString('Copy all as HAR'), this._copyAll.bind(this));
1348
Joey Arhar0e1093c2019-05-21 00:34:221349 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371350
1351 contextMenu.editSection().appendItem(Common.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1352 contextMenu.editSection().appendItem(
1353 Common.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
1354
1355 if (request) {
1356 const maxBlockedURLLength = 20;
1357 const manager = SDK.multitargetNetworkManager;
1358 let patterns = manager.blockedPatterns();
1359
Tim van der Lippeffa78622019-09-16 12:07:121360 /**
1361 * @param {string} url
1362 */
1363 function addBlockedURL(url) {
1364 patterns.push({enabled: true, url: url});
1365 manager.setBlockedPatterns(patterns);
1366 manager.setBlockingEnabled(true);
1367 UI.viewManager.showView('network.blocked-urls');
1368 }
1369
1370 /**
1371 * @param {string} url
1372 */
1373 function removeBlockedURL(url) {
1374 patterns = patterns.filter(pattern => pattern.url !== url);
1375 manager.setBlockedPatterns(patterns);
1376 UI.viewManager.showView('network.blocked-urls');
1377 }
1378
Blink Reformat4c46d092018-04-07 15:32:371379 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1380 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1381 contextMenu.debugSection().appendItem(
1382 Common.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
1383 } else if (urlWithoutScheme) {
1384 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1385 contextMenu.debugSection().appendItem(
1386 Common.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
1387 }
1388
1389 const domain = request.parsedURL.domain();
1390 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1391 contextMenu.debugSection().appendItem(
1392 Common.UIString('Block request domain'), addBlockedURL.bind(null, domain));
1393 } else if (domain) {
1394 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1395 contextMenu.debugSection().appendItem(
1396 Common.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
1397 }
1398
1399 if (SDK.NetworkManager.canReplayRequest(request)) {
1400 contextMenu.debugSection().appendItem(
1401 Common.UIString('Replay XHR'), SDK.NetworkManager.replayRequest.bind(null, request));
1402 }
Blink Reformat4c46d092018-04-07 15:32:371403 }
1404 }
1405
1406 _harRequests() {
Paul Lewis56509652019-12-06 12:51:581407 return SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171408 return request.finished ||
1409 (request.resourceType() === Common.resourceTypes.WebSocket && request.responseReceivedTime);
1410 });
Blink Reformat4c46d092018-04-07 15:32:371411 }
1412
1413 async _copyAll() {
Pavel Feldman18d13562018-07-31 03:31:181414 const harArchive = {log: await SDK.HARLog.build(this._harRequests())};
Tim van der Lippe50cfa9b2019-10-01 10:40:581415 Host.InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371416 }
1417
1418 /**
1419 * @param {!SDK.NetworkRequest} request
1420 * @param {string} platform
1421 */
1422 async _copyCurlCommand(request, platform) {
1423 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe50cfa9b2019-10-01 10:40:581424 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371425 }
1426
1427 /**
1428 * @param {string} platform
1429 */
1430 async _copyAllCurlCommand(platform) {
Harley Libcf41f92018-09-10 18:01:131431 const commands = await this._generateAllCurlCommand(SDK.networkLog.requests(), platform);
Tim van der Lippe50cfa9b2019-10-01 10:40:581432 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371433 }
1434
1435 /**
1436 * @param {!SDK.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291437 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371438 */
Jan Scheffler7c50d1f2019-12-17 13:33:291439 async _copyFetchCall(request, includeCookies) {
1440 const command = await this._generateFetchCall(request, includeCookies);
Tim van der Lippe50cfa9b2019-10-01 10:40:581441 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371442 }
1443
Jan Scheffler7c50d1f2019-12-17 13:33:291444 /**
1445 * @param {boolean} includeCookies
1446 */
1447 async _copyAllFetchCall(includeCookies) {
1448 const commands = await this._generateAllFetchCall(SDK.networkLog.requests(), includeCookies);
Tim van der Lippe50cfa9b2019-10-01 10:40:581449 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371450 }
1451
1452 /**
1453 * @param {!SDK.NetworkRequest} request
1454 */
1455 async _copyPowerShellCommand(request) {
1456 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe50cfa9b2019-10-01 10:40:581457 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371458 }
1459
1460 async _copyAllPowerShellCommand() {
Harley Li5a470e92019-09-26 21:38:351461 const commands = await this._generateAllPowerShellCommand(SDK.networkLog.requests());
Tim van der Lippe50cfa9b2019-10-01 10:40:581462 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371463 }
1464
Tim van der Lippe119690c2020-01-13 12:31:301465 /**
1466 * @override
1467 * @return {!Promise}
1468 */
Joey Arhar0e1093c2019-05-21 00:34:221469 async exportAll() {
Paul Lewis4ae5f4f2020-01-23 10:19:331470 const url = self.SDK.targetManager.mainTarget().inspectedURL();
Peter Marshall3e4e5692019-12-09 16:48:041471 const parsedURL = Common.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371472 const filename = parsedURL ? parsedURL.host : 'network-log';
1473 const stream = new Bindings.FileOutputStream();
1474
Tim van der Lippe1d6e57a2019-09-30 11:55:341475 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371476 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341477 }
Blink Reformat4c46d092018-04-07 15:32:371478
1479 const progressIndicator = new UI.ProgressIndicator();
1480 this._progressBarContainer.appendChild(progressIndicator.element);
Tim van der Lippe119690c2020-01-13 12:31:301481 await HARWriter.write(stream, this._harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371482 progressIndicator.done();
1483 stream.close();
1484 }
1485
1486 _clearBrowserCache() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341487 if (confirm(Common.UIString('Are you sure you want to clear browser cache?'))) {
Blink Reformat4c46d092018-04-07 15:32:371488 SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341489 }
Blink Reformat4c46d092018-04-07 15:32:371490 }
1491
1492 _clearBrowserCookies() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341493 if (confirm(Common.UIString('Are you sure you want to clear browser cookies?'))) {
Blink Reformat4c46d092018-04-07 15:32:371494 SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341495 }
Blink Reformat4c46d092018-04-07 15:32:371496 }
1497
1498 _removeAllHighlights() {
1499 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341500 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:371501 UI.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341502 }
Blink Reformat4c46d092018-04-07 15:32:371503 this._highlightedSubstringChanges = [];
1504 }
1505
1506 /**
Tim van der Lippe119690c2020-01-13 12:31:301507 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371508 * @return {boolean}
1509 */
1510 _applyFilter(node) {
1511 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341512 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371513 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341514 }
Blink Reformat4c46d092018-04-07 15:32:371515 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341516 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371517 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341518 }
1519 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371520 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341521 }
Jan Scheffler1ae7c9e2019-12-03 15:48:371522 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.hasIssues(request)) {
1523 return false;
1524 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341525 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371526 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341527 }
Blink Reformat4c46d092018-04-07 15:32:371528 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341529 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371530 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341531 }
Blink Reformat4c46d092018-04-07 15:32:371532 }
1533 return true;
1534 }
1535
1536 /**
1537 * @param {string} query
1538 */
1539 _parseFilterQuery(query) {
1540 const descriptors = this._filterParser.parse(query);
1541 this._filters = descriptors.map(descriptor => {
1542 const key = descriptor.key;
1543 const text = descriptor.text || '';
1544 const regex = descriptor.regex;
1545 let filter;
1546 if (key) {
1547 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581548 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1549 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371550 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581551 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371552 } else {
Paul Lewis56509652019-12-06 12:51:581553 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371554 }
Paul Lewis56509652019-12-06 12:51:581555 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371556 });
1557 }
1558
1559 /**
Paul Lewis56509652019-12-06 12:51:581560 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371561 * @param {string} value
1562 * @return {?Network.NetworkLogView.Filter}
1563 */
1564 _createSpecialFilter(type, value) {
1565 switch (type) {
Paul Lewis56509652019-12-06 12:51:581566 case FilterType.Domain:
1567 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371568
Paul Lewis56509652019-12-06 12:51:581569 case FilterType.HasResponseHeader:
1570 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371571
Paul Lewis56509652019-12-06 12:51:581572 case FilterType.Is:
1573 if (value.toLowerCase() === IsFilterType.Running) {
1574 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341575 }
Paul Lewis56509652019-12-06 12:51:581576 if (value.toLowerCase() === IsFilterType.FromCache) {
1577 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341578 }
Paul Lewis56509652019-12-06 12:51:581579 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1580 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341581 }
Paul Lewis56509652019-12-06 12:51:581582 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1583 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341584 }
Blink Reformat4c46d092018-04-07 15:32:371585 break;
1586
Paul Lewis56509652019-12-06 12:51:581587 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371588 return this._createSizeFilter(value.toLowerCase());
1589
Paul Lewis56509652019-12-06 12:51:581590 case FilterType.Method:
1591 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371592
Paul Lewis56509652019-12-06 12:51:581593 case FilterType.MimeType:
1594 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371595
Paul Lewis56509652019-12-06 12:51:581596 case FilterType.MixedContent:
1597 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371598
Paul Lewis56509652019-12-06 12:51:581599 case FilterType.Scheme:
1600 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371601
Paul Lewis56509652019-12-06 12:51:581602 case FilterType.SetCookieDomain:
1603 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371604
Paul Lewis56509652019-12-06 12:51:581605 case FilterType.SetCookieName:
1606 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371607
Paul Lewis56509652019-12-06 12:51:581608 case FilterType.SetCookieValue:
1609 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371610
Jan Scheffler341eea52019-12-12 09:08:411611 case FilterType.CookieDomain:
1612 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1613
1614 case FilterType.CookieName:
1615 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1616
1617 case FilterType.CookieValue:
1618 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1619
Paul Lewis56509652019-12-06 12:51:581620 case FilterType.Priority:
1621 return NetworkLogView._requestPriorityFilter.bind(null, PerfUI.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371622
Paul Lewis56509652019-12-06 12:51:581623 case FilterType.StatusCode:
1624 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371625 }
1626 return null;
1627 }
1628
1629 /**
1630 * @param {string} value
1631 * @return {?Network.NetworkLogView.Filter}
1632 */
1633 _createSizeFilter(value) {
1634 let multiplier = 1;
1635 if (value.endsWith('k')) {
1636 multiplier = 1024;
1637 value = value.substring(0, value.length - 1);
1638 } else if (value.endsWith('m')) {
1639 multiplier = 1024 * 1024;
1640 value = value.substring(0, value.length - 1);
1641 }
1642 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341643 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371644 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341645 }
Paul Lewis56509652019-12-06 12:51:581646 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371647 }
1648
1649 _filterRequests() {
1650 this._removeAllHighlights();
1651 this._invalidateAllItems();
1652 }
1653
1654 /**
1655 * @param {!SDK.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:301656 * @return {?NetworkRequestNode}
Blink Reformat4c46d092018-04-07 15:32:371657 */
1658 _reveal(request) {
1659 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581660 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341661 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371662 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341663 }
Blink Reformat4c46d092018-04-07 15:32:371664 node.reveal();
1665 return node;
1666 }
1667
1668 /**
Tim van der Lippe119690c2020-01-13 12:31:301669 * @override
Blink Reformat4c46d092018-04-07 15:32:371670 * @param {!SDK.NetworkRequest} request
1671 */
1672 revealAndHighlightRequest(request) {
1673 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341674 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371675 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341676 }
Blink Reformat4c46d092018-04-07 15:32:371677 }
1678
1679 /**
Tim van der Lippe119690c2020-01-13 12:31:301680 * @override
Blink Reformat4c46d092018-04-07 15:32:371681 * @param {!SDK.NetworkRequest} request
1682 */
1683 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141684 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371685 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341686 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371687 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341688 }
Blink Reformat4c46d092018-04-07 15:32:371689 }
1690
Tim van der Lippe119690c2020-01-13 12:31:301691 /** @override */
Blink Reformat4c46d092018-04-07 15:32:371692 removeAllNodeHighlights() {
1693 if (this._highlightedNode) {
1694 this._highlightedNode.element().classList.remove('highlighted-row');
1695 this._highlightedNode = null;
1696 }
1697 }
1698
1699 /**
Tim van der Lippe119690c2020-01-13 12:31:301700 * @param {!NetworkRequestNode} node
Blink Reformat4c46d092018-04-07 15:32:371701 */
1702 _highlightNode(node) {
1703 UI.runCSSAnimationOnce(node.element(), 'highlighted-row');
1704 this._highlightedNode = node;
1705 }
1706
1707 /**
Harley Libcf41f92018-09-10 18:01:131708 * @param {!Array<!SDK.NetworkRequest>} requests
1709 * @return {!Array<!SDK.NetworkRequest>}
1710 */
1711 _filterOutBlobRequests(requests) {
1712 return requests.filter(request => !request.isBlobRequest());
1713 }
1714
1715 /**
Blink Reformat4c46d092018-04-07 15:32:371716 * @param {!SDK.NetworkRequest} request
Jan Scheffler7c50d1f2019-12-17 13:33:291717 * @param {boolean} includeCookies
Blink Reformat4c46d092018-04-07 15:32:371718 * @return {!Promise<string>}
1719 */
Jan Scheffler7c50d1f2019-12-17 13:33:291720 async _generateFetchCall(request, includeCookies) {
Blink Reformat4c46d092018-04-07 15:32:371721 const ignoredHeaders = {
1722 // Internal headers
1723 'method': 1,
1724 'path': 1,
1725 'scheme': 1,
1726 'version': 1,
1727
1728 // Unsafe headers
1729 // Keep this list synchronized with src/net/http/http_util.cc
1730 'accept-charset': 1,
1731 'accept-encoding': 1,
1732 'access-control-request-headers': 1,
1733 'access-control-request-method': 1,
1734 'connection': 1,
1735 'content-length': 1,
1736 'cookie': 1,
1737 'cookie2': 1,
1738 'date': 1,
1739 'dnt': 1,
1740 'expect': 1,
1741 'host': 1,
1742 'keep-alive': 1,
1743 'origin': 1,
1744 'referer': 1,
1745 'te': 1,
1746 'trailer': 1,
1747 'transfer-encoding': 1,
1748 'upgrade': 1,
1749 'via': 1,
1750 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1751 'user-agent': 1
1752 };
1753
1754 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1755
1756 const url = JSON.stringify(request.url());
1757
1758 const requestHeaders = request.requestHeaders();
1759 const headerData = requestHeaders.reduce((result, header) => {
1760 const name = header.name;
1761
Tim van der Lippe1d6e57a2019-09-30 11:55:341762 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371763 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341764 }
Blink Reformat4c46d092018-04-07 15:32:371765
1766 return result;
1767 }, new Headers());
1768
1769 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341770 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411771 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341772 }
Blink Reformat4c46d092018-04-07 15:32:371773
1774 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411775 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1776 'include' :
1777 'omit';
Blink Reformat4c46d092018-04-07 15:32:371778
1779 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1780
1781 const referrer = referrerHeader ? referrerHeader.value : void 0;
1782
1783 const referrerPolicy = request.referrerPolicy() || void 0;
1784
1785 const requestBody = await request.requestFormData();
1786
1787 const fetchOptions = {
PhistucK6ed0a3e2018-08-04 06:28:411788 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371789 referrer,
1790 referrerPolicy,
1791 body: requestBody,
1792 method: request.requestMethod,
1793 mode: 'cors'
1794 };
1795
Jan Scheffler7c50d1f2019-12-17 13:33:291796 if (includeCookies) {
1797 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
1798 if (cookieHeader) {
1799 fetchOptions.headers = {
1800 ...headers,
1801 'cookie': cookieHeader.value,
1802 };
1803 }
1804 } else {
1805 fetchOptions.credentials = credentials;
1806 }
1807
Jan Scheffler172d5212020-01-02 14:42:561808 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:371809 return `fetch(${url}, ${options});`;
1810 }
1811
1812 /**
Harley Libcf41f92018-09-10 18:01:131813 * @param {!Array<!SDK.NetworkRequest>} requests
Jan Scheffler7c50d1f2019-12-17 13:33:291814 * @param {boolean} includeCookies
Harley Libcf41f92018-09-10 18:01:131815 * @return {!Promise<string>}
1816 */
Jan Scheffler7c50d1f2019-12-17 13:33:291817 async _generateAllFetchCall(requests, includeCookies) {
Harley Libcf41f92018-09-10 18:01:131818 const nonBlobRequests = this._filterOutBlobRequests(requests);
Jan Scheffler7c50d1f2019-12-17 13:33:291819 const commands =
1820 await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies)));
Harley Libcf41f92018-09-10 18:01:131821 return commands.join(' ;\n');
1822 }
1823
1824 /**
Blink Reformat4c46d092018-04-07 15:32:371825 * @param {!SDK.NetworkRequest} request
1826 * @param {string} platform
1827 * @return {!Promise<string>}
1828 */
1829 async _generateCurlCommand(request, platform) {
Jan Scheffler172d5212020-01-02 14:42:561830 let command = [];
Eric Lawrence7a7b3682019-10-17 23:06:361831 // Most of these headers are derived from the URL and are automatically added by cURL.
1832 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1833 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371834
1835 function escapeStringWin(str) {
1836 /* If there are no new line characters do not escape the " characters
1837 since it only uglifies the command.
1838
1839 Because cmd.exe parser and MS Crt arguments parsers use some of the
1840 same escape characters, they can interact with each other in
1841 horrible ways, the order of operations is critical.
1842
1843 Replace \ with \\ first because it is an escape character for certain
1844 conditions in both parsers.
1845
1846 Replace all " with \" to ensure the first parser does not remove it.
1847
1848 Then escape all characters we are not sure about with ^ to ensure it
1849 gets to MS Crt parser safely.
1850
1851 The % character is special because MS Crt parser will try and look for
1852 ENV variables and fill them in it's place. We cannot escape them with %
1853 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1854 parser); So we can get cmd.exe parser to escape the character after it,
1855 if it is followed by a valid beginning character of an ENV variable.
1856 This ensures we do not try and double escape another ^ if it was placed
1857 by the previous replace.
1858
1859 Lastly we replace new lines with ^ and TWO new lines because the first
1860 new line is there to enact the escape command the second is the character
1861 to escape (in this case new line).
1862 */
1863 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1864 return encapsChars +
1865 str.replace(/\\/g, '\\\\')
1866 .replace(/"/g, '\\"')
1867 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1868 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1869 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1870 encapsChars;
1871 }
1872
1873 /**
1874 * @param {string} str
1875 * @return {string}
1876 */
1877 function escapeStringPosix(str) {
1878 /**
1879 * @param {string} x
1880 * @return {string}
1881 */
1882 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221883 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121884 let hexString = code.toString(16);
1885 // Zero pad to four digits to comply with ANSI-C Quoting:
1886 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341887 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121888 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341889 }
Joey Arhar2d21f712019-05-20 21:07:121890
1891 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371892 }
1893
Joey Arhar512e3742019-01-25 21:33:541894 if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371895 // Use ANSI-C quoting syntax.
1896 return '$\'' +
1897 str.replace(/\\/g, '\\\\')
1898 .replace(/\'/g, '\\\'')
1899 .replace(/\n/g, '\\n')
1900 .replace(/\r/g, '\\r')
Joey Arhar512e3742019-01-25 21:33:541901 .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371902 '\'';
1903 } else {
1904 // Use single quote syntax.
1905 return '\'' + str + '\'';
1906 }
1907 }
1908
1909 // cURL command expected to run on the same platform that DevTools run
1910 // (it may be different from the inspected page platform).
1911 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1912
1913 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1914
1915 let inferredMethod = 'GET';
1916 const data = [];
1917 const requestContentType = request.requestContentType();
1918 const formData = await request.requestFormData();
1919 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
Jan Scheffler172d5212020-01-02 14:42:561920 data.push('--data ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371921 ignoredHeaders['content-length'] = true;
1922 inferredMethod = 'POST';
1923 } else if (formData) {
Jan Scheffler172d5212020-01-02 14:42:561924 data.push('--data-binary ' + escapeString(formData));
Blink Reformat4c46d092018-04-07 15:32:371925 ignoredHeaders['content-length'] = true;
1926 inferredMethod = 'POST';
1927 }
1928
1929 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:291930 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371931 }
1932
1933 const requestHeaders = request.requestHeaders();
1934 for (let i = 0; i < requestHeaders.length; i++) {
1935 const header = requestHeaders[i];
1936 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341937 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371938 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341939 }
Jan Scheffler172d5212020-01-02 14:42:561940 command.push('-H ' + escapeString(name + ': ' + header.value));
Blink Reformat4c46d092018-04-07 15:32:371941 }
1942 command = command.concat(data);
1943 command.push('--compressed');
1944
Tim van der Lippe1d6e57a2019-09-30 11:55:341945 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371946 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341947 }
Jan Scheffler172d5212020-01-02 14:42:561948 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:371949 }
1950
1951 /**
Harley Libcf41f92018-09-10 18:01:131952 * @param {!Array<!SDK.NetworkRequest>} requests
1953 * @param {string} platform
1954 * @return {!Promise<string>}
1955 */
1956 async _generateAllCurlCommand(requests, platform) {
1957 const nonBlobRequests = this._filterOutBlobRequests(requests);
1958 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:341959 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:131960 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341961 } else {
Harley Libcf41f92018-09-10 18:01:131962 return commands.join(' ;\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341963 }
Harley Libcf41f92018-09-10 18:01:131964 }
1965
1966 /**
Blink Reformat4c46d092018-04-07 15:32:371967 * @param {!SDK.NetworkRequest} request
1968 * @return {!Promise<string>}
1969 */
1970 async _generatePowerShellCommand(request) {
Jan Scheffler172d5212020-01-02 14:42:561971 const command = [];
Blink Reformat4c46d092018-04-07 15:32:371972 const ignoredHeaders =
1973 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
1974
1975 /**
1976 * @param {string} str
1977 * @return {string}
1978 */
1979 function escapeString(str) {
1980 return '"' +
1981 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
1982 }
1983
Jan Scheffler172d5212020-01-02 14:42:561984 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:371985
1986 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:561987 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:371988 }
1989
1990 const requestHeaders = request.requestHeaders();
1991 const headerNameValuePairs = [];
1992 for (const header of requestHeaders) {
1993 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341994 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:371995 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341996 }
Blink Reformat4c46d092018-04-07 15:32:371997 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
1998 }
1999 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562000 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372001 }
2002
2003 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2004 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562005 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372006 }
2007
2008 const formData = await request.requestFormData();
2009 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372010 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342011 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562012 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342013 } else {
Jan Scheffler172d5212020-01-02 14:42:562014 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342015 }
Blink Reformat4c46d092018-04-07 15:32:372016 }
2017
Jan Scheffler172d5212020-01-02 14:42:562018 return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372019 }
Harley Libcf41f92018-09-10 18:01:132020
2021 /**
2022 * @param {!Array<!SDK.NetworkRequest>} requests
2023 * @return {!Promise<string>}
2024 */
2025 async _generateAllPowerShellCommand(requests) {
2026 const nonBlobRequests = this._filterOutBlobRequests(requests);
2027 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
2028 return commands.join(';\r\n');
2029 }
Joey Arhara86c14e2019-03-12 03:20:502030
2031 /**
2032 * @return {string}
2033 */
2034 static getDCLEventColor() {
Tim van der Lippe1d6e57a2019-09-30 11:55:342035 if (UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:502036 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:342037 }
Joey Arhara86c14e2019-03-12 03:20:502038 return '#0867CB';
2039 }
2040
2041 /**
2042 * @return {string}
2043 */
2044 static getLoadEventColor() {
2045 return UI.themeSupport.patchColorText('#B31412', UI.ThemeSupport.ColorUsage.Foreground);
2046 }
Paul Lewis56509652019-12-06 12:51:582047}
Blink Reformat4c46d092018-04-07 15:32:372048
Tim van der Lippe119690c2020-01-13 12:31:302049export const isFilteredOutSymbol = Symbol('isFilteredOut');
Paul Lewis56509652019-12-06 12:51:582050export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:372051
Paul Lewis56509652019-12-06 12:51:582052export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372053 'http': true,
2054 'https': true,
2055 'ws': true,
2056 'wss': true
2057};
2058
Blink Reformat4c46d092018-04-07 15:32:372059/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582060export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372061 Domain: 'domain',
2062 HasResponseHeader: 'has-response-header',
2063 Is: 'is',
2064 LargerThan: 'larger-than',
2065 Method: 'method',
2066 MimeType: 'mime-type',
2067 MixedContent: 'mixed-content',
2068 Priority: 'priority',
2069 Scheme: 'scheme',
2070 SetCookieDomain: 'set-cookie-domain',
2071 SetCookieName: 'set-cookie-name',
2072 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412073 CookieDomain: 'cookie-domain',
2074 CookieName: 'cookie-name',
2075 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372076 StatusCode: 'status-code'
2077};
2078
2079/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582080export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372081 All: 'all',
2082 Displayed: 'displayed',
2083 Blocked: 'blocked',
2084 BlockOverridden: 'block-overridden'
2085};
2086
2087/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582088export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372089 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052090 FromCache: 'from-cache',
2091 ServiceWorkerIntercepted: 'service-worker-intercepted',
2092 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372093};
2094
2095/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582096export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372097
2098/**
2099 * @interface
2100 */
Paul Lewis56509652019-12-06 12:51:582101export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372102 /**
2103 * @param {!SDK.NetworkRequest} request
Tim van der Lippe119690c2020-01-13 12:31:302104 * @return {?NetworkGroupNode}
Blink Reformat4c46d092018-04-07 15:32:372105 */
Paul Lewis56509652019-12-06 12:51:582106 groupNodeForRequest(request) {
2107 }
Blink Reformat4c46d092018-04-07 15:32:372108
Paul Lewis56509652019-12-06 12:51:582109 reset() {
2110 }
2111}