blob: 4e909e44d55991aca9f31659c759b1103b3a0bc0 [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
31/**
32 * @implements {SDK.SDKModelObserver<!SDK.NetworkManager>}
33 */
Paul Lewis56509652019-12-06 12:51:5834export default class NetworkLogView extends UI.VBox {
Blink Reformat4c46d092018-04-07 15:32:3735 /**
36 * @param {!UI.FilterBar} filterBar
37 * @param {!Element} progressBarContainer
38 * @param {!Common.Setting} networkLogLargeRowsSetting
39 */
40 constructor(filterBar, progressBarContainer, networkLogLargeRowsSetting) {
41 super();
42 this.setMinimumSize(50, 64);
43 this.registerRequiredCSS('network/networkLogView.css');
44
45 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:0546 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:3747
48 this._networkHideDataURLSetting = Common.settings.createSetting('networkHideDataURL', false);
Jan Scheffler1ae7c9e2019-12-03 15:48:3749 this._networkShowIssuesOnlySetting = Common.settings.createSetting('networkShowIssuesOnly', false);
Blink Reformat4c46d092018-04-07 15:32:3750 this._networkResourceTypeFiltersSetting = Common.settings.createSetting('networkResourceTypeFilters', {});
51
52 this._rawRowHeight = 0;
53 this._progressBarContainer = progressBarContainer;
54 this._networkLogLargeRowsSetting = networkLogLargeRowsSetting;
55 this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
56
57 /**
Paul Lewis56509652019-12-06 12:51:5858 * @this {NetworkLogView}
Blink Reformat4c46d092018-04-07 15:32:3759 */
60 function updateRowHeight() {
61 this._rawRowHeight = !!this._networkLogLargeRowsSetting.get() ? 41 : 21;
62 this._rowHeight = this._computeRowHeight();
63 }
64 this._rawRowHeight = 0;
65 this._rowHeight = 0;
66 updateRowHeight.call(this);
67
68 /** @type {!Network.NetworkTransferTimeCalculator} */
69 this._timeCalculator = new Network.NetworkTransferTimeCalculator();
70 /** @type {!Network.NetworkTransferDurationCalculator} */
71 this._durationCalculator = new Network.NetworkTransferDurationCalculator();
72 this._calculator = this._timeCalculator;
73
74 this._columns = new Network.NetworkLogViewColumns(
75 this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting);
76 this._columns.show(this.element);
77
78 /** @type {!Set<!SDK.NetworkRequest>} */
79 this._staleRequests = new Set();
80 /** @type {number} */
81 this._mainRequestLoadTime = -1;
82 /** @type {number} */
83 this._mainRequestDOMContentLoadedTime = -1;
84 this._highlightedSubstringChanges = [];
85
86 /** @type {!Array.<!Network.NetworkLogView.Filter>} */
87 this._filters = [];
88 /** @type {?Network.NetworkLogView.Filter} */
89 this._timeFilter = null;
90 /** @type {?Network.NetworkNode} */
91 this._hoveredNode = null;
92 /** @type {?Element} */
93 this._recordingHint = null;
94 /** @type {?number} */
95 this._refreshRequestId = null;
96 /** @type {?Network.NetworkRequestNode} */
97 this._highlightedNode = null;
98
99 this.linkifier = new Components.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37100
101 this._recording = false;
102 this._needsRefresh = false;
103
104 this._headerHeight = 0;
105
Paul Lewis56509652019-12-06 12:51:58106 /** @type {!Map<string, !GroupLookupInterface>} */
Blink Reformat4c46d092018-04-07 15:32:37107 this._groupLookups = new Map();
108 this._groupLookups.set('Frame', new Network.NetworkFrameGrouper(this));
109
Paul Lewis56509652019-12-06 12:51:58110 /** @type {?GroupLookupInterface} */
Blink Reformat4c46d092018-04-07 15:32:37111 this._activeGroupLookup = null;
112
113 this._textFilterUI = new UI.TextFilterUI();
114 this._textFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged, this);
115 filterBar.addFilter(this._textFilterUI);
116
117 this._dataURLFilterUI = new UI.CheckboxFilterUI(
118 'hide-data-url', Common.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
119 this._dataURLFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Joey Arharba99d622019-02-01 19:10:48120 this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
Blink Reformat4c46d092018-04-07 15:32:37121 filterBar.addFilter(this._dataURLFilterUI);
122
123 const filterItems =
124 Object.values(Common.resourceCategories)
125 .map(category => ({name: category.title, label: category.shortTitle, title: category.title}));
126 this._resourceCategoryFilterUI = new UI.NamedBitSetFilterUI(filterItems, this._networkResourceTypeFiltersSetting);
Brandon Goddard568cef12019-06-27 17:18:20127 UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`);
Blink Reformat4c46d092018-04-07 15:32:37128 this._resourceCategoryFilterUI.addEventListener(
129 UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
130 filterBar.addFilter(this._resourceCategoryFilterUI);
131
Jan Scheffler341eea52019-12-12 09:08:41132 this._onlyIssuesFilterUI =
133 new UI.CheckboxFilterUI('only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting);
Jan Scheffler1ae7c9e2019-12-03 15:48:37134 this._onlyIssuesFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
Jan Scheffler341eea52019-12-12 09:08:41135 this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`;
Jan Scheffler1ae7c9e2019-12-03 15:48:37136 filterBar.addFilter(this._onlyIssuesFilterUI);
137
138
Paul Lewis56509652019-12-06 12:51:58139 this._filterParser = new TextUtils.FilterParser(_searchKeys);
140 this._suggestionBuilder = new UI.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues);
Blink Reformat4c46d092018-04-07 15:32:37141 this._resetSuggestionBuilder();
142
143 this._dataGrid = this._columns.dataGrid();
144 this._setupDataGrid();
145 this._columns.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49146 filterBar.filterButton().addEventListener(
147 UI.ToolbarButton.Events.Click, this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37148
Joey Arhara86c14e2019-03-12 03:20:50149 this._summaryToolbar = new UI.Toolbar('network-summary-bar', this.element);
Blink Reformat4c46d092018-04-07 15:32:37150
151 new UI.DropTarget(
152 this.element, [UI.DropTarget.Type.File], Common.UIString('Drop HAR files here'), this._handleDrop.bind(this));
153
154 Common.moduleSetting('networkColorCodeResourceTypes')
155 .addChangeListener(this._invalidateAllItems.bind(this, false), this);
156
157 SDK.targetManager.observeModels(SDK.NetworkManager, this);
Pavel Feldman18d13562018-07-31 03:31:18158 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this);
159 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this);
160 SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this);
Blink Reformat4c46d092018-04-07 15:32:37161
162 this._updateGroupByFrame();
163 Common.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame());
164
165 this._filterBar = filterBar;
Blink Reformat4c46d092018-04-07 15:32:37166 }
167
Blink Reformat4c46d092018-04-07 15:32:37168 _updateGroupByFrame() {
169 const value = Common.moduleSetting('network.group-by-frame').get();
170 this._setGrouping(value ? 'Frame' : null);
171 }
172
173 /**
174 * @param {string} key
175 * @param {!Array<string>} values
176 */
177 static _sortSearchValues(key, values) {
Paul Lewis56509652019-12-06 12:51:58178 if (key === FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37179 values.sort((a, b) => {
180 const aPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(a));
181 const bPriority = /** @type {!Protocol.Network.ResourcePriority} */ (PerfUI.uiLabelToNetworkPriority(b));
182 return PerfUI.networkPriorityWeight(aPriority) - PerfUI.networkPriorityWeight(bPriority);
183 });
184 } else {
185 values.sort();
186 }
187 }
188
189 /**
190 * @param {!Network.NetworkLogView.Filter} filter
191 * @param {!SDK.NetworkRequest} request
192 * @return {boolean}
193 */
194 static _negativeFilter(filter, request) {
195 return !filter(request);
196 }
197
198 /**
199 * @param {?RegExp} regex
200 * @param {!SDK.NetworkRequest} request
201 * @return {boolean}
202 */
203 static _requestPathFilter(regex, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34204 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37205 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34206 }
Blink Reformat4c46d092018-04-07 15:32:37207
208 return regex.test(request.path() + '/' + request.name());
209 }
210
211 /**
212 * @param {string} domain
213 * @return {!Array.<string>}
214 */
215 static _subdomains(domain) {
216 const result = [domain];
217 let indexOfPeriod = domain.indexOf('.');
218 while (indexOfPeriod !== -1) {
219 result.push('*' + domain.substring(indexOfPeriod));
220 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
221 }
222 return result;
223 }
224
225 /**
226 * @param {string} value
227 * @return {!Network.NetworkLogView.Filter}
228 */
229 static _createRequestDomainFilter(value) {
230 /**
231 * @param {string} string
232 * @return {string}
233 */
234 function escapeForRegExp(string) {
235 return string.escapeForRegExp();
236 }
237 const escapedPattern = value.split('*').map(escapeForRegExp).join('.*');
Paul Lewis56509652019-12-06 12:51:58238 return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37239 }
240
241 /**
242 * @param {!RegExp} regex
243 * @param {!SDK.NetworkRequest} request
244 * @return {boolean}
245 */
246 static _requestDomainFilter(regex, request) {
247 return regex.test(request.domain);
248 }
249
250 /**
251 * @param {!SDK.NetworkRequest} request
252 * @return {boolean}
253 */
254 static _runningRequestFilter(request) {
255 return !request.finished;
256 }
257
258 /**
259 * @param {!SDK.NetworkRequest} request
260 * @return {boolean}
261 */
262 static _fromCacheRequestFilter(request) {
263 return request.cached();
264 }
265
266 /**
Joey Arhard183e7e2019-02-28 03:37:05267 * @param {!SDK.NetworkRequest} request
268 * @return {boolean}
269 */
270 static _interceptedByServiceWorkerFilter(request) {
271 return request.fetchedViaServiceWorker;
272 }
273
274 /**
275 * @param {!SDK.NetworkRequest} request
276 * @return {boolean}
277 */
278 static _initiatedByServiceWorkerFilter(request) {
279 return request.initiatedByServiceWorker();
280 }
281
282 /**
Blink Reformat4c46d092018-04-07 15:32:37283 * @param {string} value
284 * @param {!SDK.NetworkRequest} request
285 * @return {boolean}
286 */
287 static _requestResponseHeaderFilter(value, request) {
288 return request.responseHeaderValue(value) !== undefined;
289 }
290
291 /**
292 * @param {string} value
293 * @param {!SDK.NetworkRequest} request
294 * @return {boolean}
295 */
296 static _requestMethodFilter(value, request) {
297 return request.requestMethod === value;
298 }
299
300 /**
301 * @param {string} value
302 * @param {!SDK.NetworkRequest} request
303 * @return {boolean}
304 */
305 static _requestPriorityFilter(value, request) {
306 return request.priority() === value;
307 }
308
309 /**
310 * @param {string} value
311 * @param {!SDK.NetworkRequest} request
312 * @return {boolean}
313 */
314 static _requestMimeTypeFilter(value, request) {
315 return request.mimeType === value;
316 }
317
318 /**
Paul Lewis56509652019-12-06 12:51:58319 * @param {!MixedContentFilterValues} value
Blink Reformat4c46d092018-04-07 15:32:37320 * @param {!SDK.NetworkRequest} request
321 * @return {boolean}
322 */
323 static _requestMixedContentFilter(value, request) {
Paul Lewis56509652019-12-06 12:51:58324 if (value === MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37325 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Paul Lewis56509652019-12-06 12:51:58326 } else if (value === MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37327 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58328 } else if (value === MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37329 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Paul Lewis56509652019-12-06 12:51:58330 } else if (value === MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37331 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34332 }
Blink Reformat4c46d092018-04-07 15:32:37333
334 return false;
335 }
336
337 /**
338 * @param {string} value
339 * @param {!SDK.NetworkRequest} request
340 * @return {boolean}
341 */
342 static _requestSchemeFilter(value, request) {
343 return request.scheme === value;
344 }
345
346 /**
347 * @param {string} value
348 * @param {!SDK.NetworkRequest} request
349 * @return {boolean}
350 */
Jan Scheffler341eea52019-12-12 09:08:41351 static _requestCookieDomainFilter(value, request) {
352 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
353 }
354
355 /**
356 * @param {string} value
357 * @param {!SDK.NetworkRequest} request
358 * @return {boolean}
359 */
360 static _requestCookieNameFilter(value, request) {
361 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
362 }
363
364 /**
365 * @param {string} value
366 * @param {!SDK.NetworkRequest} request
367 * @return {boolean}
368 */
369 static _requestCookieValueFilter(value, request) {
370 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
371 }
372
373 /**
374 * @param {string} value
375 * @param {!SDK.NetworkRequest} request
376 * @return {boolean}
377 */
Blink Reformat4c46d092018-04-07 15:32:37378 static _requestSetCookieDomainFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41379 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37380 }
381
382 /**
383 * @param {string} value
384 * @param {!SDK.NetworkRequest} request
385 * @return {boolean}
386 */
387 static _requestSetCookieNameFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41388 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37389 }
390
391 /**
392 * @param {string} value
393 * @param {!SDK.NetworkRequest} request
394 * @return {boolean}
395 */
396 static _requestSetCookieValueFilter(value, request) {
Jan Scheffler341eea52019-12-12 09:08:41397 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37398 }
399
400 /**
401 * @param {number} value
402 * @param {!SDK.NetworkRequest} request
403 * @return {boolean}
404 */
405 static _requestSizeLargerThanFilter(value, request) {
406 return request.transferSize >= value;
407 }
408
409 /**
410 * @param {string} value
411 * @param {!SDK.NetworkRequest} request
412 * @return {boolean}
413 */
414 static _statusCodeFilter(value, request) {
415 return ('' + request.statusCode) === value;
416 }
417
418 /**
419 * @param {!SDK.NetworkRequest} request
420 * @return {boolean}
421 */
422 static HTTPRequestsFilter(request) {
Paul Lewis56509652019-12-06 12:51:58423 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37424 }
425
426 /**
Blink Reformat4c46d092018-04-07 15:32:37427 * @param {number} windowStart
428 * @param {number} windowEnd
429 * @param {!SDK.NetworkRequest} request
430 * @return {boolean}
431 */
432 static _requestTimeFilter(windowStart, windowEnd, request) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34433 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37434 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34435 }
436 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37437 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34438 }
Blink Reformat4c46d092018-04-07 15:32:37439 return true;
440 }
441
442 /**
443 * @param {!SDK.NetworkRequest} request
444 */
445 static _copyRequestHeaders(request) {
Tim van der Lippe50cfa9b2019-10-01 10:40:58446 Host.InspectorFrontendHost.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37447 }
448
449 /**
450 * @param {!SDK.NetworkRequest} request
451 */
452 static _copyResponseHeaders(request) {
Tim van der Lippe50cfa9b2019-10-01 10:40:58453 Host.InspectorFrontendHost.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37454 }
455
456 /**
457 * @param {!SDK.NetworkRequest} request
458 */
459 static async _copyResponse(request) {
460 const contentData = await request.contentData();
Ingvar Stepanyan1c771842018-10-10 14:35:08461 let content = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34462 if (!request.contentType().isTextType()) {
Ingvar Stepanyan1c771842018-10-10 14:35:08463 content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe1d6e57a2019-09-30 11:55:34464 } else if (contentData.encoded) {
Ingvar Stepanyan1c771842018-10-10 14:35:08465 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34466 }
Tim van der Lippe50cfa9b2019-10-01 10:40:58467 Host.InspectorFrontendHost.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37468 }
469
470 /**
471 * @param {!DataTransfer} dataTransfer
472 */
473 _handleDrop(dataTransfer) {
474 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34475 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37476 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34477 }
Blink Reformat4c46d092018-04-07 15:32:37478 const entry = items[0].webkitGetAsEntry();
Tim van der Lippe1d6e57a2019-09-30 11:55:34479 if (entry.isDirectory) {
Blink Reformat4c46d092018-04-07 15:32:37480 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34481 }
Blink Reformat4c46d092018-04-07 15:32:37482
Joey Arhar0e1093c2019-05-21 00:34:22483 entry.file(this.onLoadFromFile.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37484 }
485
486 /**
487 * @param {!File} file
488 */
Joey Arhar0e1093c2019-05-21 00:34:22489 async onLoadFromFile(file) {
Blink Reformat4c46d092018-04-07 15:32:37490 const outputStream = new Common.StringOutputStream();
491 const reader = new Bindings.ChunkedFileReader(file, /* chunkSize */ 10000000);
492 const success = await reader.read(outputStream);
493 if (!success) {
494 this._harLoadFailed(reader.error().message);
495 return;
496 }
497 let harRoot;
498 try {
499 // HARRoot and JSON.parse might throw.
500 harRoot = new HARImporter.HARRoot(JSON.parse(outputStream.data()));
501 } catch (e) {
502 this._harLoadFailed(e);
503 return;
504 }
Pavel Feldman18d13562018-07-31 03:31:18505 SDK.networkLog.importRequests(HARImporter.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37506 }
507
508 /**
509 * @param {string} message
510 */
511 _harLoadFailed(message) {
512 Common.console.error('Failed to load HAR file with following error: ' + message);
513 }
514
515 /**
516 * @param {?string} groupKey
517 */
518 _setGrouping(groupKey) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34519 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:37520 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34521 }
Blink Reformat4c46d092018-04-07 15:32:37522 const groupLookup = groupKey ? this._groupLookups.get(groupKey) || null : null;
523 this._activeGroupLookup = groupLookup;
524 this._invalidateAllItems();
525 }
526
527 /**
528 * @return {number}
529 */
530 _computeRowHeight() {
531 return Math.round(this._rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
532 }
533
534 /**
535 * @param {!SDK.NetworkRequest} request
536 * @return {?Network.NetworkRequestNode}
537 */
538 nodeForRequest(request) {
Paul Lewis56509652019-12-06 12:51:58539 return request[_networkNodeSymbol] || null;
Blink Reformat4c46d092018-04-07 15:32:37540 }
541
542 /**
543 * @return {number}
544 */
545 headerHeight() {
546 return this._headerHeight;
547 }
548
549 /**
550 * @param {boolean} recording
551 */
552 setRecording(recording) {
553 this._recording = recording;
554 this._updateSummaryBar();
555 }
556
557 /**
558 * @override
559 * @param {!SDK.NetworkManager} networkManager
560 */
561 modelAdded(networkManager) {
562 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Tim van der Lippe1d6e57a2019-09-30 11:55:34563 if (networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37564 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34565 }
Blink Reformat4c46d092018-04-07 15:32:37566 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel);
567 if (resourceTreeModel) {
568 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
569 resourceTreeModel.addEventListener(
570 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
571 }
572 }
573
574 /**
575 * @override
576 * @param {!SDK.NetworkManager} networkManager
577 */
578 modelRemoved(networkManager) {
579 if (!networkManager.target().parentTarget()) {
580 const resourceTreeModel = networkManager.target().model(SDK.ResourceTreeModel);
581 if (resourceTreeModel) {
582 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this._loadEventFired, this);
583 resourceTreeModel.removeEventListener(
584 SDK.ResourceTreeModel.Events.DOMContentLoaded, this._domContentLoadedEventFired, this);
585 }
586 }
587 }
588
589 /**
590 * @param {number} start
591 * @param {number} end
592 */
593 setWindow(start, end) {
594 if (!start && !end) {
595 this._timeFilter = null;
596 this._timeCalculator.setWindow(null);
597 } else {
Paul Lewis56509652019-12-06 12:51:58598 this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end);
Blink Reformat4c46d092018-04-07 15:32:37599 this._timeCalculator.setWindow(new Network.NetworkTimeBoundary(start, end));
600 }
601 this._filterRequests();
602 }
603
Brandon Goddard88d885a2019-10-31 16:11:05604 resetFocus() {
605 this._dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37606 }
607
608 _resetSuggestionBuilder() {
609 this._suggestionBuilder.clear();
Paul Lewis56509652019-12-06 12:51:58610 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.Running);
611 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.FromCache);
612 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerIntercepted);
613 this._suggestionBuilder.addItem(FilterType.Is, IsFilterType.ServiceWorkerInitiated);
614 this._suggestionBuilder.addItem(FilterType.LargerThan, '100');
615 this._suggestionBuilder.addItem(FilterType.LargerThan, '10k');
616 this._suggestionBuilder.addItem(FilterType.LargerThan, '1M');
Blink Reformat4c46d092018-04-07 15:32:37617 this._textFilterUI.setSuggestionProvider(this._suggestionBuilder.completions.bind(this._suggestionBuilder));
618 }
619
620 /**
621 * @param {!Common.Event} event
622 */
623 _filterChanged(event) {
624 this.removeAllNodeHighlights();
625 this._parseFilterQuery(this._textFilterUI.value());
626 this._filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37627 }
628
629 _showRecordingHint() {
630 this._hideRecordingHint();
631 this._recordingHint = this.element.createChild('div', 'network-status-pane fill');
632 const hintText = this._recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18633
634 let reloadShortcutNode = null;
635 const reloadShortcutDescriptor = UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0];
636 if (reloadShortcutDescriptor) {
637 reloadShortcutNode = this._recordingHint.createChild('b');
638 reloadShortcutNode.textContent = reloadShortcutDescriptor.name;
639 }
Blink Reformat4c46d092018-04-07 15:32:37640
641 if (this._recording) {
642 const recordingText = hintText.createChild('span');
643 recordingText.textContent = Common.UIString('Recording network activity\u2026');
Joey Arhar0585e6f2018-10-30 23:11:18644 if (reloadShortcutNode) {
645 hintText.createChild('br');
646 hintText.appendChild(
647 UI.formatLocalized('Perform a request or hit %s to record the reload.', [reloadShortcutNode]));
648 }
Blink Reformat4c46d092018-04-07 15:32:37649 } else {
650 const recordNode = hintText.createChild('b');
651 recordNode.textContent = UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording');
Joey Arhar0585e6f2018-10-30 23:11:18652 if (reloadShortcutNode) {
653 hintText.appendChild(UI.formatLocalized(
654 'Record (%s) or reload (%s) to display network activity.', [recordNode, reloadShortcutNode]));
655 } else {
656 hintText.appendChild(UI.formatLocalized('Record (%s) to display network activity.', [recordNode]));
657 }
Blink Reformat4c46d092018-04-07 15:32:37658 }
Kayce Basques5444c1b2019-02-15 20:32:53659 hintText.createChild('br');
660 hintText.appendChild(UI.XLink.create(
661 'https://developers.google.com/web/tools/chrome-devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
662 'Learn more'));
Amanda Baker6761aae2019-11-05 18:59:11663
664 this._setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37665 }
666
667 _hideRecordingHint() {
Amanda Baker6761aae2019-11-05 18:59:11668 this._setHidden(false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34669 if (this._recordingHint) {
Blink Reformat4c46d092018-04-07 15:32:37670 this._recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34671 }
Blink Reformat4c46d092018-04-07 15:32:37672 this._recordingHint = null;
673 }
674
675 /**
Amanda Baker6761aae2019-11-05 18:59:11676 * @param {boolean} value
677 */
678 _setHidden(value) {
679 this._columns.setHidden(value);
680 UI.ARIAUtils.setHidden(this._summaryToolbar.element, value);
681 }
682
683 /**
Blink Reformat4c46d092018-04-07 15:32:37684 * @override
685 * @return {!Array.<!Element>}
686 */
687 elementsToRestoreScrollPositionsFor() {
688 if (!this._dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34689 {
Blink Reformat4c46d092018-04-07 15:32:37690 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34691 }
Blink Reformat4c46d092018-04-07 15:32:37692 return [this._dataGrid.scrollContainer];
693 }
694
695 columnExtensionResolved() {
696 this._invalidateAllItems(true);
697 }
698
699 _setupDataGrid() {
700 this._dataGrid.setRowContextMenuCallback((contextMenu, node) => {
701 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34702 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37703 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34704 }
Blink Reformat4c46d092018-04-07 15:32:37705 });
706 this._dataGrid.setStickToBottom(true);
707 this._dataGrid.setName('networkLog');
708 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
709 this._dataGrid.element.classList.add('network-log-grid');
710 this._dataGrid.element.addEventListener('mousedown', this._dataGridMouseDown.bind(this), true);
711 this._dataGrid.element.addEventListener('mousemove', this._dataGridMouseMove.bind(this), true);
712 this._dataGrid.element.addEventListener('mouseleave', () => this._setHoveredNode(null), true);
Brandon Goddard88d885a2019-10-31 16:11:05713 this._dataGrid.element.addEventListener('keydown', event => {
714 if (isEnterOrSpaceKey(event)) {
Paul Lewis56509652019-12-06 12:51:58715 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true);
Brandon Goddard88d885a2019-10-31 16:11:05716 event.consume(true);
717 }
718 });
719 this._dataGrid.element.addEventListener('focus', this.updateNodeBackground.bind(this), true);
720 this._dataGrid.element.addEventListener('blur', this.updateNodeBackground.bind(this), true);
Blink Reformat4c46d092018-04-07 15:32:37721 return this._dataGrid;
722 }
723
724 /**
725 * @param {!Event} event
726 */
727 _dataGridMouseMove(event) {
728 const node = (this._dataGrid.dataGridNodeFromNode(/** @type {!Node} */ (event.target)));
729 const highlightInitiatorChain = event.shiftKey;
730 this._setHoveredNode(node, highlightInitiatorChain);
731 }
732
733 /**
734 * @return {?Network.NetworkNode}
735 */
736 hoveredNode() {
737 return this._hoveredNode;
738 }
739
740 /**
741 * @param {?Network.NetworkNode} node
742 * @param {boolean=} highlightInitiatorChain
743 */
744 _setHoveredNode(node, highlightInitiatorChain) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34745 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37746 this._hoveredNode.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:34747 }
Blink Reformat4c46d092018-04-07 15:32:37748 this._hoveredNode = node;
Tim van der Lippe1d6e57a2019-09-30 11:55:34749 if (this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:37750 this._hoveredNode.setHovered(true, !!highlightInitiatorChain);
Tim van der Lippe1d6e57a2019-09-30 11:55:34751 }
Blink Reformat4c46d092018-04-07 15:32:37752 }
753
754 /**
755 * @param {!Event} event
756 */
757 _dataGridMouseDown(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34758 if (!this._dataGrid.selectedNode && event.button) {
Blink Reformat4c46d092018-04-07 15:32:37759 event.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:34760 }
Blink Reformat4c46d092018-04-07 15:32:37761 }
762
763 _updateSummaryBar() {
764 this._hideRecordingHint();
765
766 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:20767 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37768 let selectedNodeNumber = 0;
769 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:20770 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:37771 let baseTime = -1;
772 let maxTime = -1;
773
774 let nodeCount = 0;
Pavel Feldman18d13562018-07-31 03:31:18775 for (const request of SDK.networkLog.requests()) {
Paul Lewis56509652019-12-06 12:51:58776 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:34777 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:37778 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:34779 }
Blink Reformat4c46d092018-04-07 15:32:37780 nodeCount++;
781 const requestTransferSize = request.transferSize;
782 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20783 const requestResourceSize = request.resourceSize;
784 resourceSize += requestResourceSize;
Paul Lewis56509652019-12-06 12:51:58785 if (!node[_isFilteredOutSymbol]) {
Blink Reformat4c46d092018-04-07 15:32:37786 selectedNodeNumber++;
787 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:20788 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:37789 }
790 const networkManager = SDK.NetworkManager.forRequest(request);
791 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
792 // inspected url.
793 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe1d6e57a2019-09-30 11:55:34794 request.resourceType() === Common.resourceTypes.Document && !networkManager.target().parentTarget()) {
Blink Reformat4c46d092018-04-07 15:32:37795 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34796 }
797 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:37798 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:34799 }
Blink Reformat4c46d092018-04-07 15:32:37800 }
801
802 if (!nodeCount) {
803 this._showRecordingHint();
804 return;
805 }
806
Joey Arhara86c14e2019-03-12 03:20:50807 this._summaryToolbar.removeToolbarItems();
Blink Reformat4c46d092018-04-07 15:32:37808 /**
809 * @param {string} chunk
Joey Arhara86c14e2019-03-12 03:20:50810 * @param {string=} title
Blink Reformat4c46d092018-04-07 15:32:37811 * @return {!Element}
812 */
Joey Arhara86c14e2019-03-12 03:20:50813 const appendChunk = (chunk, title) => {
814 const toolbarText = new UI.ToolbarText(chunk);
815 toolbarText.setTitle(title ? title : chunk);
816 this._summaryToolbar.appendToolbarItem(toolbarText);
817 return toolbarText.element;
818 };
Blink Reformat4c46d092018-04-07 15:32:37819
820 if (selectedNodeNumber !== nodeCount) {
Joey Arhara86c14e2019-03-12 03:20:50821 appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`);
822 this._summaryToolbar.appendSeparator();
823 appendChunk(
824 ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`,
Changhao Han9ec3f6e2019-11-12 18:43:25825 ls`${selectedTransferSize} B / ${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50826 this._summaryToolbar.appendSeparator();
827 appendChunk(
828 ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`,
Changhao Han9ec3f6e2019-11-12 18:43:25829 ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37830 } else {
Joey Arhara86c14e2019-03-12 03:20:50831 appendChunk(ls`${nodeCount} requests`);
832 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25833 appendChunk(
834 ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`);
Joey Arhara86c14e2019-03-12 03:20:50835 this._summaryToolbar.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:25836 appendChunk(
837 ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`);
Blink Reformat4c46d092018-04-07 15:32:37838 }
Dan Beam87466b52018-12-01 18:41:20839
Blink Reformat4c46d092018-04-07 15:32:37840 if (baseTime !== -1 && maxTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50841 this._summaryToolbar.appendSeparator();
842 appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`);
Blink Reformat4c46d092018-04-07 15:32:37843 if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) {
Joey Arhara86c14e2019-03-12 03:20:50844 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30845 const domContentLoadedText =
846 ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58847 appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor();
Blink Reformat4c46d092018-04-07 15:32:37848 }
849 if (this._mainRequestLoadTime !== -1) {
Joey Arhara86c14e2019-03-12 03:20:50850 this._summaryToolbar.appendSeparator();
Alexei Filippovfdcd8a62018-12-17 21:32:30851 const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`;
Paul Lewis56509652019-12-06 12:51:58852 appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor();
Blink Reformat4c46d092018-04-07 15:32:37853 }
854 }
Blink Reformat4c46d092018-04-07 15:32:37855 }
856
857 scheduleRefresh() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34858 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37859 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34860 }
Blink Reformat4c46d092018-04-07 15:32:37861
862 this._needsRefresh = true;
863
Tim van der Lippe1d6e57a2019-09-30 11:55:34864 if (this.isShowing() && !this._refreshRequestId) {
Blink Reformat4c46d092018-04-07 15:32:37865 this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:34866 }
Blink Reformat4c46d092018-04-07 15:32:37867 }
868
869 /**
870 * @param {!Array<number>} times
871 */
872 addFilmStripFrames(times) {
873 this._columns.addEventDividers(times, 'network-frame-divider');
874 }
875
876 /**
877 * @param {number} time
878 */
879 selectFilmStripFrame(time) {
880 this._columns.selectFilmStripFrame(time);
881 }
882
883 clearFilmStripFrame() {
884 this._columns.clearFilmStripFrame();
885 }
886
887 _refreshIfNeeded() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34888 if (this._needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:37889 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34890 }
Blink Reformat4c46d092018-04-07 15:32:37891 }
892
893 /**
894 * @param {boolean=} deferUpdate
895 */
896 _invalidateAllItems(deferUpdate) {
Pavel Feldman18d13562018-07-31 03:31:18897 this._staleRequests = new Set(SDK.networkLog.requests());
Tim van der Lippe1d6e57a2019-09-30 11:55:34898 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:37899 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34900 } else {
Blink Reformat4c46d092018-04-07 15:32:37901 this._refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:34902 }
Blink Reformat4c46d092018-04-07 15:32:37903 }
904
905 /**
906 * @return {!Network.NetworkTimeCalculator}
907 */
908 timeCalculator() {
909 return this._timeCalculator;
910 }
911
912 /**
913 * @return {!Network.NetworkTimeCalculator}
914 */
915 calculator() {
916 return this._calculator;
917 }
918
919 /**
920 * @param {!Network.NetworkTimeCalculator} x
921 */
922 setCalculator(x) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34923 if (!x || this._calculator === x) {
Blink Reformat4c46d092018-04-07 15:32:37924 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34925 }
Blink Reformat4c46d092018-04-07 15:32:37926
927 if (this._calculator !== x) {
928 this._calculator = x;
929 this._columns.setCalculator(this._calculator);
930 }
931 this._calculator.reset();
932
Tim van der Lippe1d6e57a2019-09-30 11:55:34933 if (this._calculator.startAtZero) {
Blink Reformat4c46d092018-04-07 15:32:37934 this._columns.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34935 } else {
Blink Reformat4c46d092018-04-07 15:32:37936 this._columns.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:34937 }
Blink Reformat4c46d092018-04-07 15:32:37938
939 this._invalidateAllItems();
940 }
941
942 /**
943 * @param {!Common.Event} event
944 */
945 _loadEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34946 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37947 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34948 }
Blink Reformat4c46d092018-04-07 15:32:37949
950 const time = /** @type {number} */ (event.data.loadTime);
951 if (time) {
952 this._mainRequestLoadTime = time;
Alexei Filippovfdcd8a62018-12-17 21:32:30953 this._columns.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:37954 }
955 }
956
957 /**
958 * @param {!Common.Event} event
959 */
960 _domContentLoadedEventFired(event) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34961 if (!this._recording) {
Blink Reformat4c46d092018-04-07 15:32:37962 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34963 }
Blink Reformat4c46d092018-04-07 15:32:37964 const data = /** @type {number} */ (event.data);
965 if (data) {
966 this._mainRequestDOMContentLoadedTime = data;
Alexei Filippovfdcd8a62018-12-17 21:32:30967 this._columns.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:37968 }
969 }
970
971 /**
972 * @override
973 */
974 wasShown() {
975 this._refreshIfNeeded();
976 this._columns.wasShown();
977 }
978
979 /**
980 * @override
981 */
982 willHide() {
983 this._columns.willHide();
984 }
985
986 /**
987 * @override
988 */
989 onResize() {
990 this._rowHeight = this._computeRowHeight();
991 }
992
993 /**
994 * @return {!Array<!Network.NetworkNode>}
995 */
996 flatNodesList() {
997 return this._dataGrid.rootNode().flatChildren();
998 }
999
Brandon Goddard88d885a2019-10-31 16:11:051000 updateNodeBackground() {
1001 if (this._dataGrid.selectedNode) {
1002 this._dataGrid.selectedNode.updateBackgroundColor();
1003 }
1004 }
1005
1006 /**
1007 * @param {boolean} isSelected
1008 */
1009 updateNodeSelectedClass(isSelected) {
1010 if (isSelected) {
1011 this.element.classList.remove('no-node-selected');
1012 } else {
1013 this.element.classList.add('no-node-selected');
1014 }
1015 }
1016
Blink Reformat4c46d092018-04-07 15:32:371017 stylesChanged() {
1018 this._columns.scheduleRefresh();
1019 }
1020
1021 _refresh() {
1022 this._needsRefresh = false;
1023
1024 if (this._refreshRequestId) {
1025 this.element.window().cancelAnimationFrame(this._refreshRequestId);
1026 this._refreshRequestId = null;
1027 }
1028
1029 this.removeAllNodeHighlights();
1030
1031 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1032 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestLoadTime);
1033 this._timeCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1034 this._durationCalculator.updateBoundariesForEventTime(this._mainRequestDOMContentLoadedTime);
1035
1036 /** @type {!Map<!Network.NetworkNode, !Network.NetworkNode>} */
1037 const nodesToInsert = new Map();
1038 /** @type {!Array<!Network.NetworkNode>} */
1039 const nodesToRefresh = [];
1040
1041 /** @type {!Set<!Network.NetworkRequestNode>} */
1042 const staleNodes = new Set();
1043
1044 // While creating nodes it may add more entries into _staleRequests because redirect request nodes update the parent
1045 // node so we loop until we have no more stale requests.
1046 while (this._staleRequests.size) {
1047 const request = this._staleRequests.firstValue();
1048 this._staleRequests.delete(request);
Paul Lewis56509652019-12-06 12:51:581049 let node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341050 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371051 node = this._createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341052 }
Blink Reformat4c46d092018-04-07 15:32:371053 staleNodes.add(node);
1054 }
1055
1056 for (const node of staleNodes) {
1057 const isFilteredOut = !this._applyFilter(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341058 if (isFilteredOut && node === this._hoveredNode) {
Blink Reformat4c46d092018-04-07 15:32:371059 this._setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341060 }
Blink Reformat4c46d092018-04-07 15:32:371061
Tim van der Lippe1d6e57a2019-09-30 11:55:341062 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371063 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341064 }
Blink Reformat4c46d092018-04-07 15:32:371065 const request = node.request();
1066 this._timeCalculator.updateBoundaries(request);
1067 this._durationCalculator.updateBoundaries(request);
1068 const newParent = this._parentNodeForInsert(node);
Paul Lewis56509652019-12-06 12:51:581069 if (node[_isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371070 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341071 }
Paul Lewis56509652019-12-06 12:51:581072 node[_isFilteredOutSymbol] = isFilteredOut;
Blink Reformat4c46d092018-04-07 15:32:371073 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1074 if (removeFromParent) {
1075 let parent = node.parent;
1076 parent.removeChild(node);
1077 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1078 const grandparent = parent.parent;
1079 grandparent.removeChild(parent);
1080 parent = grandparent;
1081 }
1082 }
1083
Tim van der Lippe1d6e57a2019-09-30 11:55:341084 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371085 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 }
Blink Reformat4c46d092018-04-07 15:32:371087
1088 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
1089 nodesToInsert.set(newParent, this._dataGrid.rootNode());
1090 nodesToRefresh.push(newParent);
1091 }
1092 nodesToInsert.set(node, newParent);
1093 }
1094
Tim van der Lippe1d6e57a2019-09-30 11:55:341095 for (const node of nodesToInsert.keys()) {
Blink Reformat4c46d092018-04-07 15:32:371096 nodesToInsert.get(node).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341097 }
Blink Reformat4c46d092018-04-07 15:32:371098
Tim van der Lippe1d6e57a2019-09-30 11:55:341099 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371100 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341101 }
Blink Reformat4c46d092018-04-07 15:32:371102
1103 this._updateSummaryBar();
1104
Tim van der Lippe1d6e57a2019-09-30 11:55:341105 if (nodesToInsert.size) {
Blink Reformat4c46d092018-04-07 15:32:371106 this._columns.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341107 }
Blink Reformat4c46d092018-04-07 15:32:371108
1109 this._dataGrid.updateInstantly();
1110 this._didRefreshForTest();
1111 }
1112
1113 _didRefreshForTest() {
1114 }
1115
1116 /**
1117 * @param {!Network.NetworkRequestNode} node
1118 * @return {?Network.NetworkNode}
1119 */
1120 _parentNodeForInsert(node) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341121 if (!this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371122 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341123 }
Blink Reformat4c46d092018-04-07 15:32:371124
1125 const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341126 if (!groupNode) {
Blink Reformat4c46d092018-04-07 15:32:371127 return this._dataGrid.rootNode();
Tim van der Lippe1d6e57a2019-09-30 11:55:341128 }
Blink Reformat4c46d092018-04-07 15:32:371129 return groupNode;
1130 }
1131
1132 _reset() {
Paul Lewis56509652019-12-06 12:51:581133 this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false);
Blink Reformat4c46d092018-04-07 15:32:371134
1135 this._setHoveredNode(null);
1136 this._columns.reset();
1137
1138 this._timeFilter = null;
1139 this._calculator.reset();
1140
1141 this._timeCalculator.setWindow(null);
1142 this.linkifier.reset();
Blink Reformat4c46d092018-04-07 15:32:371143
Tim van der Lippe1d6e57a2019-09-30 11:55:341144 if (this._activeGroupLookup) {
Blink Reformat4c46d092018-04-07 15:32:371145 this._activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341146 }
Blink Reformat4c46d092018-04-07 15:32:371147 this._staleRequests.clear();
1148 this._resetSuggestionBuilder();
1149
1150 this._mainRequestLoadTime = -1;
1151 this._mainRequestDOMContentLoadedTime = -1;
1152
1153 this._dataGrid.rootNode().removeChildren();
1154 this._updateSummaryBar();
1155 this._dataGrid.setStickToBottom(true);
1156 this.scheduleRefresh();
1157 }
1158
1159 /**
1160 * @param {string} filterString
1161 */
1162 setTextFilterValue(filterString) {
1163 this._textFilterUI.setValue(filterString);
1164 this._dataURLFilterUI.setChecked(false);
Jan Scheffler1ae7c9e2019-12-03 15:48:371165 this._onlyIssuesFilterUI.setChecked(false);
Blink Reformat4c46d092018-04-07 15:32:371166 this._resourceCategoryFilterUI.reset();
1167 }
1168
1169 /**
1170 * @param {!SDK.NetworkRequest} request
1171 */
1172 _createNodeForRequest(request) {
1173 const node = new Network.NetworkRequestNode(this, request);
Paul Lewis56509652019-12-06 12:51:581174 request[_networkNodeSymbol] = node;
1175 node[_isFilteredOutSymbol] = true;
Blink Reformat4c46d092018-04-07 15:32:371176
Tim van der Lippe1d6e57a2019-09-30 11:55:341177 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Blink Reformat4c46d092018-04-07 15:32:371178 this._refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341179 }
Blink Reformat4c46d092018-04-07 15:32:371180 return node;
1181 }
1182
1183 /**
1184 * @param {!Common.Event} event
1185 */
1186 _onRequestUpdated(event) {
1187 const request = /** @type {!SDK.NetworkRequest} */ (event.data);
1188 this._refreshRequest(request);
1189 }
1190
1191 /**
1192 * @param {!SDK.NetworkRequest} request
1193 */
1194 _refreshRequest(request) {
Paul Lewis56509652019-12-06 12:51:581195 NetworkLogView._subdomains(request.domain)
1196 .forEach(this._suggestionBuilder.addItem.bind(this._suggestionBuilder, FilterType.Domain));
1197 this._suggestionBuilder.addItem(FilterType.Method, request.requestMethod);
1198 this._suggestionBuilder.addItem(FilterType.MimeType, request.mimeType);
1199 this._suggestionBuilder.addItem(FilterType.Scheme, '' + request.scheme);
1200 this._suggestionBuilder.addItem(FilterType.StatusCode, '' + request.statusCode);
Blink Reformat4c46d092018-04-07 15:32:371201
1202 const priority = request.priority();
1203 if (priority) {
Paul Lewis56509652019-12-06 12:51:581204 this._suggestionBuilder.addItem(FilterType.Priority, PerfUI.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371205 }
1206
1207 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Paul Lewis56509652019-12-06 12:51:581208 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371209 }
1210
1211 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Paul Lewis56509652019-12-06 12:51:581212 this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371213 }
1214
1215 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Paul Lewis56509652019-12-06 12:51:581216 const suggestion =
1217 request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden;
1218 this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371219 }
1220
1221 const responseHeaders = request.responseHeaders;
Tim van der Lippe1d6e57a2019-09-30 11:55:341222 for (let i = 0, l = responseHeaders.length; i < l; ++i) {
Paul Lewis56509652019-12-06 12:51:581223 this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name);
Tim van der Lippe1d6e57a2019-09-30 11:55:341224 }
Jan Scheffler341eea52019-12-12 09:08:411225
1226 for (const cookie of request.responseCookies) {
Paul Lewis56509652019-12-06 12:51:581227 this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain());
1228 this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name());
1229 this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371230 }
1231
Jan Scheffler341eea52019-12-12 09:08:411232 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
1233 this._suggestionBuilder.addItem(FilterType.CookieDomain, cookie.domain());
1234 this._suggestionBuilder.addItem(FilterType.CookieName, cookie.name());
1235 this._suggestionBuilder.addItem(FilterType.CookieValue, cookie.value());
1236 }
1237
Blink Reformat4c46d092018-04-07 15:32:371238 this._staleRequests.add(request);
1239 this.scheduleRefresh();
1240 }
1241
1242 /**
1243 * @return {number}
1244 */
1245 rowHeight() {
1246 return this._rowHeight;
1247 }
1248
1249 /**
1250 * @param {boolean} gridMode
1251 */
1252 switchViewMode(gridMode) {
1253 this._columns.switchViewMode(gridMode);
1254 }
1255
1256 /**
1257 * @param {!UI.ContextMenu} contextMenu
1258 * @param {!SDK.NetworkRequest} request
1259 */
1260 handleContextMenuForRequest(contextMenu, request) {
1261 contextMenu.appendApplicableItems(request);
1262 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString('Copy'));
1263 const footerSection = copyMenu.footerSection();
1264 if (request) {
1265 copyMenu.defaultSection().appendItem(
Tim van der Lippe50cfa9b2019-10-01 10:40:581266 UI.copyLinkAddressLabel(),
1267 Host.InspectorFrontendHost.copyText.bind(Host.InspectorFrontendHost, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371268 if (request.requestHeadersText()) {
1269 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581270 Common.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371271 }
1272
1273 if (request.responseHeadersText) {
1274 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581275 Common.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371276 }
1277
1278 if (request.finished) {
1279 copyMenu.defaultSection().appendItem(
Paul Lewis56509652019-12-06 12:51:581280 Common.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371281 }
1282
Harley Libcf41f92018-09-10 18:01:131283 const disableIfBlob = request.isBlobRequest();
Blink Reformat4c46d092018-04-07 15:32:371284 if (Host.isWin()) {
1285 footerSection.appendItem(
Harley Libcf41f92018-09-10 18:01:131286 Common.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371287 footerSection.appendItem(
Harley Libcf41f92018-09-10 18:01:131288 Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371289 footerSection.appendItem(
Harley Libcf41f92018-09-10 18:01:131290 Common.UIString('Copy as cURL (cmd)'), this._copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
1291 footerSection.appendItem(
1292 Common.UIString('Copy as cURL (bash)'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371293 footerSection.appendItem(Common.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this));
1294 footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this));
1295 footerSection.appendItem(Common.UIString('Copy all as cURL (cmd)'), this._copyAllCurlCommand.bind(this, 'win'));
1296 footerSection.appendItem(
1297 Common.UIString('Copy all as cURL (bash)'), this._copyAllCurlCommand.bind(this, 'unix'));
1298 } else {
Harley Libcf41f92018-09-10 18:01:131299 footerSection.appendItem(
1300 Common.UIString('Copy as fetch'), this._copyFetchCall.bind(this, request), disableIfBlob);
1301 footerSection.appendItem(
1302 Common.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371303 footerSection.appendItem(Common.UIString('Copy all as fetch'), this._copyAllFetchCall.bind(this));
1304 footerSection.appendItem(Common.UIString('Copy all as cURL'), this._copyAllCurlCommand.bind(this, 'unix'));
1305 }
1306 } else {
1307 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(Common.UIString('Copy'));
1308 }
1309 footerSection.appendItem(Common.UIString('Copy all as HAR'), this._copyAll.bind(this));
1310
Joey Arhar0e1093c2019-05-21 00:34:221311 contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371312
1313 contextMenu.editSection().appendItem(Common.UIString('Clear browser cache'), this._clearBrowserCache.bind(this));
1314 contextMenu.editSection().appendItem(
1315 Common.UIString('Clear browser cookies'), this._clearBrowserCookies.bind(this));
1316
1317 if (request) {
1318 const maxBlockedURLLength = 20;
1319 const manager = SDK.multitargetNetworkManager;
1320 let patterns = manager.blockedPatterns();
1321
Tim van der Lippeffa78622019-09-16 12:07:121322 /**
1323 * @param {string} url
1324 */
1325 function addBlockedURL(url) {
1326 patterns.push({enabled: true, url: url});
1327 manager.setBlockedPatterns(patterns);
1328 manager.setBlockingEnabled(true);
1329 UI.viewManager.showView('network.blocked-urls');
1330 }
1331
1332 /**
1333 * @param {string} url
1334 */
1335 function removeBlockedURL(url) {
1336 patterns = patterns.filter(pattern => pattern.url !== url);
1337 manager.setBlockedPatterns(patterns);
1338 UI.viewManager.showView('network.blocked-urls');
1339 }
1340
Blink Reformat4c46d092018-04-07 15:32:371341 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1342 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1343 contextMenu.debugSection().appendItem(
1344 Common.UIString('Block request URL'), addBlockedURL.bind(null, urlWithoutScheme));
1345 } else if (urlWithoutScheme) {
1346 const croppedURL = urlWithoutScheme.trimMiddle(maxBlockedURLLength);
1347 contextMenu.debugSection().appendItem(
1348 Common.UIString('Unblock %s', croppedURL), removeBlockedURL.bind(null, urlWithoutScheme));
1349 }
1350
1351 const domain = request.parsedURL.domain();
1352 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1353 contextMenu.debugSection().appendItem(
1354 Common.UIString('Block request domain'), addBlockedURL.bind(null, domain));
1355 } else if (domain) {
1356 const croppedDomain = domain.trimMiddle(maxBlockedURLLength);
1357 contextMenu.debugSection().appendItem(
1358 Common.UIString('Unblock %s', croppedDomain), removeBlockedURL.bind(null, domain));
1359 }
1360
1361 if (SDK.NetworkManager.canReplayRequest(request)) {
1362 contextMenu.debugSection().appendItem(
1363 Common.UIString('Replay XHR'), SDK.NetworkManager.replayRequest.bind(null, request));
1364 }
Blink Reformat4c46d092018-04-07 15:32:371365 }
1366 }
1367
1368 _harRequests() {
Paul Lewis56509652019-12-06 12:51:581369 return SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => {
Joey Arharb3d6de42019-04-23 21:26:171370 return request.finished ||
1371 (request.resourceType() === Common.resourceTypes.WebSocket && request.responseReceivedTime);
1372 });
Blink Reformat4c46d092018-04-07 15:32:371373 }
1374
1375 async _copyAll() {
Pavel Feldman18d13562018-07-31 03:31:181376 const harArchive = {log: await SDK.HARLog.build(this._harRequests())};
Tim van der Lippe50cfa9b2019-10-01 10:40:581377 Host.InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371378 }
1379
1380 /**
1381 * @param {!SDK.NetworkRequest} request
1382 * @param {string} platform
1383 */
1384 async _copyCurlCommand(request, platform) {
1385 const command = await this._generateCurlCommand(request, platform);
Tim van der Lippe50cfa9b2019-10-01 10:40:581386 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371387 }
1388
1389 /**
1390 * @param {string} platform
1391 */
1392 async _copyAllCurlCommand(platform) {
Harley Libcf41f92018-09-10 18:01:131393 const commands = await this._generateAllCurlCommand(SDK.networkLog.requests(), platform);
Tim van der Lippe50cfa9b2019-10-01 10:40:581394 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371395 }
1396
1397 /**
1398 * @param {!SDK.NetworkRequest} request
1399 * @param {string} platform
1400 */
1401 async _copyFetchCall(request, platform) {
1402 const command = await this._generateFetchCall(request);
Tim van der Lippe50cfa9b2019-10-01 10:40:581403 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371404 }
1405
1406 async _copyAllFetchCall() {
Harley Libcf41f92018-09-10 18:01:131407 const commands = await this._generateAllFetchCall(SDK.networkLog.requests());
Tim van der Lippe50cfa9b2019-10-01 10:40:581408 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371409 }
1410
1411 /**
1412 * @param {!SDK.NetworkRequest} request
1413 */
1414 async _copyPowerShellCommand(request) {
1415 const command = await this._generatePowerShellCommand(request);
Tim van der Lippe50cfa9b2019-10-01 10:40:581416 Host.InspectorFrontendHost.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371417 }
1418
1419 async _copyAllPowerShellCommand() {
Harley Li5a470e92019-09-26 21:38:351420 const commands = await this._generateAllPowerShellCommand(SDK.networkLog.requests());
Tim van der Lippe50cfa9b2019-10-01 10:40:581421 Host.InspectorFrontendHost.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371422 }
1423
Joey Arhar0e1093c2019-05-21 00:34:221424 async exportAll() {
Blink Reformat4c46d092018-04-07 15:32:371425 const url = SDK.targetManager.mainTarget().inspectedURL();
Peter Marshall3e4e5692019-12-09 16:48:041426 const parsedURL = Common.ParsedURL.fromString(url);
Blink Reformat4c46d092018-04-07 15:32:371427 const filename = parsedURL ? parsedURL.host : 'network-log';
1428 const stream = new Bindings.FileOutputStream();
1429
Tim van der Lippe1d6e57a2019-09-30 11:55:341430 if (!await stream.open(filename + '.har')) {
Blink Reformat4c46d092018-04-07 15:32:371431 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341432 }
Blink Reformat4c46d092018-04-07 15:32:371433
1434 const progressIndicator = new UI.ProgressIndicator();
1435 this._progressBarContainer.appendChild(progressIndicator.element);
1436 await Network.HARWriter.write(stream, this._harRequests(), progressIndicator);
1437 progressIndicator.done();
1438 stream.close();
1439 }
1440
1441 _clearBrowserCache() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341442 if (confirm(Common.UIString('Are you sure you want to clear browser cache?'))) {
Blink Reformat4c46d092018-04-07 15:32:371443 SDK.multitargetNetworkManager.clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341444 }
Blink Reformat4c46d092018-04-07 15:32:371445 }
1446
1447 _clearBrowserCookies() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341448 if (confirm(Common.UIString('Are you sure you want to clear browser cookies?'))) {
Blink Reformat4c46d092018-04-07 15:32:371449 SDK.multitargetNetworkManager.clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341450 }
Blink Reformat4c46d092018-04-07 15:32:371451 }
1452
1453 _removeAllHighlights() {
1454 this.removeAllNodeHighlights();
Tim van der Lippe1d6e57a2019-09-30 11:55:341455 for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:371456 UI.revertDomChanges(this._highlightedSubstringChanges[i]);
Tim van der Lippe1d6e57a2019-09-30 11:55:341457 }
Blink Reformat4c46d092018-04-07 15:32:371458 this._highlightedSubstringChanges = [];
1459 }
1460
1461 /**
1462 * @param {!Network.NetworkRequestNode} node
1463 * @return {boolean}
1464 */
1465 _applyFilter(node) {
1466 const request = node.request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341467 if (this._timeFilter && !this._timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371468 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341469 }
Blink Reformat4c46d092018-04-07 15:32:371470 const categoryName = request.resourceType().category().title;
Tim van der Lippe1d6e57a2019-09-30 11:55:341471 if (!this._resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371472 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341473 }
1474 if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371475 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341476 }
Jan Scheffler1ae7c9e2019-12-03 15:48:371477 if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.hasIssues(request)) {
1478 return false;
1479 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341480 if (request.statusText === 'Service Worker Fallback Required') {
Blink Reformat4c46d092018-04-07 15:32:371481 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341482 }
Blink Reformat4c46d092018-04-07 15:32:371483 for (let i = 0; i < this._filters.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:341484 if (!this._filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371485 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341486 }
Blink Reformat4c46d092018-04-07 15:32:371487 }
1488 return true;
1489 }
1490
1491 /**
1492 * @param {string} query
1493 */
1494 _parseFilterQuery(query) {
1495 const descriptors = this._filterParser.parse(query);
1496 this._filters = descriptors.map(descriptor => {
1497 const key = descriptor.key;
1498 const text = descriptor.text || '';
1499 const regex = descriptor.regex;
1500 let filter;
1501 if (key) {
1502 const defaultText = (key + ':' + text).escapeForRegExp();
Paul Lewis56509652019-12-06 12:51:581503 filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) ||
1504 NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371505 } else if (descriptor.regex) {
Paul Lewis56509652019-12-06 12:51:581506 filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex));
Blink Reformat4c46d092018-04-07 15:32:371507 } else {
Paul Lewis56509652019-12-06 12:51:581508 filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371509 }
Paul Lewis56509652019-12-06 12:51:581510 return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter;
Blink Reformat4c46d092018-04-07 15:32:371511 });
1512 }
1513
1514 /**
Paul Lewis56509652019-12-06 12:51:581515 * @param {!FilterType} type
Blink Reformat4c46d092018-04-07 15:32:371516 * @param {string} value
1517 * @return {?Network.NetworkLogView.Filter}
1518 */
1519 _createSpecialFilter(type, value) {
1520 switch (type) {
Paul Lewis56509652019-12-06 12:51:581521 case FilterType.Domain:
1522 return NetworkLogView._createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371523
Paul Lewis56509652019-12-06 12:51:581524 case FilterType.HasResponseHeader:
1525 return NetworkLogView._requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371526
Paul Lewis56509652019-12-06 12:51:581527 case FilterType.Is:
1528 if (value.toLowerCase() === IsFilterType.Running) {
1529 return NetworkLogView._runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341530 }
Paul Lewis56509652019-12-06 12:51:581531 if (value.toLowerCase() === IsFilterType.FromCache) {
1532 return NetworkLogView._fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341533 }
Paul Lewis56509652019-12-06 12:51:581534 if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) {
1535 return NetworkLogView._interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341536 }
Paul Lewis56509652019-12-06 12:51:581537 if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) {
1538 return NetworkLogView._initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341539 }
Blink Reformat4c46d092018-04-07 15:32:371540 break;
1541
Paul Lewis56509652019-12-06 12:51:581542 case FilterType.LargerThan:
Blink Reformat4c46d092018-04-07 15:32:371543 return this._createSizeFilter(value.toLowerCase());
1544
Paul Lewis56509652019-12-06 12:51:581545 case FilterType.Method:
1546 return NetworkLogView._requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371547
Paul Lewis56509652019-12-06 12:51:581548 case FilterType.MimeType:
1549 return NetworkLogView._requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371550
Paul Lewis56509652019-12-06 12:51:581551 case FilterType.MixedContent:
1552 return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value));
Blink Reformat4c46d092018-04-07 15:32:371553
Paul Lewis56509652019-12-06 12:51:581554 case FilterType.Scheme:
1555 return NetworkLogView._requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371556
Paul Lewis56509652019-12-06 12:51:581557 case FilterType.SetCookieDomain:
1558 return NetworkLogView._requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371559
Paul Lewis56509652019-12-06 12:51:581560 case FilterType.SetCookieName:
1561 return NetworkLogView._requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371562
Paul Lewis56509652019-12-06 12:51:581563 case FilterType.SetCookieValue:
1564 return NetworkLogView._requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371565
Jan Scheffler341eea52019-12-12 09:08:411566 case FilterType.CookieDomain:
1567 return NetworkLogView._requestCookieDomainFilter.bind(null, value);
1568
1569 case FilterType.CookieName:
1570 return NetworkLogView._requestCookieNameFilter.bind(null, value);
1571
1572 case FilterType.CookieValue:
1573 return NetworkLogView._requestCookieValueFilter.bind(null, value);
1574
Paul Lewis56509652019-12-06 12:51:581575 case FilterType.Priority:
1576 return NetworkLogView._requestPriorityFilter.bind(null, PerfUI.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371577
Paul Lewis56509652019-12-06 12:51:581578 case FilterType.StatusCode:
1579 return NetworkLogView._statusCodeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371580 }
1581 return null;
1582 }
1583
1584 /**
1585 * @param {string} value
1586 * @return {?Network.NetworkLogView.Filter}
1587 */
1588 _createSizeFilter(value) {
1589 let multiplier = 1;
1590 if (value.endsWith('k')) {
1591 multiplier = 1024;
1592 value = value.substring(0, value.length - 1);
1593 } else if (value.endsWith('m')) {
1594 multiplier = 1024 * 1024;
1595 value = value.substring(0, value.length - 1);
1596 }
1597 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341598 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371599 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341600 }
Paul Lewis56509652019-12-06 12:51:581601 return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371602 }
1603
1604 _filterRequests() {
1605 this._removeAllHighlights();
1606 this._invalidateAllItems();
1607 }
1608
1609 /**
1610 * @param {!SDK.NetworkRequest} request
1611 * @return {?Network.NetworkRequestNode}
1612 */
1613 _reveal(request) {
1614 this.removeAllNodeHighlights();
Paul Lewis56509652019-12-06 12:51:581615 const node = request[_networkNodeSymbol];
Tim van der Lippe1d6e57a2019-09-30 11:55:341616 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371617 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341618 }
Blink Reformat4c46d092018-04-07 15:32:371619 node.reveal();
1620 return node;
1621 }
1622
1623 /**
1624 * @param {!SDK.NetworkRequest} request
1625 */
1626 revealAndHighlightRequest(request) {
1627 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341628 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371629 this._highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341630 }
Blink Reformat4c46d092018-04-07 15:32:371631 }
1632
1633 /**
1634 * @param {!SDK.NetworkRequest} request
1635 */
1636 selectRequest(request) {
Eugene Ostroukhovb600f662018-05-09 00:18:141637 this.setTextFilterValue('');
Blink Reformat4c46d092018-04-07 15:32:371638 const node = this._reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341639 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371640 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341641 }
Blink Reformat4c46d092018-04-07 15:32:371642 }
1643
1644 removeAllNodeHighlights() {
1645 if (this._highlightedNode) {
1646 this._highlightedNode.element().classList.remove('highlighted-row');
1647 this._highlightedNode = null;
1648 }
1649 }
1650
1651 /**
1652 * @param {!Network.NetworkRequestNode} node
1653 */
1654 _highlightNode(node) {
1655 UI.runCSSAnimationOnce(node.element(), 'highlighted-row');
1656 this._highlightedNode = node;
1657 }
1658
1659 /**
Harley Libcf41f92018-09-10 18:01:131660 * @param {!Array<!SDK.NetworkRequest>} requests
1661 * @return {!Array<!SDK.NetworkRequest>}
1662 */
1663 _filterOutBlobRequests(requests) {
1664 return requests.filter(request => !request.isBlobRequest());
1665 }
1666
1667 /**
Blink Reformat4c46d092018-04-07 15:32:371668 * @param {!SDK.NetworkRequest} request
1669 * @return {!Promise<string>}
1670 */
1671 async _generateFetchCall(request) {
1672 const ignoredHeaders = {
1673 // Internal headers
1674 'method': 1,
1675 'path': 1,
1676 'scheme': 1,
1677 'version': 1,
1678
1679 // Unsafe headers
1680 // Keep this list synchronized with src/net/http/http_util.cc
1681 'accept-charset': 1,
1682 'accept-encoding': 1,
1683 'access-control-request-headers': 1,
1684 'access-control-request-method': 1,
1685 'connection': 1,
1686 'content-length': 1,
1687 'cookie': 1,
1688 'cookie2': 1,
1689 'date': 1,
1690 'dnt': 1,
1691 'expect': 1,
1692 'host': 1,
1693 'keep-alive': 1,
1694 'origin': 1,
1695 'referer': 1,
1696 'te': 1,
1697 'trailer': 1,
1698 'transfer-encoding': 1,
1699 'upgrade': 1,
1700 'via': 1,
1701 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
1702 'user-agent': 1
1703 };
1704
1705 const credentialHeaders = {'cookie': 1, 'authorization': 1};
1706
1707 const url = JSON.stringify(request.url());
1708
1709 const requestHeaders = request.requestHeaders();
1710 const headerData = requestHeaders.reduce((result, header) => {
1711 const name = header.name;
1712
Tim van der Lippe1d6e57a2019-09-30 11:55:341713 if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:371714 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341715 }
Blink Reformat4c46d092018-04-07 15:32:371716
1717 return result;
1718 }, new Headers());
1719
1720 const headers = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:341721 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:411722 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:341723 }
Blink Reformat4c46d092018-04-07 15:32:371724
1725 const credentials =
Jan Scheffler341eea52019-12-12 09:08:411726 request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ?
1727 'include' :
1728 'omit';
Blink Reformat4c46d092018-04-07 15:32:371729
1730 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
1731
1732 const referrer = referrerHeader ? referrerHeader.value : void 0;
1733
1734 const referrerPolicy = request.referrerPolicy() || void 0;
1735
1736 const requestBody = await request.requestFormData();
1737
1738 const fetchOptions = {
1739 credentials,
PhistucK6ed0a3e2018-08-04 06:28:411740 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:371741 referrer,
1742 referrerPolicy,
1743 body: requestBody,
1744 method: request.requestMethod,
1745 mode: 'cors'
1746 };
1747
1748 const options = JSON.stringify(fetchOptions);
1749 return `fetch(${url}, ${options});`;
1750 }
1751
1752 /**
Harley Libcf41f92018-09-10 18:01:131753 * @param {!Array<!SDK.NetworkRequest>} requests
1754 * @return {!Promise<string>}
1755 */
1756 async _generateAllFetchCall(requests) {
1757 const nonBlobRequests = this._filterOutBlobRequests(requests);
1758 const commands = await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request)));
1759 return commands.join(' ;\n');
1760 }
1761
1762 /**
Blink Reformat4c46d092018-04-07 15:32:371763 * @param {!SDK.NetworkRequest} request
1764 * @param {string} platform
1765 * @return {!Promise<string>}
1766 */
1767 async _generateCurlCommand(request, platform) {
1768 let command = ['curl'];
Eric Lawrence7a7b3682019-10-17 23:06:361769 // Most of these headers are derived from the URL and are automatically added by cURL.
1770 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
1771 const ignoredHeaders = {'accept-encoding': 1, 'host': 1, 'method': 1, 'path': 1, 'scheme': 1, 'version': 1};
Blink Reformat4c46d092018-04-07 15:32:371772
1773 function escapeStringWin(str) {
1774 /* If there are no new line characters do not escape the " characters
1775 since it only uglifies the command.
1776
1777 Because cmd.exe parser and MS Crt arguments parsers use some of the
1778 same escape characters, they can interact with each other in
1779 horrible ways, the order of operations is critical.
1780
1781 Replace \ with \\ first because it is an escape character for certain
1782 conditions in both parsers.
1783
1784 Replace all " with \" to ensure the first parser does not remove it.
1785
1786 Then escape all characters we are not sure about with ^ to ensure it
1787 gets to MS Crt parser safely.
1788
1789 The % character is special because MS Crt parser will try and look for
1790 ENV variables and fill them in it's place. We cannot escape them with %
1791 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
1792 parser); So we can get cmd.exe parser to escape the character after it,
1793 if it is followed by a valid beginning character of an ENV variable.
1794 This ensures we do not try and double escape another ^ if it was placed
1795 by the previous replace.
1796
1797 Lastly we replace new lines with ^ and TWO new lines because the first
1798 new line is there to enact the escape command the second is the character
1799 to escape (in this case new line).
1800 */
1801 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
1802 return encapsChars +
1803 str.replace(/\\/g, '\\\\')
1804 .replace(/"/g, '\\"')
1805 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
1806 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
1807 .replace(/\r\n|[\n\r]/g, '^\n\n') +
1808 encapsChars;
1809 }
1810
1811 /**
1812 * @param {string} str
1813 * @return {string}
1814 */
1815 function escapeStringPosix(str) {
1816 /**
1817 * @param {string} x
1818 * @return {string}
1819 */
1820 function escapeCharacter(x) {
Erik Luoaa676752018-08-21 05:52:221821 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:121822 let hexString = code.toString(16);
1823 // Zero pad to four digits to comply with ANSI-C Quoting:
1824 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:341825 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:121826 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:341827 }
Joey Arhar2d21f712019-05-20 21:07:121828
1829 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:371830 }
1831
Joey Arhar512e3742019-01-25 21:33:541832 if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:371833 // Use ANSI-C quoting syntax.
1834 return '$\'' +
1835 str.replace(/\\/g, '\\\\')
1836 .replace(/\'/g, '\\\'')
1837 .replace(/\n/g, '\\n')
1838 .replace(/\r/g, '\\r')
Joey Arhar512e3742019-01-25 21:33:541839 .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:371840 '\'';
1841 } else {
1842 // Use single quote syntax.
1843 return '\'' + str + '\'';
1844 }
1845 }
1846
1847 // cURL command expected to run on the same platform that DevTools run
1848 // (it may be different from the inspected page platform).
1849 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
1850
1851 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
1852
1853 let inferredMethod = 'GET';
1854 const data = [];
1855 const requestContentType = request.requestContentType();
1856 const formData = await request.requestFormData();
1857 if (requestContentType && requestContentType.startsWith('application/x-www-form-urlencoded') && formData) {
1858 data.push('--data');
1859 data.push(escapeString(formData));
1860 ignoredHeaders['content-length'] = true;
1861 inferredMethod = 'POST';
1862 } else if (formData) {
1863 data.push('--data-binary');
1864 data.push(escapeString(formData));
1865 ignoredHeaders['content-length'] = true;
1866 inferredMethod = 'POST';
1867 }
1868
1869 if (request.requestMethod !== inferredMethod) {
1870 command.push('-X');
1871 command.push(request.requestMethod);
1872 }
1873
1874 const requestHeaders = request.requestHeaders();
1875 for (let i = 0; i < requestHeaders.length; i++) {
1876 const header = requestHeaders[i];
1877 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341878 if (name.toLowerCase() in ignoredHeaders) {
Blink Reformat4c46d092018-04-07 15:32:371879 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341880 }
Blink Reformat4c46d092018-04-07 15:32:371881 command.push('-H');
1882 command.push(escapeString(name + ': ' + header.value));
1883 }
1884 command = command.concat(data);
1885 command.push('--compressed');
1886
Tim van der Lippe1d6e57a2019-09-30 11:55:341887 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:371888 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:341889 }
Blink Reformat4c46d092018-04-07 15:32:371890 return command.join(' ');
1891 }
1892
1893 /**
Harley Libcf41f92018-09-10 18:01:131894 * @param {!Array<!SDK.NetworkRequest>} requests
1895 * @param {string} platform
1896 * @return {!Promise<string>}
1897 */
1898 async _generateAllCurlCommand(requests, platform) {
1899 const nonBlobRequests = this._filterOutBlobRequests(requests);
1900 const commands = await Promise.all(nonBlobRequests.map(request => this._generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:341901 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:131902 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341903 } else {
Harley Libcf41f92018-09-10 18:01:131904 return commands.join(' ;\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:341905 }
Harley Libcf41f92018-09-10 18:01:131906 }
1907
1908 /**
Blink Reformat4c46d092018-04-07 15:32:371909 * @param {!SDK.NetworkRequest} request
1910 * @return {!Promise<string>}
1911 */
1912 async _generatePowerShellCommand(request) {
1913 const command = ['Invoke-WebRequest'];
1914 const ignoredHeaders =
1915 new Set(['host', 'connection', 'proxy-connection', 'content-length', 'expect', 'range', 'content-type']);
1916
1917 /**
1918 * @param {string} str
1919 * @return {string}
1920 */
1921 function escapeString(str) {
1922 return '"' +
1923 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
1924 }
1925
1926 command.push('-Uri');
1927 command.push(escapeString(request.url()));
1928
1929 if (request.requestMethod !== 'GET') {
1930 command.push('-Method');
1931 command.push(escapeString(request.requestMethod));
1932 }
1933
1934 const requestHeaders = request.requestHeaders();
1935 const headerNameValuePairs = [];
1936 for (const header of requestHeaders) {
1937 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:341938 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:371939 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341940 }
Blink Reformat4c46d092018-04-07 15:32:371941 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
1942 }
1943 if (headerNameValuePairs.length) {
1944 command.push('-Headers');
1945 command.push('@{' + headerNameValuePairs.join('; ') + '}');
1946 }
1947
1948 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
1949 if (contentTypeHeader) {
1950 command.push('-ContentType');
1951 command.push(escapeString(contentTypeHeader.value));
1952 }
1953
1954 const formData = await request.requestFormData();
1955 if (formData) {
1956 command.push('-Body');
1957 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:341958 if (/[^\x20-\x7E]/.test(formData)) {
Blink Reformat4c46d092018-04-07 15:32:371959 command.push('([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:341960 } else {
Blink Reformat4c46d092018-04-07 15:32:371961 command.push(body);
Tim van der Lippe1d6e57a2019-09-30 11:55:341962 }
Blink Reformat4c46d092018-04-07 15:32:371963 }
1964
1965 return command.join(' ');
1966 }
Harley Libcf41f92018-09-10 18:01:131967
1968 /**
1969 * @param {!Array<!SDK.NetworkRequest>} requests
1970 * @return {!Promise<string>}
1971 */
1972 async _generateAllPowerShellCommand(requests) {
1973 const nonBlobRequests = this._filterOutBlobRequests(requests);
1974 const commands = await Promise.all(nonBlobRequests.map(request => this._generatePowerShellCommand(request)));
1975 return commands.join(';\r\n');
1976 }
Joey Arhara86c14e2019-03-12 03:20:501977
1978 /**
1979 * @return {string}
1980 */
1981 static getDCLEventColor() {
Tim van der Lippe1d6e57a2019-09-30 11:55:341982 if (UI.themeSupport.themeName() === 'dark') {
Joey Arhara86c14e2019-03-12 03:20:501983 return '#03A9F4';
Tim van der Lippe1d6e57a2019-09-30 11:55:341984 }
Joey Arhara86c14e2019-03-12 03:20:501985 return '#0867CB';
1986 }
1987
1988 /**
1989 * @return {string}
1990 */
1991 static getLoadEventColor() {
1992 return UI.themeSupport.patchColorText('#B31412', UI.ThemeSupport.ColorUsage.Foreground);
1993 }
Paul Lewis56509652019-12-06 12:51:581994}
Blink Reformat4c46d092018-04-07 15:32:371995
Paul Lewis56509652019-12-06 12:51:581996export const _isFilteredOutSymbol = Symbol('isFilteredOut');
1997export const _networkNodeSymbol = Symbol('NetworkNode');
Blink Reformat4c46d092018-04-07 15:32:371998
Paul Lewis56509652019-12-06 12:51:581999export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372000 'http': true,
2001 'https': true,
2002 'ws': true,
2003 'wss': true
2004};
2005
2006/** @enum {symbol} */
Paul Lewis56509652019-12-06 12:51:582007export const Events = {
Brandon Goddard88d885a2019-10-31 16:11:052008 RequestSelected: Symbol('RequestSelected'),
2009 RequestActivated: Symbol('RequestActivated')
Blink Reformat4c46d092018-04-07 15:32:372010};
2011
2012/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582013export const FilterType = {
Blink Reformat4c46d092018-04-07 15:32:372014 Domain: 'domain',
2015 HasResponseHeader: 'has-response-header',
2016 Is: 'is',
2017 LargerThan: 'larger-than',
2018 Method: 'method',
2019 MimeType: 'mime-type',
2020 MixedContent: 'mixed-content',
2021 Priority: 'priority',
2022 Scheme: 'scheme',
2023 SetCookieDomain: 'set-cookie-domain',
2024 SetCookieName: 'set-cookie-name',
2025 SetCookieValue: 'set-cookie-value',
Jan Scheffler341eea52019-12-12 09:08:412026 CookieDomain: 'cookie-domain',
2027 CookieName: 'cookie-name',
2028 CookieValue: 'cookie-value',
Blink Reformat4c46d092018-04-07 15:32:372029 StatusCode: 'status-code'
2030};
2031
2032/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582033export const MixedContentFilterValues = {
Blink Reformat4c46d092018-04-07 15:32:372034 All: 'all',
2035 Displayed: 'displayed',
2036 Blocked: 'blocked',
2037 BlockOverridden: 'block-overridden'
2038};
2039
2040/** @enum {string} */
Paul Lewis56509652019-12-06 12:51:582041export const IsFilterType = {
Blink Reformat4c46d092018-04-07 15:32:372042 Running: 'running',
Joey Arhard183e7e2019-02-28 03:37:052043 FromCache: 'from-cache',
2044 ServiceWorkerIntercepted: 'service-worker-intercepted',
2045 ServiceWorkerInitiated: 'service-worker-initiated'
Blink Reformat4c46d092018-04-07 15:32:372046};
2047
2048/** @type {!Array<string>} */
Paul Lewis56509652019-12-06 12:51:582049export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]);
Blink Reformat4c46d092018-04-07 15:32:372050
2051/**
2052 * @interface
2053 */
Paul Lewis56509652019-12-06 12:51:582054export class GroupLookupInterface {
Blink Reformat4c46d092018-04-07 15:32:372055 /**
2056 * @param {!SDK.NetworkRequest} request
2057 * @return {?Network.NetworkGroupNode}
2058 */
Paul Lewis56509652019-12-06 12:51:582059 groupNodeForRequest(request) {
2060 }
Blink Reformat4c46d092018-04-07 15:32:372061
Paul Lewis56509652019-12-06 12:51:582062 reset() {
2063 }
2064}
2065
2066/* Legacy exported object */
2067self.Network = self.Network || {};
2068
2069/* Legacy exported object */
2070Network = Network || {};
2071
2072/**
2073 * @constructor
2074 */
2075Network.NetworkLogView = NetworkLogView;
2076
2077/** @typedef {function(!SDK.NetworkRequest): boolean} */
2078Network.NetworkLogView.Filter;
2079
2080Network.NetworkLogView._isFilteredOutSymbol = _isFilteredOutSymbol;
2081Network.NetworkLogView._networkNodeSymbol = _networkNodeSymbol;
2082Network.NetworkLogView.HTTPSchemas = HTTPSchemas;
2083
2084/** @enum {symbol} */
2085Network.NetworkLogView.Events = Events;
2086
2087/** @enum {string} */
2088Network.NetworkLogView.FilterType = FilterType;
2089
2090/** @enum {string} */
2091Network.NetworkLogView.MixedContentFilterValues = MixedContentFilterValues;
2092
2093/** @enum {string} */
2094Network.NetworkLogView.IsFilterType = IsFilterType;
2095
2096/** @type {!Array<string>} */
2097Network.NetworkLogView._searchKeys = _searchKeys;
2098
2099/**
2100 * @interface
2101 */
2102Network.GroupLookupInterface = GroupLookupInterface;