Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 31 | import {HARWriter} from './HARWriter.js'; |
| 32 | import {Events, NetworkGroupNode, NetworkLogViewInterface, NetworkNode, NetworkRequestNode} from './NetworkDataGridNode.js'; // eslint-disable-line no-unused-vars |
| 33 | import {NetworkFrameGrouper} from './NetworkFrameGrouper.js'; |
| 34 | import {NetworkLogViewColumns} from './NetworkLogViewColumns.js'; |
| 35 | import {NetworkTimeBoundary, NetworkTimeCalculator, NetworkTransferDurationCalculator, NetworkTransferTimeCalculator,} from './NetworkTimeCalculator.js'; // eslint-disable-line no-unused-vars |
| 36 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 37 | /** |
| 38 | * @implements {SDK.SDKModelObserver<!SDK.NetworkManager>} |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 39 | * @implements {NetworkLogViewInterface} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 40 | */ |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 41 | export class NetworkLogView extends UI.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 42 | /** |
| 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 Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 53 | this.element.classList.add('no-node-selected'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 54 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 55 | this._networkHideDataURLSetting = self.Common.settings.createSetting('networkHideDataURL', false); |
| 56 | this._networkShowIssuesOnlySetting = self.Common.settings.createSetting('networkShowIssuesOnly', false); |
| 57 | this._networkResourceTypeFiltersSetting = self.Common.settings.createSetting('networkResourceTypeFilters', {}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 58 | |
| 59 | this._rawRowHeight = 0; |
| 60 | this._progressBarContainer = progressBarContainer; |
| 61 | this._networkLogLargeRowsSetting = networkLogLargeRowsSetting; |
| 62 | this._networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this); |
| 63 | |
| 64 | /** |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 65 | * @this {NetworkLogView} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | */ |
| 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 75 | /** @type {!NetworkTransferTimeCalculator} */ |
| 76 | this._timeCalculator = new NetworkTransferTimeCalculator(); |
| 77 | /** @type {!NetworkTransferDurationCalculator} */ |
| 78 | this._durationCalculator = new NetworkTransferDurationCalculator(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | this._calculator = this._timeCalculator; |
| 80 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 81 | this._columns = |
| 82 | new NetworkLogViewColumns(this, this._timeCalculator, this._durationCalculator, networkLogLargeRowsSetting); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 97 | /** @type {?NetworkNode} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 98 | this._hoveredNode = null; |
| 99 | /** @type {?Element} */ |
| 100 | this._recordingHint = null; |
| 101 | /** @type {?number} */ |
| 102 | this._refreshRequestId = null; |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 103 | /** @type {?NetworkRequestNode} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 104 | this._highlightedNode = null; |
| 105 | |
| 106 | this.linkifier = new Components.Linkifier(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | |
| 108 | this._recording = false; |
| 109 | this._needsRefresh = false; |
| 110 | |
| 111 | this._headerHeight = 0; |
| 112 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 113 | /** @type {!Map<string, !GroupLookupInterface>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 114 | this._groupLookups = new Map(); |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 115 | this._groupLookups.set('Frame', new NetworkFrameGrouper(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 117 | /** @type {?GroupLookupInterface} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 118 | 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 Arhar | ba99d62 | 2019-02-01 19:10:48 | [diff] [blame] | 127 | this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | 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 Goddard | 568cef1 | 2019-06-27 17:18:20 | [diff] [blame] | 134 | UI.ARIAUtils.setAccessibleName(this._resourceCategoryFilterUI.element(), ls`Resource types to include`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 135 | this._resourceCategoryFilterUI.addEventListener( |
| 136 | UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this); |
| 137 | filterBar.addFilter(this._resourceCategoryFilterUI); |
| 138 | |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 139 | this._onlyIssuesFilterUI = |
| 140 | new UI.CheckboxFilterUI('only-show-issues', ls`Has blocked cookies`, true, this._networkShowIssuesOnlySetting); |
Jan Scheffler | 1ae7c9e | 2019-12-03 15:48:37 | [diff] [blame] | 141 | this._onlyIssuesFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this); |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 142 | this._onlyIssuesFilterUI.element().title = ls`Only show requests with blocked response cookies`; |
Jan Scheffler | 1ae7c9e | 2019-12-03 15:48:37 | [diff] [blame] | 143 | filterBar.addFilter(this._onlyIssuesFilterUI); |
| 144 | |
| 145 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 146 | this._filterParser = new TextUtils.FilterParser(_searchKeys); |
| 147 | this._suggestionBuilder = new UI.FilterSuggestionBuilder(_searchKeys, NetworkLogView._sortSearchValues); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | this._resetSuggestionBuilder(); |
| 149 | |
| 150 | this._dataGrid = this._columns.dataGrid(); |
| 151 | this._setupDataGrid(); |
| 152 | this._columns.sortByCurrentColumn(); |
Erik Luo | 0187a02 | 2018-05-31 18:35:49 | [diff] [blame] | 153 | filterBar.filterButton().addEventListener( |
| 154 | UI.ToolbarButton.Events.Click, this._dataGrid.scheduleUpdate.bind(this._dataGrid, true /* isFromUser */)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 155 | |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 156 | this._summaryToolbar = new UI.Toolbar('network-summary-bar', this.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | |
| 158 | new UI.DropTarget( |
| 159 | this.element, [UI.DropTarget.Type.File], Common.UIString('Drop HAR files here'), this._handleDrop.bind(this)); |
| 160 | |
Paul Lewis | 4b64b3f | 2020-01-23 11:41:20 | [diff] [blame] | 161 | self.Common.settings.moduleSetting('networkColorCodeResourceTypes') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | .addChangeListener(this._invalidateAllItems.bind(this, false), this); |
| 163 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 164 | self.SDK.targetManager.observeModels(SDK.NetworkManager, this); |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 165 | self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestAdded, this._onRequestUpdated, this); |
| 166 | self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.RequestUpdated, this._onRequestUpdated, this); |
| 167 | self.SDK.networkLog.addEventListener(SDK.NetworkLog.Events.Reset, this._reset, this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 168 | |
| 169 | this._updateGroupByFrame(); |
Paul Lewis | 4b64b3f | 2020-01-23 11:41:20 | [diff] [blame] | 170 | self.Common.settings.moduleSetting('network.group-by-frame').addChangeListener(() => this._updateGroupByFrame()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 171 | |
| 172 | this._filterBar = filterBar; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 173 | } |
| 174 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 175 | _updateGroupByFrame() { |
Paul Lewis | 4b64b3f | 2020-01-23 11:41:20 | [diff] [blame] | 176 | const value = self.Common.settings.moduleSetting('network.group-by-frame').get(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 185 | if (key === FilterType.Priority) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 211 | if (!regex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 212 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 213 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 214 | |
| 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 245 | return NetworkLogView._requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 246 | } |
| 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 Arhar | d183e7e | 2019-02-28 03:37:05 | [diff] [blame] | 274 | * @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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 290 | * @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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 326 | * @param {!MixedContentFilterValues} value |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 327 | * @param {!SDK.NetworkRequest} request |
| 328 | * @return {boolean} |
| 329 | */ |
| 330 | static _requestMixedContentFilter(value, request) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 331 | if (value === MixedContentFilterValues.Displayed) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 332 | return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable; |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 333 | } else if (value === MixedContentFilterValues.Blocked) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 334 | return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked(); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 335 | } else if (value === MixedContentFilterValues.BlockOverridden) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 336 | return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked(); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 337 | } else if (value === MixedContentFilterValues.All) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 338 | return request.mixedContentType !== Protocol.Security.MixedContentType.None; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 339 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 340 | |
| 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 Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 358 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 385 | static _requestSetCookieDomainFilter(value, request) { |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 386 | return request.responseCookies.some(cookie => cookie.domain() === value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /** |
| 390 | * @param {string} value |
| 391 | * @param {!SDK.NetworkRequest} request |
| 392 | * @return {boolean} |
| 393 | */ |
| 394 | static _requestSetCookieNameFilter(value, request) { |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 395 | return request.responseCookies.some(cookie => cookie.name() === value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /** |
| 399 | * @param {string} value |
| 400 | * @param {!SDK.NetworkRequest} request |
| 401 | * @return {boolean} |
| 402 | */ |
| 403 | static _requestSetCookieValueFilter(value, request) { |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 404 | return request.responseCookies.some(cookie => cookie.value() === value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 405 | } |
| 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 430 | return request.parsedURL.isValid && (request.scheme in HTTPSchemas); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 434 | * @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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 440 | if (request.issueTime() > windowEnd) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 441 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 442 | } |
| 443 | if (request.endTime !== -1 && request.endTime < windowStart) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 444 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 445 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 446 | return true; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * @param {!SDK.NetworkRequest} request |
| 451 | */ |
| 452 | static _copyRequestHeaders(request) { |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 453 | Host.InspectorFrontendHost.copyText(request.requestHeadersText()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * @param {!SDK.NetworkRequest} request |
| 458 | */ |
| 459 | static _copyResponseHeaders(request) { |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 460 | Host.InspectorFrontendHost.copyText(request.responseHeadersText); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @param {!SDK.NetworkRequest} request |
| 465 | */ |
| 466 | static async _copyResponse(request) { |
| 467 | const contentData = await request.contentData(); |
Ingvar Stepanyan | 1c77184 | 2018-10-10 14:35:08 | [diff] [blame] | 468 | let content = contentData.content || ''; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 469 | if (!request.contentType().isTextType()) { |
Ingvar Stepanyan | 1c77184 | 2018-10-10 14:35:08 | [diff] [blame] | 470 | content = Common.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 471 | } else if (contentData.encoded) { |
Ingvar Stepanyan | 1c77184 | 2018-10-10 14:35:08 | [diff] [blame] | 472 | content = window.atob(content); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 473 | } |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 474 | Host.InspectorFrontendHost.copyText(content); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * @param {!DataTransfer} dataTransfer |
| 479 | */ |
| 480 | _handleDrop(dataTransfer) { |
| 481 | const items = dataTransfer.items; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 482 | if (!items.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 483 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 484 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 485 | const entry = items[0].webkitGetAsEntry(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 486 | if (entry.isDirectory) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 487 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 488 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 489 | |
Joey Arhar | 0e1093c | 2019-05-21 00:34:22 | [diff] [blame] | 490 | entry.file(this.onLoadFromFile.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 494 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 495 | * @param {!File} file |
| 496 | */ |
Joey Arhar | 0e1093c | 2019-05-21 00:34:22 | [diff] [blame] | 497 | async onLoadFromFile(file) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 498 | 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 | } |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 513 | self.SDK.networkLog.importRequests(HARImporter.Importer.requestsFromHARLog(harRoot.log)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | /** |
| 517 | * @param {string} message |
| 518 | */ |
| 519 | _harLoadFailed(message) { |
Paul Lewis | 04ccecc | 2020-01-22 17:15:14 | [diff] [blame] | 520 | self.Common.console.error('Failed to load HAR file with following error: ' + message); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | /** |
| 524 | * @param {?string} groupKey |
| 525 | */ |
| 526 | _setGrouping(groupKey) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 527 | if (this._activeGroupLookup) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 528 | this._activeGroupLookup.reset(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 529 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 530 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 543 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 544 | * @param {!SDK.NetworkRequest} request |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 545 | * @return {?NetworkRequestNode} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 546 | */ |
| 547 | nodeForRequest(request) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 548 | return request[_networkNodeSymbol] || null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 552 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 553 | * @return {number} |
| 554 | */ |
| 555 | headerHeight() { |
| 556 | return this._headerHeight; |
| 557 | } |
| 558 | |
| 559 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 560 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 561 | * @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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 574 | if (networkManager.target().parentTarget()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 575 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 576 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 577 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 601 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 602 | * @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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 610 | this._timeFilter = NetworkLogView._requestTimeFilter.bind(null, start, end); |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 611 | this._timeCalculator.setWindow(new NetworkTimeBoundary(start, end)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 612 | } |
| 613 | this._filterRequests(); |
| 614 | } |
| 615 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 616 | /** @override */ |
Brandon Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 617 | resetFocus() { |
| 618 | this._dataGrid.element.focus(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | _resetSuggestionBuilder() { |
| 622 | this._suggestionBuilder.clear(); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 623 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 630 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 640 | } |
| 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 Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 646 | |
| 647 | let reloadShortcutNode = null; |
Paul Lewis | 05eb37f | 2020-01-24 14:31:40 | [diff] [blame] | 648 | const reloadShortcutDescriptor = self.UI.shortcutRegistry.shortcutDescriptorsForAction('inspector_main.reload')[0]; |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 649 | if (reloadShortcutDescriptor) { |
| 650 | reloadShortcutNode = this._recordingHint.createChild('b'); |
| 651 | reloadShortcutNode.textContent = reloadShortcutDescriptor.name; |
| 652 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 653 | |
| 654 | if (this._recording) { |
| 655 | const recordingText = hintText.createChild('span'); |
| 656 | recordingText.textContent = Common.UIString('Recording network activity\u2026'); |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 657 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 662 | } else { |
| 663 | const recordNode = hintText.createChild('b'); |
Paul Lewis | 05eb37f | 2020-01-24 14:31:40 | [diff] [blame] | 664 | recordNode.textContent = self.UI.shortcutRegistry.shortcutTitleForAction('network.toggle-recording'); |
Joey Arhar | 0585e6f | 2018-10-30 23:11:18 | [diff] [blame] | 665 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 671 | } |
Kayce Basques | 5444c1b | 2019-02-15 20:32:53 | [diff] [blame] | 672 | 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 Baker | 6761aae | 2019-11-05 18:59:11 | [diff] [blame] | 676 | |
| 677 | this._setHidden(true); |
Brandon Goddard | c992d52 | 2020-01-08 21:44:57 | [diff] [blame] | 678 | this._dataGrid.updateGridAccessibleName(''); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | _hideRecordingHint() { |
Amanda Baker | 6761aae | 2019-11-05 18:59:11 | [diff] [blame] | 682 | this._setHidden(false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 683 | if (this._recordingHint) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 684 | this._recordingHint.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 685 | } |
Brandon Goddard | c992d52 | 2020-01-08 21:44:57 | [diff] [blame] | 686 | this._dataGrid.updateGridAccessibleName(ls`Network Data Available`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 687 | this._recordingHint = null; |
| 688 | } |
| 689 | |
| 690 | /** |
Amanda Baker | 6761aae | 2019-11-05 18:59:11 | [diff] [blame] | 691 | * @param {boolean} value |
| 692 | */ |
| 693 | _setHidden(value) { |
| 694 | this._columns.setHidden(value); |
| 695 | UI.ARIAUtils.setHidden(this._summaryToolbar.element, value); |
| 696 | } |
| 697 | |
| 698 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 699 | * @override |
| 700 | * @return {!Array.<!Element>} |
| 701 | */ |
| 702 | elementsToRestoreScrollPositionsFor() { |
| 703 | if (!this._dataGrid) // Not initialized yet. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 704 | { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 705 | return []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 706 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 707 | return [this._dataGrid.scrollContainer]; |
| 708 | } |
| 709 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 710 | /** @override */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 711 | columnExtensionResolved() { |
| 712 | this._invalidateAllItems(true); |
| 713 | } |
| 714 | |
| 715 | _setupDataGrid() { |
| 716 | this._dataGrid.setRowContextMenuCallback((contextMenu, node) => { |
| 717 | const request = node.request(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 718 | if (request) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 719 | this.handleContextMenuForRequest(contextMenu, request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 720 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 721 | }); |
| 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 Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 729 | this._dataGrid.element.addEventListener('keydown', event => { |
| 730 | if (isEnterOrSpaceKey(event)) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 731 | this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ true); |
Brandon Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 732 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 737 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 750 | * @override |
| 751 | * @return {?NetworkNode} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 752 | */ |
| 753 | hoveredNode() { |
| 754 | return this._hoveredNode; |
| 755 | } |
| 756 | |
| 757 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 758 | * @param {?NetworkNode} node |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 759 | * @param {boolean=} highlightInitiatorChain |
| 760 | */ |
| 761 | _setHoveredNode(node, highlightInitiatorChain) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 762 | if (this._hoveredNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 763 | this._hoveredNode.setHovered(false, false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 764 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 765 | this._hoveredNode = node; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 766 | if (this._hoveredNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 767 | this._hoveredNode.setHovered(true, !!highlightInitiatorChain); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 768 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | /** |
| 772 | * @param {!Event} event |
| 773 | */ |
| 774 | _dataGridMouseDown(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 775 | if (!this._dataGrid.selectedNode && event.button) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 776 | event.consume(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 777 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | _updateSummaryBar() { |
| 781 | this._hideRecordingHint(); |
| 782 | |
| 783 | let transferSize = 0; |
Dan Beam | 87466b5 | 2018-12-01 18:41:20 | [diff] [blame] | 784 | let resourceSize = 0; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 785 | let selectedNodeNumber = 0; |
| 786 | let selectedTransferSize = 0; |
Dan Beam | 87466b5 | 2018-12-01 18:41:20 | [diff] [blame] | 787 | let selectedResourceSize = 0; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 788 | let baseTime = -1; |
| 789 | let maxTime = -1; |
| 790 | |
| 791 | let nodeCount = 0; |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 792 | for (const request of self.SDK.networkLog.requests()) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 793 | const node = request[_networkNodeSymbol]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 794 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 795 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 796 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 797 | nodeCount++; |
| 798 | const requestTransferSize = request.transferSize; |
| 799 | transferSize += requestTransferSize; |
Dan Beam | 87466b5 | 2018-12-01 18:41:20 | [diff] [blame] | 800 | const requestResourceSize = request.resourceSize; |
| 801 | resourceSize += requestResourceSize; |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 802 | if (!node[isFilteredOutSymbol]) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 803 | selectedNodeNumber++; |
| 804 | selectedTransferSize += requestTransferSize; |
Dan Beam | 87466b5 | 2018-12-01 18:41:20 | [diff] [blame] | 805 | selectedResourceSize += requestResourceSize; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 806 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 811 | request.resourceType() === Common.resourceTypes.Document && !networkManager.target().parentTarget()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 812 | baseTime = request.startTime; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 813 | } |
| 814 | if (request.endTime > maxTime) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 815 | maxTime = request.endTime; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 816 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | if (!nodeCount) { |
| 820 | this._showRecordingHint(); |
| 821 | return; |
| 822 | } |
| 823 | |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 824 | this._summaryToolbar.removeToolbarItems(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 825 | /** |
| 826 | * @param {string} chunk |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 827 | * @param {string=} title |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 828 | * @return {!Element} |
| 829 | */ |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 830 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 836 | |
| 837 | if (selectedNodeNumber !== nodeCount) { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 838 | appendChunk(ls`${selectedNodeNumber} / ${nodeCount} requests`); |
| 839 | this._summaryToolbar.appendSeparator(); |
| 840 | appendChunk( |
| 841 | ls`${Number.bytesToString(selectedTransferSize)} / ${Number.bytesToString(transferSize)} transferred`, |
Changhao Han | 9ec3f6e | 2019-11-12 18:43:25 | [diff] [blame] | 842 | ls`${selectedTransferSize} B / ${transferSize} B transferred over network`); |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 843 | this._summaryToolbar.appendSeparator(); |
| 844 | appendChunk( |
| 845 | ls`${Number.bytesToString(selectedResourceSize)} / ${Number.bytesToString(resourceSize)} resources`, |
Changhao Han | 9ec3f6e | 2019-11-12 18:43:25 | [diff] [blame] | 846 | ls`${selectedResourceSize} B / ${resourceSize} B resources loaded by the page`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 847 | } else { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 848 | appendChunk(ls`${nodeCount} requests`); |
| 849 | this._summaryToolbar.appendSeparator(); |
Changhao Han | 9ec3f6e | 2019-11-12 18:43:25 | [diff] [blame] | 850 | appendChunk( |
| 851 | ls`${Number.bytesToString(transferSize)} transferred`, ls`${transferSize} B transferred over network`); |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 852 | this._summaryToolbar.appendSeparator(); |
Changhao Han | 9ec3f6e | 2019-11-12 18:43:25 | [diff] [blame] | 853 | appendChunk( |
| 854 | ls`${Number.bytesToString(resourceSize)} resources`, ls`${resourceSize} B resources loaded by the page`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 855 | } |
Dan Beam | 87466b5 | 2018-12-01 18:41:20 | [diff] [blame] | 856 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 857 | if (baseTime !== -1 && maxTime !== -1) { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 858 | this._summaryToolbar.appendSeparator(); |
| 859 | appendChunk(ls`Finish: ${Number.secondsToString(maxTime - baseTime)}`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 860 | if (this._mainRequestDOMContentLoadedTime !== -1 && this._mainRequestDOMContentLoadedTime > baseTime) { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 861 | this._summaryToolbar.appendSeparator(); |
Alexei Filippov | fdcd8a6 | 2018-12-17 21:32:30 | [diff] [blame] | 862 | const domContentLoadedText = |
| 863 | ls`DOMContentLoaded: ${Number.secondsToString(this._mainRequestDOMContentLoadedTime - baseTime)}`; |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 864 | appendChunk(domContentLoadedText).style.color = NetworkLogView.getDCLEventColor(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 865 | } |
| 866 | if (this._mainRequestLoadTime !== -1) { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 867 | this._summaryToolbar.appendSeparator(); |
Alexei Filippov | fdcd8a6 | 2018-12-17 21:32:30 | [diff] [blame] | 868 | const loadText = ls`Load: ${Number.secondsToString(this._mainRequestLoadTime - baseTime)}`; |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 869 | appendChunk(loadText).style.color = NetworkLogView.getLoadEventColor(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 870 | } |
| 871 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 872 | } |
| 873 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 874 | /** @override */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 875 | scheduleRefresh() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 876 | if (this._needsRefresh) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 877 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 878 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 879 | |
| 880 | this._needsRefresh = true; |
| 881 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 882 | if (this.isShowing() && !this._refreshRequestId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 883 | this._refreshRequestId = this.element.window().requestAnimationFrame(this._refresh.bind(this)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 884 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 888 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 889 | * @param {!Array<number>} times |
| 890 | */ |
| 891 | addFilmStripFrames(times) { |
| 892 | this._columns.addEventDividers(times, 'network-frame-divider'); |
| 893 | } |
| 894 | |
| 895 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 896 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 897 | * @param {number} time |
| 898 | */ |
| 899 | selectFilmStripFrame(time) { |
| 900 | this._columns.selectFilmStripFrame(time); |
| 901 | } |
| 902 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 903 | /** @override */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 904 | clearFilmStripFrame() { |
| 905 | this._columns.clearFilmStripFrame(); |
| 906 | } |
| 907 | |
| 908 | _refreshIfNeeded() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 909 | if (this._needsRefresh) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 910 | this._refresh(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 911 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
| 915 | * @param {boolean=} deferUpdate |
| 916 | */ |
| 917 | _invalidateAllItems(deferUpdate) { |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 918 | this._staleRequests = new Set(self.SDK.networkLog.requests()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 919 | if (deferUpdate) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 920 | this.scheduleRefresh(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 921 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 922 | this._refresh(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 923 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 927 | * @override |
| 928 | * @return {!NetworkTimeCalculator} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 929 | */ |
| 930 | timeCalculator() { |
| 931 | return this._timeCalculator; |
| 932 | } |
| 933 | |
| 934 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 935 | * @override |
| 936 | * @return {!NetworkTimeCalculator} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 937 | */ |
| 938 | calculator() { |
| 939 | return this._calculator; |
| 940 | } |
| 941 | |
| 942 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 943 | * @override |
| 944 | * @param {!NetworkTimeCalculator} x |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 945 | */ |
| 946 | setCalculator(x) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 947 | if (!x || this._calculator === x) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 948 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 949 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 950 | |
| 951 | if (this._calculator !== x) { |
| 952 | this._calculator = x; |
| 953 | this._columns.setCalculator(this._calculator); |
| 954 | } |
| 955 | this._calculator.reset(); |
| 956 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 957 | if (this._calculator.startAtZero) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 958 | this._columns.hideEventDividers(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 959 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 960 | this._columns.showEventDividers(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 961 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 962 | |
| 963 | this._invalidateAllItems(); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * @param {!Common.Event} event |
| 968 | */ |
| 969 | _loadEventFired(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 970 | if (!this._recording) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 971 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 972 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 973 | |
| 974 | const time = /** @type {number} */ (event.data.loadTime); |
| 975 | if (time) { |
| 976 | this._mainRequestLoadTime = time; |
Alexei Filippov | fdcd8a6 | 2018-12-17 21:32:30 | [diff] [blame] | 977 | this._columns.addEventDividers([time], 'network-load-divider'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * @param {!Common.Event} event |
| 983 | */ |
| 984 | _domContentLoadedEventFired(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 985 | if (!this._recording) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 986 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 987 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 988 | const data = /** @type {number} */ (event.data); |
| 989 | if (data) { |
| 990 | this._mainRequestDOMContentLoadedTime = data; |
Alexei Filippov | fdcd8a6 | 2018-12-17 21:32:30 | [diff] [blame] | 991 | this._columns.addEventDividers([data], 'network-dcl-divider'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 992 | } |
| 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1018 | * @override |
| 1019 | * @return {!Array<!NetworkNode>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1020 | */ |
| 1021 | flatNodesList() { |
| 1022 | return this._dataGrid.rootNode().flatChildren(); |
| 1023 | } |
| 1024 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1025 | /** @override */ |
Brandon Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 1026 | updateNodeBackground() { |
| 1027 | if (this._dataGrid.selectedNode) { |
| 1028 | this._dataGrid.selectedNode.updateBackgroundColor(); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1033 | * @override |
Brandon Goddard | 88d885a | 2019-10-31 16:11:05 | [diff] [blame] | 1034 | * @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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1044 | /** @override */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1045 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1064 | /** @type {!Map<!NetworkNode, !Network.NetworkNode>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1065 | const nodesToInsert = new Map(); |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1066 | /** @type {!Array<!NetworkNode>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1067 | const nodesToRefresh = []; |
| 1068 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1069 | /** @type {!Set<!NetworkRequestNode>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1070 | 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1077 | let node = request[_networkNodeSymbol]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1078 | if (!node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1079 | node = this._createNodeForRequest(request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1080 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1081 | staleNodes.add(node); |
| 1082 | } |
| 1083 | |
| 1084 | for (const node of staleNodes) { |
| 1085 | const isFilteredOut = !this._applyFilter(node); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1086 | if (isFilteredOut && node === this._hoveredNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1087 | this._setHoveredNode(null); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1088 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1089 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1090 | if (!isFilteredOut) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1091 | nodesToRefresh.push(node); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1092 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1093 | const request = node.request(); |
| 1094 | this._timeCalculator.updateBoundaries(request); |
| 1095 | this._durationCalculator.updateBoundaries(request); |
| 1096 | const newParent = this._parentNodeForInsert(node); |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1097 | if (node[isFilteredOutSymbol] === isFilteredOut && node.parent === newParent) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1098 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1099 | } |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1100 | node[isFilteredOutSymbol] = isFilteredOut; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1101 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1112 | if (!newParent || isFilteredOut) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1113 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1114 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1115 | |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1123 | for (const node of nodesToInsert.keys()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1124 | nodesToInsert.get(node).appendChild(node); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1125 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1126 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1127 | for (const node of nodesToRefresh) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1128 | node.refresh(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1129 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1130 | |
| 1131 | this._updateSummaryBar(); |
| 1132 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1133 | if (nodesToInsert.size) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1134 | this._columns.sortByCurrentColumn(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1135 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1136 | |
| 1137 | this._dataGrid.updateInstantly(); |
| 1138 | this._didRefreshForTest(); |
| 1139 | } |
| 1140 | |
| 1141 | _didRefreshForTest() { |
| 1142 | } |
| 1143 | |
| 1144 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1145 | * @param {!NetworkRequestNode} node |
| 1146 | * @return {?NetworkNode} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1147 | */ |
| 1148 | _parentNodeForInsert(node) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1149 | if (!this._activeGroupLookup) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1150 | return this._dataGrid.rootNode(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1151 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1152 | |
| 1153 | const groupNode = this._activeGroupLookup.groupNodeForRequest(node.request()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1154 | if (!groupNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1155 | return this._dataGrid.rootNode(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1156 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1157 | return groupNode; |
| 1158 | } |
| 1159 | |
| 1160 | _reset() { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1161 | this.dispatchEventToListeners(Events.RequestActivated, /* showPanel */ false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1162 | |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1171 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1172 | if (this._activeGroupLookup) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1173 | this._activeGroupLookup.reset(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1174 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1175 | 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 Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1188 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1189 | * @param {string} filterString |
| 1190 | */ |
| 1191 | setTextFilterValue(filterString) { |
| 1192 | this._textFilterUI.setValue(filterString); |
| 1193 | this._dataURLFilterUI.setChecked(false); |
Jan Scheffler | 1ae7c9e | 2019-12-03 15:48:37 | [diff] [blame] | 1194 | this._onlyIssuesFilterUI.setChecked(false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1195 | this._resourceCategoryFilterUI.reset(); |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * @param {!SDK.NetworkRequest} request |
| 1200 | */ |
| 1201 | _createNodeForRequest(request) { |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1202 | const node = new NetworkRequestNode(this, request); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1203 | request[_networkNodeSymbol] = node; |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1204 | node[isFilteredOutSymbol] = true; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1205 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1206 | for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1207 | this._refreshRequest(redirect); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1208 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1209 | 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1224 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1230 | |
| 1231 | const priority = request.priority(); |
| 1232 | if (priority) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1233 | this._suggestionBuilder.addItem(FilterType.Priority, PerfUI.uiLabelForNetworkPriority(priority)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | if (request.mixedContentType !== Protocol.Security.MixedContentType.None) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1237 | this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.All); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1241 | this._suggestionBuilder.addItem(FilterType.MixedContent, MixedContentFilterValues.Displayed); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1245 | const suggestion = |
| 1246 | request.wasBlocked() ? MixedContentFilterValues.Blocked : MixedContentFilterValues.BlockOverridden; |
| 1247 | this._suggestionBuilder.addItem(FilterType.MixedContent, suggestion); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | const responseHeaders = request.responseHeaders; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1251 | for (let i = 0, l = responseHeaders.length; i < l; ++i) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1252 | this._suggestionBuilder.addItem(FilterType.HasResponseHeader, responseHeaders[i].name); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1253 | } |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 1254 | |
| 1255 | for (const cookie of request.responseCookies) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1256 | this._suggestionBuilder.addItem(FilterType.SetCookieDomain, cookie.domain()); |
| 1257 | this._suggestionBuilder.addItem(FilterType.SetCookieName, cookie.name()); |
| 1258 | this._suggestionBuilder.addItem(FilterType.SetCookieValue, cookie.value()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1259 | } |
| 1260 | |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 1261 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1267 | this._staleRequests.add(request); |
| 1268 | this.scheduleRefresh(); |
| 1269 | } |
| 1270 | |
| 1271 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1272 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1273 | * @return {number} |
| 1274 | */ |
| 1275 | rowHeight() { |
| 1276 | return this._rowHeight; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1280 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1281 | * @param {boolean} gridMode |
| 1282 | */ |
| 1283 | switchViewMode(gridMode) { |
| 1284 | this._columns.switchViewMode(gridMode); |
| 1285 | } |
| 1286 | |
| 1287 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1288 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1289 | * @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 Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1298 | UI.copyLinkAddressLabel(), |
| 1299 | Host.InspectorFrontendHost.copyText.bind(Host.InspectorFrontendHost, request.contentURL())); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1300 | if (request.requestHeadersText()) { |
| 1301 | copyMenu.defaultSection().appendItem( |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1302 | Common.UIString('Copy request headers'), NetworkLogView._copyRequestHeaders.bind(null, request)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | if (request.responseHeadersText) { |
| 1306 | copyMenu.defaultSection().appendItem( |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1307 | Common.UIString('Copy response headers'), NetworkLogView._copyResponseHeaders.bind(null, request)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | if (request.finished) { |
| 1311 | copyMenu.defaultSection().appendItem( |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1312 | Common.UIString('Copy response'), NetworkLogView._copyResponse.bind(null, request)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1313 | } |
| 1314 | |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1315 | const disableIfBlob = request.isBlobRequest(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1316 | if (Host.isWin()) { |
| 1317 | footerSection.appendItem( |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1318 | Common.UIString('Copy as PowerShell'), this._copyPowerShellCommand.bind(this, request), disableIfBlob); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1319 | footerSection.appendItem( |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1320 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1323 | footerSection.appendItem( |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1324 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1327 | footerSection.appendItem(Common.UIString('Copy all as PowerShell'), this._copyAllPowerShellCommand.bind(this)); |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1328 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1330 | 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 Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1334 | footerSection.appendItem( |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1335 | 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 Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1338 | footerSection.appendItem( |
| 1339 | Common.UIString('Copy as cURL'), this._copyCurlCommand.bind(this, request, 'unix'), disableIfBlob); |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1340 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1342 | 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 Arhar | 0e1093c | 2019-05-21 00:34:22 | [diff] [blame] | 1349 | contextMenu.saveSection().appendItem(ls`Save all as HAR with content`, this.exportAll.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1350 | |
| 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; |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 1357 | const manager = self.SDK.multitargetNetworkManager; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1358 | let patterns = manager.blockedPatterns(); |
| 1359 | |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 1360 | /** |
| 1361 | * @param {string} url |
| 1362 | */ |
| 1363 | function addBlockedURL(url) { |
| 1364 | patterns.push({enabled: true, url: url}); |
| 1365 | manager.setBlockedPatterns(patterns); |
| 1366 | manager.setBlockingEnabled(true); |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 1367 | self.UI.viewManager.showView('network.blocked-urls'); |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * @param {string} url |
| 1372 | */ |
| 1373 | function removeBlockedURL(url) { |
| 1374 | patterns = patterns.filter(pattern => pattern.url !== url); |
| 1375 | manager.setBlockedPatterns(patterns); |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 1376 | self.UI.viewManager.showView('network.blocked-urls'); |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 1377 | } |
| 1378 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1379 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | _harRequests() { |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 1407 | return self.SDK.networkLog.requests().filter(NetworkLogView.HTTPRequestsFilter).filter(request => { |
Joey Arhar | b3d6de4 | 2019-04-23 21:26:17 | [diff] [blame] | 1408 | return request.finished || |
| 1409 | (request.resourceType() === Common.resourceTypes.WebSocket && request.responseReceivedTime); |
| 1410 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | async _copyAll() { |
Pavel Feldman | 18d1356 | 2018-07-31 03:31:18 | [diff] [blame] | 1414 | const harArchive = {log: await SDK.HARLog.build(this._harRequests())}; |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1415 | Host.InspectorFrontendHost.copyText(JSON.stringify(harArchive, null, 2)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1416 | } |
| 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 Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1424 | Host.InspectorFrontendHost.copyText(command); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | /** |
| 1428 | * @param {string} platform |
| 1429 | */ |
| 1430 | async _copyAllCurlCommand(platform) { |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 1431 | const commands = await this._generateAllCurlCommand(self.SDK.networkLog.requests(), platform); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1432 | Host.InspectorFrontendHost.copyText(commands); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | /** |
| 1436 | * @param {!SDK.NetworkRequest} request |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1437 | * @param {boolean} includeCookies |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1438 | */ |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1439 | async _copyFetchCall(request, includeCookies) { |
| 1440 | const command = await this._generateFetchCall(request, includeCookies); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1441 | Host.InspectorFrontendHost.copyText(command); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1442 | } |
| 1443 | |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1444 | /** |
| 1445 | * @param {boolean} includeCookies |
| 1446 | */ |
| 1447 | async _copyAllFetchCall(includeCookies) { |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 1448 | const commands = await this._generateAllFetchCall(self.SDK.networkLog.requests(), includeCookies); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1449 | Host.InspectorFrontendHost.copyText(commands); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * @param {!SDK.NetworkRequest} request |
| 1454 | */ |
| 1455 | async _copyPowerShellCommand(request) { |
| 1456 | const command = await this._generatePowerShellCommand(request); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1457 | Host.InspectorFrontendHost.copyText(command); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | async _copyAllPowerShellCommand() { |
Paul Lewis | ca3665d | 2020-01-24 13:31:16 | [diff] [blame] | 1461 | const commands = await this._generateAllPowerShellCommand(self.SDK.networkLog.requests()); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 1462 | Host.InspectorFrontendHost.copyText(commands); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1463 | } |
| 1464 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1465 | /** |
| 1466 | * @override |
| 1467 | * @return {!Promise} |
| 1468 | */ |
Joey Arhar | 0e1093c | 2019-05-21 00:34:22 | [diff] [blame] | 1469 | async exportAll() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 1470 | const url = self.SDK.targetManager.mainTarget().inspectedURL(); |
Peter Marshall | 3e4e569 | 2019-12-09 16:48:04 | [diff] [blame] | 1471 | const parsedURL = Common.ParsedURL.fromString(url); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1472 | const filename = parsedURL ? parsedURL.host : 'network-log'; |
| 1473 | const stream = new Bindings.FileOutputStream(); |
| 1474 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1475 | if (!await stream.open(filename + '.har')) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1476 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1477 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1478 | |
| 1479 | const progressIndicator = new UI.ProgressIndicator(); |
| 1480 | this._progressBarContainer.appendChild(progressIndicator.element); |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1481 | await HARWriter.write(stream, this._harRequests(), progressIndicator); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1482 | progressIndicator.done(); |
| 1483 | stream.close(); |
| 1484 | } |
| 1485 | |
| 1486 | _clearBrowserCache() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1487 | if (confirm(Common.UIString('Are you sure you want to clear browser cache?'))) { |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 1488 | self.SDK.multitargetNetworkManager.clearBrowserCache(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1489 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | _clearBrowserCookies() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1493 | if (confirm(Common.UIString('Are you sure you want to clear browser cookies?'))) { |
Paul Lewis | 5a922e7 | 2020-01-24 11:58:08 | [diff] [blame] | 1494 | self.SDK.multitargetNetworkManager.clearBrowserCookies(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1495 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | _removeAllHighlights() { |
| 1499 | this.removeAllNodeHighlights(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1500 | for (let i = 0; i < this._highlightedSubstringChanges.length; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1501 | UI.revertDomChanges(this._highlightedSubstringChanges[i]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1502 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1503 | this._highlightedSubstringChanges = []; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1507 | * @param {!NetworkRequestNode} node |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1508 | * @return {boolean} |
| 1509 | */ |
| 1510 | _applyFilter(node) { |
| 1511 | const request = node.request(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1512 | if (this._timeFilter && !this._timeFilter(request)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1513 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1514 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1515 | const categoryName = request.resourceType().category().title; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1516 | if (!this._resourceCategoryFilterUI.accept(categoryName)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1517 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1518 | } |
| 1519 | if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1520 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1521 | } |
Jan Scheffler | 1ae7c9e | 2019-12-03 15:48:37 | [diff] [blame] | 1522 | if (this._onlyIssuesFilterUI.checked() && !SDK.IssuesModel.hasIssues(request)) { |
| 1523 | return false; |
| 1524 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1525 | if (request.statusText === 'Service Worker Fallback Required') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1526 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1527 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1528 | for (let i = 0; i < this._filters.length; ++i) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1529 | if (!this._filters[i](request)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1530 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1531 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1532 | } |
| 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1548 | filter = this._createSpecialFilter(/** @type {!FilterType} */ (key), text) || |
| 1549 | NetworkLogView._requestPathFilter.bind(null, new RegExp(defaultText, 'i')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1550 | } else if (descriptor.regex) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1551 | filter = NetworkLogView._requestPathFilter.bind(null, /** @type {!RegExp} */ (regex)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1552 | } else { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1553 | filter = NetworkLogView._requestPathFilter.bind(null, new RegExp(text.escapeForRegExp(), 'i')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1554 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1555 | return descriptor.negative ? NetworkLogView._negativeFilter.bind(null, filter) : filter; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1556 | }); |
| 1557 | } |
| 1558 | |
| 1559 | /** |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1560 | * @param {!FilterType} type |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1561 | * @param {string} value |
| 1562 | * @return {?Network.NetworkLogView.Filter} |
| 1563 | */ |
| 1564 | _createSpecialFilter(type, value) { |
| 1565 | switch (type) { |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1566 | case FilterType.Domain: |
| 1567 | return NetworkLogView._createRequestDomainFilter(value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1568 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1569 | case FilterType.HasResponseHeader: |
| 1570 | return NetworkLogView._requestResponseHeaderFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1571 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1572 | case FilterType.Is: |
| 1573 | if (value.toLowerCase() === IsFilterType.Running) { |
| 1574 | return NetworkLogView._runningRequestFilter; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1575 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1576 | if (value.toLowerCase() === IsFilterType.FromCache) { |
| 1577 | return NetworkLogView._fromCacheRequestFilter; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1578 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1579 | if (value.toLowerCase() === IsFilterType.ServiceWorkerIntercepted) { |
| 1580 | return NetworkLogView._interceptedByServiceWorkerFilter; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1581 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1582 | if (value.toLowerCase() === IsFilterType.ServiceWorkerInitiated) { |
| 1583 | return NetworkLogView._initiatedByServiceWorkerFilter; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1584 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1585 | break; |
| 1586 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1587 | case FilterType.LargerThan: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1588 | return this._createSizeFilter(value.toLowerCase()); |
| 1589 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1590 | case FilterType.Method: |
| 1591 | return NetworkLogView._requestMethodFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1592 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1593 | case FilterType.MimeType: |
| 1594 | return NetworkLogView._requestMimeTypeFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1595 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1596 | case FilterType.MixedContent: |
| 1597 | return NetworkLogView._requestMixedContentFilter.bind(null, /** @type {!MixedContentFilterValues} */ (value)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1598 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1599 | case FilterType.Scheme: |
| 1600 | return NetworkLogView._requestSchemeFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1601 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1602 | case FilterType.SetCookieDomain: |
| 1603 | return NetworkLogView._requestSetCookieDomainFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1604 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1605 | case FilterType.SetCookieName: |
| 1606 | return NetworkLogView._requestSetCookieNameFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1607 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1608 | case FilterType.SetCookieValue: |
| 1609 | return NetworkLogView._requestSetCookieValueFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1610 | |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 1611 | 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 Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1620 | case FilterType.Priority: |
| 1621 | return NetworkLogView._requestPriorityFilter.bind(null, PerfUI.uiLabelToNetworkPriority(value)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1622 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1623 | case FilterType.StatusCode: |
| 1624 | return NetworkLogView._statusCodeFilter.bind(null, value); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1625 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1643 | if (isNaN(quantity)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1644 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1645 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1646 | return NetworkLogView._requestSizeLargerThanFilter.bind(null, quantity * multiplier); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | _filterRequests() { |
| 1650 | this._removeAllHighlights(); |
| 1651 | this._invalidateAllItems(); |
| 1652 | } |
| 1653 | |
| 1654 | /** |
| 1655 | * @param {!SDK.NetworkRequest} request |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1656 | * @return {?NetworkRequestNode} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1657 | */ |
| 1658 | _reveal(request) { |
| 1659 | this.removeAllNodeHighlights(); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 1660 | const node = request[_networkNodeSymbol]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1661 | if (!node || !node.dataGrid) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1662 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1663 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1664 | node.reveal(); |
| 1665 | return node; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1669 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1670 | * @param {!SDK.NetworkRequest} request |
| 1671 | */ |
| 1672 | revealAndHighlightRequest(request) { |
| 1673 | const node = this._reveal(request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1674 | if (node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1675 | this._highlightNode(node); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1676 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1680 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1681 | * @param {!SDK.NetworkRequest} request |
| 1682 | */ |
| 1683 | selectRequest(request) { |
Eugene Ostroukhov | b600f66 | 2018-05-09 00:18:14 | [diff] [blame] | 1684 | this.setTextFilterValue(''); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1685 | const node = this._reveal(request); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1686 | if (node) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1687 | node.select(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1688 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1689 | } |
| 1690 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1691 | /** @override */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1692 | removeAllNodeHighlights() { |
| 1693 | if (this._highlightedNode) { |
| 1694 | this._highlightedNode.element().classList.remove('highlighted-row'); |
| 1695 | this._highlightedNode = null; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | /** |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 1700 | * @param {!NetworkRequestNode} node |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1701 | */ |
| 1702 | _highlightNode(node) { |
| 1703 | UI.runCSSAnimationOnce(node.element(), 'highlighted-row'); |
| 1704 | this._highlightedNode = node; |
| 1705 | } |
| 1706 | |
| 1707 | /** |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1708 | * @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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1716 | * @param {!SDK.NetworkRequest} request |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1717 | * @param {boolean} includeCookies |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1718 | * @return {!Promise<string>} |
| 1719 | */ |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1720 | async _generateFetchCall(request, includeCookies) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1721 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1762 | if (!ignoredHeaders[name.toLowerCase()] && !name.includes(':')) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1763 | result.append(name, header.value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1764 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1765 | |
| 1766 | return result; |
| 1767 | }, new Headers()); |
| 1768 | |
| 1769 | const headers = {}; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1770 | for (const headerArray of headerData) { |
PhistucK | 6ed0a3e | 2018-08-04 06:28:41 | [diff] [blame] | 1771 | headers[headerArray[0]] = headerArray[1]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1772 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1773 | |
| 1774 | const credentials = |
Jan Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 1775 | request.requestCookies.length || requestHeaders.some(({name}) => credentialHeaders[name.toLowerCase()]) ? |
| 1776 | 'include' : |
| 1777 | 'omit'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1778 | |
| 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 = { |
PhistucK | 6ed0a3e | 2018-08-04 06:28:41 | [diff] [blame] | 1788 | headers: Object.keys(headers).length ? headers : void 0, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1789 | referrer, |
| 1790 | referrerPolicy, |
| 1791 | body: requestBody, |
| 1792 | method: request.requestMethod, |
| 1793 | mode: 'cors' |
| 1794 | }; |
| 1795 | |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1796 | 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 Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1808 | const options = JSON.stringify(fetchOptions, null, 2); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1809 | return `fetch(${url}, ${options});`; |
| 1810 | } |
| 1811 | |
| 1812 | /** |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1813 | * @param {!Array<!SDK.NetworkRequest>} requests |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1814 | * @param {boolean} includeCookies |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1815 | * @return {!Promise<string>} |
| 1816 | */ |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1817 | async _generateAllFetchCall(requests, includeCookies) { |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1818 | const nonBlobRequests = this._filterOutBlobRequests(requests); |
Jan Scheffler | 7c50d1f | 2019-12-17 13:33:29 | [diff] [blame] | 1819 | const commands = |
| 1820 | await Promise.all(nonBlobRequests.map(request => this._generateFetchCall(request, includeCookies))); |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1821 | return commands.join(' ;\n'); |
| 1822 | } |
| 1823 | |
| 1824 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1825 | * @param {!SDK.NetworkRequest} request |
| 1826 | * @param {string} platform |
| 1827 | * @return {!Promise<string>} |
| 1828 | */ |
| 1829 | async _generateCurlCommand(request, platform) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1830 | let command = []; |
Eric Lawrence | 7a7b368 | 2019-10-17 23:06:36 | [diff] [blame] | 1831 | // 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1834 | |
| 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 Luo | aa67675 | 2018-08-21 05:52:22 | [diff] [blame] | 1883 | const code = x.charCodeAt(0); |
Joey Arhar | 2d21f71 | 2019-05-20 21:07:12 | [diff] [blame] | 1884 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1887 | while (hexString.length < 4) { |
Joey Arhar | 2d21f71 | 2019-05-20 21:07:12 | [diff] [blame] | 1888 | hexString = '0' + hexString; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1889 | } |
Joey Arhar | 2d21f71 | 2019-05-20 21:07:12 | [diff] [blame] | 1890 | |
| 1891 | return '\\u' + hexString; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1892 | } |
| 1893 | |
Joey Arhar | 512e374 | 2019-01-25 21:33:54 | [diff] [blame] | 1894 | if (/[\u0000-\u001f\u007f-\u009f!]|\'/.test(str)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1895 | // 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 Arhar | 512e374 | 2019-01-25 21:33:54 | [diff] [blame] | 1901 | .replace(/[\u0000-\u001f\u007f-\u009f!]/g, escapeCharacter) + |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1902 | '\''; |
| 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 Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1920 | data.push('--data ' + escapeString(formData)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1921 | ignoredHeaders['content-length'] = true; |
| 1922 | inferredMethod = 'POST'; |
| 1923 | } else if (formData) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1924 | data.push('--data-binary ' + escapeString(formData)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1925 | ignoredHeaders['content-length'] = true; |
| 1926 | inferredMethod = 'POST'; |
| 1927 | } |
| 1928 | |
| 1929 | if (request.requestMethod !== inferredMethod) { |
Jan Scheffler | a4e536a | 2020-01-09 08:51:29 | [diff] [blame] | 1930 | command.push('-X ' + escapeString(request.requestMethod)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1931 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1937 | if (name.toLowerCase() in ignoredHeaders) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1938 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1939 | } |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1940 | command.push('-H ' + escapeString(name + ': ' + header.value)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1941 | } |
| 1942 | command = command.concat(data); |
| 1943 | command.push('--compressed'); |
| 1944 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1945 | if (request.securityState() === Protocol.Security.SecurityState.Insecure) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1946 | command.push('--insecure'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1947 | } |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1948 | return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' '); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | /** |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1952 | * @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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1959 | if (platform === 'win') { |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1960 | return commands.join(' &\r\n'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1961 | } else { |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1962 | return commands.join(' ;\n'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1963 | } |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1967 | * @param {!SDK.NetworkRequest} request |
| 1968 | * @return {!Promise<string>} |
| 1969 | */ |
| 1970 | async _generatePowerShellCommand(request) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1971 | const command = []; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1972 | 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 Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1984 | command.push('-Uri ' + escapeString(request.url())); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1985 | |
| 1986 | if (request.requestMethod !== 'GET') { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 1987 | command.push('-Method ' + escapeString(request.requestMethod)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1988 | } |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1994 | if (ignoredHeaders.has(name.toLowerCase())) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1995 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1996 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1997 | headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value)); |
| 1998 | } |
| 1999 | if (headerNameValuePairs.length) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 2000 | command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type'); |
| 2004 | if (contentTypeHeader) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 2005 | command.push('-ContentType ' + escapeString(contentTypeHeader.value)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | const formData = await request.requestFormData(); |
| 2009 | if (formData) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2010 | const body = escapeString(formData); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2011 | if (/[^\x20-\x7E]/.test(formData)) { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 2012 | command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2013 | } else { |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 2014 | command.push('-Body ' + body); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2015 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2016 | } |
| 2017 | |
Jan Scheffler | 172d521 | 2020-01-02 14:42:56 | [diff] [blame] | 2018 | return 'Invoke-WebRequest ' + command.join(command.length >= 3 ? ' `\n' : ' '); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2019 | } |
Harley Li | bcf41f9 | 2018-09-10 18:01:13 | [diff] [blame] | 2020 | |
| 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 Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 2030 | |
| 2031 | /** |
| 2032 | * @return {string} |
| 2033 | */ |
| 2034 | static getDCLEventColor() { |
Paul Lewis | 93d8e2c | 2020-01-24 16:34:55 | [diff] [blame^] | 2035 | if (self.UI.themeSupport.themeName() === 'dark') { |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 2036 | return '#03A9F4'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 2037 | } |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 2038 | return '#0867CB'; |
| 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * @return {string} |
| 2043 | */ |
| 2044 | static getLoadEventColor() { |
Paul Lewis | 93d8e2c | 2020-01-24 16:34:55 | [diff] [blame^] | 2045 | return self.UI.themeSupport.patchColorText('#B31412', UI.ThemeSupport.ColorUsage.Foreground); |
Joey Arhar | a86c14e | 2019-03-12 03:20:50 | [diff] [blame] | 2046 | } |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2047 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2048 | |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 2049 | export const isFilteredOutSymbol = Symbol('isFilteredOut'); |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2050 | export const _networkNodeSymbol = Symbol('NetworkNode'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2051 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2052 | export const HTTPSchemas = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2053 | 'http': true, |
| 2054 | 'https': true, |
| 2055 | 'ws': true, |
| 2056 | 'wss': true |
| 2057 | }; |
| 2058 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2059 | /** @enum {string} */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2060 | export const FilterType = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2061 | 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 Scheffler | 341eea5 | 2019-12-12 09:08:41 | [diff] [blame] | 2073 | CookieDomain: 'cookie-domain', |
| 2074 | CookieName: 'cookie-name', |
| 2075 | CookieValue: 'cookie-value', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2076 | StatusCode: 'status-code' |
| 2077 | }; |
| 2078 | |
| 2079 | /** @enum {string} */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2080 | export const MixedContentFilterValues = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2081 | All: 'all', |
| 2082 | Displayed: 'displayed', |
| 2083 | Blocked: 'blocked', |
| 2084 | BlockOverridden: 'block-overridden' |
| 2085 | }; |
| 2086 | |
| 2087 | /** @enum {string} */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2088 | export const IsFilterType = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2089 | Running: 'running', |
Joey Arhar | d183e7e | 2019-02-28 03:37:05 | [diff] [blame] | 2090 | FromCache: 'from-cache', |
| 2091 | ServiceWorkerIntercepted: 'service-worker-intercepted', |
| 2092 | ServiceWorkerInitiated: 'service-worker-initiated' |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2093 | }; |
| 2094 | |
| 2095 | /** @type {!Array<string>} */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2096 | export const _searchKeys = Object.keys(FilterType).map(key => FilterType[key]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2097 | |
| 2098 | /** |
| 2099 | * @interface |
| 2100 | */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2101 | export class GroupLookupInterface { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2102 | /** |
| 2103 | * @param {!SDK.NetworkRequest} request |
Tim van der Lippe | 119690c | 2020-01-13 12:31:30 | [diff] [blame] | 2104 | * @return {?NetworkGroupNode} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2105 | */ |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2106 | groupNodeForRequest(request) { |
| 2107 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 2108 | |
Paul Lewis | 5650965 | 2019-12-06 12:51:58 | [diff] [blame] | 2109 | reset() { |
| 2110 | } |
| 2111 | } |