blob: 31d929ea0de88ff35647593593594fb9a0cb8aa3 [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
Benedikt Meurer918a8212025-01-09 08:47:0835import '../../ui/legacy/legacy.js';
36
Tim van der Lippe76961572021-04-06 10:48:0737import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3038import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2839import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2740import * as Platform from '../../core/platform/platform.js';
Wolfgang Beyer6a4cbb42022-05-16 13:02:2941import * as Root from '../../core/root/root.js';
Tim van der Lippee00b92f2021-03-31 16:52:1742import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0543import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5944import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5645import * as HAR from '../../models/har/har.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2746import * as Logs from '../../models/logs/logs.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3747import * as Persistence from '../../models/persistence/persistence.js';
Tim van der Lippefca98ed2021-04-08 14:10:1448import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1649import * as NetworkForward from '../../panels/network/forward/forward.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3750import * as Sources from '../../panels/sources/sources.js';
Kateryna Prokopenkod98e34c2023-09-25 18:08:4851import * as Adorners from '../../ui/components/adorners/adorners.js';
Benedikt Meurer328b3a72025-01-02 10:38:5552import * as RenderCoordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4753import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1454import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3655import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0756import * as UI from '../../ui/legacy/legacy.js';
Wolfgang Beyer8ad25a72024-01-03 12:44:2957import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1358
Jack Franklin3a802602022-07-13 08:39:4259import {
60 Events,
ioana forfota2c72e132023-09-22 12:11:4861 type EventTypes,
Jack Franklin3a802602022-07-13 08:39:4262 NetworkGroupNode,
Jack Franklin3a802602022-07-13 08:39:4263 type NetworkLogViewInterface,
64 type NetworkNode,
ioana forfota2c72e132023-09-22 12:11:4865 NetworkRequestNode,
Jack Franklin3a802602022-07-13 08:39:4266} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3067import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
Benedikt Meurerb2184622025-01-31 09:15:0868import networkLogViewStylesRaw from './networkLogView.css.legacy.js';
Tim van der Lippe119690c2020-01-13 12:31:3069import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Frankline839c0c2022-05-03 08:47:4470import {
71 NetworkTimeBoundary,
ioana forfota2c72e132023-09-22 12:11:4872 type NetworkTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4473 NetworkTransferDurationCalculator,
74 NetworkTransferTimeCalculator,
75} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3076
Benedikt Meurerb2184622025-01-31 09:15:0877// TODO(crbug.com/391381439): Fully migrate off of constructed style sheets.
78const networkLogViewStyles = new CSSStyleSheet();
79networkLogViewStyles.replaceSync(networkLogViewStylesRaw.cssContent);
80
Simon Zünd34490692021-03-01 08:25:1881const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5582 /**
Jack Franklinfd72c072022-12-21 11:45:0183 *@description Text in Network Log View of the Network panel
84 */
Victor Porof66878d62021-07-16 13:12:3785 invertFilter: 'Invert',
86 /**
Jack Franklinfd72c072022-12-21 11:45:0187 *@description Tooltip for the 'invert' checkbox in the Network panel.
88 */
Victor Porof66878d62021-07-16 13:12:3789 invertsFilter: 'Inverts the search filter',
90 /**
Jack Franklinfd72c072022-12-21 11:45:0191 *@description Text in Network Log View of the Network panel
92 */
Christy Chencac3f102021-02-03 10:07:5593 hideDataUrls: 'Hide data URLs',
94 /**
Jack Franklinfd72c072022-12-21 11:45:0195 *@description Data urlfilter ui element title in Network Log View of the Network panel
96 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:5597 hidesDataAndBlobUrls: 'Hide \'data:\' and \'blob:\' URLs',
Christy Chencac3f102021-02-03 10:07:5598 /**
ioana forfota45b44152023-07-21 14:20:5399 * @description Label for a filter in the Network panel
100 */
ioana forfotaaf54bd12023-07-28 09:46:29101 chromeExtensions: 'Hide extension URLs',
ioana forfota45b44152023-07-21 14:20:53102 /**
103 * @description Tooltip for a filter in the Network panel
104 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:55105 hideChromeExtension: 'Hide \'chrome-extension://\' URLs',
ioana forfota45b44152023-07-21 14:20:53106 /**
Jack Franklinfd72c072022-12-21 11:45:01107 *@description Aria accessible name in Network Log View of the Network panel
108 */
ioana forfota2c72e132023-09-22 12:11:48109 requestTypesToInclude: 'Request types to include',
110 /**
Wolfgang Beyerb9391362023-07-14 12:40:45111 *@description Label for a checkbox in the Network panel. When checked, only requests with
112 * blocked response cookies are shown.
Jack Franklinfd72c072022-12-21 11:45:01113 */
Wolfgang Beyerb9391362023-07-14 12:40:45114 hasBlockedCookies: 'Blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55115 /**
Jack Franklinfd72c072022-12-21 11:45:01116 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
117 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
118 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
119 */
Kateryna Prokopenko5f434d42023-11-03 10:57:49120 onlyShowRequestsWithBlockedCookies: 'Show only requests with blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55121 /**
Jack Franklinfd72c072022-12-21 11:45:01122 *@description Label for a filter in the Network panel
123 */
Sofia Emelianova25f46422023-07-04 15:20:11124 blockedRequests: 'Blocked requests',
Christy Chencac3f102021-02-03 10:07:55125 /**
Jack Franklinfd72c072022-12-21 11:45:01126 *@description Tooltip for a filter in the Network panel
127 */
Sofia Emelianova25f46422023-07-04 15:20:11128 onlyShowBlockedRequests: 'Show only blocked requests',
Christy Chencac3f102021-02-03 10:07:55129 /**
Jack Franklinfd72c072022-12-21 11:45:01130 *@description Label for a filter in the Network panel
131 */
Danil Somsikov721956a2021-07-07 08:17:27132 thirdParty: '3rd-party requests',
133 /**
Jack Franklinfd72c072022-12-21 11:45:01134 *@description Tooltip for a filter in the Network panel
135 */
Sofia Emelianova25f46422023-07-04 15:20:11136 onlyShowThirdPartyRequests: 'Show only requests with origin different from page origin',
Danil Somsikov721956a2021-07-07 08:17:27137 /**
Jack Franklinfd72c072022-12-21 11:45:01138 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
139 */
Christy Chencac3f102021-02-03 10:07:55140 dropHarFilesHere: 'Drop HAR files here',
141 /**
Jack Franklinfd72c072022-12-21 11:45:01142 *@description Recording text text content in Network Log View of the Network panel
143 */
Christy Chencac3f102021-02-03 10:07:55144 recordingNetworkActivity: 'Recording network activity…',
145 /**
Jack Franklinfd72c072022-12-21 11:45:01146 *@description Text in Network Log View of the Network panel
147 *@example {Ctrl + R} PH1
148 */
Christy Chencac3f102021-02-03 10:07:55149 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
150 /**
Jack Franklinfd72c072022-12-21 11:45:01151 *@description Shown in the Network Log View of the Network panel when the user has not yet
152 * recorded any network activity. This is an instruction to the user to start recording in order to
153 * show network activity in the current UI.
154 *@example {Ctrl + E} PH1
155 */
Wolfgang Beyerf4237472021-08-18 14:55:41156 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55157 /**
Jack Franklinfd72c072022-12-21 11:45:01158 *@description Text that is usually a hyperlink to more documentation
159 */
Christy Chencac3f102021-02-03 10:07:55160 learnMore: 'Learn more',
161 /**
Jack Franklinfd72c072022-12-21 11:45:01162 *@description Text to announce to screen readers that network data is available.
163 */
Christy Chencac3f102021-02-03 10:07:55164 networkDataAvailable: 'Network Data Available',
165 /**
Jack Franklinfd72c072022-12-21 11:45:01166 *@description Text in Network Log View of the Network panel
167 *@example {3} PH1
168 *@example {5} PH2
169 */
Christy Chencac3f102021-02-03 10:07:55170 sSRequests: '{PH1} / {PH2} requests',
171 /**
Jack Franklinfd72c072022-12-21 11:45:01172 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
173 * resources transferred during a selected time frame over the compressed size of all resources transferred during
174 * the whole network log.
175 *@example {5 B} PH1
176 *@example {10 B} PH2
177 */
Christy Chencac3f102021-02-03 10:07:55178 sSTransferred: '{PH1} / {PH2} transferred',
179 /**
Jack Franklinfd72c072022-12-21 11:45:01180 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
181 * time frame over the compressed size of all resources transferred during the whole network log.
182 *@example {10} PH1
183 *@example {15} PH2
184 */
Christy Chencac3f102021-02-03 10:07:55185 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
186 /**
Jack Franklinfd72c072022-12-21 11:45:01187 * @description Text in Network Log View of the Network panel. Appears when a particular network
188 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
189 * total size (PH2).
190 * @example {40MB} PH1
191 * @example {50MB} PH2
192 */
Christy Chencac3f102021-02-03 10:07:55193 sSResources: '{PH1} / {PH2} resources',
194 /**
Jack Franklinfd72c072022-12-21 11:45:01195 *@description Text in Network Log View of the Network panel
196 *@example {40} PH1
197 *@example {50} PH2
198 */
Christy Chencac3f102021-02-03 10:07:55199 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
200 /**
Jack Franklinfd72c072022-12-21 11:45:01201 *@description Text in Network Log View of the Network panel
202 *@example {6} PH1
203 */
Christy Chencac3f102021-02-03 10:07:55204 sRequests: '{PH1} requests',
205 /**
Jack Franklinfd72c072022-12-21 11:45:01206 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
207 * all resources transferred over network during a network activity log.
208 *@example {4 B} PH1
209 */
Christy Chencac3f102021-02-03 10:07:55210 sTransferred: '{PH1} transferred',
211 /**
Jack Franklinfd72c072022-12-21 11:45:01212 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
213 * a network activity log.
214 *@example {4} PH1
215 */
Christy Chencac3f102021-02-03 10:07:55216 sBTransferredOverNetwork: '{PH1} B transferred over network',
217 /**
Jack Franklinfd72c072022-12-21 11:45:01218 *@description Text in Network Log View of the Network panel
219 *@example {4} PH1
220 */
Christy Chencac3f102021-02-03 10:07:55221 sResources: '{PH1} resources',
222 /**
Jack Franklinfd72c072022-12-21 11:45:01223 *@description Text in Network Log View of the Network panel
224 *@example {10} PH1
225 */
Christy Chencac3f102021-02-03 10:07:55226 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
227 /**
Jack Franklinfd72c072022-12-21 11:45:01228 *@description Text in Network Log View of the Network panel
229 *@example {120ms} PH1
230 */
Christy Chencac3f102021-02-03 10:07:55231 finishS: 'Finish: {PH1}',
232 /**
Jack Franklinfd72c072022-12-21 11:45:01233 *@description Text in Network Log View of the Network panel
234 *@example {3000ms} PH1
235 */
Christy Chencac3f102021-02-03 10:07:55236 domcontentloadedS: 'DOMContentLoaded: {PH1}',
237 /**
Jack Franklinfd72c072022-12-21 11:45:01238 *@description Text in Network Log View of the Network panel
239 *@example {40ms} PH1
240 */
Christy Chencac3f102021-02-03 10:07:55241 loadS: 'Load: {PH1}',
242 /**
Jack Franklinfd72c072022-12-21 11:45:01243 *@description Text for copying
244 */
Christy Chencac3f102021-02-03 10:07:55245 copy: 'Copy',
246 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51247 *@description A context menu command in the Network panel, for copying the URL of the selected request to the clipboard.
248 */
249 copyURL: 'Copy URL',
250 /**
Jack Franklinfd72c072022-12-21 11:45:01251 *@description Text in Network Log View of the Network panel
252 */
Christy Chencac3f102021-02-03 10:07:55253 copyRequestHeaders: 'Copy request headers',
254 /**
Jack Franklinfd72c072022-12-21 11:45:01255 *@description Text in Network Log View of the Network panel
256 */
Christy Chencac3f102021-02-03 10:07:55257 copyResponseHeaders: 'Copy response headers',
258 /**
Jack Franklinfd72c072022-12-21 11:45:01259 *@description Text in Network Log View of the Network panel
260 */
Christy Chencac3f102021-02-03 10:07:55261 copyResponse: 'Copy response',
262 /**
Jack Franklinfd72c072022-12-21 11:45:01263 *@description Text in Network Log View of the Network panel
264 */
Peter Marshallf625dc82021-03-02 08:10:57265 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55266 /**
Jack Franklinfd72c072022-12-21 11:45:01267 * @description A context menu command in the Network panel, for copying to the clipboard.
268 * PowerShell refers to the format the data will be copied as.
269 */
Peter Marshallb8bd00f2021-02-24 08:25:18270 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55271 /**
Jack Franklinfd72c072022-12-21 11:45:01272 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
273 * refers to the format the data will be copied as, which is compatible with the fetch web API.
274 */
Peter Marshallb8bd00f2021-02-24 08:25:18275 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55276 /**
Jack Franklinfd72c072022-12-21 11:45:01277 * @description Text in Network Log View of the Network panel. An action that copies a command to
278 * the developer's clipboard. The command allows the developer to replay this specific network
279 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
280 * type of request that will be copied.
281 */
Benedikt Meurer8f0fee62023-12-27 12:36:51282 copyAsNodejsFetch: 'Copy as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55283 /**
Jack Franklinfd72c072022-12-21 11:45:01284 *@description Text in Network Log View of the Network panel. An action that copies a command to
285 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
286 *translatable).
287 */
Peter Marshallb8bd00f2021-02-24 08:25:18288 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
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 clipboard. It will copy the command in the format compatible with a Bash script.
292 */
Peter Marshallb8bd00f2021-02-24 08:25:18293 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55294 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51295 *@description A context menu command in the Network panel, for copying the URLs of all requestes to the clipboard.
296 */
297 copyAllURLs: 'Copy all URLs',
298 /**
Yang Guo6d1361f2024-07-11 08:23:48299 *@description A context menu command in the Network panel, for copying the URLs of all requestes
300 (after applying the Network filter) to the clipboard.
301 */
Yang Guo80af52f2024-07-16 12:06:26302 copyAllListedURLs: 'Copy all listed URLs',
Yang Guo6d1361f2024-07-11 08:23:48303 /**
Jack Franklinfd72c072022-12-21 11:45:01304 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48305 *the clipboard. It will copy the command in the format compatible with a PowerShell script to
306 *represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01307 */
Peter Marshallb8bd00f2021-02-24 08:25:18308 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55309 /**
Jack Franklinfd72c072022-12-21 11:45:01310 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48311 *the clipboard. It will copy the command in the format compatible with a PowerShell script to
312 *represent all network requests (after applying the Network filter).
313 */
Yang Guo80af52f2024-07-16 12:06:26314 copyAllListedAsPowershell: 'Copy all listed as `PowerShell`',
Yang Guo6d1361f2024-07-11 08:23:48315 /**
316 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01317 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
Yang Guo6d1361f2024-07-11 08:23:48318 *should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01319 */
Peter Marshallb8bd00f2021-02-24 08:25:18320 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55321 /**
Jack Franklinfd72c072022-12-21 11:45:01322 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48323 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
324 *should not be translated) to represent all network requests (after applying the Network filter).
325 */
Yang Guo80af52f2024-07-16 12:06:26326 copyAllListedAsFetch: 'Copy all listed as `fetch`',
Yang Guo6d1361f2024-07-11 08:23:48327 /**
328 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01329 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
Yang Guo6d1361f2024-07-11 08:23:48330 *(fetch and Node.js should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01331 */
Benedikt Meurer8f0fee62023-12-27 12:36:51332 copyAllAsNodejsFetch: 'Copy all as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55333 /**
Jack Franklinfd72c072022-12-21 11:45:01334 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48335 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
336 *(fetch and Node.js should not be translated) to represent all network requests (after applying
337 *the Network filter).
338 */
Yang Guo80af52f2024-07-16 12:06:26339 copyAllListedAsNodejsFetch: 'Copy all listed as `fetch` (`Node.js`)',
Yang Guo6d1361f2024-07-11 08:23:48340 /**
341 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01342 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48343 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01344 */
Peter Marshallb8bd00f2021-02-24 08:25:18345 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55346 /**
Jack Franklinfd72c072022-12-21 11:45:01347 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48348 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
349 *translatable) to represent all network requests (after applying the Network filter).
350 */
Yang Guo80af52f2024-07-16 12:06:26351 copyAllListedAsCurlCmd: 'Copy all listed as `cURL` (`cmd`)',
Yang Guo6d1361f2024-07-11 08:23:48352 /**
353 *@description Text in Network Log View of the Network panel. An action that copies a command to
354 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
355 *all network requests.
Jack Franklinfd72c072022-12-21 11:45:01356 */
Peter Marshallb8bd00f2021-02-24 08:25:18357 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55358 /**
Jack Franklinfd72c072022-12-21 11:45:01359 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48360 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
361 *all network requests (after applying the Network filter).
362 */
Yang Guo80af52f2024-07-16 12:06:26363 copyAllListedAsCurlBash: 'Copy all listed as `cURL` (`bash`)',
Yang Guo6d1361f2024-07-11 08:23:48364 /**
365 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01366 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
367 *translatable).
368 */
Peter Marshallb8bd00f2021-02-24 08:25:18369 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55370 /**
Jack Franklinfd72c072022-12-21 11:45:01371 *@description Text in Network Log View of the Network panel. An action that copies a command to
372 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48373 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01374 */
Peter Marshallb8bd00f2021-02-24 08:25:18375 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55376 /**
Yang Guo6d1361f2024-07-11 08:23:48377 *@description Text in Network Log View of the Network panel. An action that copies a command to
378 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
379 *translatable) to represent all network requests (after applying the Network filter).
380 */
Yang Guo80af52f2024-07-16 12:06:26381 copyAllListedAsCurl: 'Copy all listed as `cURL`',
Yang Guo6d1361f2024-07-11 08:23:48382 /**
Jack Franklinfd72c072022-12-21 11:45:01383 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24384 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
385 * sensitive data from the network requests. 'all' refers to every network request that is currently
386 * shown.
Jack Franklinfd72c072022-12-21 11:45:01387 */
Benedikt Meureracd96a62024-09-10 07:25:24388 copyAllAsHarSanitized: 'Copy all as `HAR` (sanitized)',
Christy Chencac3f102021-02-03 10:07:55389 /**
Yang Guo6d1361f2024-07-11 08:23:48390 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24391 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
392 * sensitive data from the network requests. 'all' refers to every network request that is currently
393 * shown.
Yang Guo6d1361f2024-07-11 08:23:48394 */
Benedikt Meureracd96a62024-09-10 07:25:24395 copyAllAsHarWithSensitiveData: 'Copy all as `HAR` (with sensitive data)',
396 /**
397 * @description Text in Network Log View of the Network panel. An action that copies data to the
398 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
399 * sensitive data from the network requests. 'all' refers to every network request that is currently
400 * shown (after applying the Network filter).
401 */
402 copyAllListedAsHarSanitized: 'Copy all listed as `HAR` (sanitized)',
403 /**
404 * @description Text in Network Log View of the Network panel. An action that copies data to the
405 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
406 * sensitive data from the network requests. 'all' refers to every network request that is currently
407 * shown (after applying the Network filter).
408 */
409 copyAllListedAsHarWithSensitiveData: 'Copy all listed as `HAR` (with sensitive data)',
Yang Guo6d1361f2024-07-11 08:23:48410 /**
Jack Franklinfd72c072022-12-21 11:45:01411 *@description A context menu item in the Network Log View of the Network panel
412 */
Christy Chencac3f102021-02-03 10:07:55413 clearBrowserCache: 'Clear browser cache',
414 /**
Jack Franklinfd72c072022-12-21 11:45:01415 *@description A context menu item in the Network Log View of the Network panel
416 */
Christy Chencac3f102021-02-03 10:07:55417 clearBrowserCookies: 'Clear browser cookies',
418 /**
Jack Franklinfd72c072022-12-21 11:45:01419 *@description A context menu item in the Network Log View of the Network panel
420 */
Christy Chencac3f102021-02-03 10:07:55421 blockRequestUrl: 'Block request URL',
422 /**
Jack Franklinfd72c072022-12-21 11:45:01423 *@description A context menu item in the Network Log View of the Network panel
424 *@example {example.com} PH1
425 */
Christy Chencac3f102021-02-03 10:07:55426 unblockS: 'Unblock {PH1}',
427 /**
Jack Franklinfd72c072022-12-21 11:45:01428 *@description A context menu item in the Network Log View of the Network panel
429 */
Christy Chencac3f102021-02-03 10:07:55430 blockRequestDomain: 'Block request domain',
431 /**
Jack Franklinfd72c072022-12-21 11:45:01432 *@description Text to replay an XHR request
433 */
Christy Chencac3f102021-02-03 10:07:55434 replayXhr: 'Replay XHR',
435 /**
Jack Franklinfd72c072022-12-21 11:45:01436 *@description Text in Network Log View of the Network panel
437 */
Christy Chencac3f102021-02-03 10:07:55438 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
439 /**
Jack Franklinfd72c072022-12-21 11:45:01440 *@description Text in Network Log View of the Network panel
441 */
Christy Chencac3f102021-02-03 10:07:55442 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37443 /**
Jack Franklinfd72c072022-12-21 11:45:01444 *@description A context menu item in the Network Log View of the Network panel
445 * for creating a header override
446 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41447 overrideHeaders: 'Override headers',
Silvia Eremia096e1202023-09-22 15:49:17448 /**
449 * @description Tooltip for the Show only/Hide requests dropdown of the filterbar
450 */
451 showOnlyHideRequests: 'Show only/hide requests',
452 /**
453 * @description Text for the Show only/Hide requests dropdown button of the filterbar
454 */
455 moreFilters: 'More filters',
Christy Chencac3f102021-02-03 10:07:55456};
Tim van der Lippef596ca02021-03-31 10:02:47457const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55458const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46459
460const enum FetchStyle {
Benedikt Meurer61b7a002024-09-04 08:02:31461 BROWSER = 0,
462 NODE_JS = 1,
Danil Somsikov59f4c612021-09-08 10:58:46463}
464
Simon Zünd940cb1f2021-09-16 11:46:09465export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
466 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53467 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
468 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
ioana forfota45b44152023-07-21 14:20:53469 private readonly networkHideChromeExtensions: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04470 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53471 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
472 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
473 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
Benedikt Meureracd96a62024-09-10 07:25:24474 private readonly networkShowOptionsToGenerateHarWithSensitiveData: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53475 private rawRowHeight: number;
476 private readonly progressBarContainer: Element;
477 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
478 private rowHeightInternal: number;
479 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
480 private readonly durationCalculator: NetworkTransferDurationCalculator;
481 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30482 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53483 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
484 private mainRequestLoadTime: number;
485 private mainRequestDOMContentLoadedTime: number;
486 private filters: Filter[];
487 private timeFilter: Filter|null;
488 private hoveredNodeInternal: NetworkNode|null;
489 private recordingHint: Element|null;
Jack Franklin28577db2021-10-14 08:12:53490 private highlightedNode: NetworkRequestNode|null;
491 private readonly linkifierInternal: Components.Linkifier.Linkifier;
492 private recording: boolean;
493 private needsRefresh: boolean;
494 private readonly headerHeightInternal: number;
495 private readonly groupLookups: Map<string, GroupLookupInterface>;
496 private activeGroupLookup: GroupLookupInterface|null;
497 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
498 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
Silvia Eremia096e1202023-09-22 15:49:17499 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
500 private readonly moreFiltersDropDownUI: MoreFiltersDropDownUI|undefined;
501 private readonly onlyBlockedResponseCookiesFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
502 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI|undefined;
503 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
504 private readonly hideChromeExtensionsUI: UI.FilterBar.CheckboxFilterUI|undefined;
Kateryna Prokopenko24c28f92024-08-30 15:09:28505 private readonly resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
Jack Franklin28577db2021-10-14 08:12:53506 private readonly filterParser: TextUtils.TextUtils.FilterParser;
507 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
508 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50509 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53510 private readonly filterBar: UI.FilterBar.FilterBar;
511 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38512
513 constructor(
514 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
515 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37516 super();
517 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37518
519 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05520 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37521
Danil Somsikov74217e92024-01-30 07:01:12522 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('network-invert-filter', false);
523 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
ioana forfota45b44152023-07-21 14:20:53524 this.networkHideChromeExtensions =
Danil Somsikov74217e92024-01-30 07:01:12525 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04526 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:12527 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Jack Franklin28577db2021-10-14 08:12:53528 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:12529 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Jack Franklin28577db2021-10-14 08:12:53530 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:12531 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Jack Franklin28577db2021-10-14 08:12:53532 this.networkResourceTypeFiltersSetting =
Danil Somsikov74217e92024-01-30 07:01:12533 Common.Settings.Settings.instance().createSetting('network-resource-type-filters', {});
Benedikt Meureracd96a62024-09-10 07:25:24534 this.networkShowOptionsToGenerateHarWithSensitiveData = Common.Settings.Settings.instance().createSetting(
535 'network.show-options-to-generate-har-with-sensitive-data', false);
Blink Reformat4c46d092018-04-07 15:32:37536
Jack Franklin28577db2021-10-14 08:12:53537 this.rawRowHeight = 0;
538 this.progressBarContainer = progressBarContainer;
539 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
540 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37541
Jan Schefflerd6c1d402021-02-26 16:56:38542 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53543 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
544 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37545 }
Jack Franklin28577db2021-10-14 08:12:53546 this.rawRowHeight = 0;
547 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37548 updateRowHeight.call(this);
549
Jack Franklin28577db2021-10-14 08:12:53550 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
551 this.durationCalculator = new NetworkTransferDurationCalculator();
552 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37553
Danil Somsikov2a4c4e02022-10-07 12:31:30554 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53555 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30556 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37557
Jack Franklin28577db2021-10-14 08:12:53558 this.staleRequests = new Set();
559 this.mainRequestLoadTime = -1;
560 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37561
Jack Franklin28577db2021-10-14 08:12:53562 this.filters = [];
563 this.timeFilter = null;
564 this.hoveredNodeInternal = null;
565 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53566 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37567
Jack Franklin28577db2021-10-14 08:12:53568 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37569
Jack Franklin28577db2021-10-14 08:12:53570 this.recording = false;
571 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37572
Jack Franklin28577db2021-10-14 08:12:53573 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37574
Jack Franklin28577db2021-10-14 08:12:53575 this.groupLookups = new Map();
576 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37577
Jack Franklin28577db2021-10-14 08:12:53578 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37579
Jack Franklin28577db2021-10-14 08:12:53580 this.textFilterUI = new UI.FilterBar.TextFilterUI();
Benedikt Meurerf08ab4a2024-09-03 09:37:35581 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
Jack Franklin28577db2021-10-14 08:12:53582 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37583
Jack Franklin28577db2021-10-14 08:12:53584 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyercda33c92023-12-21 16:04:32585 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting, 'invert-filter');
Jack Franklin28577db2021-10-14 08:12:53586 this.invertFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35587 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53588 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
589 filterBar.addFilter(this.invertFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00590 filterBar.addDivider();
Victor Porof66878d62021-07-16 13:12:37591
Blink Reformat4c46d092018-04-07 15:32:37592 const filterItems =
Danil Somsikovf90908e2024-02-29 15:40:36593 Object.entries(Common.ResourceType.resourceCategories).map(([key, category]) => ({
Simon Zünd9112a772024-10-17 07:02:51594 name: category.name,
Danil Somsikovf90908e2024-02-29 15:40:36595 label: () => category.shortTitle(),
596 title: category.title(),
597 jslogContext:
598 Platform.StringUtilities.toKebabCase(key),
599 }));
ioana forfota2c72e132023-09-22 12:11:48600
601 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
Kateryna Prokopenko24c28f92024-08-30 15:09:28602 this.moreFiltersDropDownUI = new MoreFiltersDropDownUI();
Benedikt Meurerf08ab4a2024-09-03 09:37:35603 this.moreFiltersDropDownUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
Kateryna Prokopenko24c28f92024-08-30 15:09:28604 filterBar.addFilter(this.moreFiltersDropDownUI);
605
606 this.resourceCategoryFilterUI =
607 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17608 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
609 this.resourceCategoryFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35610 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17611 filterBar.addFilter(this.resourceCategoryFilterUI);
ioana forfota2c72e132023-09-22 12:11:48612 } else {
Silvia Eremia096e1202023-09-22 15:49:17613 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20614 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting, 'hide-data-urls');
Silvia Eremia096e1202023-09-22 15:49:17615 this.dataURLFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35616 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17617 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
618 filterBar.addFilter(this.dataURLFilterUI);
619
620 this.hideChromeExtensionsUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20621 'chrome-extension', i18nString(UIStrings.chromeExtensions), true, this.networkHideChromeExtensions,
622 'hide-extension-urls');
Silvia Eremia096e1202023-09-22 15:49:17623 this.hideChromeExtensionsUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35624 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17625 UI.Tooltip.Tooltip.install(this.hideChromeExtensionsUI.element(), i18nString(UIStrings.hideChromeExtension));
626 filterBar.addFilter(this.hideChromeExtensionsUI);
627
ioana forfota2c72e132023-09-22 12:11:48628 this.resourceCategoryFilterUI =
629 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17630 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
631 this.resourceCategoryFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35632 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17633 filterBar.addFilter(this.resourceCategoryFilterUI);
634
635 this.onlyBlockedResponseCookiesFilterUI = new UI.FilterBar.CheckboxFilterUI(
636 'only-show-blocked-cookies', i18nString(UIStrings.hasBlockedCookies), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20637 this.networkShowBlockedCookiesOnlySetting, 'only-show-blocked-cookies');
Silvia Eremia096e1202023-09-22 15:49:17638 this.onlyBlockedResponseCookiesFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35639 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17640 UI.Tooltip.Tooltip.install(
641 this.onlyBlockedResponseCookiesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
642 filterBar.addFilter(this.onlyBlockedResponseCookiesFilterUI);
643
644 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
645 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20646 this.networkOnlyBlockedRequestsSetting, 'only-show-blocked-requests');
Silvia Eremia096e1202023-09-22 15:49:17647 this.onlyBlockedRequestsUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35648 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17649 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
650 filterBar.addFilter(this.onlyBlockedRequestsUI);
651
652 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20653 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting,
654 'only-show-third-party');
Silvia Eremia096e1202023-09-22 15:49:17655 this.onlyThirdPartyFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35656 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17657 UI.Tooltip.Tooltip.install(
658 this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
659 filterBar.addFilter(this.onlyThirdPartyFilterUI);
ioana forfota2c72e132023-09-22 12:11:48660 }
Danil Somsikov721956a2021-07-07 08:17:27661
Jack Franklin28577db2021-10-14 08:12:53662 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
663 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38664 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
665 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37666
Danil Somsikov2a4c4e02022-10-07 12:31:30667 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38668 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30669 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49670 filterBar.filterButton().addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35671 UI.Toolbar.ToolbarButton.Events.CLICK, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37672
Benedikt Meurer918a8212025-01-09 08:47:08673 this.summaryToolbarInternal = this.element.createChild('devtools-toolbar', 'network-summary-bar');
674 this.summaryToolbarInternal.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37675
Tim van der Lippe0ed1d2b2020-02-04 13:45:13676 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38677 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37678
Paul Lewis2d7d65c2020-03-16 17:26:30679 Common.Settings.Settings.instance()
Danil Somsikov74217e92024-01-30 07:01:12680 .moduleSetting('network-color-code-resource-types')
Jan Scheffler17b8fb42021-08-12 12:28:38681 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37682
Danil Somsikov62bc5782023-03-21 10:48:50683 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27684 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38685 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27686 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38687 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
Wolfgang Beyer51f2f252023-07-27 17:09:51688 Logs.NetworkLog.NetworkLog.instance().addEventListener(
689 Logs.NetworkLog.Events.RequestRemoved, this.onRequestRemoved, this);
Jan Scheffler17b8fb42021-08-12 12:28:38690 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37691
Jan Scheffler17b8fb42021-08-12 12:28:38692 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30693 Common.Settings.Settings.instance()
694 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38695 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37696
Jack Franklin28577db2021-10-14 08:12:53697 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03698
Danil Somsikov74217e92024-01-30 07:01:12699 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('network-text-filter', '');
Jack Franklin28577db2021-10-14 08:12:53700 if (this.textFilterSetting.get()) {
701 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03702 }
Blink Reformat4c46d092018-04-07 15:32:37703 }
704
Silvia Eremia096e1202023-09-22 15:49:17705 getMoreFiltersDropdown(): MoreFiltersDropDownUI|undefined {
706 return this.moreFiltersDropDownUI;
707 }
708
Jan Scheffler17b8fb42021-08-12 12:28:38709 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30710 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38711 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37712 }
713
Jan Scheffler17b8fb42021-08-12 12:28:38714 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16715 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37716 values.sort((a, b) => {
Paul Irisha8a15972024-04-30 15:14:19717 const aPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a);
718 const bPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b);
Tim van der Lippeded23fb2020-02-13 13:33:50719 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
720 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37721 });
722 } else {
723 values.sort();
724 }
725 }
726
Jan Scheffler17b8fb42021-08-12 12:28:38727 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37728 return !filter(request);
729 }
730
Jan Scheffler17b8fb42021-08-12 12:28:38731 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34732 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37733 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34734 }
Blink Reformat4c46d092018-04-07 15:32:37735
736 return regex.test(request.path() + '/' + request.name());
737 }
738
Jan Scheffler17b8fb42021-08-12 12:28:38739 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37740 const result = [domain];
741 let indexOfPeriod = domain.indexOf('.');
742 while (indexOfPeriod !== -1) {
743 result.push('*' + domain.substring(indexOfPeriod));
744 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
745 }
746 return result;
747 }
748
Jan Scheffler17b8fb42021-08-12 12:28:38749 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17750 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38751 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37752 }
753
Jan Scheffler17b8fb42021-08-12 12:28:38754 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37755 return regex.test(request.domain);
756 }
757
Jan Scheffler17b8fb42021-08-12 12:28:38758 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37759 return !request.finished;
760 }
761
Jan Scheffler17b8fb42021-08-12 12:28:38762 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37763 return request.cached();
764 }
765
Jan Scheffler17b8fb42021-08-12 12:28:38766 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05767 return request.fetchedViaServiceWorker;
768 }
769
Jan Scheffler17b8fb42021-08-12 12:28:38770 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05771 return request.initiatedByServiceWorker();
772 }
773
Jan Scheffler17b8fb42021-08-12 12:28:38774 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37775 return request.responseHeaderValue(value) !== undefined;
776 }
777
Jan Scheffler17b8fb42021-08-12 12:28:38778 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
779 boolean {
Jack Franklin28577db2021-10-14 08:12:53780 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51781 // filter via `includes` instead of strict equality.
782 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
783 }
784
Jan Scheffler17b8fb42021-08-12 12:28:38785 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37786 return request.requestMethod === value;
787 }
788
Jan Scheffler17b8fb42021-08-12 12:28:38789 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37790 return request.priority() === value;
791 }
792
Jan Scheffler17b8fb42021-08-12 12:28:38793 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37794 return request.mimeType === value;
795 }
796
Jan Scheffler17b8fb42021-08-12 12:28:38797 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16798 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
Benedikt Meurer61b7a002024-09-04 08:02:31799 if (value === NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED) {
Blink Reformat4c46d092018-04-07 15:32:37800 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28801 }
Benedikt Meurer61b7a002024-09-04 08:02:31802 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED) {
Blink Reformat4c46d092018-04-07 15:32:37803 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28804 }
Benedikt Meurer61b7a002024-09-04 08:02:31805 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN) {
Blink Reformat4c46d092018-04-07 15:32:37806 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28807 }
Benedikt Meurer61b7a002024-09-04 08:02:31808 if (value === NetworkForward.UIFilter.MixedContentFilterValues.ALL) {
Blink Reformat4c46d092018-04-07 15:32:37809 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34810 }
Blink Reformat4c46d092018-04-07 15:32:37811
812 return false;
813 }
814
Jan Scheffler17b8fb42021-08-12 12:28:38815 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37816 return request.scheme === value;
817 }
818
Jan Scheffler17b8fb42021-08-12 12:28:38819 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41820 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
821 }
822
Jan Scheffler17b8fb42021-08-12 12:28:38823 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41824 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
825 }
826
Jan Scheffler17b8fb42021-08-12 12:28:38827 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54828 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
829 }
830
Jan Scheffler17b8fb42021-08-12 12:28:38831 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41832 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
833 }
834
Jan Scheffler17b8fb42021-08-12 12:28:38835 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41836 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37837 }
838
Jan Scheffler17b8fb42021-08-12 12:28:38839 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41840 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37841 }
842
Jan Scheffler17b8fb42021-08-12 12:28:38843 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41844 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37845 }
846
Jan Scheffler17b8fb42021-08-12 12:28:38847 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37848 return request.transferSize >= value;
849 }
850
Jan Scheffler17b8fb42021-08-12 12:28:38851 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24852 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37853 }
854
Jecelyn Yeen77c83462023-08-16 16:13:17855 private static hasOverridesFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
856 if (!value) {
857 return false;
858 }
859
860 if (value === overrideFilter.no) {
861 return request.overrideTypes.length === 0;
862 }
863
864 if (value === overrideFilter.yes) {
865 return request.overrideTypes.length > 0;
866 }
867
868 if (value === overrideFilter.content) {
869 return request.overrideTypes.includes('content');
870 }
871
872 if (value === overrideFilter.headers) {
873 return request.overrideTypes.includes('headers');
874 }
875
876 return request.overrideTypes.join(',').includes(value);
877 }
878
Sigurd Schneider576ca9a2021-07-16 05:58:04879 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58880 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37881 }
882
Jan Scheffler17b8fb42021-08-12 12:28:38883 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03884 return request.resourceType().name() === value;
885 }
886
Jan Scheffler17b8fb42021-08-12 12:28:38887 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17888 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03889 return regex.test(request.url());
890 }
891
Jan Scheffler17b8fb42021-08-12 12:28:38892 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38893 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34894 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37895 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34896 }
897 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37898 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34899 }
Blink Reformat4c46d092018-04-07 15:32:37900 return true;
901 }
902
Jan Scheffler17b8fb42021-08-12 12:28:38903 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13904 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37905 }
906
Jan Scheffler17b8fb42021-08-12 12:28:38907 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13908 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37909 }
910
Jan Scheffler17b8fb42021-08-12 12:28:38911 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Simon Zünd0d87db62024-05-27 07:26:27912 const contentData = await request.requestContentData();
Simon Zünd3b583882023-12-22 05:23:43913 let content: string;
Simon Zünd7fb55c02024-01-29 12:00:27914 if (TextUtils.ContentData.ContentData.isError(contentData)) {
Simon Zünd3b583882023-12-22 05:23:43915 content = '';
Simon Zündebe01922024-01-18 10:11:58916 } else if (!contentData.isTextContent) {
Simon Zünd3b583882023-12-22 05:23:43917 content = contentData.asDataUrl() ?? '';
918 } else {
919 content = contentData.text;
Tim van der Lippe1d6e57a2019-09-30 11:55:34920 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13921 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37922 }
923
Jan Scheffler17b8fb42021-08-12 12:28:38924 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37925 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34926 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37927 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34928 }
Simon Zünd99961242021-09-08 11:02:12929 const file = items[0].getAsFile();
930 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03931 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34932 }
Blink Reformat4c46d092018-04-07 15:32:37933 }
934
Jan Schefflerd6c1d402021-02-26 16:56:38935 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13936 const outputStream = new Common.StringOutputStream.StringOutputStream();
937 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37938 const success = await reader.read(outputStream);
939 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37940 const error = reader.error();
941 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38942 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37943 }
Blink Reformat4c46d092018-04-07 15:32:37944 return;
945 }
946 let harRoot;
947 try {
948 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56949 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37950 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38951 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37952 return;
953 }
Tim van der Lippe09cf5032021-04-29 15:08:09954 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37955 }
956
Jan Scheffler17b8fb42021-08-12 12:28:38957 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36958 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37959 }
960
Jan Scheffler17b8fb42021-08-12 12:28:38961 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53962 if (this.activeGroupLookup) {
963 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34964 }
Jack Franklin28577db2021-10-14 08:12:53965 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
966 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38967 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37968 }
969
Jan Scheffler17b8fb42021-08-12 12:28:38970 private computeRowHeight(): number {
Benedikt Meurera0d809e2024-02-28 14:20:54971 return this.rawRowHeight;
Blink Reformat4c46d092018-04-07 15:32:37972 }
973
Jan Schefflerd6c1d402021-02-26 16:56:38974 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37975 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37976 }
977
Jan Schefflerd6c1d402021-02-26 16:56:38978 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53979 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37980 }
981
Jan Schefflerd6c1d402021-02-26 16:56:38982 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53983 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38984 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37985 }
986
Danil Somsikov2a4c4e02022-10-07 12:31:30987 columns(): NetworkLogViewColumns {
988 return this.columnsInternal;
989 }
990
Wolfgang Beyer8fc262f2023-04-11 13:22:50991 summaryToolbar(): UI.Toolbar.Toolbar {
992 return this.summaryToolbarInternal;
993 }
994
Jan Schefflerd6c1d402021-02-26 16:56:38995 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37996 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22997 const target = networkManager.target();
998 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37999 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341000 }
Danil Somsikov88384322023-03-22 13:53:221001 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:371002 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:381003 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:371004 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:381005 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:371006 }
Danil Somsikov88384322023-03-22 13:53:221007 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:041008 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:251009 this.refreshRequest(request);
1010 }
Danil Somsikov88384322023-03-22 13:53:221011 }
Blink Reformat4c46d092018-04-07 15:32:371012 }
1013
Jan Schefflerd6c1d402021-02-26 16:56:381014 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:221015 const target = networkManager.target();
1016 if (target.outermostTarget() !== target) {
1017 return;
1018 }
1019 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
1020 if (resourceTreeModel) {
1021 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
1022 resourceTreeModel.removeEventListener(
1023 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
1024 }
Danil Somsikovac291c82024-01-30 13:47:461025 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network-log.preserve-log').get();
Danil Somsikov88384322023-03-22 13:53:221026 if (!preserveLog) {
1027 this.reset();
Blink Reformat4c46d092018-04-07 15:32:371028 }
1029 }
1030
Jan Schefflerd6c1d402021-02-26 16:56:381031 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:531032 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:131033 }
1034
Jan Schefflerd6c1d402021-02-26 16:56:381035 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:371036 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:531037 this.timeFilter = null;
1038 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:371039 } else {
Jack Franklin28577db2021-10-14 08:12:531040 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
1041 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:371042 }
Jan Scheffler17b8fb42021-08-12 12:28:381043 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:371044 }
1045
Jan Schefflerd6c1d402021-02-26 16:56:381046 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531047 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:371048 }
1049
Jan Scheffler17b8fb42021-08-12 12:28:381050 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:531051 this.suggestionBuilder.clear();
Benedikt Meurer61b7a002024-09-04 08:02:311052 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.RUNNING);
Jack Franklin28577db2021-10-14 08:12:531053 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311054 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FROM_CACHE);
Jack Franklin28577db2021-10-14 08:12:531055 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311056 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED);
Jack Franklin28577db2021-10-14 08:12:531057 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311058 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED);
Jack Franklin28577db2021-10-14 08:12:531059 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
1060 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
1061 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
1062 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Jecelyn Yeen77c83462023-08-16 16:13:171063 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.yes);
1064 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.no);
1065 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.content);
1066 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.headers);
Blink Reformat4c46d092018-04-07 15:32:371067 }
1068
Simon Zünda2bae2e2021-09-16 07:57:131069 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371070 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:531071 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:381072 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:531073 this.textFilterSetting.set(this.textFilterUI.value());
Kateryna Prokopenkod98e34c2023-09-25 18:08:481074 this.moreFiltersDropDownUI?.updateActiveFiltersCount();
Kateryna Prokopenko5f434d42023-11-03 10:57:491075 this.moreFiltersDropDownUI?.updateTooltip();
Blink Reformat4c46d092018-04-07 15:32:371076 }
1077
Jan Schefflerd6c1d402021-02-26 16:56:381078 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:531079 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:121080 }
1081
Jan Scheffler17b8fb42021-08-12 12:28:381082 private showRecordingHint(): void {
1083 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:531084 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
1085 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:181086
Jack Franklin28577db2021-10-14 08:12:531087 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:381088 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:041089 const reloadShortcut =
Benedikt Meurere0b4b922024-01-15 13:33:531090 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector-main.reload')[0];
Wolfgang Beyer5c385b92020-11-09 15:20:041091 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:531092 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:041093 reloadShortcutNode.textContent = reloadShortcut.title();
1094 }
1095
Blink Reformat4c46d092018-04-07 15:32:371096 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:551097 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:181098 if (reloadShortcutNode) {
1099 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:551100 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
1101 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:181102 }
Blink Reformat4c46d092018-04-07 15:32:371103 } else {
1104 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:171105 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:371106 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:551107 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:411108 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:371109 }
Kayce Basques5444c1b2019-02-15 20:32:531110 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:131111 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:351112 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Kateryna Prokopenko1a4e2612023-12-21 13:23:451113 i18nString(UIStrings.learnMore), undefined, undefined, 'learn-more'));
Amanda Baker6761aae2019-11-05 18:59:111114
Jan Scheffler17b8fb42021-08-12 12:28:381115 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:371116 }
1117
Jan Scheffler17b8fb42021-08-12 12:28:381118 private hideRecordingHint(): void {
1119 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:531120 if (this.recordingHint) {
1121 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:341122 }
Michael Liao7322dee2021-04-07 18:33:301123 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:531124 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:371125 }
1126
Jan Scheffler17b8fb42021-08-12 12:28:381127 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301128 this.columnsInternal.setHidden(value);
Benedikt Meurer918a8212025-01-09 08:47:081129 UI.ARIAUtils.setHidden(this.summaryToolbarInternal, value);
Amanda Baker6761aae2019-11-05 18:59:111130 }
1131
Randolf Jungffd14242023-04-19 00:32:251132 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:531133 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:341134 {
Blink Reformat4c46d092018-04-07 15:32:371135 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:341136 }
Jack Franklin28577db2021-10-14 08:12:531137 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:371138 }
1139
Jan Schefflerd6c1d402021-02-26 16:56:381140 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381141 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:371142 }
1143
Jan Scheffler17b8fb42021-08-12 12:28:381144 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:531145 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:381146 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341147 if (request) {
Blink Reformat4c46d092018-04-07 15:32:371148 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341149 }
Blink Reformat4c46d092018-04-07 15:32:371150 });
Paul Irishf2ff58b2024-11-06 23:52:001151 this.dataGrid.setEnableAutoScrollToBottom(true);
Danil Somsikova6ce6ed2024-01-31 08:10:121152 this.dataGrid.setName('network-log');
Benedikt Meurerf08ab4a2024-09-03 09:37:351153 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.LAST);
Jack Franklin28577db2021-10-14 08:12:531154 this.dataGrid.element.classList.add('network-log-grid');
1155 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
1156 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
1157 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
1158 this.dataGrid.element.addEventListener('keydown', event => {
1159 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
Danil Somsikove10a94c2024-03-11 08:31:321160 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('button.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:431161 if (initiatorLink) {
1162 (initiatorLink as HTMLElement).focus();
1163 }
1164 }
ergunshee4a6132021-11-05 16:21:251165
Jack Franklin5e685be2022-10-17 14:27:091166 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051167 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051168 event.consume(true);
1169 }
1170 });
ergunshee4a6132021-11-05 16:21:251171 this.dataGrid.element.addEventListener('keyup', event => {
1172 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1173 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1174 if (!request) {
1175 return;
1176 }
1177
1178 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1179 SDK.NetworkManager.NetworkManager.replayRequest(request);
Danil Somsikov1a4a3322024-03-11 16:27:271180 void VisualLogging.logKeyDown(this.dataGrid.selectedNode.element(), event, 'replay-xhr');
ergunshee4a6132021-11-05 16:21:251181 }
1182 }
1183 });
Jack Franklin28577db2021-10-14 08:12:531184 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1185 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1186 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371187 }
1188
Jan Scheffler17b8fb42021-08-12 12:28:381189 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381190 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531191 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371192 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381193 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371194 }
1195
Jan Schefflerd6c1d402021-02-26 16:56:381196 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531197 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371198 }
1199
Jan Scheffler17b8fb42021-08-12 12:28:381200 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531201 if (this.hoveredNodeInternal) {
1202 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341203 }
Jack Franklin28577db2021-10-14 08:12:531204 this.hoveredNodeInternal = node;
1205 if (this.hoveredNodeInternal) {
1206 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 }
Blink Reformat4c46d092018-04-07 15:32:371208 }
1209
Jan Scheffler17b8fb42021-08-12 12:28:381210 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381211 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531212 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371213 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341214 }
Blink Reformat4c46d092018-04-07 15:32:371215 }
1216
Jan Scheffler17b8fb42021-08-12 12:28:381217 private updateSummaryBar(): void {
1218 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371219
1220 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201221 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371222 let selectedNodeNumber = 0;
1223 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201224 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371225 let baseTime = -1;
1226 let maxTime = -1;
1227
1228 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271229 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371230 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341231 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371232 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341233 }
Blink Reformat4c46d092018-04-07 15:32:371234 nodeCount++;
1235 const requestTransferSize = request.transferSize;
1236 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201237 const requestResourceSize = request.resourceSize;
1238 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371239 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371240 selectedNodeNumber++;
1241 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201242 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371243 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131244 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371245 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1246 // inspected url.
1247 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131248 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Benedikt Meurerb7d85042024-08-23 13:38:321249 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.FRAME) {
Adithya Srinivasan77770382024-05-17 20:22:091250 // If the primary main frame's document was fetched from the prefetch cache,
1251 // we should use the issueTime (i.e. when the navigation request was about to start)
1252 // instead of startTime, which is when the prefetch network request started
1253 // (which is typically well before the navigation starts).
1254 baseTime = request.fromPrefetchCache() ? request.issueTime() : request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341255 }
1256 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371257 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341258 }
Blink Reformat4c46d092018-04-07 15:32:371259 }
1260
1261 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381262 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371263 return;
1264 }
1265
Wolfgang Beyer8fc262f2023-04-11 13:22:501266 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381267 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131268 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501269 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501270 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381271 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501272 };
Blink Reformat4c46d092018-04-07 15:32:371273
1274 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551275 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501276 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501277 appendChunk(
Christy Chencac3f102021-02-03 10:07:551278 i18nString(UIStrings.sSTransferred, {
Connor Clarkcc5008a2024-11-08 23:17:001279 PH1: i18n.ByteUtilities.bytesToString(selectedTransferSize),
1280 PH2: i18n.ByteUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551281 }),
1282 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501283 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501284 appendChunk(
Christy Chencac3f102021-02-03 10:07:551285 i18nString(UIStrings.sSResources, {
Connor Clarkcc5008a2024-11-08 23:17:001286 PH1: i18n.ByteUtilities.bytesToString(selectedResourceSize),
1287 PH2: i18n.ByteUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551288 }),
1289 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371290 } else {
Christy Chencac3f102021-02-03 10:07:551291 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501292 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251293 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001294 i18nString(UIStrings.sTransferred, {PH1: i18n.ByteUtilities.bytesToString(transferSize)}),
Christy Chencac3f102021-02-03 10:07:551295 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501296 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251297 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001298 i18nString(UIStrings.sResources, {PH1: i18n.ByteUtilities.bytesToString(resourceSize)}),
Christy Chencac3f102021-02-03 10:07:551299 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371300 }
Dan Beam87466b52018-12-01 18:41:201301
Blink Reformat4c46d092018-04-07 15:32:371302 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501303 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581304 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531305 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501306 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551307 const domContentLoadedText = i18nString(
1308 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531309 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381310 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371311 }
Jack Franklin28577db2021-10-14 08:12:531312 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501313 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531314 const loadText =
1315 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381316 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371317 }
1318 }
Blink Reformat4c46d092018-04-07 15:32:371319 }
1320
Jan Schefflerd6c1d402021-02-26 16:56:381321 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531322 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371323 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341324 }
Blink Reformat4c46d092018-04-07 15:32:371325
Jack Franklin28577db2021-10-14 08:12:531326 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371327
Danil Somsikovf3b437f2023-03-23 16:15:391328 if (this.isShowing()) {
Benedikt Meurer328b3a72025-01-02 10:38:551329 void RenderCoordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341330 }
Blink Reformat4c46d092018-04-07 15:32:371331 }
1332
Jan Schefflerd6c1d402021-02-26 16:56:381333 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301334 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371335 }
1336
Jan Schefflerd6c1d402021-02-26 16:56:381337 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301338 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371339 }
1340
Jan Schefflerd6c1d402021-02-26 16:56:381341 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301342 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371343 }
1344
Jan Scheffler17b8fb42021-08-12 12:28:381345 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531346 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381347 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341348 }
Blink Reformat4c46d092018-04-07 15:32:371349 }
1350
Jan Scheffler17b8fb42021-08-12 12:28:381351 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041352 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341353 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371354 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341355 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381356 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341357 }
Blink Reformat4c46d092018-04-07 15:32:371358 }
1359
Jan Schefflerd6c1d402021-02-26 16:56:381360 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531361 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371362 }
1363
Jan Schefflerd6c1d402021-02-26 16:56:381364 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531365 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371366 }
1367
Jan Schefflerd6c1d402021-02-26 16:56:381368 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531369 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371370 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341371 }
Blink Reformat4c46d092018-04-07 15:32:371372
Jack Franklin28577db2021-10-14 08:12:531373 if (this.calculatorInternal !== x) {
1374 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301375 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371376 }
Jack Franklin28577db2021-10-14 08:12:531377 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371378
Jack Franklin28577db2021-10-14 08:12:531379 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301380 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341381 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301382 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341383 }
Blink Reformat4c46d092018-04-07 15:32:371384
Jan Scheffler17b8fb42021-08-12 12:28:381385 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371386 }
1387
Jan Scheffler17b8fb42021-08-12 12:28:381388 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271389 event: Common.EventTarget
1390 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531391 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371392 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341393 }
Blink Reformat4c46d092018-04-07 15:32:371394
Simon Zünd1a930492021-07-30 08:22:271395 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371396 if (time) {
Jack Franklin28577db2021-10-14 08:12:531397 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301398 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371399 }
1400 }
1401
Jan Scheffler17b8fb42021-08-12 12:28:381402 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531403 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371404 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341405 }
Simon Zünd1a930492021-07-30 08:22:271406 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371407 if (data) {
Jack Franklin28577db2021-10-14 08:12:531408 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301409 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371410 }
1411 }
1412
Randolf Jungffd14242023-04-19 00:32:251413 override wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381414 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301415 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301416 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371417 }
1418
Randolf Jungffd14242023-04-19 00:32:251419 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301420 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371421 }
1422
Randolf Jungffd14242023-04-19 00:32:251423 override onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531424 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371425 }
1426
Jan Schefflerd6c1d402021-02-26 16:56:381427 flatNodesList(): NetworkNode[] {
1428 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531429 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381430 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1431 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371432 }
1433
Jan Scheffler17b8fb42021-08-12 12:28:381434 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531435 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351436 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381437 }
Brandon Goddard44934902020-03-25 16:03:181438 this.updateNodeBackground();
1439 }
1440
Jan Scheffler17b8fb42021-08-12 12:28:381441 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181442 this.element.classList.remove('grid-focused');
1443 this.updateNodeBackground();
1444 }
1445
Jan Schefflerd6c1d402021-02-26 16:56:381446 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531447 if (this.dataGrid.selectedNode) {
1448 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051449 }
1450 }
1451
Jan Schefflerd6c1d402021-02-26 16:56:381452 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051453 if (isSelected) {
1454 this.element.classList.remove('no-node-selected');
1455 } else {
1456 this.element.classList.add('no-node-selected');
1457 }
1458 }
1459
Jan Schefflerd6c1d402021-02-26 16:56:381460 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301461 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371462 }
1463
Wolfgang Beyer51f2f252023-07-27 17:09:511464 private removeNodeAndMaybeAncestors(node: NetworkRequestNode): void {
1465 let parent: NetworkNode|
1466 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1467 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1468 null) = node.parent;
1469 if (!parent) {
1470 return;
1471 }
1472 parent.removeChild(node);
1473 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1474 const grandparent = (parent.parent as NetworkNode);
1475 grandparent.removeChild(parent);
1476 parent = grandparent;
1477 }
1478 }
1479
Jan Scheffler17b8fb42021-08-12 12:28:381480 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531481 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371482
Blink Reformat4c46d092018-04-07 15:32:371483 this.removeAllNodeHighlights();
1484
Jack Franklin28577db2021-10-14 08:12:531485 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1486 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1487 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1488 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371489
Jan Schefflerd6c1d402021-02-26 16:56:381490 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1491 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371492
Jan Schefflerd6c1d402021-02-26 16:56:381493 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371494
Jack Franklin28577db2021-10-14 08:12:531495 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371496 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531497 while (this.staleRequests.size) {
Simon Zündf0d3b5c2024-10-10 06:28:021498 const request = this.staleRequests.values().next().value as SDK.NetworkRequest.NetworkRequest;
Jack Franklin28577db2021-10-14 08:12:531499 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371500 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341501 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381502 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341503 }
Blink Reformat4c46d092018-04-07 15:32:371504 staleNodes.add(node);
1505 }
1506
1507 for (const node of staleNodes) {
Yang Guo6d1361f2024-07-11 08:23:481508 const request = node.request();
1509 const isFilteredOut = !this.applyFilter(request);
Benedikt Meurere4391232024-06-07 10:47:251510 if (isFilteredOut) {
1511 if (node === this.hoveredNodeInternal) {
1512 this.setHoveredNode(null);
1513 }
1514 node.selected = false;
1515 } else {
Blink Reformat4c46d092018-04-07 15:32:371516 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341517 }
Jack Franklin28577db2021-10-14 08:12:531518 this.timeCalculatorInternal.updateBoundaries(request);
1519 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381520 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371521 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1522 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371523 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341524 }
Tim van der Lippe224a8622020-09-23 12:14:371525 if (isFilteredOut) {
1526 filteredNetworkRequests.add(node);
1527 } else {
1528 filteredNetworkRequests.delete(node);
1529 }
Blink Reformat4c46d092018-04-07 15:32:371530 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1531 if (removeFromParent) {
Wolfgang Beyer51f2f252023-07-27 17:09:511532 this.removeNodeAndMaybeAncestors(node);
Blink Reformat4c46d092018-04-07 15:32:371533 }
1534
Tim van der Lippe1d6e57a2019-09-30 11:55:341535 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371536 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341537 }
Blink Reformat4c46d092018-04-07 15:32:371538
1539 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531540 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371541 nodesToRefresh.push(newParent);
1542 }
1543 nodesToInsert.set(node, newParent);
1544 }
1545
Tim van der Lippe1d6e57a2019-09-30 11:55:341546 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381547 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341548 }
Blink Reformat4c46d092018-04-07 15:32:371549
Tim van der Lippe1d6e57a2019-09-30 11:55:341550 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371551 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341552 }
Blink Reformat4c46d092018-04-07 15:32:371553
Jan Scheffler17b8fb42021-08-12 12:28:381554 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371555
Tim van der Lippe1d6e57a2019-09-30 11:55:341556 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301557 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341558 }
Blink Reformat4c46d092018-04-07 15:32:371559
Jack Franklin28577db2021-10-14 08:12:531560 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381561 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371562 }
1563
Jan Scheffler17b8fb42021-08-12 12:28:381564 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371565 }
1566
Jan Scheffler17b8fb42021-08-12 12:28:381567 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531568 if (!this.activeGroupLookup) {
1569 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341570 }
Blink Reformat4c46d092018-04-07 15:32:371571
Jack Franklin28577db2021-10-14 08:12:531572 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341573 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531574 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341575 }
Blink Reformat4c46d092018-04-07 15:32:371576 return groupNode;
1577 }
1578
Jan Scheffler17b8fb42021-08-12 12:28:381579 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151580 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371581
Jan Scheffler17b8fb42021-08-12 12:28:381582 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301583 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371584
Jack Franklin28577db2021-10-14 08:12:531585 this.timeFilter = null;
1586 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371587
Jack Franklin28577db2021-10-14 08:12:531588 this.timeCalculatorInternal.setWindow(null);
1589 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371590
Jack Franklin28577db2021-10-14 08:12:531591 if (this.activeGroupLookup) {
1592 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341593 }
Jack Franklin28577db2021-10-14 08:12:531594 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381595 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371596
Jack Franklin28577db2021-10-14 08:12:531597 this.mainRequestLoadTime = -1;
1598 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371599
Jack Franklin28577db2021-10-14 08:12:531600 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381601 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371602 this.scheduleRefresh();
1603 }
1604
Silvia Eremia096e1202023-09-22 15:49:171605 // TODO(crbug.com/1477668)
Jan Schefflerd6c1d402021-02-26 16:56:381606 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531607 this.textFilterUI.setValue(filterString);
Silvia Eremia096e1202023-09-22 15:49:171608 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
1609 this.networkHideDataURLSetting.set(false);
1610 this.networkShowBlockedCookiesOnlySetting.set(false);
1611 this.networkOnlyBlockedRequestsSetting.set(false);
1612 this.networkOnlyThirdPartySetting.set(false);
1613 this.networkHideChromeExtensions.set(false);
1614 } else {
1615 this.dataURLFilterUI?.setChecked(false);
1616 this.onlyBlockedResponseCookiesFilterUI?.setChecked(false);
1617 this.onlyBlockedRequestsUI?.setChecked(false);
1618 this.onlyThirdPartyFilterUI?.setChecked(false);
1619 this.hideChromeExtensionsUI?.setChecked(false);
1620 }
Jack Franklin28577db2021-10-14 08:12:531621 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371622 }
1623
Jan Scheffler17b8fb42021-08-12 12:28:381624 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301625 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371626 networkRequestToNode.set(request, node);
1627 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371628
Tim van der Lippe1d6e57a2019-09-30 11:55:341629 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381630 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341631 }
Blink Reformat4c46d092018-04-07 15:32:371632 return node;
1633 }
1634
Danil Somsikov123c3ef2023-06-14 10:07:041635 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1636 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1637 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1638 }
1639
Wolfgang Beyer393dc2b2024-01-05 15:07:401640 private onRequestUpdated(
1641 event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest, preserveLog?: boolean}>):
1642 void {
1643 const {request, preserveLog} = event.data;
1644 if (this.isInScope(request) || preserveLog) {
Danil Somsikova09c4de2023-03-27 10:35:251645 this.refreshRequest(request);
1646 }
Blink Reformat4c46d092018-04-07 15:32:371647 }
1648
Wolfgang Beyer393dc2b2024-01-05 15:07:401649 private onRequestRemoved(event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest}>):
1650 void {
1651 const {request} = event.data;
Wolfgang Beyer51f2f252023-07-27 17:09:511652 this.staleRequests.delete(request);
1653 const node = networkRequestToNode.get(request);
1654 if (node) {
1655 this.removeNodeAndMaybeAncestors(node);
1656 }
1657 }
1658
Jan Scheffler17b8fb42021-08-12 12:28:381659 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1660 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161661 .forEach(
Jack Franklin28577db2021-10-14 08:12:531662 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1663 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1664 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1665 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1666 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1667 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1668 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371669
1670 const priority = request.priority();
1671 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531672 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161673 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371674 }
1675
1676 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531677 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311678 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.ALL);
Blink Reformat4c46d092018-04-07 15:32:371679 }
1680
1681 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531682 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311683 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED);
Blink Reformat4c46d092018-04-07 15:32:371684 }
1685
1686 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Benedikt Meurer61b7a002024-09-04 08:02:311687 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED :
1688 NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN;
Jack Franklin28577db2021-10-14 08:12:531689 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371690 }
1691
1692 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511693 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531694 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511695 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531696 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511697 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341698 }
Jan Scheffler341eea52019-12-12 09:08:411699
1700 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531701 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1702 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1703 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371704 }
1705
Jan Scheffler341eea52019-12-12 09:08:411706 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531707 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1708 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1709 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1710 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411711 }
1712
Jack Franklin28577db2021-10-14 08:12:531713 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371714 this.scheduleRefresh();
1715 }
1716
Jan Schefflerd6c1d402021-02-26 16:56:381717 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531718 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371719 }
1720
Jan Schefflerd6c1d402021-02-26 16:56:381721 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301722 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371723 }
1724
Jan Schefflerd6c1d402021-02-26 16:56:381725 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1726 void {
Blink Reformat4c46d092018-04-07 15:32:371727 contextMenu.appendApplicableItems(request);
Yang Guo6d1361f2024-07-11 08:23:481728 const filtered = this.filterBar.hasActiveFilter();
Danil Somsikov23eacf62024-02-23 08:46:301729 const copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy), false, 'copy');
Blink Reformat4c46d092018-04-07 15:32:371730 if (request) {
Samiya Caurb2be2652024-09-12 05:50:541731 if (UI.ActionRegistry.ActionRegistry.instance().hasAction('drjones.network-panel-context')) {
Samiya Caur7618ee12024-09-20 14:22:221732 UI.Context.Context.instance().setFlavor(SDK.NetworkRequest.NetworkRequest, request);
Samiya Caurb2be2652024-09-12 05:50:541733 contextMenu.headerSection().appendAction(
1734 'drjones.network-panel-context',
1735 );
1736 }
Blink Reformat4c46d092018-04-07 15:32:371737 copyMenu.defaultSection().appendItem(
Benedikt Meurer8f0fee62023-12-27 12:36:511738 i18nString(UIStrings.copyURL),
Tim van der Lippe0ed1d2b2020-02-04 13:45:131739 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
Danil Somsikov23eacf62024-02-23 08:46:301740 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()),
1741 {jslogContext: 'copy-url'});
1742 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261743 filtered ? i18nString(UIStrings.copyAllListedURLs) : i18nString(UIStrings.copyAllURLs),
Yang Guo6d1361f2024-07-11 08:23:481744 this.copyAllURLs.bind(this), {jslogContext: 'copy-all-urls'});
Blink Reformat4c46d092018-04-07 15:32:371745 if (request.requestHeadersText()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511746 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301747 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request),
1748 {jslogContext: 'copy-request-headers'});
Blink Reformat4c46d092018-04-07 15:32:371749 }
1750
1751 if (request.responseHeadersText) {
Benedikt Meurer8f0fee62023-12-27 12:36:511752 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301753 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request),
1754 {jslogContext: 'copy-response-headers'});
Blink Reformat4c46d092018-04-07 15:32:371755 }
1756
1757 if (request.finished) {
Benedikt Meurer8f0fee62023-12-27 12:36:511758 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301759 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request),
1760 {jslogContext: 'copy-response'});
Blink Reformat4c46d092018-04-07 15:32:371761 }
1762
Tim van der Lippeb4faf5a2020-11-06 15:02:021763 const initiator = request.initiator();
1764
1765 if (initiator) {
1766 const stack = initiator.stack;
1767 if (stack) {
1768 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531769 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021770 // any callFrames, but its parent frames do.
1771 const stackTraceText = computeStackTraceText(stack);
1772 if (stackTraceText !== '') {
Benedikt Meurer8f0fee62023-12-27 12:36:511773 copyMenu.saveSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021774 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
Danil Somsikov23eacf62024-02-23 08:46:301775 }, {jslogContext: 'copy-stacktrace'});
Tim van der Lippeb4faf5a2020-11-06 15:02:021776 }
1777 }
1778 }
1779
Harley Libcf41f92018-09-10 18:01:131780 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131781 if (Host.Platform.isWin()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511782 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391783 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'),
Danil Somsikov23eacf62024-02-23 08:46:301784 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511785 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391786 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301787 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-bash'});
Blink Reformat4c46d092018-04-07 15:32:371788 } else {
Benedikt Meurer8f0fee62023-12-27 12:36:511789 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391790 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301791 {disabled: disableIfBlob, jslogContext: 'copy-as-curl'});
Blink Reformat4c46d092018-04-07 15:32:371792 }
Benedikt Meurer8f0fee62023-12-27 12:36:511793 copyMenu.defaultSection().appendItem(
1794 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
Danil Somsikov23eacf62024-02-23 08:46:301795 {disabled: disableIfBlob, jslogContext: 'copy-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511796 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311797 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.BROWSER),
Danil Somsikov23eacf62024-02-23 08:46:301798 {disabled: disableIfBlob, jslogContext: 'copy-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511799 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311800 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NODE_JS),
Danil Somsikov23eacf62024-02-23 08:46:301801 {disabled: disableIfBlob, jslogContext: 'copy-as-nodejs-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511802
1803 if (Host.Platform.isWin()) {
1804 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261805 filtered ? i18nString(UIStrings.copyAllListedAsCurlCmd) : i18nString(UIStrings.copyAllAsCurlCmd),
Yang Guo6d1361f2024-07-11 08:23:481806 this.copyAllCurlCommand.bind(this, 'win'), {jslogContext: 'copy-all-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511807 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261808 filtered ? i18nString(UIStrings.copyAllListedAsCurlBash) : i18nString(UIStrings.copyAllAsCurlBash),
Yang Guo6d1361f2024-07-11 08:23:481809 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl-bash'});
Benedikt Meurer8f0fee62023-12-27 12:36:511810 } else {
1811 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261812 filtered ? i18nString(UIStrings.copyAllListedAsCurl) : i18nString(UIStrings.copyAllAsCurl),
Yang Guo6d1361f2024-07-11 08:23:481813 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl'});
Benedikt Meurer8f0fee62023-12-27 12:36:511814 }
1815 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261816 filtered ? i18nString(UIStrings.copyAllListedAsPowershell) : i18nString(UIStrings.copyAllAsPowershell),
Yang Guo6d1361f2024-07-11 08:23:481817 this.copyAllPowerShellCommand.bind(this), {jslogContext: 'copy-all-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511818 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261819 filtered ? i18nString(UIStrings.copyAllListedAsFetch) : i18nString(UIStrings.copyAllAsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311820 this.copyAllFetchCall.bind(this, FetchStyle.BROWSER), {jslogContext: 'copy-all-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511821 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261822 filtered ? i18nString(UIStrings.copyAllListedAsNodejsFetch) : i18nString(UIStrings.copyAllAsNodejsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311823 this.copyAllFetchCall.bind(this, FetchStyle.NODE_JS), {jslogContext: 'copy-all-as-nodejs-fetch'});
Blink Reformat4c46d092018-04-07 15:32:371824 }
Danil Somsikov23eacf62024-02-23 08:46:301825 copyMenu.footerSection().appendItem(
Benedikt Meureracd96a62024-09-10 07:25:241826 filtered ? i18nString(UIStrings.copyAllListedAsHarSanitized) : i18nString(UIStrings.copyAllAsHarSanitized),
1827 this.copyAllAsHAR.bind(this, {sanitize: true}), {jslogContext: 'copy-all-as-har'});
Benedikt Meurerd553c502024-10-17 19:07:181828 if (this.networkShowOptionsToGenerateHarWithSensitiveData.get()) {
Benedikt Meureracd96a62024-09-10 07:25:241829 copyMenu.footerSection().appendItem(
1830 filtered ? i18nString(UIStrings.copyAllListedAsHarWithSensitiveData) :
1831 i18nString(UIStrings.copyAllAsHarWithSensitiveData),
1832 this.copyAllAsHAR.bind(this, {sanitize: false}), {jslogContext: 'copy-all-as-har-with-sensitive-data'});
1833 }
Blink Reformat4c46d092018-04-07 15:32:371834
Wolfgang Beyer650e9572023-11-29 12:45:081835 contextMenu.overrideSection().appendItem(
Wolfgang Beyer9d9affb2024-05-08 10:14:441836 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request), {
1837 disabled:
1838 Persistence.NetworkPersistenceManager.NetworkPersistenceManager.isForbiddenNetworkUrl(request.url()),
1839 jslogContext: 'override-headers',
1840 });
Wolfgang Beyerc6fe2be2022-11-03 15:39:411841
Blink Reformat4c46d092018-04-07 15:32:371842 contextMenu.editSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301843 i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this),
1844 {jslogContext: 'clear-browser-cache'});
1845 contextMenu.editSection().appendItem(
1846 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this),
1847 {jslogContext: 'clear-browser-cookies'});
Blink Reformat4c46d092018-04-07 15:32:371848
1849 if (request) {
1850 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211851 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371852 let patterns = manager.blockedPatterns();
1853
Jan Schefflerd6c1d402021-02-26 16:56:381854 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201855 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121856 manager.setBlockedPatterns(patterns);
1857 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031858 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121859 }
1860
Jan Schefflerd6c1d402021-02-26 16:56:381861 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121862 patterns = patterns.filter(pattern => pattern.url !== url);
1863 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031864 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121865 }
1866
Blink Reformat4c46d092018-04-07 15:32:371867 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1868 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1869 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301870 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme),
1871 {jslogContext: 'block-request-url'});
Blink Reformat4c46d092018-04-07 15:32:371872 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311873 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371874 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301875 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme),
1876 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371877 }
1878
1879 const domain = request.parsedURL.domain();
1880 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1881 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301882 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain),
1883 {jslogContext: 'block-request-domain'});
Blink Reformat4c46d092018-04-07 15:32:371884 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311885 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371886 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301887 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain),
1888 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371889 }
1890
Tim van der Lippe0ed1d2b2020-02-04 13:45:131891 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371892 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301893 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request),
1894 {jslogContext: 'replay-xhr'});
Blink Reformat4c46d092018-04-07 15:32:371895 }
Blink Reformat4c46d092018-04-07 15:32:371896 }
1897 }
1898
Jan Scheffler17b8fb42021-08-12 12:28:381899 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Yang Guo6d1361f2024-07-11 08:23:481900 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1901 return requests.filter(NetworkLogView.getHTTPRequestsFilter).filter(request => {
1902 return request.finished ||
1903 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1904 });
Blink Reformat4c46d092018-04-07 15:32:371905 }
1906
Benedikt Meureracd96a62024-09-10 07:25:241907 private async copyAllAsHAR(options: HAR.Log.BuildOptions): Promise<void> {
1908 const harArchive = {log: await HAR.Log.Log.build(this.harRequests(), options)};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131909 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371910 }
1911
Benedikt Meurer8f0fee62023-12-27 12:36:511912 private copyAllURLs(): void {
Yang Guo6d1361f2024-07-11 08:23:481913 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1914 const nonBlobRequests = this.filterOutBlobRequests(requests);
Benedikt Meurer8f0fee62023-12-27 12:36:511915 const urls = nonBlobRequests.map(request => request.url());
1916 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(urls.join('\n'));
1917 }
1918
Benedikt Meurer64b7e722023-12-15 09:03:581919 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351920 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131921 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371922 }
1923
Benedikt Meurer64b7e722023-12-15 09:03:581924 private async copyAllCurlCommand(platform: 'unix'|'win'): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481925 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1926 const commands = await this.generateAllCurlCommand(requests, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131927 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371928 }
1929
Danil Somsikov59f4c612021-09-08 10:58:461930 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1931 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131932 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371933 }
1934
Danil Somsikov59f4c612021-09-08 10:58:461935 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481936 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1937 const commands = await this.generateAllFetchCall(requests, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131938 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371939 }
1940
Jan Scheffler17b8fb42021-08-12 12:28:381941 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1942 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131943 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371944 }
1945
Jan Scheffler17b8fb42021-08-12 12:28:381946 private async copyAllPowerShellCommand(): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481947 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1948 const commands = await this.generateAllPowerShellCommand(requests);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131949 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371950 }
1951
Benedikt Meureracd96a62024-09-10 07:25:241952 async exportAll(options: HAR.Log.BuildOptions): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501953 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371954 if (!mainTarget) {
1955 return;
1956 }
1957 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131958 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321959 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131960 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371961
Kateryna Prokopenko380fdfa2022-03-16 16:39:321962 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371963 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341964 }
Blink Reformat4c46d092018-04-07 15:32:371965
Tim van der Lippe0ed1d2b2020-02-04 13:45:131966 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531967 this.progressBarContainer.appendChild(progressIndicator.element);
Benedikt Meureracd96a62024-09-10 07:25:241968 await HAR.Writer.Writer.write(stream, this.harRequests(), options, progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371969 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031970 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371971 }
1972
Wolfgang Beyer5b433b02022-05-12 13:57:371973 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411974 const requestLocation =
1975 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271976 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1977 if (networkPersistanceManager.project()) {
Danil Somsikovde84fb52024-01-30 13:53:091978 Common.Settings.Settings.instance().moduleSetting('persistence-network-overrides-enabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271979 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411980 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371981 } else { // If folder for local overrides has not been provided yet
Danil Somsikovacd635c2024-02-09 12:56:511982 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async () => {
Wolfgang Beyer5b433b02022-05-12 13:57:371983 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271984 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411985 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371986 });
1987 }
1988 }
1989
Jan Scheffler17b8fb42021-08-12 12:28:381990 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551991 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211992 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 }
Blink Reformat4c46d092018-04-07 15:32:371994 }
1995
Jan Scheffler17b8fb42021-08-12 12:28:381996 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551997 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211998 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341999 }
Blink Reformat4c46d092018-04-07 15:32:372000 }
2001
Yang Guo6d1361f2024-07-11 08:23:482002 private applyFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Jack Franklin28577db2021-10-14 08:12:532003 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:372004 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342005 }
Simon Zündb3042fb2024-12-11 06:43:062006 const categoryName = request.resourceType().category().name;
Jack Franklin28577db2021-10-14 08:12:532007 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:372008 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342009 }
Silvia Eremia096e1202023-09-22 15:49:172010 const [hideDataURL, blockedCookies, blockedRequests, thirdParty, hideExtensionURL] =
2011 Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN) ?
2012 [
2013 this.networkHideDataURLSetting.get(),
2014 this.networkShowBlockedCookiesOnlySetting.get(),
2015 this.networkOnlyBlockedRequestsSetting.get(),
2016 this.networkOnlyThirdPartySetting.get(),
2017 this.networkHideChromeExtensions.get(),
2018 ] :
2019 [
2020 this.dataURLFilterUI?.checked(),
2021 this.onlyBlockedResponseCookiesFilterUI?.checked(),
2022 this.onlyBlockedRequestsUI?.checked(),
2023 this.onlyThirdPartyFilterUI?.checked(),
2024 this.hideChromeExtensionsUI?.checked(),
2025 ];
2026
2027 if (hideDataURL && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:372028 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342029 }
Silvia Eremia096e1202023-09-22 15:49:172030 if (blockedCookies && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:372031 return false;
2032 }
Silvia Eremia096e1202023-09-22 15:49:172033 if (blockedRequests && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:132034 return false;
2035 }
Silvia Eremia096e1202023-09-22 15:49:172036 if (thirdParty && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:272037 return false;
2038 }
Silvia Eremia096e1202023-09-22 15:49:172039 if (hideExtensionURL && request.scheme === 'chrome-extension') {
ioana forfota45b44152023-07-21 14:20:532040 return false;
2041 }
Jack Franklin28577db2021-10-14 08:12:532042 for (let i = 0; i < this.filters.length; ++i) {
2043 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:372044 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342045 }
Blink Reformat4c46d092018-04-07 15:32:372046 }
2047 return true;
2048 }
2049
Danil Somsikov7a392fb2021-09-13 11:09:462050 private isValidUrl(url: string): boolean {
2051 try {
2052 new URL(url);
2053 return true;
Nikolay Vitkovb4e8dc72025-01-07 13:03:022054 } catch {
Danil Somsikov7a392fb2021-09-13 11:09:462055 return false;
2056 }
2057 }
2058
Jan Scheffler17b8fb42021-08-12 12:28:382059 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:532060 // A query string can have multiple filters, some of them regular
2061 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:372062 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:532063 // checkbox therefore inverts each one of those individual filters.
2064 const descriptors = this.filterParser.parse(query);
2065 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:372066 const key = descriptor.key;
2067 const text = descriptor.text || '';
2068 const regex = descriptor.regex;
2069 let filter;
2070 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:172071 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:382072 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
2073 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:372074 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:382075 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:462076 } else if (this.isValidUrl(text)) {
2077 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:372078 } else {
Jan Scheffler17b8fb42021-08-12 12:28:382079 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:172080 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:372081 }
Victor Porof66878d62021-07-16 13:12:372082 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:382083 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:372084 }
2085 return filter;
Blink Reformat4c46d092018-04-07 15:32:372086 });
2087 }
2088
Jan Scheffler17b8fb42021-08-12 12:28:382089 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372090 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:162091 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:382092 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:372093
Sigurd Schneider30722582021-06-16 06:54:162094 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:382095 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372096
Simon Zünd6dedde52021-08-03 09:04:512097 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:382098 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:512099
Sigurd Schneider30722582021-06-16 06:54:162100 case NetworkForward.UIFilter.FilterType.Is:
Benedikt Meurer61b7a002024-09-04 08:02:312101 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.RUNNING) {
Jan Scheffler17b8fb42021-08-12 12:28:382102 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342103 }
Benedikt Meurer61b7a002024-09-04 08:02:312104 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FROM_CACHE) {
Jan Scheffler17b8fb42021-08-12 12:28:382105 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342106 }
Benedikt Meurer61b7a002024-09-04 08:02:312107 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED) {
Jan Scheffler17b8fb42021-08-12 12:28:382108 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342109 }
Benedikt Meurer61b7a002024-09-04 08:02:312110 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED) {
Jan Scheffler17b8fb42021-08-12 12:28:382111 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342112 }
Blink Reformat4c46d092018-04-07 15:32:372113 break;
2114
Sigurd Schneider30722582021-06-16 06:54:162115 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:382116 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:372117
Sigurd Schneider30722582021-06-16 06:54:162118 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:382119 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372120
Sigurd Schneider30722582021-06-16 06:54:162121 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:382122 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372123
Sigurd Schneider30722582021-06-16 06:54:162124 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:382125 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:162126 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:372127
Sigurd Schneider30722582021-06-16 06:54:162128 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:382129 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372130
Sigurd Schneider30722582021-06-16 06:54:162131 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382132 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372133
Sigurd Schneider30722582021-06-16 06:54:162134 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382135 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372136
Sigurd Schneider30722582021-06-16 06:54:162137 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382138 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372139
Sigurd Schneider30722582021-06-16 06:54:162140 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382141 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412142
Sigurd Schneider30722582021-06-16 06:54:162143 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382144 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412145
Sigurd Schneider30722582021-06-16 06:54:162146 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:382147 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:542148
Sigurd Schneider30722582021-06-16 06:54:162149 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382150 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412151
Sigurd Schneider30722582021-06-16 06:54:162152 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:382153 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:502154 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:372155
Sigurd Schneider30722582021-06-16 06:54:162156 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:382157 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:032158
Jecelyn Yeen77c83462023-08-16 16:13:172159 case NetworkForward.UIFilter.FilterType.HasOverrides:
2160 return NetworkLogView.hasOverridesFilter.bind(null, value);
2161
Sigurd Schneider30722582021-06-16 06:54:162162 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:382163 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:032164
Sigurd Schneider30722582021-06-16 06:54:162165 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:382166 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372167 }
2168 return null;
2169 }
2170
Jan Scheffler17b8fb42021-08-12 12:28:382171 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372172 let multiplier = 1;
2173 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542174 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:372175 value = value.substring(0, value.length - 1);
2176 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542177 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:372178 value = value.substring(0, value.length - 1);
2179 }
2180 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342181 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:372182 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342183 }
Jan Scheffler17b8fb42021-08-12 12:28:382184 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:372185 }
2186
Jan Scheffler17b8fb42021-08-12 12:28:382187 private filterRequests(): void {
Nancy Liffb3c7e2024-08-01 14:58:152188 this.removeAllNodeHighlights();
Jan Scheffler17b8fb42021-08-12 12:28:382189 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:372190 }
2191
Jan Scheffler17b8fb42021-08-12 12:28:382192 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:372193 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:372194 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342195 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:372196 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342197 }
Brandon Goddard5e4244d2020-04-08 22:08:472198 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:532199 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:472200 // reveal and expand parent to ensure child is revealable.
2201 if (node.parent && node.parent instanceof NetworkGroupNode) {
2202 node.parent.reveal();
2203 node.parent.expand();
2204 }
Blink Reformat4c46d092018-04-07 15:32:372205 node.reveal();
2206 return node;
2207 }
2208
Jan Schefflerd6c1d402021-02-26 16:56:382209 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:382210 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342211 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:382212 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:342213 }
Blink Reformat4c46d092018-04-07 15:32:372214 }
2215
Sigurd Schneider722301e2021-06-15 13:41:202216 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:072217 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
2218 if (request) {
2219 this.revealAndHighlightRequest(request);
2220 }
2221 }
2222
Sigurd Schneider14d3e9f2021-06-14 08:29:012223 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
2224 void {
chait pinnamaneni6bc1c122020-10-30 17:30:522225 const defaultOptions = {clearFilter: true};
2226 const {clearFilter} = options || defaultOptions;
2227 if (clearFilter) {
2228 this.setTextFilterValue('');
2229 }
Jan Scheffler17b8fb42021-08-12 12:28:382230 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342231 if (node) {
Blink Reformat4c46d092018-04-07 15:32:372232 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:342233 }
Blink Reformat4c46d092018-04-07 15:32:372234 }
2235
Jan Schefflerd6c1d402021-02-26 16:56:382236 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:532237 if (this.highlightedNode) {
2238 this.highlightedNode.element().classList.remove('highlighted-row');
2239 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:372240 }
2241 }
2242
Jan Scheffler17b8fb42021-08-12 12:28:382243 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132244 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:532245 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:372246 }
2247
Jan Scheffler17b8fb42021-08-12 12:28:382248 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:132249 return requests.filter(request => !request.isBlobRequest());
2250 }
2251
Danil Somsikov59f4c612021-09-08 10:58:462252 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382253 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:372254 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372255 'method',
2256 'path',
2257 'scheme',
2258 'version',
Blink Reformat4c46d092018-04-07 15:32:372259
2260 // Unsafe headers
2261 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372262 'accept-charset',
2263 'accept-encoding',
2264 'access-control-request-headers',
2265 'access-control-request-method',
2266 'connection',
2267 'content-length',
2268 'cookie',
2269 'cookie2',
2270 'date',
2271 'dnt',
2272 'expect',
2273 'host',
2274 'keep-alive',
2275 'origin',
2276 'referer',
2277 'te',
2278 'trailer',
2279 'transfer-encoding',
2280 'upgrade',
2281 'via',
Blink Reformat4c46d092018-04-07 15:32:372282 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372283 'user-agent',
2284 ]);
Blink Reformat4c46d092018-04-07 15:32:372285
Jan Schefflerd6c1d402021-02-26 16:56:382286 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372287
2288 const url = JSON.stringify(request.url());
2289
2290 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382291 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372292 const name = header.name;
2293
Tim van der Lippe224a8622020-09-23 12:14:372294 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372295 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342296 }
Blink Reformat4c46d092018-04-07 15:32:372297
2298 return result;
2299 }, new Headers());
2300
Jan Schefflerd6c1d402021-02-26 16:56:382301 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342302 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412303 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342304 }
Blink Reformat4c46d092018-04-07 15:32:372305
Sigurd Schneider0e88b912020-05-08 08:28:232306 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372307 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412308 'include' :
2309 'omit';
Blink Reformat4c46d092018-04-07 15:32:372310
2311 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2312
2313 const referrer = referrerHeader ? referrerHeader.value : void 0;
2314
2315 const referrerPolicy = request.referrerPolicy() || void 0;
2316
2317 const requestBody = await request.requestFormData();
2318
Jan Schefflerd6c1d402021-02-26 16:56:382319 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412320 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372321 referrer,
2322 referrerPolicy,
2323 body: requestBody,
2324 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372325 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372326 };
2327
Benedikt Meurer61b7a002024-09-04 08:02:312328 if (style === FetchStyle.NODE_JS) {
Jan Scheffler7c50d1f2019-12-17 13:33:292329 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462330 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532331 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462332 // following properties are not implemented in Node.js.
2333 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292334 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462335 extraHeaders['cookie'] = cookieHeader.value;
2336 }
2337 if (referrer) {
2338 delete fetchOptions.referrer;
2339 extraHeaders['Referer'] = referrer;
2340 }
2341 if (referrer) {
2342 delete fetchOptions.referrerPolicy;
2343 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2344 }
2345 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292346 fetchOptions.headers = {
2347 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462348 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292349 };
2350 }
2351 } else {
2352 fetchOptions.credentials = credentials;
2353 }
2354
Jan Scheffler172d5212020-01-02 14:42:562355 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372356 return `fetch(${url}, ${options});`;
2357 }
2358
Danil Somsikov59f4c612021-09-08 10:58:462359 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382360 Promise<string> {
2361 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462362 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132363 return commands.join(' ;\n');
2364 }
2365
Benedikt Meurer64b7e722023-12-15 09:03:582366 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'):
2367 Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382368 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362369 // Most of these headers are derived from the URL and are automatically added by cURL.
2370 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Barry Pollard0a176b42024-01-30 10:19:232371 const ignoredHeaders =
2372 new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version', 'authority', 'protocol']);
Blink Reformat4c46d092018-04-07 15:32:372373
Jan Schefflerd6c1d402021-02-26 16:56:382374 function escapeStringWin(str: string): string {
Danil Somsikovf4447112024-09-10 12:22:302375 /* Always escape the " characters so that we can use caret escaping.
Blink Reformat4c46d092018-04-07 15:32:372376
Jan Schefflerd6c1d402021-02-26 16:56:382377 Because cmd.exe parser and MS Crt arguments parsers use some of the
2378 same escape characters, they can interact with each other in
2379 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372380
Jan Schefflerd6c1d402021-02-26 16:56:382381 Replace \ with \\ first because it is an escape character for certain
2382 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372383
Jan Schefflerd6c1d402021-02-26 16:56:382384 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372385
Jan Schefflerd6c1d402021-02-26 16:56:382386 Then escape all characters we are not sure about with ^ to ensure it
2387 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372388
Jan Schefflerd6c1d402021-02-26 16:56:382389 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352390 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382391 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2392 parser); So we can get cmd.exe parser to escape the character after it,
2393 if it is followed by a valid beginning character of an ENV variable.
2394 This ensures we do not try and double escape another ^ if it was placed
2395 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372396
Jan Schefflerd6c1d402021-02-26 16:56:382397 Lastly we replace new lines with ^ and TWO new lines because the first
2398 new line is there to enact the escape command the second is the character
2399 to escape (in this case new line).
2400 */
Danil Somsikovf4447112024-09-10 12:22:302401 const encapsChars = '^"';
Blink Reformat4c46d092018-04-07 15:32:372402 return encapsChars +
2403 str.replace(/\\/g, '\\\\')
2404 .replace(/"/g, '\\"')
Danil Somsikovf4447112024-09-10 12:22:302405 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372406 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542407 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372408 encapsChars;
2409 }
2410
Jan Schefflerd6c1d402021-02-26 16:56:382411 function escapeStringPosix(str: string): string {
2412 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222413 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122414 let hexString = code.toString(16);
2415 // Zero pad to four digits to comply with ANSI-C Quoting:
2416 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342417 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122418 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342419 }
Joey Arhar2d21f712019-05-20 21:07:122420
2421 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372422 }
2423
Mathias Bynensf06e8c02020-02-28 13:58:282424 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372425 // Use ANSI-C quoting syntax.
2426 return '$\'' +
2427 str.replace(/\\/g, '\\\\')
2428 .replace(/\'/g, '\\\'')
2429 .replace(/\n/g, '\\n')
2430 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282431 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372432 '\'';
Blink Reformat4c46d092018-04-07 15:32:372433 }
Mathias Bynensf06e8c02020-02-28 13:58:282434 // Use single quote syntax.
2435 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372436 }
2437
2438 // cURL command expected to run on the same platform that DevTools run
2439 // (it may be different from the inspected page platform).
2440 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2441
2442 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2443
2444 let inferredMethod = 'GET';
2445 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372446 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082447 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272448 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532449 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272450 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372451 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372452 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372453 }
2454
2455 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292456 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372457 }
2458
2459 const requestHeaders = request.requestHeaders();
2460 for (let i = 0; i < requestHeaders.length; i++) {
2461 const header = requestHeaders[i];
2462 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372463 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372464 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342465 }
Benedikt Meurerb1bf2352024-12-16 13:38:492466 const value = header.value;
2467 if (!value.trim()) {
Wolfgang Beyer26b7e892022-08-16 11:02:352468 // A header passed with -H with no value or only whitespace as its
2469 // value tells curl to not set the header at all. To post an empty
2470 // header, you have to terminate it with a semicolon.
2471 command.push('-H ' + escapeString(name + ';'));
Benedikt Meurerb1bf2352024-12-16 13:38:492472 } else if (name.toLowerCase() === 'cookie') {
2473 command.push('-b ' + escapeString(value));
2474 } else {
2475 command.push('-H ' + escapeString(name + ': ' + value));
Wolfgang Beyer26b7e892022-08-16 11:02:352476 }
Blink Reformat4c46d092018-04-07 15:32:372477 }
2478 command = command.concat(data);
Blink Reformat4c46d092018-04-07 15:32:372479
Tim van der Lippe1d6e57a2019-09-30 11:55:342480 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372481 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342482 }
Jan Scheffler172d5212020-01-02 14:42:562483 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372484 }
2485
Benedikt Meurer64b7e722023-12-15 09:03:582486 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: 'unix'|'win'):
Jan Scheffler17b8fb42021-08-12 12:28:382487 Promise<string> {
2488 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352489 const commands =
2490 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342491 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132492 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342493 }
Mathias Bynensf06e8c02020-02-28 13:58:282494 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132495 }
2496
Jan Scheffler17b8fb42021-08-12 12:28:382497 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562498 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242499 const ignoredHeaders = new Set<string>([
2500 'host',
2501 'connection',
2502 'proxy-connection',
2503 'content-length',
2504 'expect',
2505 'range',
2506 'content-type',
2507 'user-agent',
2508 'cookie',
2509 ]);
Blink Reformat4c46d092018-04-07 15:32:372510
Jan Schefflerd6c1d402021-02-26 16:56:382511 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372512 return '"' +
2513 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2514 }
2515
Brandon Walderman153b8d72021-06-28 18:45:242516 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2517 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2518 // command does not allow setting these headers through the -Headers parameter. See docs at:
2519 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2520 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2521 const requestHeaders = request.requestHeaders();
2522 const props = [];
2523
2524 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2525 if (userAgentHeader) {
2526 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2527 }
2528
Shuran Huang670281e2024-02-15 16:29:542529 for (const includedCookie of request.includedRequestCookies()) {
2530 const name = escapeString(includedCookie.cookie.name());
2531 const value = escapeString(includedCookie.cookie.value());
2532 const domain = escapeString(includedCookie.cookie.domain());
Brandon Walderman153b8d72021-06-28 18:45:242533 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2534 }
2535
2536 if (props.length) {
2537 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2538 }
2539
2540 return null;
2541 }
2542
Jan Scheffler172d5212020-01-02 14:42:562543 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372544
2545 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562546 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372547 }
2548
Brandon Walderman153b8d72021-06-28 18:45:242549 const session = generatePowerShellSession(request);
2550 if (session) {
2551 command.push('-WebSession $session');
2552 }
2553
Blink Reformat4c46d092018-04-07 15:32:372554 const requestHeaders = request.requestHeaders();
2555 const headerNameValuePairs = [];
2556 for (const header of requestHeaders) {
2557 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342558 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372559 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342560 }
Blink Reformat4c46d092018-04-07 15:32:372561 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2562 }
2563 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562564 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372565 }
2566
2567 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2568 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562569 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372570 }
2571
2572 const formData = await request.requestFormData();
2573 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372574 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342575 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562576 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342577 } else {
Jan Scheffler172d5212020-01-02 14:42:562578 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342579 }
Blink Reformat4c46d092018-04-07 15:32:372580 }
2581
Brandon Walderman153b8d72021-06-28 18:45:242582 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2583 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2584 // compatibility only.
2585 const prelude = session || '';
2586 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372587 }
Harley Libcf41f92018-09-10 18:01:132588
Jan Scheffler17b8fb42021-08-12 12:28:382589 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2590 const nonBlobRequests = this.filterOutBlobRequests(requests);
2591 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132592 return commands.join(';\r\n');
2593 }
Joey Arhara86c14e2019-03-12 03:20:502594
Jan Schefflerd6c1d402021-02-26 16:56:382595 static getDCLEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142596 return '--sys-color-blue';
Joey Arhara86c14e2019-03-12 03:20:502597 }
2598
Jan Schefflerd6c1d402021-02-26 16:56:382599 static getLoadEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142600 return '--sys-color-error';
Joey Arhara86c14e2019-03-12 03:20:502601 }
Paul Lewis56509652019-12-06 12:51:582602}
Blink Reformat4c46d092018-04-07 15:32:372603
Jan Schefflerd6c1d402021-02-26 16:56:382604export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022605 let stackTraceText = '';
2606 for (const frame of stackTrace.callFrames) {
2607 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2608 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2609 }
2610 if (stackTrace.parent) {
2611 stackTraceText += computeStackTraceText(stackTrace.parent);
2612 }
2613 return stackTraceText;
2614}
2615
Jan Schefflerd6c1d402021-02-26 16:56:382616const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2617const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372618
Jan Schefflerd6c1d402021-02-26 16:56:382619export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372620 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222621}
2622
Paul Lewis56509652019-12-06 12:51:582623export const HTTPSchemas = {
Nikolay Vitkov47310242024-09-04 10:00:072624 http: true,
2625 https: true,
2626 ws: true,
2627 wss: true,
Blink Reformat4c46d092018-04-07 15:32:372628};
2629
Sigurd Schneider576ca9a2021-07-16 05:58:042630const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382631
2632export interface GroupLookupInterface {
2633 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2634 reset(): void;
2635}
2636
Jecelyn Yeen77c83462023-08-16 16:13:172637export const overrideFilter = {
2638 yes: 'yes',
2639 no: 'no',
2640 content: 'content',
2641 headers: 'headers',
2642};
2643
Nikolay Vitkov937f4632025-01-03 14:02:022644export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;
ioana forfota2c72e132023-09-22 12:11:482645
Silvia Eremia096e1202023-09-22 15:49:172646export class MoreFiltersDropDownUI extends
2647 Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes> implements UI.FilterBar.FilterUI {
2648 private readonly filterElement: HTMLDivElement;
Kateryna Prokopenko17cba892024-07-26 13:33:562649 private readonly dropDownButton: UI.Toolbar.ToolbarCombobox;
Silvia Eremia096e1202023-09-22 15:49:172650 private networkHideDataURLSetting: Common.Settings.Setting<boolean>;
2651 private networkHideChromeExtensionsSetting: Common.Settings.Setting<boolean>;
2652 private networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
2653 private networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
2654 private networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
2655 private contextMenu?: UI.ContextMenu.ContextMenu;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482656 private activeFiltersCount: HTMLElement;
2657 private activeFiltersCountAdorner: Adorners.Adorner.Adorner;
Silvia Eremia096e1202023-09-22 15:49:172658
Benedikt Meurer6b3ebf22024-01-12 10:00:512659 constructor() {
Silvia Eremia096e1202023-09-22 15:49:172660 super();
Silvia Eremia096e1202023-09-22 15:49:172661
Danil Somsikov74217e92024-01-30 07:01:122662 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
Silvia Eremia096e1202023-09-22 15:49:172663 this.networkHideChromeExtensionsSetting =
Danil Somsikov74217e92024-01-30 07:01:122664 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Silvia Eremia096e1202023-09-22 15:49:172665 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:122666 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172667 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:122668 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Silvia Eremia096e1202023-09-22 15:49:172669 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:122670 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172671
2672 this.filterElement = document.createElement('div');
2673 this.filterElement.setAttribute('aria-label', 'Show only/hide requests dropdown');
Danil Somsikov0cb97462024-01-30 15:11:292674 this.filterElement.setAttribute('jslog', `${VisualLogging.dropDown('more-filters').track({click: true})}`);
Kateryna Prokopenkod98e34c2023-09-25 18:08:482675
2676 this.activeFiltersCountAdorner = new Adorners.Adorner.Adorner();
2677 this.activeFiltersCount = document.createElement('span');
2678 this.activeFiltersCountAdorner.data = {
2679 name: 'countWrapper',
2680 content: this.activeFiltersCount,
2681 };
2682 this.activeFiltersCountAdorner.classList.add('active-filters-count');
2683 this.updateActiveFiltersCount();
2684
Kateryna Prokopenko17cba892024-07-26 13:33:562685 this.dropDownButton = new UI.Toolbar.ToolbarCombobox(i18nString(UIStrings.showOnlyHideRequests));
2686 this.dropDownButton.setText(i18nString(UIStrings.moreFilters));
2687 this.dropDownButton.setAdorner(this.activeFiltersCountAdorner);
Silvia Eremia096e1202023-09-22 15:49:172688 this.filterElement.appendChild(this.dropDownButton.element);
Silvia Eremia096e1202023-09-22 15:49:172689 this.dropDownButton.element.classList.add('dropdown-filterbar');
2690 this.dropDownButton.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:352691 UI.Toolbar.ToolbarButton.Events.CLICK, this.showMoreFiltersContextMenu.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172692 UI.ARIAUtils.markAsMenuButton(this.dropDownButton.element);
Kateryna Prokopenko5f434d42023-11-03 10:57:492693 this.updateTooltip();
Silvia Eremia096e1202023-09-22 15:49:172694 }
2695
Wolfgang Beyer3b382582023-11-16 12:40:022696 #onSettingChanged(): void {
Benedikt Meurerf08ab4a2024-09-03 09:37:352697 this.dispatchEventToListeners(UI.FilterBar.FilterUIEvents.FILTER_CHANGED);
Wolfgang Beyer3b382582023-11-16 12:40:022698 }
2699
Silvia Eremia096e1202023-09-22 15:49:172700 showMoreFiltersContextMenu(event: Common.EventTarget.EventTargetEvent<Event>): void {
2701 const mouseEvent = event.data;
2702
Wolfgang Beyer3b382582023-11-16 12:40:022703 this.networkHideDataURLSetting.addChangeListener(this.#onSettingChanged.bind(this));
2704 this.networkHideChromeExtensionsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2705 this.networkShowBlockedCookiesOnlySetting.addChangeListener(this.#onSettingChanged.bind(this));
2706 this.networkOnlyBlockedRequestsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2707 this.networkOnlyThirdPartySetting.addChangeListener(this.#onSettingChanged.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172708 this.contextMenu = new UI.ContextMenu.ContextMenu(mouseEvent, {
2709 useSoftMenu: true,
2710 keepOpen: true,
2711 x: this.dropDownButton.element.getBoundingClientRect().left,
2712 y: this.dropDownButton.element.getBoundingClientRect().top +
2713 (this.dropDownButton.element as HTMLElement).offsetHeight,
2714 });
2715
2716 this.contextMenu.defaultSection().appendCheckboxItem(
2717 i18nString(UIStrings.hideDataUrls),
Danil Somsikov66fa2262024-02-22 13:02:492718 () => this.networkHideDataURLSetting.set(!this.networkHideDataURLSetting.get()), {
2719 checked: this.networkHideDataURLSetting.get(),
2720 tooltip: i18nString(UIStrings.hidesDataAndBlobUrls),
2721 jslogContext: 'hide-data-urls',
2722 });
Silvia Eremia096e1202023-09-22 15:49:172723 this.contextMenu.defaultSection().appendCheckboxItem(
2724 i18nString(UIStrings.chromeExtensions),
Danil Somsikov66fa2262024-02-22 13:02:492725 () => this.networkHideChromeExtensionsSetting.set(!this.networkHideChromeExtensionsSetting.get()), {
2726 checked: this.networkHideChromeExtensionsSetting.get(),
2727 tooltip: i18nString(UIStrings.hideChromeExtension),
2728 jslogContext: 'hide-extension-urls',
2729 });
Silvia Eremia096e1202023-09-22 15:49:172730 this.contextMenu.defaultSection().appendSeparator();
Kateryna Prokopenkod98e34c2023-09-25 18:08:482731
Silvia Eremia096e1202023-09-22 15:49:172732 this.contextMenu.defaultSection().appendCheckboxItem(
2733 i18nString(UIStrings.hasBlockedCookies),
Danil Somsikov66fa2262024-02-22 13:02:492734 () => this.networkShowBlockedCookiesOnlySetting.set(!this.networkShowBlockedCookiesOnlySetting.get()), {
2735 checked: this.networkShowBlockedCookiesOnlySetting.get(),
2736 tooltip: i18nString(UIStrings.onlyShowRequestsWithBlockedCookies),
2737 jslogContext: 'only-blocked-response-cookies',
2738 });
Silvia Eremia096e1202023-09-22 15:49:172739 this.contextMenu.defaultSection().appendCheckboxItem(
2740 i18nString(UIStrings.blockedRequests),
Danil Somsikov66fa2262024-02-22 13:02:492741 () => this.networkOnlyBlockedRequestsSetting.set(!this.networkOnlyBlockedRequestsSetting.get()), {
2742 checked: this.networkOnlyBlockedRequestsSetting.get(),
2743 tooltip: i18nString(UIStrings.onlyShowBlockedRequests),
2744 jslogContext: 'only-blocked-requests',
2745 });
Silvia Eremia096e1202023-09-22 15:49:172746 this.contextMenu.defaultSection().appendCheckboxItem(
2747 i18nString(UIStrings.thirdParty),
Danil Somsikov66fa2262024-02-22 13:02:492748 () => this.networkOnlyThirdPartySetting.set(!this.networkOnlyThirdPartySetting.get()), {
2749 checked: this.networkOnlyThirdPartySetting.get(),
2750 tooltip: i18nString(UIStrings.onlyShowThirdPartyRequests),
2751 jslogContext: 'only-3rd-party-requests',
2752 });
Silvia Eremia096e1202023-09-22 15:49:172753
2754 void this.contextMenu.show();
2755 }
2756
Kateryna Prokopenko5f434d42023-11-03 10:57:492757 selectedFilters(): string[] {
2758 const filters = [
2759 ...this.networkHideDataURLSetting.get() ? [i18nString(UIStrings.hideDataUrls)] : [],
2760 ...this.networkHideChromeExtensionsSetting.get() ? [i18nString(UIStrings.chromeExtensions)] : [],
2761 ...this.networkShowBlockedCookiesOnlySetting.get() ? [i18nString(UIStrings.hasBlockedCookies)] : [],
2762 ...this.networkOnlyBlockedRequestsSetting.get() ? [i18nString(UIStrings.blockedRequests)] : [],
2763 ...this.networkOnlyThirdPartySetting.get() ? [i18nString(UIStrings.thirdParty)] : [],
Kateryna Prokopenkod98e34c2023-09-25 18:08:482764 ];
Kateryna Prokopenko5f434d42023-11-03 10:57:492765 return filters;
2766 }
2767
2768 updateActiveFiltersCount(): void {
2769 const count = this.selectedFilters().length;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482770 this.activeFiltersCount.textContent = count.toString();
2771 count ? this.activeFiltersCountAdorner.classList.remove('hidden') :
2772 this.activeFiltersCountAdorner.classList.add('hidden');
2773 }
2774
Kateryna Prokopenko5f434d42023-11-03 10:57:492775 updateTooltip(): void {
2776 if (this.selectedFilters().length) {
2777 this.dropDownButton.setTitle(this.selectedFilters().join(', '));
2778 } else {
2779 this.dropDownButton.setTitle(UIStrings.showOnlyHideRequests);
2780 }
2781 }
2782
Silvia Eremia096e1202023-09-22 15:49:172783 discard(): void {
2784 if (this.contextMenu) {
2785 this.contextMenu.discard();
2786 }
2787 }
2788
2789 isActive(): boolean {
Benedikt Meurer6b3ebf22024-01-12 10:00:512790 return this.selectedFilters().length !== 0;
Silvia Eremia096e1202023-09-22 15:49:172791 }
2792
2793 element(): HTMLDivElement {
2794 return this.filterElement;
2795 }
2796}