blob: 4125e6d5c4790bc8bf9504ab09058a13debda1b9 [file] [log] [blame]
Jan Schefflerd6c1d402021-02-26 16:56:381// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Blink Reformat4c46d092018-04-07 15:32:375/*
6 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Tim van der Lippe76961572021-04-06 10:48:0735import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3036import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2837import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2738import * as Platform from '../../core/platform/platform.js';
Wolfgang Beyer6a4cbb42022-05-16 13:02:2939import * as Root from '../../core/root/root.js';
Tim van der Lippee00b92f2021-03-31 16:52:1740import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0541import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5942import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5643import * as HAR from '../../models/har/har.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2744import * as Logs from '../../models/logs/logs.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3745import * as Persistence from '../../models/persistence/persistence.js';
Tim van der Lippefca98ed2021-04-08 14:10:1446import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1647import * as NetworkForward from '../../panels/network/forward/forward.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3748import * as Sources from '../../panels/sources/sources.js';
Kateryna Prokopenkod98e34c2023-09-25 18:08:4849import * as Adorners from '../../ui/components/adorners/adorners.js';
Danil Somsikovf3b437f2023-03-23 16:15:3950import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4751import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1452import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3653import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0754import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1355
Jack Franklin3a802602022-07-13 08:39:4256import {
57 Events,
ioana forfota2c72e132023-09-22 12:11:4858 type EventTypes,
Jack Franklin3a802602022-07-13 08:39:4259 NetworkGroupNode,
Jack Franklin3a802602022-07-13 08:39:4260 type NetworkLogViewInterface,
61 type NetworkNode,
ioana forfota2c72e132023-09-22 12:11:4862 NetworkRequestNode,
Jack Franklin3a802602022-07-13 08:39:4263} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3064import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
ioana forfota2c72e132023-09-22 12:11:4865import networkLogViewStyles from './networkLogView.css.js';
Tim van der Lippe119690c2020-01-13 12:31:3066import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Frankline839c0c2022-05-03 08:47:4467import {
68 NetworkTimeBoundary,
ioana forfota2c72e132023-09-22 12:11:4869 type NetworkTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4470 NetworkTransferDurationCalculator,
71 NetworkTransferTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4472} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3073
Simon Zünd34490692021-03-01 08:25:1874const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5575 /**
Jack Franklinfd72c072022-12-21 11:45:0176 *@description Text in Network Log View of the Network panel
77 */
Victor Porof66878d62021-07-16 13:12:3778 invertFilter: 'Invert',
79 /**
Jack Franklinfd72c072022-12-21 11:45:0180 *@description Tooltip for the 'invert' checkbox in the Network panel.
81 */
Victor Porof66878d62021-07-16 13:12:3782 invertsFilter: 'Inverts the search filter',
83 /**
ioana forfota2c72e132023-09-22 12:11:4884 *@description Text for everything
85 */
86 allStrings: 'All',
87 /**
Jack Franklinfd72c072022-12-21 11:45:0188 *@description Text in Network Log View of the Network panel
89 */
Christy Chencac3f102021-02-03 10:07:5590 hideDataUrls: 'Hide data URLs',
91 /**
Jack Franklinfd72c072022-12-21 11:45:0192 *@description Data urlfilter ui element title in Network Log View of the Network panel
93 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:5594 hidesDataAndBlobUrls: 'Hide \'data:\' and \'blob:\' URLs',
Christy Chencac3f102021-02-03 10:07:5595 /**
ioana forfota45b44152023-07-21 14:20:5396 * @description Label for a filter in the Network panel
97 */
ioana forfotaaf54bd12023-07-28 09:46:2998 chromeExtensions: 'Hide extension URLs',
ioana forfota45b44152023-07-21 14:20:5399 /**
100 * @description Tooltip for a filter in the Network panel
101 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:55102 hideChromeExtension: 'Hide \'chrome-extension://\' URLs',
ioana forfota45b44152023-07-21 14:20:53103 /**
Jack Franklinfd72c072022-12-21 11:45:01104 *@description Aria accessible name in Network Log View of the Network panel
105 */
ioana forfota2c72e132023-09-22 12:11:48106 requestTypesToInclude: 'Request types to include',
107 /**
108 * @description Tooltip for the `Request types` dropdown in the Network Panel
109 */
110 requestTypesTooltip: 'Filter requests by type',
111 /**
Kateryna Prokopenko96e792b2023-09-26 14:05:32112 * @description Label for the dropdown in the Network Panel
ioana forfota2c72e132023-09-22 12:11:48113 */
Kateryna Prokopenko96e792b2023-09-26 14:05:32114 requestTypes: 'Request types',
115 /**
116 * @description Dynamic label for the `Request types` dropdown in the Network panel
117 * @example {Doc} PH1
118 * @example {CSS} PH2
119 */
120 twoTypesSelected: '{PH1}, {PH2}',
121 /**
122 * @description: Dynamic label for the `Request types` dropdown in the Network panel
123 * @example {Doc} PH1
124 * @example {CSS} PH2
125 */
126 overTwoTypesSelected: '{PH1}, {PH2}...',
Christy Chencac3f102021-02-03 10:07:55127 /**
Wolfgang Beyerb9391362023-07-14 12:40:45128 *@description Label for a checkbox in the Network panel. When checked, only requests with
129 * blocked response cookies are shown.
Jack Franklinfd72c072022-12-21 11:45:01130 */
Wolfgang Beyerb9391362023-07-14 12:40:45131 hasBlockedCookies: 'Blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55132 /**
Jack Franklinfd72c072022-12-21 11:45:01133 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
134 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
135 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
136 */
Kateryna Prokopenko5f434d42023-11-03 10:57:49137 onlyShowRequestsWithBlockedCookies: 'Show only requests with blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55138 /**
Jack Franklinfd72c072022-12-21 11:45:01139 *@description Label for a filter in the Network panel
140 */
Sofia Emelianova25f46422023-07-04 15:20:11141 blockedRequests: 'Blocked requests',
Christy Chencac3f102021-02-03 10:07:55142 /**
Jack Franklinfd72c072022-12-21 11:45:01143 *@description Tooltip for a filter in the Network panel
144 */
Sofia Emelianova25f46422023-07-04 15:20:11145 onlyShowBlockedRequests: 'Show only blocked requests',
Christy Chencac3f102021-02-03 10:07:55146 /**
Jack Franklinfd72c072022-12-21 11:45:01147 *@description Label for a filter in the Network panel
148 */
Danil Somsikov721956a2021-07-07 08:17:27149 thirdParty: '3rd-party requests',
150 /**
Jack Franklinfd72c072022-12-21 11:45:01151 *@description Tooltip for a filter in the Network panel
152 */
Sofia Emelianova25f46422023-07-04 15:20:11153 onlyShowThirdPartyRequests: 'Show only requests with origin different from page origin',
Danil Somsikov721956a2021-07-07 08:17:27154 /**
Jack Franklinfd72c072022-12-21 11:45:01155 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
156 */
Christy Chencac3f102021-02-03 10:07:55157 dropHarFilesHere: 'Drop HAR files here',
158 /**
Jack Franklinfd72c072022-12-21 11:45:01159 *@description Recording text text content in Network Log View of the Network panel
160 */
Christy Chencac3f102021-02-03 10:07:55161 recordingNetworkActivity: 'Recording network activity…',
162 /**
Jack Franklinfd72c072022-12-21 11:45:01163 *@description Text in Network Log View of the Network panel
164 *@example {Ctrl + R} PH1
165 */
Christy Chencac3f102021-02-03 10:07:55166 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
167 /**
Jack Franklinfd72c072022-12-21 11:45:01168 *@description Shown in the Network Log View of the Network panel when the user has not yet
169 * recorded any network activity. This is an instruction to the user to start recording in order to
170 * show network activity in the current UI.
171 *@example {Ctrl + E} PH1
172 */
Wolfgang Beyerf4237472021-08-18 14:55:41173 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55174 /**
Jack Franklinfd72c072022-12-21 11:45:01175 *@description Text that is usually a hyperlink to more documentation
176 */
Christy Chencac3f102021-02-03 10:07:55177 learnMore: 'Learn more',
178 /**
Jack Franklinfd72c072022-12-21 11:45:01179 *@description Text to announce to screen readers that network data is available.
180 */
Christy Chencac3f102021-02-03 10:07:55181 networkDataAvailable: 'Network Data Available',
182 /**
Jack Franklinfd72c072022-12-21 11:45:01183 *@description Text in Network Log View of the Network panel
184 *@example {3} PH1
185 *@example {5} PH2
186 */
Christy Chencac3f102021-02-03 10:07:55187 sSRequests: '{PH1} / {PH2} requests',
188 /**
Jack Franklinfd72c072022-12-21 11:45:01189 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
190 * resources transferred during a selected time frame over the compressed size of all resources transferred during
191 * the whole network log.
192 *@example {5 B} PH1
193 *@example {10 B} PH2
194 */
Christy Chencac3f102021-02-03 10:07:55195 sSTransferred: '{PH1} / {PH2} transferred',
196 /**
Jack Franklinfd72c072022-12-21 11:45:01197 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
198 * time frame over the compressed size of all resources transferred during the whole network log.
199 *@example {10} PH1
200 *@example {15} PH2
201 */
Christy Chencac3f102021-02-03 10:07:55202 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
203 /**
Jack Franklinfd72c072022-12-21 11:45:01204 * @description Text in Network Log View of the Network panel. Appears when a particular network
205 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
206 * total size (PH2).
207 * @example {40MB} PH1
208 * @example {50MB} PH2
209 */
Christy Chencac3f102021-02-03 10:07:55210 sSResources: '{PH1} / {PH2} resources',
211 /**
Jack Franklinfd72c072022-12-21 11:45:01212 *@description Text in Network Log View of the Network panel
213 *@example {40} PH1
214 *@example {50} PH2
215 */
Christy Chencac3f102021-02-03 10:07:55216 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
217 /**
Jack Franklinfd72c072022-12-21 11:45:01218 *@description Text in Network Log View of the Network panel
219 *@example {6} PH1
220 */
Christy Chencac3f102021-02-03 10:07:55221 sRequests: '{PH1} requests',
222 /**
Jack Franklinfd72c072022-12-21 11:45:01223 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
224 * all resources transferred over network during a network activity log.
225 *@example {4 B} PH1
226 */
Christy Chencac3f102021-02-03 10:07:55227 sTransferred: '{PH1} transferred',
228 /**
Jack Franklinfd72c072022-12-21 11:45:01229 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
230 * a network activity log.
231 *@example {4} PH1
232 */
Christy Chencac3f102021-02-03 10:07:55233 sBTransferredOverNetwork: '{PH1} B transferred over network',
234 /**
Jack Franklinfd72c072022-12-21 11:45:01235 *@description Text in Network Log View of the Network panel
236 *@example {4} PH1
237 */
Christy Chencac3f102021-02-03 10:07:55238 sResources: '{PH1} resources',
239 /**
Jack Franklinfd72c072022-12-21 11:45:01240 *@description Text in Network Log View of the Network panel
241 *@example {10} PH1
242 */
Christy Chencac3f102021-02-03 10:07:55243 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
244 /**
Jack Franklinfd72c072022-12-21 11:45:01245 *@description Text in Network Log View of the Network panel
246 *@example {120ms} PH1
247 */
Christy Chencac3f102021-02-03 10:07:55248 finishS: 'Finish: {PH1}',
249 /**
Jack Franklinfd72c072022-12-21 11:45:01250 *@description Text in Network Log View of the Network panel
251 *@example {3000ms} PH1
252 */
Christy Chencac3f102021-02-03 10:07:55253 domcontentloadedS: 'DOMContentLoaded: {PH1}',
254 /**
Jack Franklinfd72c072022-12-21 11:45:01255 *@description Text in Network Log View of the Network panel
256 *@example {40ms} PH1
257 */
Christy Chencac3f102021-02-03 10:07:55258 loadS: 'Load: {PH1}',
259 /**
Jack Franklinfd72c072022-12-21 11:45:01260 *@description Text for copying
261 */
Christy Chencac3f102021-02-03 10:07:55262 copy: 'Copy',
263 /**
Jack Franklinfd72c072022-12-21 11:45:01264 *@description Text in Network Log View of the Network panel
265 */
Christy Chencac3f102021-02-03 10:07:55266 copyRequestHeaders: 'Copy request headers',
267 /**
Jack Franklinfd72c072022-12-21 11:45:01268 *@description Text in Network Log View of the Network panel
269 */
Christy Chencac3f102021-02-03 10:07:55270 copyResponseHeaders: 'Copy response headers',
271 /**
Jack Franklinfd72c072022-12-21 11:45:01272 *@description Text in Network Log View of the Network panel
273 */
Christy Chencac3f102021-02-03 10:07:55274 copyResponse: 'Copy response',
275 /**
Jack Franklinfd72c072022-12-21 11:45:01276 *@description Text in Network Log View of the Network panel
277 */
Peter Marshallf625dc82021-03-02 08:10:57278 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55279 /**
Jack Franklinfd72c072022-12-21 11:45:01280 * @description A context menu command in the Network panel, for copying to the clipboard.
281 * PowerShell refers to the format the data will be copied as.
282 */
Peter Marshallb8bd00f2021-02-24 08:25:18283 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55284 /**
Jack Franklinfd72c072022-12-21 11:45:01285 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
286 * refers to the format the data will be copied as, which is compatible with the fetch web API.
287 */
Peter Marshallb8bd00f2021-02-24 08:25:18288 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55289 /**
Jack Franklinfd72c072022-12-21 11:45:01290 * @description Text in Network Log View of the Network panel. An action that copies a command to
291 * the developer's clipboard. The command allows the developer to replay this specific network
292 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
293 * type of request that will be copied.
294 */
Peter Marshallb8bd00f2021-02-24 08:25:18295 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55296 /**
Jack Franklinfd72c072022-12-21 11:45:01297 *@description Text in Network Log View of the Network panel. An action that copies a command to
298 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
299 *translatable).
300 */
Peter Marshallb8bd00f2021-02-24 08:25:18301 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55302 /**
Jack Franklinfd72c072022-12-21 11:45:01303 *@description Text in Network Log View of the Network panel. An action that copies a command to
304 *the clipboard. It will copy the command in the format compatible with a Bash script.
305 */
Peter Marshallb8bd00f2021-02-24 08:25:18306 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55307 /**
Jack Franklinfd72c072022-12-21 11:45:01308 *@description Text in Network Log View of the Network panel. An action that copies a command to
309 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
310 */
Peter Marshallb8bd00f2021-02-24 08:25:18311 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55312 /**
Jack Franklinfd72c072022-12-21 11:45:01313 *@description Text in Network Log View of the Network panel. An action that copies a command to
314 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
315 *should not be translated).
316 */
Peter Marshallb8bd00f2021-02-24 08:25:18317 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55318 /**
Jack Franklinfd72c072022-12-21 11:45:01319 *@description Text in Network Log View of the Network panel. An action that copies a command to
320 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
321 *(fetch and Node.js should not be translated).
322 */
Peter Marshallb8bd00f2021-02-24 08:25:18323 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55324 /**
Jack Franklinfd72c072022-12-21 11:45:01325 *@description Text in Network Log View of the Network panel. An action that copies a command to
326 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
327 *translatable).
328 */
Peter Marshallb8bd00f2021-02-24 08:25:18329 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55330 /**
Jack Franklinfd72c072022-12-21 11:45:01331 *@description Text in Network Log View of the Network panel. An action that copies a command to
332 *the clipboard. It will copy the command in the format compatible with a Bash script.
333 */
Peter Marshallb8bd00f2021-02-24 08:25:18334 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55335 /**
Jack Franklinfd72c072022-12-21 11:45:01336 *@description Text in Network Log View of the Network panel. An action that copies a command to
337 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
338 *translatable).
339 */
Peter Marshallb8bd00f2021-02-24 08:25:18340 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55341 /**
Jack Franklinfd72c072022-12-21 11:45:01342 *@description Text in Network Log View of the Network panel. An action that copies a command to
343 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
344 *translatable).
345 */
Peter Marshallb8bd00f2021-02-24 08:25:18346 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55347 /**
Jack Franklinfd72c072022-12-21 11:45:01348 * @description Text in Network Log View of the Network panel. An action that copies data to the
349 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
350 * network request that is currently shown.
351 */
Peter Marshallb8bd00f2021-02-24 08:25:18352 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55353 /**
Jack Franklinfd72c072022-12-21 11:45:01354 *@description A context menu item in the Network Log View of the Network panel
355 */
Peter Marshallb8bd00f2021-02-24 08:25:18356 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55357 /**
Jack Franklinfd72c072022-12-21 11:45:01358 *@description A context menu item in the Network Log View of the Network panel
359 */
Christy Chencac3f102021-02-03 10:07:55360 clearBrowserCache: 'Clear browser cache',
361 /**
Jack Franklinfd72c072022-12-21 11:45:01362 *@description A context menu item in the Network Log View of the Network panel
363 */
Christy Chencac3f102021-02-03 10:07:55364 clearBrowserCookies: 'Clear browser cookies',
365 /**
Jack Franklinfd72c072022-12-21 11:45:01366 *@description A context menu item in the Network Log View of the Network panel
367 */
Christy Chencac3f102021-02-03 10:07:55368 blockRequestUrl: 'Block request URL',
369 /**
Jack Franklinfd72c072022-12-21 11:45:01370 *@description A context menu item in the Network Log View of the Network panel
371 *@example {example.com} PH1
372 */
Christy Chencac3f102021-02-03 10:07:55373 unblockS: 'Unblock {PH1}',
374 /**
Jack Franklinfd72c072022-12-21 11:45:01375 *@description A context menu item in the Network Log View of the Network panel
376 */
Christy Chencac3f102021-02-03 10:07:55377 blockRequestDomain: 'Block request domain',
378 /**
Jack Franklinfd72c072022-12-21 11:45:01379 *@description Text to replay an XHR request
380 */
Christy Chencac3f102021-02-03 10:07:55381 replayXhr: 'Replay XHR',
382 /**
Jack Franklinfd72c072022-12-21 11:45:01383 *@description Text in Network Log View of the Network panel
384 */
Christy Chencac3f102021-02-03 10:07:55385 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
386 /**
Jack Franklinfd72c072022-12-21 11:45:01387 *@description Text in Network Log View of the Network panel
388 */
Christy Chencac3f102021-02-03 10:07:55389 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37390 /**
Jack Franklinfd72c072022-12-21 11:45:01391 *@description A context menu item in the Network Log View of the Network panel
392 * for creating a header override
393 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41394 overrideHeaders: 'Override headers',
Silvia Eremia096e1202023-09-22 15:49:17395 /**
396 * @description Tooltip for the Show only/Hide requests dropdown of the filterbar
397 */
398 showOnlyHideRequests: 'Show only/hide requests',
399 /**
400 * @description Text for the Show only/Hide requests dropdown button of the filterbar
401 */
402 moreFilters: 'More filters',
Kateryna Prokopenko5f434d42023-11-03 10:57:49403 /**
404 * @description Text for the Request types dropdown button tooltip
405 * @example {Media, Images} PH1
406 */
407 showOnly: 'Show only {PH1}',
Christy Chencac3f102021-02-03 10:07:55408};
Tim van der Lippef596ca02021-03-31 10:02:47409const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55410const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46411
412const enum FetchStyle {
413 Browser = 0,
414 NodeJs = 1,
415}
416
Danil Somsikovf3b437f2023-03-23 16:15:39417const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
418
Simon Zünd940cb1f2021-09-16 11:46:09419export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
420 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53421 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
422 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
ioana forfota45b44152023-07-21 14:20:53423 private readonly networkHideChromeExtensions: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04424 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53425 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
426 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
427 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
428 private rawRowHeight: number;
429 private readonly progressBarContainer: Element;
430 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
431 private rowHeightInternal: number;
432 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
433 private readonly durationCalculator: NetworkTransferDurationCalculator;
434 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30435 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53436 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
437 private mainRequestLoadTime: number;
438 private mainRequestDOMContentLoadedTime: number;
439 private filters: Filter[];
440 private timeFilter: Filter|null;
441 private hoveredNodeInternal: NetworkNode|null;
442 private recordingHint: Element|null;
Jack Franklin28577db2021-10-14 08:12:53443 private highlightedNode: NetworkRequestNode|null;
444 private readonly linkifierInternal: Components.Linkifier.Linkifier;
445 private recording: boolean;
446 private needsRefresh: boolean;
447 private readonly headerHeightInternal: number;
448 private readonly groupLookups: Map<string, GroupLookupInterface>;
449 private activeGroupLookup: GroupLookupInterface|null;
450 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
451 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
Silvia Eremia096e1202023-09-22 15:49:17452 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
453 private readonly moreFiltersDropDownUI: MoreFiltersDropDownUI|undefined;
454 private readonly onlyBlockedResponseCookiesFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
455 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI|undefined;
456 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
457 private readonly hideChromeExtensionsUI: UI.FilterBar.CheckboxFilterUI|undefined;
ioana forfota2c72e132023-09-22 12:11:48458 private readonly resourceCategoryFilterUI: DropDownTypesUI|UI.FilterBar.NamedBitSetFilterUI;
Jack Franklin28577db2021-10-14 08:12:53459 private readonly filterParser: TextUtils.TextUtils.FilterParser;
460 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
461 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50462 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53463 private readonly filterBar: UI.FilterBar.FilterBar;
464 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38465
466 constructor(
467 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
468 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37469 super();
470 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37471
472 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05473 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37474
Jack Franklin28577db2021-10-14 08:12:53475 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('networkInvertFilter', false);
476 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
ioana forfota45b44152023-07-21 14:20:53477 this.networkHideChromeExtensions =
ioana forfotaaf54bd12023-07-28 09:46:29478 Common.Settings.Settings.instance().createSetting('networkHideChromeExtensions', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04479 this.networkShowBlockedCookiesOnlySetting =
480 Common.Settings.Settings.instance().createSetting('networkShowBlockedCookiesOnlySetting', false);
Jack Franklin28577db2021-10-14 08:12:53481 this.networkOnlyBlockedRequestsSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30482 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
Jack Franklin28577db2021-10-14 08:12:53483 this.networkOnlyThirdPartySetting =
Danil Somsikov721956a2021-07-07 08:17:27484 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
Jack Franklin28577db2021-10-14 08:12:53485 this.networkResourceTypeFiltersSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30486 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37487
Jack Franklin28577db2021-10-14 08:12:53488 this.rawRowHeight = 0;
489 this.progressBarContainer = progressBarContainer;
490 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
491 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37492
Jan Schefflerd6c1d402021-02-26 16:56:38493 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53494 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
495 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37496 }
Jack Franklin28577db2021-10-14 08:12:53497 this.rawRowHeight = 0;
498 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37499 updateRowHeight.call(this);
500
Jack Franklin28577db2021-10-14 08:12:53501 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
502 this.durationCalculator = new NetworkTransferDurationCalculator();
503 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37504
Danil Somsikov2a4c4e02022-10-07 12:31:30505 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53506 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30507 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37508
Jack Franklin28577db2021-10-14 08:12:53509 this.staleRequests = new Set();
510 this.mainRequestLoadTime = -1;
511 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37512
Jack Franklin28577db2021-10-14 08:12:53513 this.filters = [];
514 this.timeFilter = null;
515 this.hoveredNodeInternal = null;
516 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53517 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37518
Jack Franklin28577db2021-10-14 08:12:53519 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37520
Jack Franklin28577db2021-10-14 08:12:53521 this.recording = false;
522 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37523
Jack Franklin28577db2021-10-14 08:12:53524 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37525
Jack Franklin28577db2021-10-14 08:12:53526 this.groupLookups = new Map();
527 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37528
Jack Franklin28577db2021-10-14 08:12:53529 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37530
Jack Franklin28577db2021-10-14 08:12:53531 this.textFilterUI = new UI.FilterBar.TextFilterUI();
532 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
533 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37534
Jack Franklin28577db2021-10-14 08:12:53535 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
536 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting);
537 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38538 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53539 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
540 filterBar.addFilter(this.invertFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00541 filterBar.addDivider();
Victor Porof66878d62021-07-16 13:12:37542
Blink Reformat4c46d092018-04-07 15:32:37543 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13544 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38545 .map(
546 category =>
547 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
ioana forfota2c72e132023-09-22 12:11:48548
549 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
550 this.resourceCategoryFilterUI =
551 new DropDownTypesUI(filterItems, this.filterChanged.bind(this), this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17552 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
553 this.resourceCategoryFilterUI.addEventListener(
554 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
555 filterBar.addFilter(this.resourceCategoryFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00556 filterBar.addDivider();
557
Silvia Eremia096e1202023-09-22 15:49:17558 this.moreFiltersDropDownUI = new MoreFiltersDropDownUI(this.filterChanged.bind(this));
559 filterBar.addFilter(this.moreFiltersDropDownUI);
ioana forfota2c72e132023-09-22 12:11:48560 } else {
Silvia Eremia096e1202023-09-22 15:49:17561 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
562 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting);
563 this.dataURLFilterUI.addEventListener(
564 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
565 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
566 filterBar.addFilter(this.dataURLFilterUI);
567
568 this.hideChromeExtensionsUI = new UI.FilterBar.CheckboxFilterUI(
569 'chrome-extension', i18nString(UIStrings.chromeExtensions), true, this.networkHideChromeExtensions);
570 this.hideChromeExtensionsUI.addEventListener(
571 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
572 UI.Tooltip.Tooltip.install(this.hideChromeExtensionsUI.element(), i18nString(UIStrings.hideChromeExtension));
573 filterBar.addFilter(this.hideChromeExtensionsUI);
574
ioana forfota2c72e132023-09-22 12:11:48575 this.resourceCategoryFilterUI =
576 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17577 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
578 this.resourceCategoryFilterUI.addEventListener(
579 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
580 filterBar.addFilter(this.resourceCategoryFilterUI);
581
582 this.onlyBlockedResponseCookiesFilterUI = new UI.FilterBar.CheckboxFilterUI(
583 'only-show-blocked-cookies', i18nString(UIStrings.hasBlockedCookies), true,
584 this.networkShowBlockedCookiesOnlySetting);
585 this.onlyBlockedResponseCookiesFilterUI.addEventListener(
586 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
587 UI.Tooltip.Tooltip.install(
588 this.onlyBlockedResponseCookiesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
589 filterBar.addFilter(this.onlyBlockedResponseCookiesFilterUI);
590
591 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
592 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
593 this.networkOnlyBlockedRequestsSetting);
594 this.onlyBlockedRequestsUI.addEventListener(
595 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
596 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
597 filterBar.addFilter(this.onlyBlockedRequestsUI);
598
599 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
600 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting);
601 this.onlyThirdPartyFilterUI.addEventListener(
602 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
603 UI.Tooltip.Tooltip.install(
604 this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
605 filterBar.addFilter(this.onlyThirdPartyFilterUI);
ioana forfota2c72e132023-09-22 12:11:48606 }
Danil Somsikov721956a2021-07-07 08:17:27607
Jack Franklin28577db2021-10-14 08:12:53608 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
609 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38610 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
611 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37612
Danil Somsikov2a4c4e02022-10-07 12:31:30613 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38614 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30615 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49616 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53617 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37618
Wolfgang Beyer8fc262f2023-04-11 13:22:50619 this.summaryToolbarInternal = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
620 this.summaryToolbarInternal.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37621
Tim van der Lippe0ed1d2b2020-02-04 13:45:13622 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38623 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37624
Paul Lewis2d7d65c2020-03-16 17:26:30625 Common.Settings.Settings.instance()
626 .moduleSetting('networkColorCodeResourceTypes')
Jan Scheffler17b8fb42021-08-12 12:28:38627 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37628
Danil Somsikov62bc5782023-03-21 10:48:50629 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27630 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38631 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27632 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38633 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
Wolfgang Beyer51f2f252023-07-27 17:09:51634 Logs.NetworkLog.NetworkLog.instance().addEventListener(
635 Logs.NetworkLog.Events.RequestRemoved, this.onRequestRemoved, this);
Jan Scheffler17b8fb42021-08-12 12:28:38636 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37637
Jan Scheffler17b8fb42021-08-12 12:28:38638 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30639 Common.Settings.Settings.instance()
640 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38641 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37642
Jack Franklin28577db2021-10-14 08:12:53643 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03644
Jack Franklin28577db2021-10-14 08:12:53645 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
646 if (this.textFilterSetting.get()) {
647 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03648 }
Blink Reformat4c46d092018-04-07 15:32:37649 }
650
Silvia Eremia096e1202023-09-22 15:49:17651 getMoreFiltersDropdown(): MoreFiltersDropDownUI|undefined {
652 return this.moreFiltersDropDownUI;
653 }
654
Jan Scheffler17b8fb42021-08-12 12:28:38655 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30656 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38657 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37658 }
659
Jan Scheffler17b8fb42021-08-12 12:28:38660 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16661 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37662 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38663 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
664 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50665 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
666 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37667 });
668 } else {
669 values.sort();
670 }
671 }
672
Jan Scheffler17b8fb42021-08-12 12:28:38673 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37674 return !filter(request);
675 }
676
Jan Scheffler17b8fb42021-08-12 12:28:38677 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34678 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37679 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34680 }
Blink Reformat4c46d092018-04-07 15:32:37681
682 return regex.test(request.path() + '/' + request.name());
683 }
684
Jan Scheffler17b8fb42021-08-12 12:28:38685 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37686 const result = [domain];
687 let indexOfPeriod = domain.indexOf('.');
688 while (indexOfPeriod !== -1) {
689 result.push('*' + domain.substring(indexOfPeriod));
690 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
691 }
692 return result;
693 }
694
Jan Scheffler17b8fb42021-08-12 12:28:38695 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17696 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38697 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37698 }
699
Jan Scheffler17b8fb42021-08-12 12:28:38700 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37701 return regex.test(request.domain);
702 }
703
Jan Scheffler17b8fb42021-08-12 12:28:38704 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37705 return !request.finished;
706 }
707
Jan Scheffler17b8fb42021-08-12 12:28:38708 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37709 return request.cached();
710 }
711
Jan Scheffler17b8fb42021-08-12 12:28:38712 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05713 return request.fetchedViaServiceWorker;
714 }
715
Jan Scheffler17b8fb42021-08-12 12:28:38716 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05717 return request.initiatedByServiceWorker();
718 }
719
Jan Scheffler17b8fb42021-08-12 12:28:38720 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37721 return request.responseHeaderValue(value) !== undefined;
722 }
723
Jan Scheffler17b8fb42021-08-12 12:28:38724 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
725 boolean {
Jack Franklin28577db2021-10-14 08:12:53726 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51727 // filter via `includes` instead of strict equality.
728 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
729 }
730
Jan Scheffler17b8fb42021-08-12 12:28:38731 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37732 return request.requestMethod === value;
733 }
734
Jan Scheffler17b8fb42021-08-12 12:28:38735 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37736 return request.priority() === value;
737 }
738
Jan Scheffler17b8fb42021-08-12 12:28:38739 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37740 return request.mimeType === value;
741 }
742
Jan Scheffler17b8fb42021-08-12 12:28:38743 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16744 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
745 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37746 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28747 }
Sigurd Schneider30722582021-06-16 06:54:16748 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37749 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28750 }
Sigurd Schneider30722582021-06-16 06:54:16751 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37752 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28753 }
Sigurd Schneider30722582021-06-16 06:54:16754 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37755 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34756 }
Blink Reformat4c46d092018-04-07 15:32:37757
758 return false;
759 }
760
Jan Scheffler17b8fb42021-08-12 12:28:38761 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37762 return request.scheme === value;
763 }
764
Jan Scheffler17b8fb42021-08-12 12:28:38765 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41766 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
767 }
768
Jan Scheffler17b8fb42021-08-12 12:28:38769 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41770 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
771 }
772
Jan Scheffler17b8fb42021-08-12 12:28:38773 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54774 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
775 }
776
Jan Scheffler17b8fb42021-08-12 12:28:38777 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41778 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
779 }
780
Jan Scheffler17b8fb42021-08-12 12:28:38781 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41782 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37783 }
784
Jan Scheffler17b8fb42021-08-12 12:28:38785 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41786 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37787 }
788
Jan Scheffler17b8fb42021-08-12 12:28:38789 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41790 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37791 }
792
Jan Scheffler17b8fb42021-08-12 12:28:38793 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37794 return request.transferSize >= value;
795 }
796
Jan Scheffler17b8fb42021-08-12 12:28:38797 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24798 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37799 }
800
Jecelyn Yeen77c83462023-08-16 16:13:17801 private static hasOverridesFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
802 if (!value) {
803 return false;
804 }
805
806 if (value === overrideFilter.no) {
807 return request.overrideTypes.length === 0;
808 }
809
810 if (value === overrideFilter.yes) {
811 return request.overrideTypes.length > 0;
812 }
813
814 if (value === overrideFilter.content) {
815 return request.overrideTypes.includes('content');
816 }
817
818 if (value === overrideFilter.headers) {
819 return request.overrideTypes.includes('headers');
820 }
821
822 return request.overrideTypes.join(',').includes(value);
823 }
824
Sigurd Schneider576ca9a2021-07-16 05:58:04825 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58826 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37827 }
828
Jan Scheffler17b8fb42021-08-12 12:28:38829 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03830 return request.resourceType().name() === value;
831 }
832
Jan Scheffler17b8fb42021-08-12 12:28:38833 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17834 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03835 return regex.test(request.url());
836 }
837
Jan Scheffler17b8fb42021-08-12 12:28:38838 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38839 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34840 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37841 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 }
843 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37844 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34845 }
Blink Reformat4c46d092018-04-07 15:32:37846 return true;
847 }
848
Jan Scheffler17b8fb42021-08-12 12:28:38849 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13850 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37851 }
852
Jan Scheffler17b8fb42021-08-12 12:28:38853 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13854 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37855 }
856
Jan Scheffler17b8fb42021-08-12 12:28:38857 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37858 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38859 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34860 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40861 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37862 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08863 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34864 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13865 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37866 }
867
Jan Scheffler17b8fb42021-08-12 12:28:38868 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37869 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34870 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37871 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34872 }
Simon Zünd99961242021-09-08 11:02:12873 const file = items[0].getAsFile();
874 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03875 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34876 }
Blink Reformat4c46d092018-04-07 15:32:37877 }
878
Jan Schefflerd6c1d402021-02-26 16:56:38879 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13880 const outputStream = new Common.StringOutputStream.StringOutputStream();
881 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37882 const success = await reader.read(outputStream);
883 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37884 const error = reader.error();
885 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38886 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37887 }
Blink Reformat4c46d092018-04-07 15:32:37888 return;
889 }
890 let harRoot;
891 try {
892 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56893 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37894 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38895 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37896 return;
897 }
Tim van der Lippe09cf5032021-04-29 15:08:09898 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37899 }
900
Jan Scheffler17b8fb42021-08-12 12:28:38901 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36902 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37903 }
904
Jan Scheffler17b8fb42021-08-12 12:28:38905 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53906 if (this.activeGroupLookup) {
907 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34908 }
Jack Franklin28577db2021-10-14 08:12:53909 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
910 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38911 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37912 }
913
Jan Scheffler17b8fb42021-08-12 12:28:38914 private computeRowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53915 return Math.round(this.rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
Blink Reformat4c46d092018-04-07 15:32:37916 }
917
Jan Schefflerd6c1d402021-02-26 16:56:38918 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37919 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37920 }
921
Jan Schefflerd6c1d402021-02-26 16:56:38922 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53923 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37924 }
925
Jan Schefflerd6c1d402021-02-26 16:56:38926 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53927 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38928 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37929 }
930
Danil Somsikov2a4c4e02022-10-07 12:31:30931 columns(): NetworkLogViewColumns {
932 return this.columnsInternal;
933 }
934
Wolfgang Beyer8fc262f2023-04-11 13:22:50935 summaryToolbar(): UI.Toolbar.Toolbar {
936 return this.summaryToolbarInternal;
937 }
938
Jan Schefflerd6c1d402021-02-26 16:56:38939 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37940 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22941 const target = networkManager.target();
942 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37943 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34944 }
Danil Somsikov88384322023-03-22 13:53:22945 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37946 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38947 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37948 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38949 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37950 }
Danil Somsikov88384322023-03-22 13:53:22951 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:04952 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:25953 this.refreshRequest(request);
954 }
Danil Somsikov88384322023-03-22 13:53:22955 }
Blink Reformat4c46d092018-04-07 15:32:37956 }
957
Jan Schefflerd6c1d402021-02-26 16:56:38958 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:22959 const target = networkManager.target();
960 if (target.outermostTarget() !== target) {
961 return;
962 }
963 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
964 if (resourceTreeModel) {
965 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
966 resourceTreeModel.removeEventListener(
967 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
968 }
969 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network_log.preserve-log').get();
970 if (!preserveLog) {
971 this.reset();
Blink Reformat4c46d092018-04-07 15:32:37972 }
973 }
974
Jan Schefflerd6c1d402021-02-26 16:56:38975 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53976 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13977 }
978
Jan Schefflerd6c1d402021-02-26 16:56:38979 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37980 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53981 this.timeFilter = null;
982 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37983 } else {
Jack Franklin28577db2021-10-14 08:12:53984 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
985 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37986 }
Jan Scheffler17b8fb42021-08-12 12:28:38987 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37988 }
989
Jan Schefflerd6c1d402021-02-26 16:56:38990 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53991 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37992 }
993
Jan Scheffler17b8fb42021-08-12 12:28:38994 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:53995 this.suggestionBuilder.clear();
996 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
997 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16998 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:53999 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161000 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:531001 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161002 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:531003 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
1004 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
1005 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
1006 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Jecelyn Yeen77c83462023-08-16 16:13:171007 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.yes);
1008 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.no);
1009 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.content);
1010 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.headers);
Blink Reformat4c46d092018-04-07 15:32:371011 }
1012
Simon Zünda2bae2e2021-09-16 07:57:131013 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371014 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:531015 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:381016 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:531017 this.textFilterSetting.set(this.textFilterUI.value());
Kateryna Prokopenkod98e34c2023-09-25 18:08:481018 this.moreFiltersDropDownUI?.updateActiveFiltersCount();
Kateryna Prokopenko5f434d42023-11-03 10:57:491019 this.moreFiltersDropDownUI?.updateTooltip();
Blink Reformat4c46d092018-04-07 15:32:371020 }
1021
Jan Schefflerd6c1d402021-02-26 16:56:381022 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:531023 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:121024 }
1025
Jan Scheffler17b8fb42021-08-12 12:28:381026 private showRecordingHint(): void {
1027 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:531028 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
1029 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:181030
Jack Franklin28577db2021-10-14 08:12:531031 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:381032 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:041033 const reloadShortcut =
1034 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
1035 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:531036 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:041037 reloadShortcutNode.textContent = reloadShortcut.title();
1038 }
1039
Blink Reformat4c46d092018-04-07 15:32:371040 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:551041 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:181042 if (reloadShortcutNode) {
1043 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:551044 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
1045 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:181046 }
Blink Reformat4c46d092018-04-07 15:32:371047 } else {
1048 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:171049 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:371050 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:551051 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:411052 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:371053 }
Kayce Basques5444c1b2019-02-15 20:32:531054 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:131055 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:351056 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:551057 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:111058
Jan Scheffler17b8fb42021-08-12 12:28:381059 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:371060 }
1061
Jan Scheffler17b8fb42021-08-12 12:28:381062 private hideRecordingHint(): void {
1063 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:531064 if (this.recordingHint) {
1065 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:341066 }
Michael Liao7322dee2021-04-07 18:33:301067 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:531068 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:371069 }
1070
Jan Scheffler17b8fb42021-08-12 12:28:381071 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301072 this.columnsInternal.setHidden(value);
Wolfgang Beyer8fc262f2023-04-11 13:22:501073 UI.ARIAUtils.setHidden(this.summaryToolbarInternal.element, value);
Amanda Baker6761aae2019-11-05 18:59:111074 }
1075
Randolf Jungffd14242023-04-19 00:32:251076 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:531077 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:341078 {
Blink Reformat4c46d092018-04-07 15:32:371079 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:341080 }
Jack Franklin28577db2021-10-14 08:12:531081 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:371082 }
1083
Jan Schefflerd6c1d402021-02-26 16:56:381084 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381085 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:371086 }
1087
Jan Scheffler17b8fb42021-08-12 12:28:381088 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:531089 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:381090 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341091 if (request) {
Blink Reformat4c46d092018-04-07 15:32:371092 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341093 }
Blink Reformat4c46d092018-04-07 15:32:371094 });
Jack Franklin28577db2021-10-14 08:12:531095 this.dataGrid.setStickToBottom(true);
1096 this.dataGrid.setName('networkLog');
1097 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
1098 this.dataGrid.element.classList.add('network-log-grid');
1099 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
1100 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
1101 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
1102 this.dataGrid.element.addEventListener('keydown', event => {
1103 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
1104 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('span.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:431105 if (initiatorLink) {
1106 (initiatorLink as HTMLElement).focus();
1107 }
1108 }
ergunshee4a6132021-11-05 16:21:251109
Jack Franklin5e685be2022-10-17 14:27:091110 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051111 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051112 event.consume(true);
1113 }
1114 });
ergunshee4a6132021-11-05 16:21:251115 this.dataGrid.element.addEventListener('keyup', event => {
1116 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1117 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1118 if (!request) {
1119 return;
1120 }
1121
1122 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1123 SDK.NetworkManager.NetworkManager.replayRequest(request);
1124 }
1125 }
1126 });
Jack Franklin28577db2021-10-14 08:12:531127 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1128 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1129 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371130 }
1131
Jan Scheffler17b8fb42021-08-12 12:28:381132 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381133 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531134 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371135 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381136 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371137 }
1138
Jan Schefflerd6c1d402021-02-26 16:56:381139 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531140 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371141 }
1142
Jan Scheffler17b8fb42021-08-12 12:28:381143 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531144 if (this.hoveredNodeInternal) {
1145 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341146 }
Jack Franklin28577db2021-10-14 08:12:531147 this.hoveredNodeInternal = node;
1148 if (this.hoveredNodeInternal) {
1149 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341150 }
Blink Reformat4c46d092018-04-07 15:32:371151 }
1152
Jan Scheffler17b8fb42021-08-12 12:28:381153 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381154 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531155 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371156 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341157 }
Blink Reformat4c46d092018-04-07 15:32:371158 }
1159
Jan Scheffler17b8fb42021-08-12 12:28:381160 private updateSummaryBar(): void {
1161 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371162
1163 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201164 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371165 let selectedNodeNumber = 0;
1166 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201167 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371168 let baseTime = -1;
1169 let maxTime = -1;
1170
1171 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271172 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371173 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341174 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371175 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341176 }
Blink Reformat4c46d092018-04-07 15:32:371177 nodeCount++;
1178 const requestTransferSize = request.transferSize;
1179 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201180 const requestResourceSize = request.resourceSize;
1181 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371182 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371183 selectedNodeNumber++;
1184 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201185 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371186 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131187 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371188 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1189 // inspected url.
1190 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131191 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Wolfgang Beyer8fc262f2023-04-11 13:22:501192 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.Frame) {
Blink Reformat4c46d092018-04-07 15:32:371193 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341194 }
1195 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371196 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 }
Blink Reformat4c46d092018-04-07 15:32:371198 }
1199
1200 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381201 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371202 return;
1203 }
1204
Wolfgang Beyer8fc262f2023-04-11 13:22:501205 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381206 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131207 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501208 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501209 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381210 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501211 };
Blink Reformat4c46d092018-04-07 15:32:371212
1213 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551214 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501215 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501216 appendChunk(
Christy Chencac3f102021-02-03 10:07:551217 i18nString(UIStrings.sSTransferred, {
1218 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381219 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551220 }),
1221 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501222 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501223 appendChunk(
Christy Chencac3f102021-02-03 10:07:551224 i18nString(UIStrings.sSResources, {
1225 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381226 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551227 }),
1228 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371229 } else {
Christy Chencac3f102021-02-03 10:07:551230 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501231 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251232 appendChunk(
Christy Chencac3f102021-02-03 10:07:551233 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1234 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501235 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251236 appendChunk(
Christy Chencac3f102021-02-03 10:07:551237 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1238 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371239 }
Dan Beam87466b52018-12-01 18:41:201240
Blink Reformat4c46d092018-04-07 15:32:371241 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501242 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581243 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531244 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501245 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551246 const domContentLoadedText = i18nString(
1247 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531248 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381249 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371250 }
Jack Franklin28577db2021-10-14 08:12:531251 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501252 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531253 const loadText =
1254 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381255 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371256 }
1257 }
Blink Reformat4c46d092018-04-07 15:32:371258 }
1259
Jan Schefflerd6c1d402021-02-26 16:56:381260 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531261 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371262 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341263 }
Blink Reformat4c46d092018-04-07 15:32:371264
Jack Franklin28577db2021-10-14 08:12:531265 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371266
Danil Somsikovf3b437f2023-03-23 16:15:391267 if (this.isShowing()) {
Simon Siefke03d72372023-06-26 14:44:461268 void coordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341269 }
Blink Reformat4c46d092018-04-07 15:32:371270 }
1271
Jan Schefflerd6c1d402021-02-26 16:56:381272 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301273 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371274 }
1275
Jan Schefflerd6c1d402021-02-26 16:56:381276 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301277 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371278 }
1279
Jan Schefflerd6c1d402021-02-26 16:56:381280 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301281 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371282 }
1283
Jan Scheffler17b8fb42021-08-12 12:28:381284 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531285 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381286 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341287 }
Blink Reformat4c46d092018-04-07 15:32:371288 }
1289
Jan Scheffler17b8fb42021-08-12 12:28:381290 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041291 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341292 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371293 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341294 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381295 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341296 }
Blink Reformat4c46d092018-04-07 15:32:371297 }
1298
Jan Schefflerd6c1d402021-02-26 16:56:381299 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531300 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371301 }
1302
Jan Schefflerd6c1d402021-02-26 16:56:381303 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531304 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371305 }
1306
Jan Schefflerd6c1d402021-02-26 16:56:381307 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531308 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371309 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341310 }
Blink Reformat4c46d092018-04-07 15:32:371311
Jack Franklin28577db2021-10-14 08:12:531312 if (this.calculatorInternal !== x) {
1313 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301314 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371315 }
Jack Franklin28577db2021-10-14 08:12:531316 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371317
Jack Franklin28577db2021-10-14 08:12:531318 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301319 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341320 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301321 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341322 }
Blink Reformat4c46d092018-04-07 15:32:371323
Jan Scheffler17b8fb42021-08-12 12:28:381324 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371325 }
1326
Jan Scheffler17b8fb42021-08-12 12:28:381327 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271328 event: Common.EventTarget
1329 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531330 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371331 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341332 }
Blink Reformat4c46d092018-04-07 15:32:371333
Simon Zünd1a930492021-07-30 08:22:271334 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371335 if (time) {
Jack Franklin28577db2021-10-14 08:12:531336 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301337 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371338 }
1339 }
1340
Jan Scheffler17b8fb42021-08-12 12:28:381341 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531342 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371343 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341344 }
Simon Zünd1a930492021-07-30 08:22:271345 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371346 if (data) {
Jack Franklin28577db2021-10-14 08:12:531347 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301348 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371349 }
1350 }
1351
Randolf Jungffd14242023-04-19 00:32:251352 override wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381353 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301354 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301355 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371356 }
1357
Randolf Jungffd14242023-04-19 00:32:251358 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301359 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371360 }
1361
Randolf Jungffd14242023-04-19 00:32:251362 override onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531363 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371364 }
1365
Jan Schefflerd6c1d402021-02-26 16:56:381366 flatNodesList(): NetworkNode[] {
1367 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531368 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381369 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1370 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371371 }
1372
Jan Scheffler17b8fb42021-08-12 12:28:381373 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531374 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351375 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381376 }
Brandon Goddard44934902020-03-25 16:03:181377 this.updateNodeBackground();
1378 }
1379
Jan Scheffler17b8fb42021-08-12 12:28:381380 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181381 this.element.classList.remove('grid-focused');
1382 this.updateNodeBackground();
1383 }
1384
Jan Schefflerd6c1d402021-02-26 16:56:381385 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531386 if (this.dataGrid.selectedNode) {
1387 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051388 }
1389 }
1390
Jan Schefflerd6c1d402021-02-26 16:56:381391 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051392 if (isSelected) {
1393 this.element.classList.remove('no-node-selected');
1394 } else {
1395 this.element.classList.add('no-node-selected');
1396 }
1397 }
1398
Jan Schefflerd6c1d402021-02-26 16:56:381399 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301400 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371401 }
1402
Wolfgang Beyer51f2f252023-07-27 17:09:511403 private removeNodeAndMaybeAncestors(node: NetworkRequestNode): void {
1404 let parent: NetworkNode|
1405 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1406 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1407 null) = node.parent;
1408 if (!parent) {
1409 return;
1410 }
1411 parent.removeChild(node);
1412 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1413 const grandparent = (parent.parent as NetworkNode);
1414 grandparent.removeChild(parent);
1415 parent = grandparent;
1416 }
1417 }
1418
Jan Scheffler17b8fb42021-08-12 12:28:381419 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531420 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371421
Blink Reformat4c46d092018-04-07 15:32:371422 this.removeAllNodeHighlights();
1423
Jack Franklin28577db2021-10-14 08:12:531424 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1425 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1426 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1427 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371428
Jan Schefflerd6c1d402021-02-26 16:56:381429 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1430 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371431
Jan Schefflerd6c1d402021-02-26 16:56:381432 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371433
Jack Franklin28577db2021-10-14 08:12:531434 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371435 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531436 while (this.staleRequests.size) {
1437 const request = this.staleRequests.values().next().value;
1438 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371439 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341440 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381441 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341442 }
Blink Reformat4c46d092018-04-07 15:32:371443 staleNodes.add(node);
1444 }
1445
1446 for (const node of staleNodes) {
Jan Scheffler17b8fb42021-08-12 12:28:381447 const isFilteredOut = !this.applyFilter(node);
Jack Franklin28577db2021-10-14 08:12:531448 if (isFilteredOut && node === this.hoveredNodeInternal) {
Jan Scheffler17b8fb42021-08-12 12:28:381449 this.setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341450 }
Blink Reformat4c46d092018-04-07 15:32:371451
Tim van der Lippe1d6e57a2019-09-30 11:55:341452 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371453 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341454 }
Blink Reformat4c46d092018-04-07 15:32:371455 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531456 this.timeCalculatorInternal.updateBoundaries(request);
1457 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381458 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371459 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1460 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371461 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341462 }
Tim van der Lippe224a8622020-09-23 12:14:371463 if (isFilteredOut) {
1464 filteredNetworkRequests.add(node);
1465 } else {
1466 filteredNetworkRequests.delete(node);
1467 }
Blink Reformat4c46d092018-04-07 15:32:371468 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1469 if (removeFromParent) {
Wolfgang Beyer51f2f252023-07-27 17:09:511470 this.removeNodeAndMaybeAncestors(node);
Blink Reformat4c46d092018-04-07 15:32:371471 }
1472
Tim van der Lippe1d6e57a2019-09-30 11:55:341473 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371474 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341475 }
Blink Reformat4c46d092018-04-07 15:32:371476
1477 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531478 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371479 nodesToRefresh.push(newParent);
1480 }
1481 nodesToInsert.set(node, newParent);
1482 }
1483
Tim van der Lippe1d6e57a2019-09-30 11:55:341484 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381485 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341486 }
Blink Reformat4c46d092018-04-07 15:32:371487
Tim van der Lippe1d6e57a2019-09-30 11:55:341488 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371489 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341490 }
Blink Reformat4c46d092018-04-07 15:32:371491
Jan Scheffler17b8fb42021-08-12 12:28:381492 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371493
Tim van der Lippe1d6e57a2019-09-30 11:55:341494 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301495 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341496 }
Blink Reformat4c46d092018-04-07 15:32:371497
Jack Franklin28577db2021-10-14 08:12:531498 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381499 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371500 }
1501
Jan Scheffler17b8fb42021-08-12 12:28:381502 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371503 }
1504
Jan Scheffler17b8fb42021-08-12 12:28:381505 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531506 if (!this.activeGroupLookup) {
1507 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341508 }
Blink Reformat4c46d092018-04-07 15:32:371509
Jack Franklin28577db2021-10-14 08:12:531510 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341511 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531512 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341513 }
Blink Reformat4c46d092018-04-07 15:32:371514 return groupNode;
1515 }
1516
Jan Scheffler17b8fb42021-08-12 12:28:381517 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151518 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371519
Jan Scheffler17b8fb42021-08-12 12:28:381520 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301521 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371522
Jack Franklin28577db2021-10-14 08:12:531523 this.timeFilter = null;
1524 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371525
Jack Franklin28577db2021-10-14 08:12:531526 this.timeCalculatorInternal.setWindow(null);
1527 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371528
Jack Franklin28577db2021-10-14 08:12:531529 if (this.activeGroupLookup) {
1530 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341531 }
Jack Franklin28577db2021-10-14 08:12:531532 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381533 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371534
Jack Franklin28577db2021-10-14 08:12:531535 this.mainRequestLoadTime = -1;
1536 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371537
Jack Franklin28577db2021-10-14 08:12:531538 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381539 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531540 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371541 this.scheduleRefresh();
1542 }
1543
Silvia Eremia096e1202023-09-22 15:49:171544 // TODO(crbug.com/1477668)
Jan Schefflerd6c1d402021-02-26 16:56:381545 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531546 this.textFilterUI.setValue(filterString);
Silvia Eremia096e1202023-09-22 15:49:171547 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
1548 this.networkHideDataURLSetting.set(false);
1549 this.networkShowBlockedCookiesOnlySetting.set(false);
1550 this.networkOnlyBlockedRequestsSetting.set(false);
1551 this.networkOnlyThirdPartySetting.set(false);
1552 this.networkHideChromeExtensions.set(false);
1553 } else {
1554 this.dataURLFilterUI?.setChecked(false);
1555 this.onlyBlockedResponseCookiesFilterUI?.setChecked(false);
1556 this.onlyBlockedRequestsUI?.setChecked(false);
1557 this.onlyThirdPartyFilterUI?.setChecked(false);
1558 this.hideChromeExtensionsUI?.setChecked(false);
1559 }
Jack Franklin28577db2021-10-14 08:12:531560 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371561 }
1562
Jan Scheffler17b8fb42021-08-12 12:28:381563 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301564 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371565 networkRequestToNode.set(request, node);
1566 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371567
Tim van der Lippe1d6e57a2019-09-30 11:55:341568 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381569 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341570 }
Blink Reformat4c46d092018-04-07 15:32:371571 return node;
1572 }
1573
Danil Somsikov123c3ef2023-06-14 10:07:041574 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1575 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1576 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1577 }
1578
Kateryna Prokopenko460f5492021-08-27 08:20:281579 private onRequestUpdated(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1580 const request = event.data;
Danil Somsikov123c3ef2023-06-14 10:07:041581 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:251582 this.refreshRequest(request);
1583 }
Blink Reformat4c46d092018-04-07 15:32:371584 }
1585
Wolfgang Beyer51f2f252023-07-27 17:09:511586 private onRequestRemoved(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1587 const request = event.data;
1588 this.staleRequests.delete(request);
1589 const node = networkRequestToNode.get(request);
1590 if (node) {
1591 this.removeNodeAndMaybeAncestors(node);
1592 }
1593 }
1594
Jan Scheffler17b8fb42021-08-12 12:28:381595 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1596 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161597 .forEach(
Jack Franklin28577db2021-10-14 08:12:531598 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1599 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1600 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1601 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1602 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1603 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1604 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371605
1606 const priority = request.priority();
1607 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531608 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161609 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371610 }
1611
1612 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531613 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161614 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371615 }
1616
1617 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531618 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161619 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371620 }
1621
1622 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161623 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1624 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531625 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371626 }
1627
1628 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511629 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531630 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511631 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531632 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511633 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341634 }
Jan Scheffler341eea52019-12-12 09:08:411635
1636 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531637 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1638 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1639 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371640 }
1641
Jan Scheffler341eea52019-12-12 09:08:411642 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531643 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1644 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1645 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1646 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411647 }
1648
Jack Franklin28577db2021-10-14 08:12:531649 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371650 this.scheduleRefresh();
1651 }
1652
Jan Schefflerd6c1d402021-02-26 16:56:381653 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531654 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371655 }
1656
Jan Schefflerd6c1d402021-02-26 16:56:381657 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301658 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371659 }
1660
Jan Schefflerd6c1d402021-02-26 16:56:381661 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1662 void {
Blink Reformat4c46d092018-04-07 15:32:371663 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551664 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371665 const footerSection = copyMenu.footerSection();
1666 if (request) {
1667 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131668 UI.UIUtils.copyLinkAddressLabel(),
1669 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1670 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371671 if (request.requestHeadersText()) {
1672 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381673 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371674 }
1675
1676 if (request.responseHeadersText) {
1677 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381678 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371679 }
1680
1681 if (request.finished) {
1682 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381683 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371684 }
1685
Tim van der Lippeb4faf5a2020-11-06 15:02:021686 const initiator = request.initiator();
1687
1688 if (initiator) {
1689 const stack = initiator.stack;
1690 if (stack) {
1691 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531692 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021693 // any callFrames, but its parent frames do.
1694 const stackTraceText = computeStackTraceText(stack);
1695 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551696 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021697 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1698 });
1699 }
1700 }
1701 }
1702
Harley Libcf41f92018-09-10 18:01:131703 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131704 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371705 footerSection.appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391706 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
1707 {disabled: disableIfBlob});
Blink Reformat4c46d092018-04-07 15:32:371708 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461709 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
Danil Somsikov712aaa52023-11-09 16:43:391710 {disabled: disableIfBlob});
Jan Scheffler7c50d1f2019-12-17 13:33:291711 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461712 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
Danil Somsikov712aaa52023-11-09 16:43:391713 {disabled: disableIfBlob});
Blink Reformat4c46d092018-04-07 15:32:371714 footerSection.appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391715 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'),
1716 {disabled: disableIfBlob});
Harley Libcf41f92018-09-10 18:01:131717 footerSection.appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391718 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'),
1719 {disabled: disableIfBlob});
Jan Scheffler17b8fb42021-08-12 12:28:381720 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461721 footerSection.appendItem(
1722 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1723 footerSection.appendItem(
1724 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381725 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this.copyAllCurlCommand.bind(this, 'win'));
1726 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371727 } else {
Harley Libcf41f92018-09-10 18:01:131728 footerSection.appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391729 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
1730 {disabled: disableIfBlob});
Danil Somsikova4b089c2021-11-09 14:32:091731 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461732 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
Danil Somsikov712aaa52023-11-09 16:43:391733 {disabled: disableIfBlob});
Jan Scheffler7c50d1f2019-12-17 13:33:291734 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461735 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
Danil Somsikov712aaa52023-11-09 16:43:391736 {disabled: disableIfBlob});
Harley Libcf41f92018-09-10 18:01:131737 footerSection.appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391738 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'),
1739 {disabled: disableIfBlob});
Danil Somsikova4b089c2021-11-09 14:32:091740 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461741 footerSection.appendItem(
1742 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1743 footerSection.appendItem(
1744 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381745 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371746 }
1747 } else {
Christy Chencac3f102021-02-03 10:07:551748 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371749 }
Jan Scheffler17b8fb42021-08-12 12:28:381750 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this.copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371751
Christy Chencac3f102021-02-03 10:07:551752 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291753 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.HEADER_OVERRIDES)) {
Jecelyn Yeen5cc23742023-08-01 13:12:411754 contextMenu.overrideSection().appendItem(
Wolfgang Beyerc6fe2be2022-11-03 15:39:411755 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291756 }
Wolfgang Beyerc6fe2be2022-11-03 15:39:411757
Jan Scheffler17b8fb42021-08-12 12:28:381758 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371759 contextMenu.editSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381760 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371761
1762 if (request) {
1763 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211764 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371765 let patterns = manager.blockedPatterns();
1766
Jan Schefflerd6c1d402021-02-26 16:56:381767 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201768 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121769 manager.setBlockedPatterns(patterns);
1770 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031771 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121772 }
1773
Jan Schefflerd6c1d402021-02-26 16:56:381774 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121775 patterns = patterns.filter(pattern => pattern.url !== url);
1776 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031777 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121778 }
1779
Blink Reformat4c46d092018-04-07 15:32:371780 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1781 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1782 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551783 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371784 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311785 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371786 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551787 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371788 }
1789
1790 const domain = request.parsedURL.domain();
1791 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1792 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551793 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371794 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311795 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371796 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551797 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371798 }
1799
Tim van der Lippe0ed1d2b2020-02-04 13:45:131800 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371801 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551802 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371803 }
Blink Reformat4c46d092018-04-07 15:32:371804 }
1805 }
1806
Jan Scheffler17b8fb42021-08-12 12:28:381807 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271808 return Logs.NetworkLog.NetworkLog.instance()
1809 .requests()
Sigurd Schneider576ca9a2021-07-16 05:58:041810 .filter(NetworkLogView.getHTTPRequestsFilter)
Sigurd Schneidercf5b8302021-04-23 07:52:271811 .filter(request => {
1812 return request.finished ||
1813 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1814 });
Blink Reformat4c46d092018-04-07 15:32:371815 }
1816
Jan Scheffler17b8fb42021-08-12 12:28:381817 private async copyAll(): Promise<void> {
1818 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131819 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371820 }
1821
Jan Scheffler17b8fb42021-08-12 12:28:381822 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351823 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131824 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371825 }
1826
Jan Scheffler17b8fb42021-08-12 12:28:381827 private async copyAllCurlCommand(platform: string): Promise<void> {
1828 const commands = await this.generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131829 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371830 }
1831
Danil Somsikov59f4c612021-09-08 10:58:461832 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1833 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131834 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371835 }
1836
Danil Somsikov59f4c612021-09-08 10:58:461837 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
1838 const commands = await this.generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131839 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371840 }
1841
Jan Scheffler17b8fb42021-08-12 12:28:381842 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1843 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131844 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371845 }
1846
Jan Scheffler17b8fb42021-08-12 12:28:381847 private async copyAllPowerShellCommand(): Promise<void> {
1848 const commands = await this.generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131849 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371850 }
1851
Jan Schefflerd6c1d402021-02-26 16:56:381852 async exportAll(): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501853 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371854 if (!mainTarget) {
1855 return;
1856 }
1857 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131858 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321859 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131860 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371861
Kateryna Prokopenko380fdfa2022-03-16 16:39:321862 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371863 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341864 }
Blink Reformat4c46d092018-04-07 15:32:371865
Tim van der Lippe0ed1d2b2020-02-04 13:45:131866 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531867 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381868 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371869 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031870 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371871 }
1872
Wolfgang Beyer5b433b02022-05-12 13:57:371873 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411874 const requestLocation =
1875 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271876 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1877 if (networkPersistanceManager.project()) {
Wolfgang Beyer1e62b692022-11-07 13:52:081878 Common.Settings.Settings.instance().moduleSetting('persistenceNetworkOverridesEnabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271879 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411880 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371881 } else { // If folder for local overrides has not been provided yet
1882 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async(): Promise<void> => {
1883 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271884 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411885 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371886 });
1887 }
1888 }
1889
Jan Scheffler17b8fb42021-08-12 12:28:381890 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551891 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211892 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341893 }
Blink Reformat4c46d092018-04-07 15:32:371894 }
1895
Jan Scheffler17b8fb42021-08-12 12:28:381896 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551897 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211898 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341899 }
Blink Reformat4c46d092018-04-07 15:32:371900 }
1901
Jan Scheffler17b8fb42021-08-12 12:28:381902 private removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371903 this.removeAllNodeHighlights();
Blink Reformat4c46d092018-04-07 15:32:371904 }
1905
Jan Scheffler17b8fb42021-08-12 12:28:381906 private applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371907 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531908 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371909 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341910 }
Christy Chen1825c612021-02-25 10:28:441911 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531912 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371913 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341914 }
Silvia Eremia096e1202023-09-22 15:49:171915 const [hideDataURL, blockedCookies, blockedRequests, thirdParty, hideExtensionURL] =
1916 Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN) ?
1917 [
1918 this.networkHideDataURLSetting.get(),
1919 this.networkShowBlockedCookiesOnlySetting.get(),
1920 this.networkOnlyBlockedRequestsSetting.get(),
1921 this.networkOnlyThirdPartySetting.get(),
1922 this.networkHideChromeExtensions.get(),
1923 ] :
1924 [
1925 this.dataURLFilterUI?.checked(),
1926 this.onlyBlockedResponseCookiesFilterUI?.checked(),
1927 this.onlyBlockedRequestsUI?.checked(),
1928 this.onlyThirdPartyFilterUI?.checked(),
1929 this.hideChromeExtensionsUI?.checked(),
1930 ];
1931
1932 if (hideDataURL && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371933 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341934 }
Silvia Eremia096e1202023-09-22 15:49:171935 if (blockedCookies && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371936 return false;
1937 }
Silvia Eremia096e1202023-09-22 15:49:171938 if (blockedRequests && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131939 return false;
1940 }
Silvia Eremia096e1202023-09-22 15:49:171941 if (thirdParty && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271942 return false;
1943 }
Silvia Eremia096e1202023-09-22 15:49:171944 if (hideExtensionURL && request.scheme === 'chrome-extension') {
ioana forfota45b44152023-07-21 14:20:531945 return false;
1946 }
Jack Franklin28577db2021-10-14 08:12:531947 for (let i = 0; i < this.filters.length; ++i) {
1948 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371949 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341950 }
Blink Reformat4c46d092018-04-07 15:32:371951 }
1952 return true;
1953 }
1954
Danil Somsikov7a392fb2021-09-13 11:09:461955 private isValidUrl(url: string): boolean {
1956 try {
1957 new URL(url);
1958 return true;
1959 } catch (e) {
1960 return false;
1961 }
1962 }
1963
Jan Scheffler17b8fb42021-08-12 12:28:381964 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531965 // A query string can have multiple filters, some of them regular
1966 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371967 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:531968 // checkbox therefore inverts each one of those individual filters.
1969 const descriptors = this.filterParser.parse(query);
1970 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:371971 const key = descriptor.key;
1972 const text = descriptor.text || '';
1973 const regex = descriptor.regex;
1974 let filter;
1975 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171976 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:381977 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
1978 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371979 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:381980 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:461981 } else if (this.isValidUrl(text)) {
1982 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:371983 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381984 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:171985 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371986 }
Victor Porof66878d62021-07-16 13:12:371987 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:381988 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:371989 }
1990 return filter;
Blink Reformat4c46d092018-04-07 15:32:371991 });
1992 }
1993
Jan Scheffler17b8fb42021-08-12 12:28:381994 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371995 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:161996 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:381997 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371998
Sigurd Schneider30722582021-06-16 06:54:161999 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:382000 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372001
Simon Zünd6dedde52021-08-03 09:04:512002 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:382003 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:512004
Sigurd Schneider30722582021-06-16 06:54:162005 case NetworkForward.UIFilter.FilterType.Is:
2006 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:382007 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342008 }
Sigurd Schneider30722582021-06-16 06:54:162009 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:382010 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342011 }
Sigurd Schneider30722582021-06-16 06:54:162012 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:382013 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342014 }
Sigurd Schneider30722582021-06-16 06:54:162015 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:382016 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342017 }
Blink Reformat4c46d092018-04-07 15:32:372018 break;
2019
Sigurd Schneider30722582021-06-16 06:54:162020 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:382021 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:372022
Sigurd Schneider30722582021-06-16 06:54:162023 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:382024 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372025
Sigurd Schneider30722582021-06-16 06:54:162026 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:382027 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372028
Sigurd Schneider30722582021-06-16 06:54:162029 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:382030 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:162031 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:372032
Sigurd Schneider30722582021-06-16 06:54:162033 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:382034 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372035
Sigurd Schneider30722582021-06-16 06:54:162036 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382037 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372038
Sigurd Schneider30722582021-06-16 06:54:162039 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382040 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372041
Sigurd Schneider30722582021-06-16 06:54:162042 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382043 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372044
Sigurd Schneider30722582021-06-16 06:54:162045 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382046 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412047
Sigurd Schneider30722582021-06-16 06:54:162048 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382049 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412050
Sigurd Schneider30722582021-06-16 06:54:162051 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:382052 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:542053
Sigurd Schneider30722582021-06-16 06:54:162054 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382055 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412056
Sigurd Schneider30722582021-06-16 06:54:162057 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:382058 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:502059 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:372060
Sigurd Schneider30722582021-06-16 06:54:162061 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:382062 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:032063
Jecelyn Yeen77c83462023-08-16 16:13:172064 case NetworkForward.UIFilter.FilterType.HasOverrides:
2065 return NetworkLogView.hasOverridesFilter.bind(null, value);
2066
Sigurd Schneider30722582021-06-16 06:54:162067 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:382068 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:032069
Sigurd Schneider30722582021-06-16 06:54:162070 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:382071 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372072 }
2073 return null;
2074 }
2075
Jan Scheffler17b8fb42021-08-12 12:28:382076 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372077 let multiplier = 1;
2078 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542079 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:372080 value = value.substring(0, value.length - 1);
2081 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542082 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:372083 value = value.substring(0, value.length - 1);
2084 }
2085 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342086 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:372087 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342088 }
Jan Scheffler17b8fb42021-08-12 12:28:382089 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:372090 }
2091
Jan Scheffler17b8fb42021-08-12 12:28:382092 private filterRequests(): void {
2093 this.removeAllHighlights();
2094 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:372095 }
2096
Jan Scheffler17b8fb42021-08-12 12:28:382097 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:372098 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:372099 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342100 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:372101 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342102 }
Brandon Goddard5e4244d2020-04-08 22:08:472103 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:532104 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:472105 // reveal and expand parent to ensure child is revealable.
2106 if (node.parent && node.parent instanceof NetworkGroupNode) {
2107 node.parent.reveal();
2108 node.parent.expand();
2109 }
Blink Reformat4c46d092018-04-07 15:32:372110 node.reveal();
2111 return node;
2112 }
2113
Jan Schefflerd6c1d402021-02-26 16:56:382114 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:382115 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342116 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:382117 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:342118 }
Blink Reformat4c46d092018-04-07 15:32:372119 }
2120
Sigurd Schneider722301e2021-06-15 13:41:202121 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:072122 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
2123 if (request) {
2124 this.revealAndHighlightRequest(request);
2125 }
2126 }
2127
Sigurd Schneider14d3e9f2021-06-14 08:29:012128 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
2129 void {
chait pinnamaneni6bc1c122020-10-30 17:30:522130 const defaultOptions = {clearFilter: true};
2131 const {clearFilter} = options || defaultOptions;
2132 if (clearFilter) {
2133 this.setTextFilterValue('');
2134 }
Jan Scheffler17b8fb42021-08-12 12:28:382135 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342136 if (node) {
Blink Reformat4c46d092018-04-07 15:32:372137 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:342138 }
Blink Reformat4c46d092018-04-07 15:32:372139 }
2140
Jan Schefflerd6c1d402021-02-26 16:56:382141 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:532142 if (this.highlightedNode) {
2143 this.highlightedNode.element().classList.remove('highlighted-row');
2144 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:372145 }
2146 }
2147
Jan Scheffler17b8fb42021-08-12 12:28:382148 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132149 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:532150 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:372151 }
2152
Jan Scheffler17b8fb42021-08-12 12:28:382153 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:132154 return requests.filter(request => !request.isBlobRequest());
2155 }
2156
Danil Somsikov59f4c612021-09-08 10:58:462157 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382158 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:372159 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372160 'method',
2161 'path',
2162 'scheme',
2163 'version',
Blink Reformat4c46d092018-04-07 15:32:372164
2165 // Unsafe headers
2166 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372167 'accept-charset',
2168 'accept-encoding',
2169 'access-control-request-headers',
2170 'access-control-request-method',
2171 'connection',
2172 'content-length',
2173 'cookie',
2174 'cookie2',
2175 'date',
2176 'dnt',
2177 'expect',
2178 'host',
2179 'keep-alive',
2180 'origin',
2181 'referer',
2182 'te',
2183 'trailer',
2184 'transfer-encoding',
2185 'upgrade',
2186 'via',
Blink Reformat4c46d092018-04-07 15:32:372187 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372188 'user-agent',
2189 ]);
Blink Reformat4c46d092018-04-07 15:32:372190
Jan Schefflerd6c1d402021-02-26 16:56:382191 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372192
2193 const url = JSON.stringify(request.url());
2194
2195 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382196 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372197 const name = header.name;
2198
Tim van der Lippe224a8622020-09-23 12:14:372199 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372200 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342201 }
Blink Reformat4c46d092018-04-07 15:32:372202
2203 return result;
2204 }, new Headers());
2205
Jan Schefflerd6c1d402021-02-26 16:56:382206 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342207 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412208 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342209 }
Blink Reformat4c46d092018-04-07 15:32:372210
Sigurd Schneider0e88b912020-05-08 08:28:232211 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372212 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412213 'include' :
2214 'omit';
Blink Reformat4c46d092018-04-07 15:32:372215
2216 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2217
2218 const referrer = referrerHeader ? referrerHeader.value : void 0;
2219
2220 const referrerPolicy = request.referrerPolicy() || void 0;
2221
2222 const requestBody = await request.requestFormData();
2223
Jan Schefflerd6c1d402021-02-26 16:56:382224 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412225 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372226 referrer,
2227 referrerPolicy,
2228 body: requestBody,
2229 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372230 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372231 };
2232
Danil Somsikov59f4c612021-09-08 10:58:462233 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292234 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462235 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532236 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462237 // following properties are not implemented in Node.js.
2238 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292239 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462240 extraHeaders['cookie'] = cookieHeader.value;
2241 }
2242 if (referrer) {
2243 delete fetchOptions.referrer;
2244 extraHeaders['Referer'] = referrer;
2245 }
2246 if (referrer) {
2247 delete fetchOptions.referrerPolicy;
2248 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2249 }
2250 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292251 fetchOptions.headers = {
2252 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462253 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292254 };
2255 }
2256 } else {
2257 fetchOptions.credentials = credentials;
2258 }
2259
Jan Scheffler172d5212020-01-02 14:42:562260 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372261 return `fetch(${url}, ${options});`;
2262 }
2263
Danil Somsikov59f4c612021-09-08 10:58:462264 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382265 Promise<string> {
2266 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462267 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132268 return commands.join(' ;\n');
2269 }
2270
Wolfgang Beyer26b7e892022-08-16 11:02:352271 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382272 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362273 // Most of these headers are derived from the URL and are automatically added by cURL.
2274 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:382275 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372276
Jan Schefflerd6c1d402021-02-26 16:56:382277 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372278 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:382279 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:372280
Jan Schefflerd6c1d402021-02-26 16:56:382281 Because cmd.exe parser and MS Crt arguments parsers use some of the
2282 same escape characters, they can interact with each other in
2283 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372284
Jan Schefflerd6c1d402021-02-26 16:56:382285 Replace \ with \\ first because it is an escape character for certain
2286 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372287
Jan Schefflerd6c1d402021-02-26 16:56:382288 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372289
Jan Schefflerd6c1d402021-02-26 16:56:382290 Then escape all characters we are not sure about with ^ to ensure it
2291 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372292
Jan Schefflerd6c1d402021-02-26 16:56:382293 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352294 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382295 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2296 parser); So we can get cmd.exe parser to escape the character after it,
2297 if it is followed by a valid beginning character of an ENV variable.
2298 This ensures we do not try and double escape another ^ if it was placed
2299 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372300
Jan Schefflerd6c1d402021-02-26 16:56:382301 Lastly we replace new lines with ^ and TWO new lines because the first
2302 new line is there to enact the escape command the second is the character
2303 to escape (in this case new line).
2304 */
Blink Reformat4c46d092018-04-07 15:32:372305 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2306 return encapsChars +
2307 str.replace(/\\/g, '\\\\')
2308 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542309 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372310 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542311 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372312 encapsChars;
2313 }
2314
Jan Schefflerd6c1d402021-02-26 16:56:382315 function escapeStringPosix(str: string): string {
2316 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222317 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122318 let hexString = code.toString(16);
2319 // Zero pad to four digits to comply with ANSI-C Quoting:
2320 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342321 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122322 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342323 }
Joey Arhar2d21f712019-05-20 21:07:122324
2325 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372326 }
2327
Mathias Bynensf06e8c02020-02-28 13:58:282328 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372329 // Use ANSI-C quoting syntax.
2330 return '$\'' +
2331 str.replace(/\\/g, '\\\\')
2332 .replace(/\'/g, '\\\'')
2333 .replace(/\n/g, '\\n')
2334 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282335 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372336 '\'';
Blink Reformat4c46d092018-04-07 15:32:372337 }
Mathias Bynensf06e8c02020-02-28 13:58:282338 // Use single quote syntax.
2339 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372340 }
2341
2342 // cURL command expected to run on the same platform that DevTools run
2343 // (it may be different from the inspected page platform).
2344 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2345
2346 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2347
2348 let inferredMethod = 'GET';
2349 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372350 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082351 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272352 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532353 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272354 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372355 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372356 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372357 }
2358
2359 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292360 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372361 }
2362
2363 const requestHeaders = request.requestHeaders();
2364 for (let i = 0; i < requestHeaders.length; i++) {
2365 const header = requestHeaders[i];
2366 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372367 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372368 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342369 }
Wolfgang Beyer26b7e892022-08-16 11:02:352370 if (header.value.trim()) {
2371 command.push('-H ' + escapeString(name + ': ' + header.value));
2372 } else {
2373 // A header passed with -H with no value or only whitespace as its
2374 // value tells curl to not set the header at all. To post an empty
2375 // header, you have to terminate it with a semicolon.
2376 command.push('-H ' + escapeString(name + ';'));
2377 }
Blink Reformat4c46d092018-04-07 15:32:372378 }
2379 command = command.concat(data);
2380 command.push('--compressed');
2381
Tim van der Lippe1d6e57a2019-09-30 11:55:342382 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372383 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342384 }
Jan Scheffler172d5212020-01-02 14:42:562385 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372386 }
2387
Jan Scheffler17b8fb42021-08-12 12:28:382388 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string):
2389 Promise<string> {
2390 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352391 const commands =
2392 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342393 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132394 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342395 }
Mathias Bynensf06e8c02020-02-28 13:58:282396 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132397 }
2398
Jan Scheffler17b8fb42021-08-12 12:28:382399 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562400 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242401 const ignoredHeaders = new Set<string>([
2402 'host',
2403 'connection',
2404 'proxy-connection',
2405 'content-length',
2406 'expect',
2407 'range',
2408 'content-type',
2409 'user-agent',
2410 'cookie',
2411 ]);
Blink Reformat4c46d092018-04-07 15:32:372412
Jan Schefflerd6c1d402021-02-26 16:56:382413 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372414 return '"' +
2415 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2416 }
2417
Brandon Walderman153b8d72021-06-28 18:45:242418 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2419 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2420 // command does not allow setting these headers through the -Headers parameter. See docs at:
2421 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2422 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2423 const requestHeaders = request.requestHeaders();
2424 const props = [];
2425
2426 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2427 if (userAgentHeader) {
2428 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2429 }
2430
2431 for (const cookie of request.includedRequestCookies()) {
2432 const name = escapeString(cookie.name());
2433 const value = escapeString(cookie.value());
2434 const domain = escapeString(cookie.domain());
2435 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2436 }
2437
2438 if (props.length) {
2439 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2440 }
2441
2442 return null;
2443 }
2444
Jan Scheffler172d5212020-01-02 14:42:562445 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372446
2447 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562448 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372449 }
2450
Brandon Walderman153b8d72021-06-28 18:45:242451 const session = generatePowerShellSession(request);
2452 if (session) {
2453 command.push('-WebSession $session');
2454 }
2455
Blink Reformat4c46d092018-04-07 15:32:372456 const requestHeaders = request.requestHeaders();
2457 const headerNameValuePairs = [];
2458 for (const header of requestHeaders) {
2459 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342460 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372461 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342462 }
Blink Reformat4c46d092018-04-07 15:32:372463 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2464 }
2465 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562466 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372467 }
2468
2469 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2470 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562471 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372472 }
2473
2474 const formData = await request.requestFormData();
2475 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372476 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342477 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562478 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342479 } else {
Jan Scheffler172d5212020-01-02 14:42:562480 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342481 }
Blink Reformat4c46d092018-04-07 15:32:372482 }
2483
Brandon Walderman153b8d72021-06-28 18:45:242484 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2485 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2486 // compatibility only.
2487 const prelude = session || '';
2488 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372489 }
Harley Libcf41f92018-09-10 18:01:132490
Jan Scheffler17b8fb42021-08-12 12:28:382491 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2492 const nonBlobRequests = this.filterOutBlobRequests(requests);
2493 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132494 return commands.join(';\r\n');
2495 }
Joey Arhara86c14e2019-03-12 03:20:502496
Jan Schefflerd6c1d402021-02-26 16:56:382497 static getDCLEventColor(): string {
Kateryna Prokopenkof85f4d12023-10-05 14:24:402498 return '--sys-color-token-attribute-value';
Joey Arhara86c14e2019-03-12 03:20:502499 }
2500
Jan Schefflerd6c1d402021-02-26 16:56:382501 static getLoadEventColor(): string {
Kateryna Prokopenkof85f4d12023-10-05 14:24:402502 return '--sys-color-token-property-special';
Joey Arhara86c14e2019-03-12 03:20:502503 }
Paul Lewis56509652019-12-06 12:51:582504}
Blink Reformat4c46d092018-04-07 15:32:372505
Jan Schefflerd6c1d402021-02-26 16:56:382506export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022507 let stackTraceText = '';
2508 for (const frame of stackTrace.callFrames) {
2509 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2510 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2511 }
2512 if (stackTrace.parent) {
2513 stackTraceText += computeStackTraceText(stackTrace.parent);
2514 }
2515 return stackTraceText;
2516}
2517
Jan Schefflerd6c1d402021-02-26 16:56:382518const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2519const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372520
Jan Schefflerd6c1d402021-02-26 16:56:382521export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372522 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222523}
2524
Paul Lewis56509652019-12-06 12:51:582525export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372526 'http': true,
2527 'https': true,
2528 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382529 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372530};
2531
Sigurd Schneider576ca9a2021-07-16 05:58:042532const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382533
2534export interface GroupLookupInterface {
2535 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2536 reset(): void;
2537}
2538
Jecelyn Yeen77c83462023-08-16 16:13:172539export const overrideFilter = {
2540 yes: 'yes',
2541 no: 'no',
2542 content: 'content',
2543 headers: 'headers',
2544};
2545
Jan Schefflerd6c1d402021-02-26 16:56:382546export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;
ioana forfota2c72e132023-09-22 12:11:482547
2548export class DropDownTypesUI extends Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes> implements
2549 UI.FilterBar.FilterUI {
2550 private readonly filterElement: HTMLDivElement;
2551 private readonly dropDownButton: UI.Toolbar.ToolbarButton;
2552 private readonly filterChanged: () => void;
2553 private displayedTypes: Set<string>;
2554 private readonly setting: Common.Settings.Setting<{[key: string]: boolean}>;
2555 private readonly items: UI.FilterBar.Item[];
2556 private contextMenu?: UI.ContextMenu.ContextMenu;
Kateryna Prokopenko862a31e2023-09-25 21:06:002557 private selectedTypesCount: HTMLElement;
2558 private typesCountAdorner: Adorners.Adorner.Adorner;
Wolfgang Beyer19b9fb42023-11-16 12:31:372559 private hasChanged = false;
ioana forfota2c72e132023-09-22 12:11:482560
2561 constructor(
2562 items: UI.FilterBar.Item[], filterChangedCallback: () => void,
2563 setting: Common.Settings.Setting<{[key: string]: boolean}>) {
2564 super();
2565 this.items = items;
2566 this.filterChanged = filterChangedCallback;
2567
2568 this.filterElement = document.createElement('div');
Kateryna Prokopenko862a31e2023-09-25 21:06:002569
2570 this.typesCountAdorner = new Adorners.Adorner.Adorner();
2571 this.selectedTypesCount = document.createElement('span');
2572 this.typesCountAdorner.data = {
2573 name: 'countWrapper',
2574 content: this.selectedTypesCount,
2575 };
2576 this.typesCountAdorner.classList.add('active-filters-count');
2577
Kateryna Prokopenko5f434d42023-11-03 10:57:492578 this.dropDownButton =
2579 new UI.Toolbar.ToolbarButton(i18nString(UIStrings.requestTypesTooltip), this.typesCountAdorner);
2580 this.dropDownButton.setText(i18nString(UIStrings.requestTypes));
ioana forfota2c72e132023-09-22 12:11:482581 this.filterElement.appendChild(this.dropDownButton.element);
2582 this.dropDownButton.turnIntoSelect();
2583 this.dropDownButton.element.classList.add('dropdown-filterbar');
2584
2585 this.dropDownButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click, this.showContextMenu.bind(this));
2586 UI.ARIAUtils.markAsMenuButton(this.dropDownButton.element);
2587
2588 this.displayedTypes = new Set();
2589
2590 this.setting = setting;
2591 setting.addChangeListener(this.settingChanged.bind(this));
2592 this.setting.addChangeListener(this.filterChanged.bind(this));
2593 this.settingChanged();
2594 }
2595
2596 discard(): void {
2597 this.contextMenu?.discard();
2598 }
2599
Wolfgang Beyer19b9fb42023-11-16 12:31:372600 emitUMA(): void {
2601 if (this.hasChanged) {
2602 Host.userMetrics.resourceTypeFilterNumberOfSelectedChanged(this.displayedTypes.size);
2603 for (const displayedType of this.displayedTypes) {
2604 Host.userMetrics.resourceTypeFilterItemSelected(displayedType);
2605 }
2606 }
2607 }
2608
ioana forfota2c72e132023-09-22 12:11:482609 showContextMenu(event: Common.EventTarget.EventTargetEvent<Event>): void {
2610 const mouseEvent = event.data;
Wolfgang Beyer19b9fb42023-11-16 12:31:372611 this.hasChanged = false;
ioana forfota2c72e132023-09-22 12:11:482612 this.contextMenu = new UI.ContextMenu.ContextMenu(mouseEvent, {
2613 useSoftMenu: true,
2614 keepOpen: true,
2615 x: this.dropDownButton.element.getBoundingClientRect().left,
2616 y: this.dropDownButton.element.getBoundingClientRect().top +
2617 (this.dropDownButton.element as HTMLElement).offsetHeight,
Wolfgang Beyer19b9fb42023-11-16 12:31:372618 onSoftMenuClosed: this.emitUMA.bind(this),
ioana forfota2c72e132023-09-22 12:11:482619 });
2620
2621 this.addRequestType(this.contextMenu, DropDownTypesUI.ALL_TYPES, i18nString(UIStrings.allStrings));
2622 this.contextMenu.defaultSection().appendSeparator();
2623
2624 for (const item of this.items) {
2625 this.addRequestType(this.contextMenu, item.name, item.name);
2626 }
2627
2628 this.update();
2629 void this.contextMenu.show();
2630 }
2631
2632 private addRequestType(contextMenu: UI.ContextMenu.ContextMenu, name: string, label: string): void {
2633 contextMenu.defaultSection().appendCheckboxItem(label, () => {
2634 this.setting.get()[name] = !this.setting.get()[name];
2635 this.toggleTypeFilter(name);
2636 }, this.setting.get()[name]);
2637 }
2638
2639 private toggleTypeFilter(typeName: string): void {
2640 if (typeName !== DropDownTypesUI.ALL_TYPES) {
2641 this.displayedTypes.delete(DropDownTypesUI.ALL_TYPES);
2642 } else {
2643 this.displayedTypes = new Set();
2644 }
2645
2646 if (this.displayedTypes.has(typeName)) {
2647 this.displayedTypes.delete(typeName);
2648 } else {
2649 this.displayedTypes.add(typeName);
2650 }
2651
2652 if (this.displayedTypes.size === 0) {
2653 this.displayedTypes.add(DropDownTypesUI.ALL_TYPES);
2654 }
2655
2656 // Settings do not support `Sets` so convert it back to the Map-like object.
2657 const updatedSetting = {} as {[key: string]: boolean};
2658 for (const type of this.displayedTypes) {
2659 updatedSetting[type] = true;
2660 }
2661
2662 this.setting.set(updatedSetting);
2663
2664 // For the feature of keeping the dropdown open while choosing its options:
2665 // this code provides the dinamic changes of the checkboxes' state in this dropdown
2666 const menuItems = this.contextMenu?.getItems() || [];
2667 for (const i of menuItems) {
2668 if (i.label) {
2669 this.contextMenu?.setChecked(i, this.displayedTypes.has(i.label));
2670 }
2671 }
2672 this.contextMenu?.setChecked(menuItems[0], this.displayedTypes.has('all'));
2673 }
2674
2675 private settingChanged(): void {
Wolfgang Beyer19b9fb42023-11-16 12:31:372676 this.hasChanged = true;
ioana forfota2c72e132023-09-22 12:11:482677 this.displayedTypes = new Set();
2678
2679 for (const s in this.setting.get()) {
2680 this.displayedTypes.add(s);
2681 }
2682 this.update();
2683 }
2684
2685 private update(): void {
2686 if (this.displayedTypes.size === 0 || this.displayedTypes.has(DropDownTypesUI.ALL_TYPES)) {
2687 this.displayedTypes = new Set();
2688 this.displayedTypes.add(DropDownTypesUI.ALL_TYPES);
2689 }
Kateryna Prokopenko96e792b2023-09-26 14:05:322690 this.updateSelectedTypesCount();
2691 this.updateLabel();
Kateryna Prokopenko5f434d42023-11-03 10:57:492692 this.updateTooltip();
ioana forfota2c72e132023-09-22 12:11:482693 }
2694
Kateryna Prokopenko862a31e2023-09-25 21:06:002695 updateSelectedTypesCount(): void {
2696 if (!this.displayedTypes.has(DropDownTypesUI.ALL_TYPES)) {
2697 this.selectedTypesCount.textContent = this.displayedTypes.size.toString();
2698 this.typesCountAdorner.classList.remove('hidden');
2699 } else {
2700 this.typesCountAdorner.classList.add('hidden');
2701 }
2702 }
2703
Kateryna Prokopenko96e792b2023-09-26 14:05:322704 updateLabel(): void {
2705 if (this.displayedTypes.has(DropDownTypesUI.ALL_TYPES)) {
2706 this.dropDownButton.setText(i18nString(UIStrings.requestTypes));
2707 return;
2708 }
2709
2710 let newLabel;
2711 if (this.displayedTypes.size === 1) {
2712 const type = this.displayedTypes.values().next().value;
2713 newLabel = Common.ResourceType.ResourceCategory.categoryByTitle(type)?.shortTitle() || '';
2714 } else {
2715 // show up to two last selected types
Kateryna Prokopenko5f434d42023-11-03 10:57:492716 const twoLastSelected = [...this.displayedTypes].slice(-2).reverse();
Kateryna Prokopenko96e792b2023-09-26 14:05:322717 const shortNames =
2718 twoLastSelected.map(type => Common.ResourceType.ResourceCategory.categoryByTitle(type)?.shortTitle() || '');
2719 const valuesToDisplay = {PH1: shortNames[0], PH2: shortNames[1]};
2720 newLabel = this.displayedTypes.size === 2 ? i18nString(UIStrings.twoTypesSelected, valuesToDisplay) :
2721 i18nString(UIStrings.overTwoTypesSelected, valuesToDisplay);
2722 }
2723 this.dropDownButton.setText(newLabel);
2724 }
2725
Kateryna Prokopenko5f434d42023-11-03 10:57:492726 updateTooltip(): void {
2727 let tooltipText = i18nString(UIStrings.requestTypesTooltip);
2728 if (!this.displayedTypes.has(DropDownTypesUI.ALL_TYPES)) {
2729 // reverse the order to match the button label
2730 const selectedTypes = [...this.displayedTypes].reverse();
2731 const localized =
2732 selectedTypes.map(type => Common.ResourceType.ResourceCategory.categoryByTitle(type)?.title() || '')
2733 .join(', ');
2734 tooltipText = i18nString(UIStrings.showOnly, {PH1: localized});
2735 }
2736 this.dropDownButton.setTitle(tooltipText);
2737 }
2738
ioana forfota2c72e132023-09-22 12:11:482739 isActive(): boolean {
2740 return !this.displayedTypes.has(DropDownTypesUI.ALL_TYPES);
2741 }
2742
2743 element(): HTMLDivElement {
2744 return this.filterElement;
2745 }
2746
2747 reset(): void {
2748 this.toggleTypeFilter(DropDownTypesUI.ALL_TYPES);
2749 }
2750
2751 accept(typeName: string): boolean {
2752 return this.displayedTypes.has(DropDownTypesUI.ALL_TYPES) || this.displayedTypes.has(typeName);
2753 }
2754
2755 static readonly ALL_TYPES = 'all';
2756}
Silvia Eremia096e1202023-09-22 15:49:172757
2758export class MoreFiltersDropDownUI extends
2759 Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes> implements UI.FilterBar.FilterUI {
2760 private readonly filterElement: HTMLDivElement;
2761 private readonly dropDownButton: UI.Toolbar.ToolbarButton;
2762 private readonly filterChangedCallback: () => void;
2763 private networkHideDataURLSetting: Common.Settings.Setting<boolean>;
2764 private networkHideChromeExtensionsSetting: Common.Settings.Setting<boolean>;
2765 private networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
2766 private networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
2767 private networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
2768 private contextMenu?: UI.ContextMenu.ContextMenu;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482769 private activeFiltersCount: HTMLElement;
2770 private activeFiltersCountAdorner: Adorners.Adorner.Adorner;
Wolfgang Beyer3b382582023-11-16 12:40:022771 private hasChanged = false;
Silvia Eremia096e1202023-09-22 15:49:172772
2773 constructor(filterChangedCallback: () => void) {
2774 super();
2775 this.filterChangedCallback = filterChangedCallback;
2776
2777 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
2778 this.networkHideChromeExtensionsSetting =
2779 Common.Settings.Settings.instance().createSetting('networkHideChromeExtensions', false);
2780 this.networkShowBlockedCookiesOnlySetting =
2781 Common.Settings.Settings.instance().createSetting('networkShowBlockedCookiesOnlySetting', false);
2782 this.networkOnlyBlockedRequestsSetting =
2783 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
2784 this.networkOnlyThirdPartySetting =
2785 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
2786
2787 this.filterElement = document.createElement('div');
2788 this.filterElement.setAttribute('aria-label', 'Show only/hide requests dropdown');
Kateryna Prokopenkod98e34c2023-09-25 18:08:482789
2790 this.activeFiltersCountAdorner = new Adorners.Adorner.Adorner();
2791 this.activeFiltersCount = document.createElement('span');
2792 this.activeFiltersCountAdorner.data = {
2793 name: 'countWrapper',
2794 content: this.activeFiltersCount,
2795 };
2796 this.activeFiltersCountAdorner.classList.add('active-filters-count');
2797 this.updateActiveFiltersCount();
2798
Silvia Eremia096e1202023-09-22 15:49:172799 this.dropDownButton = new UI.Toolbar.ToolbarButton(
Kateryna Prokopenkod98e34c2023-09-25 18:08:482800 i18nString(UIStrings.showOnlyHideRequests), this.activeFiltersCountAdorner, i18nString(UIStrings.moreFilters));
Silvia Eremia096e1202023-09-22 15:49:172801 this.filterElement.appendChild(this.dropDownButton.element);
2802 this.dropDownButton.turnIntoSelect();
2803 this.dropDownButton.element.classList.add('dropdown-filterbar');
2804 this.dropDownButton.addEventListener(
2805 UI.Toolbar.ToolbarButton.Events.Click, this.showMoreFiltersContextMenu.bind(this));
2806 UI.ARIAUtils.markAsMenuButton(this.dropDownButton.element);
Kateryna Prokopenko5f434d42023-11-03 10:57:492807 this.updateTooltip();
Silvia Eremia096e1202023-09-22 15:49:172808 }
2809
Wolfgang Beyer3b382582023-11-16 12:40:022810 emitUMA(): void {
2811 if (this.hasChanged) {
2812 const selectedFilters = this.selectedFilters();
2813 Host.userMetrics.networkPanelMoreFiltersNumberOfSelectedChanged(selectedFilters.length);
2814 for (const selectedFilter of selectedFilters) {
2815 Host.userMetrics.networkPanelMoreFiltersItemSelected(selectedFilter);
2816 }
2817 }
2818 }
2819
2820 #onSettingChanged(): void {
2821 this.hasChanged = true;
2822 this.filterChangedCallback();
2823 }
2824
Silvia Eremia096e1202023-09-22 15:49:172825 showMoreFiltersContextMenu(event: Common.EventTarget.EventTargetEvent<Event>): void {
2826 const mouseEvent = event.data;
Wolfgang Beyer3b382582023-11-16 12:40:022827 this.hasChanged = false;
Silvia Eremia096e1202023-09-22 15:49:172828
Wolfgang Beyer3b382582023-11-16 12:40:022829 this.networkHideDataURLSetting.addChangeListener(this.#onSettingChanged.bind(this));
2830 this.networkHideChromeExtensionsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2831 this.networkShowBlockedCookiesOnlySetting.addChangeListener(this.#onSettingChanged.bind(this));
2832 this.networkOnlyBlockedRequestsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2833 this.networkOnlyThirdPartySetting.addChangeListener(this.#onSettingChanged.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172834 this.contextMenu = new UI.ContextMenu.ContextMenu(mouseEvent, {
2835 useSoftMenu: true,
2836 keepOpen: true,
2837 x: this.dropDownButton.element.getBoundingClientRect().left,
2838 y: this.dropDownButton.element.getBoundingClientRect().top +
2839 (this.dropDownButton.element as HTMLElement).offsetHeight,
Wolfgang Beyer3b382582023-11-16 12:40:022840 onSoftMenuClosed: this.emitUMA.bind(this),
Silvia Eremia096e1202023-09-22 15:49:172841 });
2842
2843 this.contextMenu.defaultSection().appendCheckboxItem(
2844 i18nString(UIStrings.hideDataUrls),
2845 () => this.networkHideDataURLSetting.set(!this.networkHideDataURLSetting.get()),
2846 this.networkHideDataURLSetting.get(), undefined, undefined, i18nString(UIStrings.hidesDataAndBlobUrls));
2847 this.contextMenu.defaultSection().appendCheckboxItem(
2848 i18nString(UIStrings.chromeExtensions),
2849 () => this.networkHideChromeExtensionsSetting.set(!this.networkHideChromeExtensionsSetting.get()),
2850 this.networkHideChromeExtensionsSetting.get(), undefined, undefined, i18nString(UIStrings.hideChromeExtension));
2851 this.contextMenu.defaultSection().appendSeparator();
Kateryna Prokopenkod98e34c2023-09-25 18:08:482852
Silvia Eremia096e1202023-09-22 15:49:172853 this.contextMenu.defaultSection().appendCheckboxItem(
2854 i18nString(UIStrings.hasBlockedCookies),
Kateryna Prokopenkod98e34c2023-09-25 18:08:482855 () => this.networkShowBlockedCookiesOnlySetting.set(!this.networkShowBlockedCookiesOnlySetting.get()),
Silvia Eremia096e1202023-09-22 15:49:172856 this.networkShowBlockedCookiesOnlySetting.get(), undefined, undefined,
2857 i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
Silvia Eremia096e1202023-09-22 15:49:172858 this.contextMenu.defaultSection().appendCheckboxItem(
2859 i18nString(UIStrings.blockedRequests),
2860 () => this.networkOnlyBlockedRequestsSetting.set(!this.networkOnlyBlockedRequestsSetting.get()),
2861 this.networkOnlyBlockedRequestsSetting.get(), undefined, undefined,
2862 i18nString(UIStrings.onlyShowBlockedRequests));
2863 this.contextMenu.defaultSection().appendCheckboxItem(
2864 i18nString(UIStrings.thirdParty),
2865 () => this.networkOnlyThirdPartySetting.set(!this.networkOnlyThirdPartySetting.get()),
2866 this.networkOnlyThirdPartySetting.get(), undefined, undefined,
2867 i18nString(UIStrings.onlyShowThirdPartyRequests));
2868
2869 void this.contextMenu.show();
2870 }
2871
Kateryna Prokopenko5f434d42023-11-03 10:57:492872 selectedFilters(): string[] {
2873 const filters = [
2874 ...this.networkHideDataURLSetting.get() ? [i18nString(UIStrings.hideDataUrls)] : [],
2875 ...this.networkHideChromeExtensionsSetting.get() ? [i18nString(UIStrings.chromeExtensions)] : [],
2876 ...this.networkShowBlockedCookiesOnlySetting.get() ? [i18nString(UIStrings.hasBlockedCookies)] : [],
2877 ...this.networkOnlyBlockedRequestsSetting.get() ? [i18nString(UIStrings.blockedRequests)] : [],
2878 ...this.networkOnlyThirdPartySetting.get() ? [i18nString(UIStrings.thirdParty)] : [],
Kateryna Prokopenkod98e34c2023-09-25 18:08:482879 ];
Kateryna Prokopenko5f434d42023-11-03 10:57:492880 return filters;
2881 }
2882
2883 updateActiveFiltersCount(): void {
2884 const count = this.selectedFilters().length;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482885 this.activeFiltersCount.textContent = count.toString();
2886 count ? this.activeFiltersCountAdorner.classList.remove('hidden') :
2887 this.activeFiltersCountAdorner.classList.add('hidden');
2888 }
2889
Kateryna Prokopenko5f434d42023-11-03 10:57:492890 updateTooltip(): void {
2891 if (this.selectedFilters().length) {
2892 this.dropDownButton.setTitle(this.selectedFilters().join(', '));
2893 } else {
2894 this.dropDownButton.setTitle(UIStrings.showOnlyHideRequests);
2895 }
2896 }
2897
Silvia Eremia096e1202023-09-22 15:49:172898 discard(): void {
2899 if (this.contextMenu) {
2900 this.contextMenu.discard();
2901 }
2902 }
2903
2904 isActive(): boolean {
2905 return true;
2906 }
2907
2908 element(): HTMLDivElement {
2909 return this.filterElement;
2910 }
2911}