blob: 6f5d2c2528a7d324066e64da985e2f056833b3f2 [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.
Danil Somsikovd03a01e2025-04-01 15:03:584/* eslint-disable rulesdir/no-imperative-dom-api */
Jan Schefflerd6c1d402021-02-26 16:56:385
Blink Reformat4c46d092018-04-07 15:32:376/*
7 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
8 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
9 * Copyright (C) 2011 Google Inc. All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
21 * its contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
25 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
Benedikt Meurer918a8212025-01-09 08:47:0836import '../../ui/legacy/legacy.js';
37
Tim van der Lippe76961572021-04-06 10:48:0738import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3039import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2840import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2741import * as Platform from '../../core/platform/platform.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';
Kim-Anh Tranf705a3f2025-02-20 06:42:3252import * as Buttons from '../../ui/components/buttons/buttons.js';
Benedikt Meurer328b3a72025-01-02 10:38:5553import * as RenderCoordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4754import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1455import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3656import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0757import * as UI from '../../ui/legacy/legacy.js';
Wolfgang Beyer8ad25a72024-01-03 12:44:2958import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1359
Jack Franklin3a802602022-07-13 08:39:4260import {
61 Events,
ioana forfota2c72e132023-09-22 12:11:4862 type EventTypes,
Jack Franklin3a802602022-07-13 08:39:4263 NetworkGroupNode,
Jack Franklin3a802602022-07-13 08:39:4264 type NetworkLogViewInterface,
65 type NetworkNode,
ioana forfota2c72e132023-09-22 12:11:4866 NetworkRequestNode,
Jack Franklin3a802602022-07-13 08:39:4267} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3068import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
Benedikt Meurerd604ae22025-01-31 15:12:2169import networkLogViewStyles from './networkLogView.css.js';
Tim van der Lippe119690c2020-01-13 12:31:3070import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Frankline839c0c2022-05-03 08:47:4471import {
72 NetworkTimeBoundary,
ioana forfota2c72e132023-09-22 12:11:4873 type NetworkTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4474 NetworkTransferDurationCalculator,
75 NetworkTransferTimeCalculator,
76} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3077
Simon Zünd34490692021-03-01 08:25:1878const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5579 /**
Jack Franklinfd72c072022-12-21 11:45:0180 *@description Text in Network Log View of the Network panel
81 */
Victor Porof66878d62021-07-16 13:12:3782 invertFilter: 'Invert',
83 /**
Jack Franklinfd72c072022-12-21 11:45:0184 *@description Tooltip for the 'invert' checkbox in the Network panel.
85 */
Victor Porof66878d62021-07-16 13:12:3786 invertsFilter: 'Inverts the search filter',
87 /**
Jack Franklinfd72c072022-12-21 11:45:0188 *@description Text in Network Log View of the Network panel
89 */
Christy Chencac3f102021-02-03 10:07:5590 hideDataUrls: 'Hide data URLs',
91 /**
Jack Franklinfd72c072022-12-21 11:45:0192 *@description Data urlfilter ui element title in Network Log View of the Network panel
93 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:5594 hidesDataAndBlobUrls: 'Hide \'data:\' and \'blob:\' URLs',
Christy Chencac3f102021-02-03 10:07:5595 /**
ioana forfota45b44152023-07-21 14:20:5396 * @description Label for a filter in the Network panel
97 */
ioana forfotaaf54bd12023-07-28 09:46:2998 chromeExtensions: 'Hide extension URLs',
ioana forfota45b44152023-07-21 14:20:5399 /**
100 * @description Tooltip for a filter in the Network panel
101 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:55102 hideChromeExtension: 'Hide \'chrome-extension://\' URLs',
ioana forfota45b44152023-07-21 14:20:53103 /**
Jack Franklinfd72c072022-12-21 11:45:01104 *@description Aria accessible name in Network Log View of the Network panel
105 */
ioana forfota2c72e132023-09-22 12:11:48106 requestTypesToInclude: 'Request types to include',
107 /**
Wolfgang Beyerb9391362023-07-14 12:40:45108 *@description Label for a checkbox in the Network panel. When checked, only requests with
109 * blocked response cookies are shown.
Jack Franklinfd72c072022-12-21 11:45:01110 */
Wolfgang Beyerb9391362023-07-14 12:40:45111 hasBlockedCookies: 'Blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55112 /**
Jack Franklinfd72c072022-12-21 11:45:01113 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
114 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
115 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
116 */
Kateryna Prokopenko5f434d42023-11-03 10:57:49117 onlyShowRequestsWithBlockedCookies: 'Show only requests with blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55118 /**
Jack Franklinfd72c072022-12-21 11:45:01119 *@description Label for a filter in the Network panel
120 */
Sofia Emelianova25f46422023-07-04 15:20:11121 blockedRequests: 'Blocked requests',
Christy Chencac3f102021-02-03 10:07:55122 /**
Jack Franklinfd72c072022-12-21 11:45:01123 *@description Tooltip for a filter in the Network panel
124 */
Sofia Emelianova25f46422023-07-04 15:20:11125 onlyShowBlockedRequests: 'Show only blocked requests',
Christy Chencac3f102021-02-03 10:07:55126 /**
Jack Franklinfd72c072022-12-21 11:45:01127 *@description Label for a filter in the Network panel
128 */
Danil Somsikov721956a2021-07-07 08:17:27129 thirdParty: '3rd-party requests',
130 /**
Jack Franklinfd72c072022-12-21 11:45:01131 *@description Tooltip for a filter in the Network panel
132 */
Sofia Emelianova25f46422023-07-04 15:20:11133 onlyShowThirdPartyRequests: 'Show only requests with origin different from page origin',
Danil Somsikov721956a2021-07-07 08:17:27134 /**
Jack Franklinfd72c072022-12-21 11:45:01135 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
136 */
Christy Chencac3f102021-02-03 10:07:55137 dropHarFilesHere: 'Drop HAR files here',
138 /**
Kim-Anh Tranf705a3f2025-02-20 06:42:32139 *@description Recording text content in Network Log View of the Network panel
Jack Franklinfd72c072022-12-21 11:45:01140 */
Kim-Anh Tranf705a3f2025-02-20 06:42:32141 recordingNetworkActivity: 'Currently recording network activity',
Christy Chencac3f102021-02-03 10:07:55142 /**
Kim-Anh Tranf705a3f2025-02-20 06:42:32143 *@description Shown in the Network Log View of the Network panel when the user has not yet
144 * recorded any network activity. This is an instruction to the user to reload the page in order to
145 * show network activity in the current UI.
146 *@example {Reload page} PH1
147 *@example {Ctrl + R} PH2
Jack Franklinfd72c072022-12-21 11:45:01148 */
Kim-Anh Tranf705a3f2025-02-20 06:42:32149 performARequestOrHitSToRecordThe:
Kim-Anh Tran66efa482025-04-28 07:48:28150 'Perform a request or reload the page by using the "{PH1}" button or by pressing {PH2}.',
Christy Chencac3f102021-02-03 10:07:55151 /**
Jack Franklinfd72c072022-12-21 11:45:01152 *@description Shown in the Network Log View of the Network panel when the user has not yet
153 * recorded any network activity. This is an instruction to the user to start recording in order to
154 * show network activity in the current UI.
Kim-Anh Tranf705a3f2025-02-20 06:42:32155 * @example {Start recording} PH1
156 * @example {Ctrl + E} PH2
Jack Franklinfd72c072022-12-21 11:45:01157 */
Kim-Anh Tranf705a3f2025-02-20 06:42:32158 recordToDisplayNetworkActivity:
Kim-Anh Tran66efa482025-04-28 07:48:28159 'Record network log to display network activity by using the "{PH1}" button or by pressing {PH2}.',
Christy Chencac3f102021-02-03 10:07:55160 /**
Kim-Anh Tranf705a3f2025-02-20 06:42:32161 *@description Label of a button in the Network Log View of the Network panel.
Jack Franklinfd72c072022-12-21 11:45:01162 */
Kim-Anh Tranf705a3f2025-02-20 06:42:32163 reloadPage: 'Reload page',
164 /**
165 *@description Label of a button in the Network Log View of the Network panel.
166 */
167 startRecording: 'Start recording',
168 /**
169 *@description Shown in the Network Log View of the Network panel when the user has not yet
170 * recorded any network activity.
171 */
172 noNetworkActivityRecorded: 'No network activity recorded',
Christy Chencac3f102021-02-03 10:07:55173 /**
Jack Franklinfd72c072022-12-21 11:45:01174 *@description Text to announce to screen readers that network data is available.
175 */
Christy Chencac3f102021-02-03 10:07:55176 networkDataAvailable: 'Network Data Available',
177 /**
Jack Franklinfd72c072022-12-21 11:45:01178 *@description Text in Network Log View of the Network panel
179 *@example {3} PH1
180 *@example {5} PH2
181 */
Christy Chencac3f102021-02-03 10:07:55182 sSRequests: '{PH1} / {PH2} requests',
183 /**
Jack Franklinfd72c072022-12-21 11:45:01184 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
185 * resources transferred during a selected time frame over the compressed size of all resources transferred during
186 * the whole network log.
187 *@example {5 B} PH1
188 *@example {10 B} PH2
189 */
Christy Chencac3f102021-02-03 10:07:55190 sSTransferred: '{PH1} / {PH2} transferred',
191 /**
Jack Franklinfd72c072022-12-21 11:45:01192 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
193 * time frame over the compressed size of all resources transferred during the whole network log.
194 *@example {10} PH1
195 *@example {15} PH2
196 */
Christy Chencac3f102021-02-03 10:07:55197 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
198 /**
Jack Franklinfd72c072022-12-21 11:45:01199 * @description Text in Network Log View of the Network panel. Appears when a particular network
200 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
201 * total size (PH2).
202 * @example {40MB} PH1
203 * @example {50MB} PH2
204 */
Christy Chencac3f102021-02-03 10:07:55205 sSResources: '{PH1} / {PH2} resources',
206 /**
Jack Franklinfd72c072022-12-21 11:45:01207 *@description Text in Network Log View of the Network panel
208 *@example {40} PH1
209 *@example {50} PH2
210 */
Christy Chencac3f102021-02-03 10:07:55211 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
212 /**
Jack Franklinfd72c072022-12-21 11:45:01213 *@description Text in Network Log View of the Network panel
214 *@example {6} PH1
215 */
Christy Chencac3f102021-02-03 10:07:55216 sRequests: '{PH1} requests',
217 /**
Jack Franklinfd72c072022-12-21 11:45:01218 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
219 * all resources transferred over network during a network activity log.
220 *@example {4 B} PH1
221 */
Christy Chencac3f102021-02-03 10:07:55222 sTransferred: '{PH1} transferred',
223 /**
Jack Franklinfd72c072022-12-21 11:45:01224 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
225 * a network activity log.
226 *@example {4} PH1
227 */
Christy Chencac3f102021-02-03 10:07:55228 sBTransferredOverNetwork: '{PH1} B transferred over network',
229 /**
Jack Franklinfd72c072022-12-21 11:45:01230 *@description Text in Network Log View of the Network panel
231 *@example {4} PH1
232 */
Christy Chencac3f102021-02-03 10:07:55233 sResources: '{PH1} resources',
234 /**
Jack Franklinfd72c072022-12-21 11:45:01235 *@description Text in Network Log View of the Network panel
236 *@example {10} PH1
237 */
Christy Chencac3f102021-02-03 10:07:55238 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
239 /**
Jack Franklinfd72c072022-12-21 11:45:01240 *@description Text in Network Log View of the Network panel
241 *@example {120ms} PH1
242 */
Christy Chencac3f102021-02-03 10:07:55243 finishS: 'Finish: {PH1}',
244 /**
Jack Franklinfd72c072022-12-21 11:45:01245 *@description Text in Network Log View of the Network panel
246 *@example {3000ms} PH1
247 */
Christy Chencac3f102021-02-03 10:07:55248 domcontentloadedS: 'DOMContentLoaded: {PH1}',
249 /**
Jack Franklinfd72c072022-12-21 11:45:01250 *@description Text in Network Log View of the Network panel
251 *@example {40ms} PH1
252 */
Christy Chencac3f102021-02-03 10:07:55253 loadS: 'Load: {PH1}',
254 /**
Jack Franklinfd72c072022-12-21 11:45:01255 *@description Text for copying
256 */
Christy Chencac3f102021-02-03 10:07:55257 copy: 'Copy',
258 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51259 *@description A context menu command in the Network panel, for copying the URL of the selected request to the clipboard.
260 */
261 copyURL: 'Copy URL',
262 /**
Jack Franklinfd72c072022-12-21 11:45:01263 *@description Text in Network Log View of the Network panel
264 */
Christy Chencac3f102021-02-03 10:07:55265 copyRequestHeaders: 'Copy request headers',
266 /**
Jack Franklinfd72c072022-12-21 11:45:01267 *@description Text in Network Log View of the Network panel
268 */
Christy Chencac3f102021-02-03 10:07:55269 copyResponseHeaders: 'Copy response headers',
270 /**
Jack Franklinfd72c072022-12-21 11:45:01271 *@description Text in Network Log View of the Network panel
272 */
Christy Chencac3f102021-02-03 10:07:55273 copyResponse: 'Copy response',
274 /**
Jack Franklinfd72c072022-12-21 11:45:01275 *@description Text in Network Log View of the Network panel
276 */
Peter Marshallf625dc82021-03-02 08:10:57277 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55278 /**
Jack Franklinfd72c072022-12-21 11:45:01279 * @description A context menu command in the Network panel, for copying to the clipboard.
280 * PowerShell refers to the format the data will be copied as.
281 */
Peter Marshallb8bd00f2021-02-24 08:25:18282 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55283 /**
Jack Franklinfd72c072022-12-21 11:45:01284 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
285 * refers to the format the data will be copied as, which is compatible with the fetch web API.
286 */
Peter Marshallb8bd00f2021-02-24 08:25:18287 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55288 /**
Jack Franklinfd72c072022-12-21 11:45:01289 * @description Text in Network Log View of the Network panel. An action that copies a command to
290 * the developer's clipboard. The command allows the developer to replay this specific network
291 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
292 * type of request that will be copied.
293 */
Benedikt Meurer8f0fee62023-12-27 12:36:51294 copyAsNodejsFetch: 'Copy as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55295 /**
Jack Franklinfd72c072022-12-21 11:45:01296 *@description Text in Network Log View of the Network panel. An action that copies a command to
297 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
298 *translatable).
299 */
Peter Marshallb8bd00f2021-02-24 08:25:18300 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55301 /**
Jack Franklinfd72c072022-12-21 11:45:01302 *@description Text in Network Log View of the Network panel. An action that copies a command to
303 *the clipboard. It will copy the command in the format compatible with a Bash script.
304 */
Peter Marshallb8bd00f2021-02-24 08:25:18305 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55306 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51307 *@description A context menu command in the Network panel, for copying the URLs of all requestes to the clipboard.
308 */
309 copyAllURLs: 'Copy all URLs',
310 /**
Yang Guo6d1361f2024-07-11 08:23:48311 *@description A context menu command in the Network panel, for copying the URLs of all requestes
312 (after applying the Network filter) to the clipboard.
313 */
Yang Guo80af52f2024-07-16 12:06:26314 copyAllListedURLs: 'Copy all listed URLs',
Yang Guo6d1361f2024-07-11 08:23:48315 /**
Jack Franklinfd72c072022-12-21 11:45:01316 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48317 *the clipboard. It will copy the command in the format compatible with a PowerShell script to
318 *represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01319 */
Peter Marshallb8bd00f2021-02-24 08:25:18320 copyAllAsPowershell: 'Copy all as `PowerShell`',
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 PowerShell script to
324 *represent all network requests (after applying the Network filter).
325 */
Yang Guo80af52f2024-07-16 12:06:26326 copyAllListedAsPowershell: 'Copy all listed as `PowerShell`',
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 'fetch' command (fetch
Yang Guo6d1361f2024-07-11 08:23:48330 *should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01331 */
Peter Marshallb8bd00f2021-02-24 08:25:18332 copyAllAsFetch: 'Copy all as `fetch`',
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 'fetch' command (fetch
336 *should not be translated) to represent all network requests (after applying the Network filter).
337 */
Yang Guo80af52f2024-07-16 12:06:26338 copyAllListedAsFetch: 'Copy all listed as `fetch`',
Yang Guo6d1361f2024-07-11 08:23:48339 /**
340 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01341 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
Yang Guo6d1361f2024-07-11 08:23:48342 *(fetch and Node.js should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01343 */
Benedikt Meurer8f0fee62023-12-27 12:36:51344 copyAllAsNodejsFetch: 'Copy all as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55345 /**
Jack Franklinfd72c072022-12-21 11:45:01346 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48347 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
348 *(fetch and Node.js should not be translated) to represent all network requests (after applying
349 *the Network filter).
350 */
Yang Guo80af52f2024-07-16 12:06:26351 copyAllListedAsNodejsFetch: 'Copy all listed as `fetch` (`Node.js`)',
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
Jack Franklinfd72c072022-12-21 11:45:01354 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48355 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01356 */
Peter Marshallb8bd00f2021-02-24 08:25:18357 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
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 cURL (a program, not
361 *translatable) to represent all network requests (after applying the Network filter).
362 */
Yang Guo80af52f2024-07-16 12:06:26363 copyAllListedAsCurlCmd: 'Copy all listed as `cURL` (`cmd`)',
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
366 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
367 *all network requests.
Jack Franklinfd72c072022-12-21 11:45:01368 */
Peter Marshallb8bd00f2021-02-24 08:25:18369 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
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
Yang Guo6d1361f2024-07-11 08:23:48372 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
373 *all network requests (after applying the Network filter).
374 */
Yang Guo80af52f2024-07-16 12:06:26375 copyAllListedAsCurlBash: 'Copy all listed as `cURL` (`bash`)',
Yang Guo6d1361f2024-07-11 08:23:48376 /**
377 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01378 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
379 *translatable).
380 */
Peter Marshallb8bd00f2021-02-24 08:25:18381 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55382 /**
Jack Franklinfd72c072022-12-21 11:45:01383 *@description Text in Network Log View of the Network panel. An action that copies a command to
384 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48385 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01386 */
Peter Marshallb8bd00f2021-02-24 08:25:18387 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55388 /**
Yang Guo6d1361f2024-07-11 08:23:48389 *@description Text in Network Log View of the Network panel. An action that copies a command to
390 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
391 *translatable) to represent all network requests (after applying the Network filter).
392 */
Yang Guo80af52f2024-07-16 12:06:26393 copyAllListedAsCurl: 'Copy all listed as `cURL`',
Yang Guo6d1361f2024-07-11 08:23:48394 /**
Jack Franklinfd72c072022-12-21 11:45:01395 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24396 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
397 * sensitive data from the network requests. 'all' refers to every network request that is currently
398 * shown.
Jack Franklinfd72c072022-12-21 11:45:01399 */
Benedikt Meureracd96a62024-09-10 07:25:24400 copyAllAsHarSanitized: 'Copy all as `HAR` (sanitized)',
Christy Chencac3f102021-02-03 10:07:55401 /**
Yang Guo6d1361f2024-07-11 08:23:48402 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24403 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
404 * sensitive data from the network requests. 'all' refers to every network request that is currently
405 * shown.
Yang Guo6d1361f2024-07-11 08:23:48406 */
Benedikt Meureracd96a62024-09-10 07:25:24407 copyAllAsHarWithSensitiveData: 'Copy all as `HAR` (with sensitive data)',
408 /**
409 * @description Text in Network Log View of the Network panel. An action that copies data to the
410 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
411 * sensitive data from the network requests. 'all' refers to every network request that is currently
412 * shown (after applying the Network filter).
413 */
414 copyAllListedAsHarSanitized: 'Copy all listed as `HAR` (sanitized)',
415 /**
416 * @description Text in Network Log View of the Network panel. An action that copies data to the
417 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
418 * sensitive data from the network requests. 'all' refers to every network request that is currently
419 * shown (after applying the Network filter).
420 */
421 copyAllListedAsHarWithSensitiveData: 'Copy all listed as `HAR` (with sensitive data)',
Yang Guo6d1361f2024-07-11 08:23:48422 /**
Jack Franklinfd72c072022-12-21 11:45:01423 *@description A context menu item in the Network Log View of the Network panel
424 */
Christy Chencac3f102021-02-03 10:07:55425 clearBrowserCache: 'Clear browser cache',
426 /**
Jack Franklinfd72c072022-12-21 11:45:01427 *@description A context menu item in the Network Log View of the Network panel
428 */
Christy Chencac3f102021-02-03 10:07:55429 clearBrowserCookies: 'Clear browser cookies',
430 /**
Jack Franklinfd72c072022-12-21 11:45:01431 *@description A context menu item in the Network Log View of the Network panel
432 */
Christy Chencac3f102021-02-03 10:07:55433 blockRequestUrl: 'Block request URL',
434 /**
Jack Franklinfd72c072022-12-21 11:45:01435 *@description A context menu item in the Network Log View of the Network panel
436 *@example {example.com} PH1
437 */
Christy Chencac3f102021-02-03 10:07:55438 unblockS: 'Unblock {PH1}',
439 /**
Jack Franklinfd72c072022-12-21 11:45:01440 *@description A context menu item in the Network Log View of the Network panel
441 */
Christy Chencac3f102021-02-03 10:07:55442 blockRequestDomain: 'Block request domain',
443 /**
Jack Franklinfd72c072022-12-21 11:45:01444 *@description Text to replay an XHR request
445 */
Christy Chencac3f102021-02-03 10:07:55446 replayXhr: 'Replay XHR',
447 /**
Jack Franklinfd72c072022-12-21 11:45:01448 *@description Text in Network Log View of the Network panel
449 */
Christy Chencac3f102021-02-03 10:07:55450 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
451 /**
Jack Franklinfd72c072022-12-21 11:45:01452 *@description Text in Network Log View of the Network panel
453 */
Christy Chencac3f102021-02-03 10:07:55454 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37455 /**
Jack Franklinfd72c072022-12-21 11:45:01456 *@description A context menu item in the Network Log View of the Network panel
457 * for creating a header override
458 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41459 overrideHeaders: 'Override headers',
Silvia Eremia096e1202023-09-22 15:49:17460 /**
461 * @description Tooltip for the Show only/Hide requests dropdown of the filterbar
462 */
463 showOnlyHideRequests: 'Show only/hide requests',
464 /**
465 * @description Text for the Show only/Hide requests dropdown button of the filterbar
466 */
467 moreFilters: 'More filters',
Ergun Erdogmus5efc7e92025-02-21 11:36:50468} as const;
Tim van der Lippef596ca02021-03-31 10:02:47469const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55470const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46471
472const enum FetchStyle {
Benedikt Meurer61b7a002024-09-04 08:02:31473 BROWSER = 0,
474 NODE_JS = 1,
Danil Somsikov59f4c612021-09-08 10:58:46475}
476
Simon Zünd940cb1f2021-09-16 11:46:09477export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
478 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53479 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
480 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
ioana forfota45b44152023-07-21 14:20:53481 private readonly networkHideChromeExtensions: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04482 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53483 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
484 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
Nikolay Vitkov74a532c2025-05-16 10:55:58485 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<Record<string, boolean>>;
Benedikt Meureracd96a62024-09-10 07:25:24486 private readonly networkShowOptionsToGenerateHarWithSensitiveData: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53487 private readonly progressBarContainer: Element;
488 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
489 private rowHeightInternal: number;
490 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
491 private readonly durationCalculator: NetworkTransferDurationCalculator;
492 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30493 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53494 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
495 private mainRequestLoadTime: number;
496 private mainRequestDOMContentLoadedTime: number;
497 private filters: Filter[];
498 private timeFilter: Filter|null;
499 private hoveredNodeInternal: NetworkNode|null;
Kim-Anh Tranf705a3f2025-02-20 06:42:32500 private recordingHint: UI.EmptyWidget.EmptyWidget|null;
Jack Franklin28577db2021-10-14 08:12:53501 private highlightedNode: NetworkRequestNode|null;
502 private readonly linkifierInternal: Components.Linkifier.Linkifier;
503 private recording: boolean;
504 private needsRefresh: boolean;
505 private readonly headerHeightInternal: number;
506 private readonly groupLookups: Map<string, GroupLookupInterface>;
507 private activeGroupLookup: GroupLookupInterface|null;
508 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
509 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
Silvia Eremia096e1202023-09-22 15:49:17510 private readonly moreFiltersDropDownUI: MoreFiltersDropDownUI|undefined;
Kateryna Prokopenko24c28f92024-08-30 15:09:28511 private readonly resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
Jack Franklin28577db2021-10-14 08:12:53512 private readonly filterParser: TextUtils.TextUtils.FilterParser;
513 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
514 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50515 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53516 private readonly filterBar: UI.FilterBar.FilterBar;
517 private readonly textFilterSetting: Common.Settings.Setting<string>;
Simon Zünd2ec237c2025-07-17 05:30:52518 private networkRequestToNode: WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>;
Jan Schefflerd6c1d402021-02-26 16:56:38519
520 constructor(
521 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
522 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37523 super();
Benedikt Meurer296c5d42025-01-31 14:02:26524 this.registerRequiredCSS(networkLogViewStyles);
Blink Reformat4c46d092018-04-07 15:32:37525 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37526
527 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05528 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37529
Simon Zünd2ec237c2025-07-17 05:30:52530 this.networkRequestToNode = new WeakMap();
531
Danil Somsikov74217e92024-01-30 07:01:12532 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('network-invert-filter', false);
533 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
ioana forfota45b44152023-07-21 14:20:53534 this.networkHideChromeExtensions =
Danil Somsikov74217e92024-01-30 07:01:12535 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04536 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:12537 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Jack Franklin28577db2021-10-14 08:12:53538 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:12539 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Jack Franklin28577db2021-10-14 08:12:53540 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:12541 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Jack Franklin28577db2021-10-14 08:12:53542 this.networkResourceTypeFiltersSetting =
Danil Somsikov74217e92024-01-30 07:01:12543 Common.Settings.Settings.instance().createSetting('network-resource-type-filters', {});
Benedikt Meureracd96a62024-09-10 07:25:24544 this.networkShowOptionsToGenerateHarWithSensitiveData = Common.Settings.Settings.instance().createSetting(
545 'network.show-options-to-generate-har-with-sensitive-data', false);
Blink Reformat4c46d092018-04-07 15:32:37546
Jack Franklin28577db2021-10-14 08:12:53547 this.progressBarContainer = progressBarContainer;
548 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
549 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37550
Jan Schefflerd6c1d402021-02-26 16:56:38551 function updateRowHeight(this: NetworkLogView): void {
Kim-Anh Trana0ef2a32025-06-17 11:46:16552 this.rowHeightInternal = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
Blink Reformat4c46d092018-04-07 15:32:37553 }
Jack Franklin28577db2021-10-14 08:12:53554 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37555 updateRowHeight.call(this);
556
Jack Franklin28577db2021-10-14 08:12:53557 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
558 this.durationCalculator = new NetworkTransferDurationCalculator();
559 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37560
Danil Somsikov2a4c4e02022-10-07 12:31:30561 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53562 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30563 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37564
Jack Franklin28577db2021-10-14 08:12:53565 this.staleRequests = new Set();
566 this.mainRequestLoadTime = -1;
567 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37568
Jack Franklin28577db2021-10-14 08:12:53569 this.filters = [];
570 this.timeFilter = null;
571 this.hoveredNodeInternal = null;
572 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53573 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37574
Jack Franklin28577db2021-10-14 08:12:53575 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37576
Jack Franklin28577db2021-10-14 08:12:53577 this.recording = false;
578 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37579
Jack Franklin28577db2021-10-14 08:12:53580 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37581
Jack Franklin28577db2021-10-14 08:12:53582 this.groupLookups = new Map();
583 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37584
Jack Franklin28577db2021-10-14 08:12:53585 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37586
Jack Franklin28577db2021-10-14 08:12:53587 this.textFilterUI = new UI.FilterBar.TextFilterUI();
Benedikt Meurerf08ab4a2024-09-03 09:37:35588 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
Jack Franklin28577db2021-10-14 08:12:53589 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37590
Jack Franklin28577db2021-10-14 08:12:53591 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
Nikolay Vitkove068bd72025-04-10 06:40:39592 i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting, 'invert-filter');
Jack Franklin28577db2021-10-14 08:12:53593 this.invertFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35594 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53595 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
596 filterBar.addFilter(this.invertFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00597 filterBar.addDivider();
Victor Porof66878d62021-07-16 13:12:37598
Blink Reformat4c46d092018-04-07 15:32:37599 const filterItems =
Danil Somsikovf90908e2024-02-29 15:40:36600 Object.entries(Common.ResourceType.resourceCategories).map(([key, category]) => ({
Simon Zünd9112a772024-10-17 07:02:51601 name: category.name,
Danil Somsikovf90908e2024-02-29 15:40:36602 label: () => category.shortTitle(),
603 title: category.title(),
604 jslogContext:
605 Platform.StringUtilities.toKebabCase(key),
606 }));
Wolfgang Beyerd6f111c2025-05-05 08:43:49607 this.moreFiltersDropDownUI = new MoreFiltersDropDownUI();
608 this.moreFiltersDropDownUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
609 filterBar.addFilter(this.moreFiltersDropDownUI);
ioana forfota2c72e132023-09-22 12:11:48610
Wolfgang Beyerd6f111c2025-05-05 08:43:49611 this.resourceCategoryFilterUI =
612 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
613 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
614 this.resourceCategoryFilterUI.addEventListener(
615 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
616 filterBar.addFilter(this.resourceCategoryFilterUI);
Danil Somsikov721956a2021-07-07 08:17:27617
Jack Franklin28577db2021-10-14 08:12:53618 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
619 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38620 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
621 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37622
Danil Somsikov2a4c4e02022-10-07 12:31:30623 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38624 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30625 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49626 filterBar.filterButton().addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35627 UI.Toolbar.ToolbarButton.Events.CLICK, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37628
Benedikt Meurer918a8212025-01-09 08:47:08629 this.summaryToolbarInternal = this.element.createChild('devtools-toolbar', 'network-summary-bar');
630 this.summaryToolbarInternal.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37631
Tim van der Lippe0ed1d2b2020-02-04 13:45:13632 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38633 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37634
Paul Lewis2d7d65c2020-03-16 17:26:30635 Common.Settings.Settings.instance()
Danil Somsikov74217e92024-01-30 07:01:12636 .moduleSetting('network-color-code-resource-types')
Jan Scheffler17b8fb42021-08-12 12:28:38637 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37638
Danil Somsikov62bc5782023-03-21 10:48:50639 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27640 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38641 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27642 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38643 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
Wolfgang Beyer51f2f252023-07-27 17:09:51644 Logs.NetworkLog.NetworkLog.instance().addEventListener(
645 Logs.NetworkLog.Events.RequestRemoved, this.onRequestRemoved, this);
Jan Scheffler17b8fb42021-08-12 12:28:38646 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37647
Jan Scheffler17b8fb42021-08-12 12:28:38648 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30649 Common.Settings.Settings.instance()
650 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38651 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37652
Jack Franklin28577db2021-10-14 08:12:53653 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03654
Danil Somsikov74217e92024-01-30 07:01:12655 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('network-text-filter', '');
Jack Franklin28577db2021-10-14 08:12:53656 if (this.textFilterSetting.get()) {
657 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03658 }
Blink Reformat4c46d092018-04-07 15:32:37659 }
660
Jan Scheffler17b8fb42021-08-12 12:28:38661 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30662 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38663 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37664 }
665
Jan Scheffler17b8fb42021-08-12 12:28:38666 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16667 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37668 values.sort((a, b) => {
Paul Irisha8a15972024-04-30 15:14:19669 const aPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a);
670 const bPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b);
Tim van der Lippeded23fb2020-02-13 13:33:50671 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
672 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37673 });
674 } else {
675 values.sort();
676 }
677 }
678
Jan Scheffler17b8fb42021-08-12 12:28:38679 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37680 return !filter(request);
681 }
682
Jan Scheffler17b8fb42021-08-12 12:28:38683 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34684 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37685 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34686 }
Blink Reformat4c46d092018-04-07 15:32:37687
688 return regex.test(request.path() + '/' + request.name());
689 }
690
Jan Scheffler17b8fb42021-08-12 12:28:38691 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37692 const result = [domain];
693 let indexOfPeriod = domain.indexOf('.');
694 while (indexOfPeriod !== -1) {
695 result.push('*' + domain.substring(indexOfPeriod));
696 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
697 }
698 return result;
699 }
700
Jan Scheffler17b8fb42021-08-12 12:28:38701 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17702 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38703 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37704 }
705
Jan Scheffler17b8fb42021-08-12 12:28:38706 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37707 return regex.test(request.domain);
708 }
709
Jan Scheffler17b8fb42021-08-12 12:28:38710 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37711 return !request.finished;
712 }
713
Jan Scheffler17b8fb42021-08-12 12:28:38714 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37715 return request.cached();
716 }
717
Jan Scheffler17b8fb42021-08-12 12:28:38718 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05719 return request.fetchedViaServiceWorker;
720 }
721
Jan Scheffler17b8fb42021-08-12 12:28:38722 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05723 return request.initiatedByServiceWorker();
724 }
725
Jan Scheffler17b8fb42021-08-12 12:28:38726 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37727 return request.responseHeaderValue(value) !== undefined;
728 }
729
Garima Chadha8dde1c22025-05-19 19:52:47730 private static requestRequestHeaderFilter(headerName: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
731 return request.requestHeaders().some(header => header.name.toLowerCase() === headerName.toLowerCase());
732 }
733
Jan Scheffler17b8fb42021-08-12 12:28:38734 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
735 boolean {
Jack Franklin28577db2021-10-14 08:12:53736 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51737 // filter via `includes` instead of strict equality.
738 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
739 }
740
Jan Scheffler17b8fb42021-08-12 12:28:38741 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37742 return request.requestMethod === value;
743 }
744
Jan Scheffler17b8fb42021-08-12 12:28:38745 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37746 return request.priority() === value;
747 }
748
Jan Scheffler17b8fb42021-08-12 12:28:38749 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37750 return request.mimeType === value;
751 }
752
Jan Scheffler17b8fb42021-08-12 12:28:38753 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16754 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
Benedikt Meurer61b7a002024-09-04 08:02:31755 if (value === NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED) {
Blink Reformat4c46d092018-04-07 15:32:37756 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28757 }
Benedikt Meurer61b7a002024-09-04 08:02:31758 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED) {
Blink Reformat4c46d092018-04-07 15:32:37759 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28760 }
Benedikt Meurer61b7a002024-09-04 08:02:31761 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN) {
Blink Reformat4c46d092018-04-07 15:32:37762 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28763 }
Benedikt Meurer61b7a002024-09-04 08:02:31764 if (value === NetworkForward.UIFilter.MixedContentFilterValues.ALL) {
Blink Reformat4c46d092018-04-07 15:32:37765 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34766 }
Blink Reformat4c46d092018-04-07 15:32:37767
768 return false;
769 }
770
Jan Scheffler17b8fb42021-08-12 12:28:38771 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37772 return request.scheme === value;
773 }
774
Jan Scheffler17b8fb42021-08-12 12:28:38775 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41776 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
777 }
778
Jan Scheffler17b8fb42021-08-12 12:28:38779 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41780 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
781 }
782
Jan Scheffler17b8fb42021-08-12 12:28:38783 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54784 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
785 }
786
Jan Scheffler17b8fb42021-08-12 12:28:38787 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41788 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
789 }
790
Jan Scheffler17b8fb42021-08-12 12:28:38791 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41792 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37793 }
794
Jan Scheffler17b8fb42021-08-12 12:28:38795 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41796 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37797 }
798
Jan Scheffler17b8fb42021-08-12 12:28:38799 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41800 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37801 }
802
Jan Scheffler17b8fb42021-08-12 12:28:38803 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37804 return request.transferSize >= value;
805 }
806
Jan Scheffler17b8fb42021-08-12 12:28:38807 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24808 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37809 }
810
Jecelyn Yeen77c83462023-08-16 16:13:17811 private static hasOverridesFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
812 if (!value) {
813 return false;
814 }
815
816 if (value === overrideFilter.no) {
817 return request.overrideTypes.length === 0;
818 }
819
820 if (value === overrideFilter.yes) {
821 return request.overrideTypes.length > 0;
822 }
823
824 if (value === overrideFilter.content) {
825 return request.overrideTypes.includes('content');
826 }
827
828 if (value === overrideFilter.headers) {
829 return request.overrideTypes.includes('headers');
830 }
831
832 return request.overrideTypes.join(',').includes(value);
833 }
834
Sigurd Schneider576ca9a2021-07-16 05:58:04835 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58836 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37837 }
838
Jan Scheffler17b8fb42021-08-12 12:28:38839 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03840 return request.resourceType().name() === value;
841 }
842
Jan Scheffler17b8fb42021-08-12 12:28:38843 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17844 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03845 return regex.test(request.url());
846 }
847
Jan Scheffler17b8fb42021-08-12 12:28:38848 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38849 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34850 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37851 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34852 }
853 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37854 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34855 }
Blink Reformat4c46d092018-04-07 15:32:37856 return true;
857 }
858
Jan Scheffler17b8fb42021-08-12 12:28:38859 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13860 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37861 }
862
Jan Scheffler17b8fb42021-08-12 12:28:38863 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13864 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37865 }
866
Jan Scheffler17b8fb42021-08-12 12:28:38867 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Simon Zünd0d87db62024-05-27 07:26:27868 const contentData = await request.requestContentData();
Simon Zünd3b583882023-12-22 05:23:43869 let content: string;
Simon Zünd7fb55c02024-01-29 12:00:27870 if (TextUtils.ContentData.ContentData.isError(contentData)) {
Simon Zünd3b583882023-12-22 05:23:43871 content = '';
Simon Zündebe01922024-01-18 10:11:58872 } else if (!contentData.isTextContent) {
Simon Zünd3b583882023-12-22 05:23:43873 content = contentData.asDataUrl() ?? '';
874 } else {
875 content = contentData.text;
Tim van der Lippe1d6e57a2019-09-30 11:55:34876 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13877 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37878 }
879
Jan Scheffler17b8fb42021-08-12 12:28:38880 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37881 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34882 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37883 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34884 }
Simon Zünd99961242021-09-08 11:02:12885 const file = items[0].getAsFile();
886 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03887 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34888 }
Blink Reformat4c46d092018-04-07 15:32:37889 }
890
Jan Schefflerd6c1d402021-02-26 16:56:38891 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13892 const outputStream = new Common.StringOutputStream.StringOutputStream();
893 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37894 const success = await reader.read(outputStream);
895 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37896 const error = reader.error();
897 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38898 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37899 }
Blink Reformat4c46d092018-04-07 15:32:37900 return;
901 }
902 let harRoot;
903 try {
904 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56905 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37906 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38907 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37908 return;
909 }
Tim van der Lippe09cf5032021-04-29 15:08:09910 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37911 }
912
Jan Scheffler17b8fb42021-08-12 12:28:38913 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36914 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37915 }
916
Jan Scheffler17b8fb42021-08-12 12:28:38917 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53918 if (this.activeGroupLookup) {
919 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34920 }
Jack Franklin28577db2021-10-14 08:12:53921 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
922 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38923 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37924 }
925
Jan Schefflerd6c1d402021-02-26 16:56:38926 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Simon Zünd2ec237c2025-07-17 05:30:52927 return this.networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37928 }
929
Jan Schefflerd6c1d402021-02-26 16:56:38930 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53931 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37932 }
933
Jan Schefflerd6c1d402021-02-26 16:56:38934 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53935 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38936 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37937 }
938
Danil Somsikov2a4c4e02022-10-07 12:31:30939 columns(): NetworkLogViewColumns {
940 return this.columnsInternal;
941 }
942
Wolfgang Beyer8fc262f2023-04-11 13:22:50943 summaryToolbar(): UI.Toolbar.Toolbar {
944 return this.summaryToolbarInternal;
945 }
946
Jan Schefflerd6c1d402021-02-26 16:56:38947 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37948 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22949 const target = networkManager.target();
950 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37951 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34952 }
Danil Somsikov88384322023-03-22 13:53:22953 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37954 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38955 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37956 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38957 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37958 }
Danil Somsikov88384322023-03-22 13:53:22959 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:04960 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:25961 this.refreshRequest(request);
962 }
Danil Somsikov88384322023-03-22 13:53:22963 }
Blink Reformat4c46d092018-04-07 15:32:37964 }
965
Jan Schefflerd6c1d402021-02-26 16:56:38966 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:22967 const target = networkManager.target();
968 if (target.outermostTarget() !== target) {
969 return;
970 }
971 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
972 if (resourceTreeModel) {
973 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
974 resourceTreeModel.removeEventListener(
975 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
976 }
Danil Somsikovac291c82024-01-30 13:47:46977 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network-log.preserve-log').get();
Danil Somsikov88384322023-03-22 13:53:22978 if (!preserveLog) {
979 this.reset();
Blink Reformat4c46d092018-04-07 15:32:37980 }
981 }
982
Jan Schefflerd6c1d402021-02-26 16:56:38983 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53984 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13985 }
986
Jan Schefflerd6c1d402021-02-26 16:56:38987 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37988 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53989 this.timeFilter = null;
990 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37991 } else {
Jack Franklin28577db2021-10-14 08:12:53992 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
993 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37994 }
Jan Scheffler17b8fb42021-08-12 12:28:38995 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37996 }
997
Jan Schefflerd6c1d402021-02-26 16:56:38998 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53999 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:371000 }
1001
Jan Scheffler17b8fb42021-08-12 12:28:381002 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:531003 this.suggestionBuilder.clear();
Benedikt Meurer61b7a002024-09-04 08:02:311004 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.RUNNING);
Jack Franklin28577db2021-10-14 08:12:531005 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311006 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FROM_CACHE);
Jack Franklin28577db2021-10-14 08:12:531007 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311008 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED);
Jack Franklin28577db2021-10-14 08:12:531009 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311010 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED);
Jack Franklin28577db2021-10-14 08:12:531011 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
1012 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
1013 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
1014 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Jecelyn Yeen77c83462023-08-16 16:13:171015 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.yes);
1016 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.no);
1017 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.content);
1018 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.headers);
Blink Reformat4c46d092018-04-07 15:32:371019 }
1020
Simon Zünda2bae2e2021-09-16 07:57:131021 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371022 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:531023 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:381024 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:531025 this.textFilterSetting.set(this.textFilterUI.value());
Kateryna Prokopenkod98e34c2023-09-25 18:08:481026 this.moreFiltersDropDownUI?.updateActiveFiltersCount();
Kateryna Prokopenko5f434d42023-11-03 10:57:491027 this.moreFiltersDropDownUI?.updateTooltip();
Finnur Thorarinsson884bac52025-05-14 14:41:091028 this.columnsInternal.filterChanged();
Blink Reformat4c46d092018-04-07 15:32:371029 }
1030
Jan Schefflerd6c1d402021-02-26 16:56:381031 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:531032 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:121033 }
1034
Jan Scheffler17b8fb42021-08-12 12:28:381035 private showRecordingHint(): void {
1036 this.hideRecordingHint();
Joey Arhar0585e6f2018-10-30 23:11:181037
Kim-Anh Tran7bddf9c2025-03-10 08:43:141038 const actionRegistry = UI.ActionRegistry.ActionRegistry.instance();
Kim-Anh Tranf705a3f2025-02-20 06:42:321039 const actionName = this.recording ? 'inspector-main.reload' : 'network.toggle-recording';
Kim-Anh Tran7bddf9c2025-03-10 08:43:141040 const action = actionRegistry.hasAction(actionName) ? actionRegistry.getAction(actionName) : null;
Kim-Anh Tranf705a3f2025-02-20 06:42:321041 const shortcutTitle = UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction(actionName) ?? '';
Wolfgang Beyer5c385b92020-11-09 15:20:041042
Kim-Anh Tranf705a3f2025-02-20 06:42:321043 const header = this.recording ? i18nString(UIStrings.recordingNetworkActivity) :
1044 i18nString(UIStrings.noNetworkActivityRecorded);
1045 const instruction =
1046 this.recording ? UIStrings.performARequestOrHitSToRecordThe : UIStrings.recordToDisplayNetworkActivity;
1047 const buttonText = this.recording ? i18nString(UIStrings.reloadPage) : i18nString(UIStrings.startRecording);
1048 // eslint-disable-next-line rulesdir/l10n-i18nString-call-only-with-uistrings
1049 const description = i18nString(instruction, {
1050 PH1: buttonText,
1051 PH2: shortcutTitle,
1052 });
Amanda Baker6761aae2019-11-05 18:59:111053
Kim-Anh Tranf705a3f2025-02-20 06:42:321054 this.recordingHint = new UI.EmptyWidget.EmptyWidget(header, shortcutTitle ? description : '');
1055 this.recordingHint.element.classList.add('network-status-pane');
Danil Somsikova865f232025-05-22 10:40:441056 this.recordingHint.link = 'https://developer.chrome.com/docs/devtools/network/' as Platform.DevToolsPath.UrlString;
Kim-Anh Tran7bddf9c2025-03-10 08:43:141057 if (shortcutTitle && action) {
1058 const button = UI.UIUtils.createTextButton(buttonText, () => action.execute(), {
1059 jslogContext: actionName,
1060 variant: Buttons.Button.Variant.TONAL,
1061 });
1062 this.recordingHint.contentElement.appendChild(button);
1063 }
Kim-Anh Tranf705a3f2025-02-20 06:42:321064
1065 this.recordingHint.show(this.element);
Jan Scheffler17b8fb42021-08-12 12:28:381066 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:371067 }
1068
Jan Scheffler17b8fb42021-08-12 12:28:381069 private hideRecordingHint(): void {
1070 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:531071 if (this.recordingHint) {
Kim-Anh Tranf705a3f2025-02-20 06:42:321072 this.recordingHint.detach();
1073 this.recordingHint = null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341074 }
Ergun Erdogmusd4f01d42025-07-14 16:24:001075 UI.ARIAUtils.LiveAnnouncer.alert(i18nString(UIStrings.networkDataAvailable));
Blink Reformat4c46d092018-04-07 15:32:371076 }
1077
Jan Scheffler17b8fb42021-08-12 12:28:381078 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301079 this.columnsInternal.setHidden(value);
Jack Franklin7c055842025-04-14 07:54:591080 this.dataGrid.setInert(value);
Benedikt Meurer918a8212025-01-09 08:47:081081 UI.ARIAUtils.setHidden(this.summaryToolbarInternal, value);
Amanda Baker6761aae2019-11-05 18:59:111082 }
1083
Randolf Jungffd14242023-04-19 00:32:251084 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:531085 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 {
Blink Reformat4c46d092018-04-07 15:32:371087 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:341088 }
Jack Franklin28577db2021-10-14 08:12:531089 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:371090 }
1091
Jan Schefflerd6c1d402021-02-26 16:56:381092 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381093 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:371094 }
1095
Jan Scheffler17b8fb42021-08-12 12:28:381096 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:531097 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:381098 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341099 if (request) {
Blink Reformat4c46d092018-04-07 15:32:371100 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341101 }
Blink Reformat4c46d092018-04-07 15:32:371102 });
Paul Irishf2ff58b2024-11-06 23:52:001103 this.dataGrid.setEnableAutoScrollToBottom(true);
Danil Somsikova6ce6ed2024-01-31 08:10:121104 this.dataGrid.setName('network-log');
Benedikt Meurerf08ab4a2024-09-03 09:37:351105 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.LAST);
Jack Franklin28577db2021-10-14 08:12:531106 this.dataGrid.element.classList.add('network-log-grid');
1107 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
1108 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
1109 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
1110 this.dataGrid.element.addEventListener('keydown', event => {
1111 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
Danil Somsikove10a94c2024-03-11 08:31:321112 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('button.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:431113 if (initiatorLink) {
1114 (initiatorLink as HTMLElement).focus();
1115 }
1116 }
ergunshee4a6132021-11-05 16:21:251117
Jack Franklin5e685be2022-10-17 14:27:091118 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051119 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051120 event.consume(true);
1121 }
1122 });
ergunshee4a6132021-11-05 16:21:251123 this.dataGrid.element.addEventListener('keyup', event => {
1124 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1125 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1126 if (!request) {
1127 return;
1128 }
1129
1130 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1131 SDK.NetworkManager.NetworkManager.replayRequest(request);
Danil Somsikov1a4a3322024-03-11 16:27:271132 void VisualLogging.logKeyDown(this.dataGrid.selectedNode.element(), event, 'replay-xhr');
ergunshee4a6132021-11-05 16:21:251133 }
1134 }
1135 });
Jack Franklin28577db2021-10-14 08:12:531136 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1137 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1138 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371139 }
1140
Jan Scheffler17b8fb42021-08-12 12:28:381141 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381142 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531143 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371144 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381145 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371146 }
1147
Jan Schefflerd6c1d402021-02-26 16:56:381148 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531149 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371150 }
1151
Jan Scheffler17b8fb42021-08-12 12:28:381152 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531153 if (this.hoveredNodeInternal) {
1154 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341155 }
Jack Franklin28577db2021-10-14 08:12:531156 this.hoveredNodeInternal = node;
1157 if (this.hoveredNodeInternal) {
1158 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341159 }
Blink Reformat4c46d092018-04-07 15:32:371160 }
1161
Jan Scheffler17b8fb42021-08-12 12:28:381162 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381163 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531164 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371165 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341166 }
Blink Reformat4c46d092018-04-07 15:32:371167 }
1168
Jan Scheffler17b8fb42021-08-12 12:28:381169 private updateSummaryBar(): void {
1170 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371171
1172 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201173 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371174 let selectedNodeNumber = 0;
1175 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201176 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371177 let baseTime = -1;
1178 let maxTime = -1;
1179
1180 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271181 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Simon Zünd2ec237c2025-07-17 05:30:521182 const node = this.networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341183 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371184 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341185 }
Blink Reformat4c46d092018-04-07 15:32:371186 nodeCount++;
1187 const requestTransferSize = request.transferSize;
1188 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201189 const requestResourceSize = request.resourceSize;
1190 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371191 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371192 selectedNodeNumber++;
1193 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201194 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371195 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131196 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371197 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1198 // inspected url.
1199 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131200 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Benedikt Meurerb7d85042024-08-23 13:38:321201 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.FRAME) {
Adithya Srinivasan77770382024-05-17 20:22:091202 // If the primary main frame's document was fetched from the prefetch cache,
1203 // we should use the issueTime (i.e. when the navigation request was about to start)
1204 // instead of startTime, which is when the prefetch network request started
1205 // (which is typically well before the navigation starts).
1206 baseTime = request.fromPrefetchCache() ? request.issueTime() : request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341207 }
1208 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371209 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341210 }
Blink Reformat4c46d092018-04-07 15:32:371211 }
1212
1213 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381214 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371215 return;
1216 }
1217
Wolfgang Beyer8fc262f2023-04-11 13:22:501218 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381219 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131220 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501221 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501222 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381223 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501224 };
Blink Reformat4c46d092018-04-07 15:32:371225
1226 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551227 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501228 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501229 appendChunk(
Christy Chencac3f102021-02-03 10:07:551230 i18nString(UIStrings.sSTransferred, {
Adriana Ixba7a9b9372025-03-19 21:53:171231 PH1: i18n.ByteUtilities.formatBytesToKb(selectedTransferSize),
1232 PH2: i18n.ByteUtilities.formatBytesToKb(transferSize),
Christy Chencac3f102021-02-03 10:07:551233 }),
1234 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501235 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501236 appendChunk(
Christy Chencac3f102021-02-03 10:07:551237 i18nString(UIStrings.sSResources, {
Adriana Ixba7a9b9372025-03-19 21:53:171238 PH1: i18n.ByteUtilities.formatBytesToKb(selectedResourceSize),
1239 PH2: i18n.ByteUtilities.formatBytesToKb(resourceSize),
Christy Chencac3f102021-02-03 10:07:551240 }),
1241 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371242 } else {
Christy Chencac3f102021-02-03 10:07:551243 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501244 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251245 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001246 i18nString(UIStrings.sTransferred, {PH1: i18n.ByteUtilities.bytesToString(transferSize)}),
Christy Chencac3f102021-02-03 10:07:551247 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501248 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251249 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001250 i18nString(UIStrings.sResources, {PH1: i18n.ByteUtilities.bytesToString(resourceSize)}),
Christy Chencac3f102021-02-03 10:07:551251 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371252 }
Dan Beam87466b52018-12-01 18:41:201253
Blink Reformat4c46d092018-04-07 15:32:371254 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501255 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581256 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531257 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501258 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551259 const domContentLoadedText = i18nString(
1260 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531261 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381262 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371263 }
Jack Franklin28577db2021-10-14 08:12:531264 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501265 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531266 const loadText =
1267 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381268 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371269 }
1270 }
Blink Reformat4c46d092018-04-07 15:32:371271 }
1272
Jan Schefflerd6c1d402021-02-26 16:56:381273 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531274 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371275 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341276 }
Blink Reformat4c46d092018-04-07 15:32:371277
Jack Franklin28577db2021-10-14 08:12:531278 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371279
Danil Somsikovf3b437f2023-03-23 16:15:391280 if (this.isShowing()) {
Benedikt Meurer328b3a72025-01-02 10:38:551281 void RenderCoordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341282 }
Blink Reformat4c46d092018-04-07 15:32:371283 }
1284
Jan Schefflerd6c1d402021-02-26 16:56:381285 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301286 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371287 }
1288
Jan Schefflerd6c1d402021-02-26 16:56:381289 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301290 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371291 }
1292
Jan Schefflerd6c1d402021-02-26 16:56:381293 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301294 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371295 }
1296
Jan Scheffler17b8fb42021-08-12 12:28:381297 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531298 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381299 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341300 }
Blink Reformat4c46d092018-04-07 15:32:371301 }
1302
Jan Scheffler17b8fb42021-08-12 12:28:381303 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041304 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341305 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371306 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341307 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381308 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341309 }
Blink Reformat4c46d092018-04-07 15:32:371310 }
1311
Jan Schefflerd6c1d402021-02-26 16:56:381312 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531313 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371314 }
1315
Jan Schefflerd6c1d402021-02-26 16:56:381316 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531317 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371318 }
1319
Jan Schefflerd6c1d402021-02-26 16:56:381320 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531321 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371322 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341323 }
Blink Reformat4c46d092018-04-07 15:32:371324
Jack Franklin28577db2021-10-14 08:12:531325 if (this.calculatorInternal !== x) {
1326 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301327 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371328 }
Jack Franklin28577db2021-10-14 08:12:531329 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371330
Jack Franklin28577db2021-10-14 08:12:531331 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301332 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341333 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301334 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341335 }
Blink Reformat4c46d092018-04-07 15:32:371336
Jan Scheffler17b8fb42021-08-12 12:28:381337 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371338 }
1339
Jan Scheffler17b8fb42021-08-12 12:28:381340 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271341 event: Common.EventTarget
1342 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531343 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371344 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341345 }
Blink Reformat4c46d092018-04-07 15:32:371346
Simon Zünd1a930492021-07-30 08:22:271347 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371348 if (time) {
Jack Franklin28577db2021-10-14 08:12:531349 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301350 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371351 }
1352 }
1353
Jan Scheffler17b8fb42021-08-12 12:28:381354 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531355 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371356 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341357 }
Simon Zünd1a930492021-07-30 08:22:271358 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371359 if (data) {
Jack Franklin28577db2021-10-14 08:12:531360 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301361 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371362 }
1363 }
1364
Randolf Jungffd14242023-04-19 00:32:251365 override wasShown(): void {
Benedikt Meurer296c5d42025-01-31 14:02:261366 super.wasShown();
Jan Scheffler17b8fb42021-08-12 12:28:381367 this.refreshIfNeeded();
Danil Somsikov2a4c4e02022-10-07 12:31:301368 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371369 }
1370
Randolf Jungffd14242023-04-19 00:32:251371 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301372 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371373 }
1374
Jan Schefflerd6c1d402021-02-26 16:56:381375 flatNodesList(): NetworkNode[] {
1376 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531377 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381378 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1379 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381
Jan Scheffler17b8fb42021-08-12 12:28:381382 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531383 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351384 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381385 }
Brandon Goddard44934902020-03-25 16:03:181386 this.updateNodeBackground();
1387 }
1388
Jan Scheffler17b8fb42021-08-12 12:28:381389 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181390 this.element.classList.remove('grid-focused');
1391 this.updateNodeBackground();
1392 }
1393
Jan Schefflerd6c1d402021-02-26 16:56:381394 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531395 if (this.dataGrid.selectedNode) {
1396 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051397 }
1398 }
1399
Jan Schefflerd6c1d402021-02-26 16:56:381400 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051401 if (isSelected) {
1402 this.element.classList.remove('no-node-selected');
1403 } else {
1404 this.element.classList.add('no-node-selected');
1405 }
1406 }
1407
Jan Schefflerd6c1d402021-02-26 16:56:381408 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301409 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371410 }
1411
Wolfgang Beyer51f2f252023-07-27 17:09:511412 private removeNodeAndMaybeAncestors(node: NetworkRequestNode): void {
1413 let parent: NetworkNode|
1414 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1415 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1416 null) = node.parent;
1417 if (!parent) {
1418 return;
1419 }
1420 parent.removeChild(node);
1421 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1422 const grandparent = (parent.parent as NetworkNode);
1423 grandparent.removeChild(parent);
1424 parent = grandparent;
1425 }
1426 }
1427
Jan Scheffler17b8fb42021-08-12 12:28:381428 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531429 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371430
Blink Reformat4c46d092018-04-07 15:32:371431 this.removeAllNodeHighlights();
1432
Jack Franklin28577db2021-10-14 08:12:531433 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1434 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1435 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1436 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371437
Jan Schefflerd6c1d402021-02-26 16:56:381438 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1439 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371440
Jan Schefflerd6c1d402021-02-26 16:56:381441 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371442
Jack Franklin28577db2021-10-14 08:12:531443 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371444 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531445 while (this.staleRequests.size) {
Simon Zündf0d3b5c2024-10-10 06:28:021446 const request = this.staleRequests.values().next().value as SDK.NetworkRequest.NetworkRequest;
Jack Franklin28577db2021-10-14 08:12:531447 this.staleRequests.delete(request);
Simon Zünd2ec237c2025-07-17 05:30:521448 let node = this.networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341449 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381450 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341451 }
Blink Reformat4c46d092018-04-07 15:32:371452 staleNodes.add(node);
1453 }
1454
1455 for (const node of staleNodes) {
Yang Guo6d1361f2024-07-11 08:23:481456 const request = node.request();
1457 const isFilteredOut = !this.applyFilter(request);
Benedikt Meurere4391232024-06-07 10:47:251458 if (isFilteredOut) {
1459 if (node === this.hoveredNodeInternal) {
1460 this.setHoveredNode(null);
1461 }
1462 node.selected = false;
1463 } else {
Blink Reformat4c46d092018-04-07 15:32:371464 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341465 }
Jack Franklin28577db2021-10-14 08:12:531466 this.timeCalculatorInternal.updateBoundaries(request);
1467 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381468 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371469 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1470 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371471 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341472 }
Tim van der Lippe224a8622020-09-23 12:14:371473 if (isFilteredOut) {
1474 filteredNetworkRequests.add(node);
1475 } else {
1476 filteredNetworkRequests.delete(node);
1477 }
Blink Reformat4c46d092018-04-07 15:32:371478 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1479 if (removeFromParent) {
Wolfgang Beyer51f2f252023-07-27 17:09:511480 this.removeNodeAndMaybeAncestors(node);
Blink Reformat4c46d092018-04-07 15:32:371481 }
1482
Tim van der Lippe1d6e57a2019-09-30 11:55:341483 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371484 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341485 }
Blink Reformat4c46d092018-04-07 15:32:371486
1487 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531488 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371489 nodesToRefresh.push(newParent);
1490 }
1491 nodesToInsert.set(node, newParent);
1492 }
1493
Tim van der Lippe1d6e57a2019-09-30 11:55:341494 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381495 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341496 }
Blink Reformat4c46d092018-04-07 15:32:371497
Tim van der Lippe1d6e57a2019-09-30 11:55:341498 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371499 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341500 }
Blink Reformat4c46d092018-04-07 15:32:371501
Jan Scheffler17b8fb42021-08-12 12:28:381502 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371503
Tim van der Lippe1d6e57a2019-09-30 11:55:341504 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301505 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341506 }
Blink Reformat4c46d092018-04-07 15:32:371507
Jack Franklin28577db2021-10-14 08:12:531508 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381509 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371510 }
1511
Jan Scheffler17b8fb42021-08-12 12:28:381512 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371513 }
1514
Jan Scheffler17b8fb42021-08-12 12:28:381515 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531516 if (!this.activeGroupLookup) {
1517 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341518 }
Blink Reformat4c46d092018-04-07 15:32:371519
Jack Franklin28577db2021-10-14 08:12:531520 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341521 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531522 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341523 }
Blink Reformat4c46d092018-04-07 15:32:371524 return groupNode;
1525 }
1526
Jan Scheffler17b8fb42021-08-12 12:28:381527 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151528 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371529
Jan Scheffler17b8fb42021-08-12 12:28:381530 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301531 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371532
Jack Franklin28577db2021-10-14 08:12:531533 this.timeFilter = null;
1534 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371535
Jack Franklin28577db2021-10-14 08:12:531536 this.timeCalculatorInternal.setWindow(null);
1537 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371538
Jack Franklin28577db2021-10-14 08:12:531539 if (this.activeGroupLookup) {
1540 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341541 }
Jack Franklin28577db2021-10-14 08:12:531542 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381543 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371544
Jack Franklin28577db2021-10-14 08:12:531545 this.mainRequestLoadTime = -1;
1546 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371547
Simon Zünd2ec237c2025-07-17 05:30:521548 this.networkRequestToNode = new WeakMap();
1549
Jack Franklin28577db2021-10-14 08:12:531550 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381551 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371552 this.scheduleRefresh();
1553 }
1554
Silvia Eremia096e1202023-09-22 15:49:171555 // TODO(crbug.com/1477668)
Jan Schefflerd6c1d402021-02-26 16:56:381556 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531557 this.textFilterUI.setValue(filterString);
Wolfgang Beyerd6f111c2025-05-05 08:43:491558 this.networkHideDataURLSetting.set(false);
1559 this.networkShowBlockedCookiesOnlySetting.set(false);
1560 this.networkOnlyBlockedRequestsSetting.set(false);
1561 this.networkOnlyThirdPartySetting.set(false);
1562 this.networkHideChromeExtensions.set(false);
Jack Franklin28577db2021-10-14 08:12:531563 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371564 }
1565
Jan Scheffler17b8fb42021-08-12 12:28:381566 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301567 const node = new NetworkRequestNode(this, request);
Simon Zünd2ec237c2025-07-17 05:30:521568 this.networkRequestToNode.set(request, node);
Tim van der Lippe224a8622020-09-23 12:14:371569 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371570
Tim van der Lippe1d6e57a2019-09-30 11:55:341571 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381572 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341573 }
Blink Reformat4c46d092018-04-07 15:32:371574 return node;
1575 }
1576
Danil Somsikov123c3ef2023-06-14 10:07:041577 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1578 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1579 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1580 }
1581
Wolfgang Beyer393dc2b2024-01-05 15:07:401582 private onRequestUpdated(
1583 event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest, preserveLog?: boolean}>):
1584 void {
1585 const {request, preserveLog} = event.data;
1586 if (this.isInScope(request) || preserveLog) {
Danil Somsikova09c4de2023-03-27 10:35:251587 this.refreshRequest(request);
1588 }
Blink Reformat4c46d092018-04-07 15:32:371589 }
1590
Wolfgang Beyer393dc2b2024-01-05 15:07:401591 private onRequestRemoved(event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest}>):
1592 void {
1593 const {request} = event.data;
Wolfgang Beyer51f2f252023-07-27 17:09:511594 this.staleRequests.delete(request);
Simon Zünd2ec237c2025-07-17 05:30:521595 const node = this.networkRequestToNode.get(request);
Wolfgang Beyer51f2f252023-07-27 17:09:511596 if (node) {
1597 this.removeNodeAndMaybeAncestors(node);
1598 }
1599 }
1600
Jan Scheffler17b8fb42021-08-12 12:28:381601 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1602 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161603 .forEach(
Jack Franklin28577db2021-10-14 08:12:531604 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1605 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1606 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1607 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1608 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1609 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1610 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371611
1612 const priority = request.priority();
1613 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531614 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161615 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371616 }
1617
1618 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531619 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311620 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.ALL);
Blink Reformat4c46d092018-04-07 15:32:371621 }
1622
1623 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531624 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311625 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED);
Blink Reformat4c46d092018-04-07 15:32:371626 }
1627
1628 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Benedikt Meurer61b7a002024-09-04 08:02:311629 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED :
1630 NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN;
Jack Franklin28577db2021-10-14 08:12:531631 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371632 }
1633
1634 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511635 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531636 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511637 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531638 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511639 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341640 }
Jan Scheffler341eea52019-12-12 09:08:411641
Garima Chadha8dde1c22025-05-19 19:52:471642 for (const header of request.requestHeaders()) {
1643 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasRequestHeader, header.name);
1644 }
1645
Jan Scheffler341eea52019-12-12 09:08:411646 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531647 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1648 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1649 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371650 }
1651
Jan Scheffler341eea52019-12-12 09:08:411652 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531653 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1654 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1655 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1656 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411657 }
1658
Jack Franklin28577db2021-10-14 08:12:531659 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371660 this.scheduleRefresh();
1661 }
1662
Jan Schefflerd6c1d402021-02-26 16:56:381663 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531664 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371665 }
1666
Jan Schefflerd6c1d402021-02-26 16:56:381667 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301668 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371669 }
1670
Jan Schefflerd6c1d402021-02-26 16:56:381671 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1672 void {
Blink Reformat4c46d092018-04-07 15:32:371673 contextMenu.appendApplicableItems(request);
Yang Guo6d1361f2024-07-11 08:23:481674 const filtered = this.filterBar.hasActiveFilter();
Danil Somsikov23eacf62024-02-23 08:46:301675 const copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy), false, 'copy');
Blink Reformat4c46d092018-04-07 15:32:371676 if (request) {
Samiya Caurb2be2652024-09-12 05:50:541677 if (UI.ActionRegistry.ActionRegistry.instance().hasAction('drjones.network-panel-context')) {
Samiya Caur7618ee12024-09-20 14:22:221678 UI.Context.Context.instance().setFlavor(SDK.NetworkRequest.NetworkRequest, request);
Wolfgang Beyerbafe6ca2025-01-31 11:16:001679 contextMenu.footerSection().appendAction(
Samiya Caurb2be2652024-09-12 05:50:541680 'drjones.network-panel-context',
1681 );
1682 }
Blink Reformat4c46d092018-04-07 15:32:371683 copyMenu.defaultSection().appendItem(
Benedikt Meurer8f0fee62023-12-27 12:36:511684 i18nString(UIStrings.copyURL),
Tim van der Lippe0ed1d2b2020-02-04 13:45:131685 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
Danil Somsikov23eacf62024-02-23 08:46:301686 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()),
1687 {jslogContext: 'copy-url'});
1688 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261689 filtered ? i18nString(UIStrings.copyAllListedURLs) : i18nString(UIStrings.copyAllURLs),
Yang Guo6d1361f2024-07-11 08:23:481690 this.copyAllURLs.bind(this), {jslogContext: 'copy-all-urls'});
Blink Reformat4c46d092018-04-07 15:32:371691 if (request.requestHeadersText()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511692 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301693 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request),
1694 {jslogContext: 'copy-request-headers'});
Blink Reformat4c46d092018-04-07 15:32:371695 }
1696
1697 if (request.responseHeadersText) {
Benedikt Meurer8f0fee62023-12-27 12:36:511698 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301699 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request),
1700 {jslogContext: 'copy-response-headers'});
Blink Reformat4c46d092018-04-07 15:32:371701 }
1702
1703 if (request.finished) {
Benedikt Meurer8f0fee62023-12-27 12:36:511704 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301705 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request),
1706 {jslogContext: 'copy-response'});
Blink Reformat4c46d092018-04-07 15:32:371707 }
1708
Tim van der Lippeb4faf5a2020-11-06 15:02:021709 const initiator = request.initiator();
1710
1711 if (initiator) {
1712 const stack = initiator.stack;
1713 if (stack) {
1714 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531715 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021716 // any callFrames, but its parent frames do.
1717 const stackTraceText = computeStackTraceText(stack);
1718 if (stackTraceText !== '') {
Benedikt Meurer8f0fee62023-12-27 12:36:511719 copyMenu.saveSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021720 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
Danil Somsikov23eacf62024-02-23 08:46:301721 }, {jslogContext: 'copy-stacktrace'});
Tim van der Lippeb4faf5a2020-11-06 15:02:021722 }
1723 }
1724 }
1725
Harley Libcf41f92018-09-10 18:01:131726 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131727 if (Host.Platform.isWin()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511728 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391729 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'),
Danil Somsikov23eacf62024-02-23 08:46:301730 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511731 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391732 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301733 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-bash'});
Blink Reformat4c46d092018-04-07 15:32:371734 } else {
Benedikt Meurer8f0fee62023-12-27 12:36:511735 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391736 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301737 {disabled: disableIfBlob, jslogContext: 'copy-as-curl'});
Blink Reformat4c46d092018-04-07 15:32:371738 }
Benedikt Meurer8f0fee62023-12-27 12:36:511739 copyMenu.defaultSection().appendItem(
1740 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
Danil Somsikov23eacf62024-02-23 08:46:301741 {disabled: disableIfBlob, jslogContext: 'copy-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511742 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311743 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.BROWSER),
Danil Somsikov23eacf62024-02-23 08:46:301744 {disabled: disableIfBlob, jslogContext: 'copy-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511745 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311746 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NODE_JS),
Danil Somsikov23eacf62024-02-23 08:46:301747 {disabled: disableIfBlob, jslogContext: 'copy-as-nodejs-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511748
1749 if (Host.Platform.isWin()) {
1750 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261751 filtered ? i18nString(UIStrings.copyAllListedAsCurlCmd) : i18nString(UIStrings.copyAllAsCurlCmd),
Yang Guo6d1361f2024-07-11 08:23:481752 this.copyAllCurlCommand.bind(this, 'win'), {jslogContext: 'copy-all-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511753 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261754 filtered ? i18nString(UIStrings.copyAllListedAsCurlBash) : i18nString(UIStrings.copyAllAsCurlBash),
Yang Guo6d1361f2024-07-11 08:23:481755 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl-bash'});
Benedikt Meurer8f0fee62023-12-27 12:36:511756 } else {
1757 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261758 filtered ? i18nString(UIStrings.copyAllListedAsCurl) : i18nString(UIStrings.copyAllAsCurl),
Yang Guo6d1361f2024-07-11 08:23:481759 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl'});
Benedikt Meurer8f0fee62023-12-27 12:36:511760 }
1761 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261762 filtered ? i18nString(UIStrings.copyAllListedAsPowershell) : i18nString(UIStrings.copyAllAsPowershell),
Yang Guo6d1361f2024-07-11 08:23:481763 this.copyAllPowerShellCommand.bind(this), {jslogContext: 'copy-all-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511764 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261765 filtered ? i18nString(UIStrings.copyAllListedAsFetch) : i18nString(UIStrings.copyAllAsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311766 this.copyAllFetchCall.bind(this, FetchStyle.BROWSER), {jslogContext: 'copy-all-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511767 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261768 filtered ? i18nString(UIStrings.copyAllListedAsNodejsFetch) : i18nString(UIStrings.copyAllAsNodejsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311769 this.copyAllFetchCall.bind(this, FetchStyle.NODE_JS), {jslogContext: 'copy-all-as-nodejs-fetch'});
Blink Reformat4c46d092018-04-07 15:32:371770 }
Danil Somsikov23eacf62024-02-23 08:46:301771 copyMenu.footerSection().appendItem(
Benedikt Meureracd96a62024-09-10 07:25:241772 filtered ? i18nString(UIStrings.copyAllListedAsHarSanitized) : i18nString(UIStrings.copyAllAsHarSanitized),
1773 this.copyAllAsHAR.bind(this, {sanitize: true}), {jslogContext: 'copy-all-as-har'});
Benedikt Meurerd553c502024-10-17 19:07:181774 if (this.networkShowOptionsToGenerateHarWithSensitiveData.get()) {
Benedikt Meureracd96a62024-09-10 07:25:241775 copyMenu.footerSection().appendItem(
1776 filtered ? i18nString(UIStrings.copyAllListedAsHarWithSensitiveData) :
1777 i18nString(UIStrings.copyAllAsHarWithSensitiveData),
1778 this.copyAllAsHAR.bind(this, {sanitize: false}), {jslogContext: 'copy-all-as-har-with-sensitive-data'});
1779 }
Blink Reformat4c46d092018-04-07 15:32:371780
Wolfgang Beyer650e9572023-11-29 12:45:081781 contextMenu.overrideSection().appendItem(
Wolfgang Beyer9d9affb2024-05-08 10:14:441782 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request), {
1783 disabled:
1784 Persistence.NetworkPersistenceManager.NetworkPersistenceManager.isForbiddenNetworkUrl(request.url()),
1785 jslogContext: 'override-headers',
1786 });
Wolfgang Beyerc6fe2be2022-11-03 15:39:411787
Blink Reformat4c46d092018-04-07 15:32:371788 contextMenu.editSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301789 i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this),
1790 {jslogContext: 'clear-browser-cache'});
1791 contextMenu.editSection().appendItem(
1792 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this),
1793 {jslogContext: 'clear-browser-cookies'});
Blink Reformat4c46d092018-04-07 15:32:371794
1795 if (request) {
1796 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211797 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371798 let patterns = manager.blockedPatterns();
1799
Jan Schefflerd6c1d402021-02-26 16:56:381800 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201801 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121802 manager.setBlockedPatterns(patterns);
1803 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031804 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121805 }
1806
Jan Schefflerd6c1d402021-02-26 16:56:381807 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121808 patterns = patterns.filter(pattern => pattern.url !== url);
1809 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031810 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121811 }
1812
Blink Reformat4c46d092018-04-07 15:32:371813 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1814 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1815 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301816 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme),
1817 {jslogContext: 'block-request-url'});
Blink Reformat4c46d092018-04-07 15:32:371818 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311819 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371820 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301821 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme),
1822 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371823 }
1824
1825 const domain = request.parsedURL.domain();
1826 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1827 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301828 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain),
1829 {jslogContext: 'block-request-domain'});
Blink Reformat4c46d092018-04-07 15:32:371830 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311831 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371832 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301833 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain),
1834 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371835 }
1836
Tim van der Lippe0ed1d2b2020-02-04 13:45:131837 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371838 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301839 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request),
1840 {jslogContext: 'replay-xhr'});
Blink Reformat4c46d092018-04-07 15:32:371841 }
Blink Reformat4c46d092018-04-07 15:32:371842 }
1843 }
1844
Jan Scheffler17b8fb42021-08-12 12:28:381845 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Yang Guo6d1361f2024-07-11 08:23:481846 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1847 return requests.filter(NetworkLogView.getHTTPRequestsFilter).filter(request => {
1848 return request.finished ||
1849 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1850 });
Blink Reformat4c46d092018-04-07 15:32:371851 }
1852
Benedikt Meureracd96a62024-09-10 07:25:241853 private async copyAllAsHAR(options: HAR.Log.BuildOptions): Promise<void> {
1854 const harArchive = {log: await HAR.Log.Log.build(this.harRequests(), options)};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131855 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371856 }
1857
Benedikt Meurer8f0fee62023-12-27 12:36:511858 private copyAllURLs(): void {
Yang Guo6d1361f2024-07-11 08:23:481859 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1860 const nonBlobRequests = this.filterOutBlobRequests(requests);
Benedikt Meurer8f0fee62023-12-27 12:36:511861 const urls = nonBlobRequests.map(request => request.url());
1862 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(urls.join('\n'));
1863 }
1864
Benedikt Meurer64b7e722023-12-15 09:03:581865 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351866 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131867 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371868 }
1869
Benedikt Meurer64b7e722023-12-15 09:03:581870 private async copyAllCurlCommand(platform: 'unix'|'win'): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481871 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1872 const commands = await this.generateAllCurlCommand(requests, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131873 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371874 }
1875
Danil Somsikov59f4c612021-09-08 10:58:461876 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1877 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131878 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371879 }
1880
Danil Somsikov59f4c612021-09-08 10:58:461881 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481882 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1883 const commands = await this.generateAllFetchCall(requests, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131884 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371885 }
1886
Jan Scheffler17b8fb42021-08-12 12:28:381887 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1888 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131889 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371890 }
1891
Jan Scheffler17b8fb42021-08-12 12:28:381892 private async copyAllPowerShellCommand(): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481893 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1894 const commands = await this.generateAllPowerShellCommand(requests);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131895 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371896 }
1897
Benedikt Meureracd96a62024-09-10 07:25:241898 async exportAll(options: HAR.Log.BuildOptions): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501899 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371900 if (!mainTarget) {
1901 return;
1902 }
1903 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131904 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321905 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131906 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371907
Kateryna Prokopenko380fdfa2022-03-16 16:39:321908 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371909 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341910 }
Blink Reformat4c46d092018-04-07 15:32:371911
Tim van der Lippe0ed1d2b2020-02-04 13:45:131912 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531913 this.progressBarContainer.appendChild(progressIndicator.element);
Benedikt Meureracd96a62024-09-10 07:25:241914 await HAR.Writer.Writer.write(stream, this.harRequests(), options, progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371915 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031916 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371917 }
1918
Wolfgang Beyer5b433b02022-05-12 13:57:371919 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411920 const requestLocation =
1921 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271922 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1923 if (networkPersistanceManager.project()) {
Danil Somsikovde84fb52024-01-30 13:53:091924 Common.Settings.Settings.instance().moduleSetting('persistence-network-overrides-enabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271925 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411926 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371927 } else { // If folder for local overrides has not been provided yet
Danil Somsikovacd635c2024-02-09 12:56:511928 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async () => {
Wolfgang Beyer5b433b02022-05-12 13:57:371929 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271930 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411931 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371932 });
1933 }
1934 }
1935
Jan Scheffler17b8fb42021-08-12 12:28:381936 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551937 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211938 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341939 }
Blink Reformat4c46d092018-04-07 15:32:371940 }
1941
Jan Scheffler17b8fb42021-08-12 12:28:381942 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551943 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211944 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341945 }
Blink Reformat4c46d092018-04-07 15:32:371946 }
1947
Yang Guo6d1361f2024-07-11 08:23:481948 private applyFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Jack Franklin28577db2021-10-14 08:12:531949 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371950 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341951 }
Simon Zündb3042fb2024-12-11 06:43:061952 const categoryName = request.resourceType().category().name;
Jack Franklin28577db2021-10-14 08:12:531953 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371954 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341955 }
Wolfgang Beyerd6f111c2025-05-05 08:43:491956 const [hideDataURL, blockedCookies, blockedRequests, thirdParty, hideExtensionURL] = [
1957 this.networkHideDataURLSetting.get(),
1958 this.networkShowBlockedCookiesOnlySetting.get(),
1959 this.networkOnlyBlockedRequestsSetting.get(),
1960 this.networkOnlyThirdPartySetting.get(),
1961 this.networkHideChromeExtensions.get(),
1962 ];
Silvia Eremia096e1202023-09-22 15:49:171963
1964 if (hideDataURL && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371965 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341966 }
Silvia Eremia096e1202023-09-22 15:49:171967 if (blockedCookies && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371968 return false;
1969 }
Silvia Eremia096e1202023-09-22 15:49:171970 if (blockedRequests && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131971 return false;
1972 }
Silvia Eremia096e1202023-09-22 15:49:171973 if (thirdParty && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271974 return false;
1975 }
Silvia Eremia096e1202023-09-22 15:49:171976 if (hideExtensionURL && request.scheme === 'chrome-extension') {
ioana forfota45b44152023-07-21 14:20:531977 return false;
1978 }
Jack Franklin28577db2021-10-14 08:12:531979 for (let i = 0; i < this.filters.length; ++i) {
1980 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371981 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341982 }
Blink Reformat4c46d092018-04-07 15:32:371983 }
1984 return true;
1985 }
1986
Danil Somsikov7a392fb2021-09-13 11:09:461987 private isValidUrl(url: string): boolean {
1988 try {
1989 new URL(url);
1990 return true;
Nikolay Vitkovb4e8dc72025-01-07 13:03:021991 } catch {
Danil Somsikov7a392fb2021-09-13 11:09:461992 return false;
1993 }
1994 }
1995
Jan Scheffler17b8fb42021-08-12 12:28:381996 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531997 // A query string can have multiple filters, some of them regular
1998 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371999 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:532000 // checkbox therefore inverts each one of those individual filters.
2001 const descriptors = this.filterParser.parse(query);
2002 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:372003 const key = descriptor.key;
2004 const text = descriptor.text || '';
2005 const regex = descriptor.regex;
2006 let filter;
2007 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:172008 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:382009 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
2010 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:372011 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:382012 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:462013 } else if (this.isValidUrl(text)) {
2014 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:372015 } else {
Jan Scheffler17b8fb42021-08-12 12:28:382016 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:172017 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:372018 }
Victor Porof66878d62021-07-16 13:12:372019 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:382020 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:372021 }
2022 return filter;
Blink Reformat4c46d092018-04-07 15:32:372023 });
2024 }
2025
Jan Scheffler17b8fb42021-08-12 12:28:382026 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372027 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:162028 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:382029 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:372030
Sigurd Schneider30722582021-06-16 06:54:162031 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:382032 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372033
Simon Zünd6dedde52021-08-03 09:04:512034 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:382035 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:512036
Garima Chadha8dde1c22025-05-19 19:52:472037 case NetworkForward.UIFilter.FilterType.HasRequestHeader:
2038 return NetworkLogView.requestRequestHeaderFilter.bind(null, value);
2039
Sigurd Schneider30722582021-06-16 06:54:162040 case NetworkForward.UIFilter.FilterType.Is:
Benedikt Meurer61b7a002024-09-04 08:02:312041 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.RUNNING) {
Jan Scheffler17b8fb42021-08-12 12:28:382042 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342043 }
Benedikt Meurer61b7a002024-09-04 08:02:312044 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FROM_CACHE) {
Jan Scheffler17b8fb42021-08-12 12:28:382045 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342046 }
Benedikt Meurer61b7a002024-09-04 08:02:312047 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED) {
Jan Scheffler17b8fb42021-08-12 12:28:382048 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342049 }
Benedikt Meurer61b7a002024-09-04 08:02:312050 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED) {
Jan Scheffler17b8fb42021-08-12 12:28:382051 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342052 }
Blink Reformat4c46d092018-04-07 15:32:372053 break;
2054
Sigurd Schneider30722582021-06-16 06:54:162055 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:382056 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:372057
Sigurd Schneider30722582021-06-16 06:54:162058 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:382059 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372060
Sigurd Schneider30722582021-06-16 06:54:162061 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:382062 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372063
Sigurd Schneider30722582021-06-16 06:54:162064 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:382065 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:162066 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:372067
Sigurd Schneider30722582021-06-16 06:54:162068 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:382069 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372070
Sigurd Schneider30722582021-06-16 06:54:162071 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382072 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372073
Sigurd Schneider30722582021-06-16 06:54:162074 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382075 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372076
Sigurd Schneider30722582021-06-16 06:54:162077 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382078 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372079
Sigurd Schneider30722582021-06-16 06:54:162080 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382081 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412082
Sigurd Schneider30722582021-06-16 06:54:162083 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382084 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412085
Sigurd Schneider30722582021-06-16 06:54:162086 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:382087 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:542088
Sigurd Schneider30722582021-06-16 06:54:162089 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382090 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412091
Sigurd Schneider30722582021-06-16 06:54:162092 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:382093 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:502094 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:372095
Sigurd Schneider30722582021-06-16 06:54:162096 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:382097 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:032098
Jecelyn Yeen77c83462023-08-16 16:13:172099 case NetworkForward.UIFilter.FilterType.HasOverrides:
2100 return NetworkLogView.hasOverridesFilter.bind(null, value);
2101
Sigurd Schneider30722582021-06-16 06:54:162102 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:382103 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:032104
Sigurd Schneider30722582021-06-16 06:54:162105 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:382106 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372107 }
2108 return null;
2109 }
2110
Jan Scheffler17b8fb42021-08-12 12:28:382111 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372112 let multiplier = 1;
2113 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542114 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:372115 value = value.substring(0, value.length - 1);
2116 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542117 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:372118 value = value.substring(0, value.length - 1);
2119 }
2120 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342121 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:372122 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342123 }
Jan Scheffler17b8fb42021-08-12 12:28:382124 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:372125 }
2126
Jan Scheffler17b8fb42021-08-12 12:28:382127 private filterRequests(): void {
Nancy Liffb3c7e2024-08-01 14:58:152128 this.removeAllNodeHighlights();
Jan Scheffler17b8fb42021-08-12 12:28:382129 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:372130 }
2131
Jan Scheffler17b8fb42021-08-12 12:28:382132 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:372133 this.removeAllNodeHighlights();
Simon Zünd2ec237c2025-07-17 05:30:522134 const node = this.networkRequestToNode.get(request);
Nikolay Vitkov68140172025-02-20 19:25:392135 if (!node?.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:372136 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342137 }
Brandon Goddard5e4244d2020-04-08 22:08:472138 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:532139 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:472140 // reveal and expand parent to ensure child is revealable.
2141 if (node.parent && node.parent instanceof NetworkGroupNode) {
2142 node.parent.reveal();
2143 node.parent.expand();
2144 }
Blink Reformat4c46d092018-04-07 15:32:372145 node.reveal();
2146 return node;
2147 }
2148
Jan Schefflerd6c1d402021-02-26 16:56:382149 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:382150 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342151 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:382152 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:342153 }
Blink Reformat4c46d092018-04-07 15:32:372154 }
2155
Sigurd Schneider722301e2021-06-15 13:41:202156 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:072157 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
2158 if (request) {
2159 this.revealAndHighlightRequest(request);
2160 }
2161 }
2162
Sigurd Schneider14d3e9f2021-06-14 08:29:012163 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
2164 void {
chait pinnamaneni6bc1c122020-10-30 17:30:522165 const defaultOptions = {clearFilter: true};
2166 const {clearFilter} = options || defaultOptions;
2167 if (clearFilter) {
2168 this.setTextFilterValue('');
2169 }
Jan Scheffler17b8fb42021-08-12 12:28:382170 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342171 if (node) {
Blink Reformat4c46d092018-04-07 15:32:372172 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:342173 }
Blink Reformat4c46d092018-04-07 15:32:372174 }
2175
Jan Schefflerd6c1d402021-02-26 16:56:382176 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:532177 if (this.highlightedNode) {
2178 this.highlightedNode.element().classList.remove('highlighted-row');
2179 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:372180 }
2181 }
2182
Jan Scheffler17b8fb42021-08-12 12:28:382183 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132184 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:532185 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:372186 }
2187
Jan Scheffler17b8fb42021-08-12 12:28:382188 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:132189 return requests.filter(request => !request.isBlobRequest());
2190 }
2191
Danil Somsikov59f4c612021-09-08 10:58:462192 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382193 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:372194 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372195 'method',
2196 'path',
2197 'scheme',
2198 'version',
Blink Reformat4c46d092018-04-07 15:32:372199
2200 // Unsafe headers
2201 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372202 'accept-charset',
2203 'accept-encoding',
2204 'access-control-request-headers',
2205 'access-control-request-method',
2206 'connection',
2207 'content-length',
2208 'cookie',
2209 'cookie2',
2210 'date',
2211 'dnt',
2212 'expect',
2213 'host',
2214 'keep-alive',
2215 'origin',
2216 'referer',
2217 'te',
2218 'trailer',
2219 'transfer-encoding',
2220 'upgrade',
2221 'via',
Blink Reformat4c46d092018-04-07 15:32:372222 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372223 'user-agent',
2224 ]);
Blink Reformat4c46d092018-04-07 15:32:372225
Jan Schefflerd6c1d402021-02-26 16:56:382226 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372227
2228 const url = JSON.stringify(request.url());
2229
2230 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382231 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372232 const name = header.name;
2233
Tim van der Lippe224a8622020-09-23 12:14:372234 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372235 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342236 }
Blink Reformat4c46d092018-04-07 15:32:372237
2238 return result;
2239 }, new Headers());
2240
Jan Schefflerd6c1d402021-02-26 16:56:382241 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342242 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412243 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342244 }
Blink Reformat4c46d092018-04-07 15:32:372245
Sigurd Schneider0e88b912020-05-08 08:28:232246 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372247 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412248 'include' :
2249 'omit';
Blink Reformat4c46d092018-04-07 15:32:372250
2251 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2252
2253 const referrer = referrerHeader ? referrerHeader.value : void 0;
2254
Blink Reformat4c46d092018-04-07 15:32:372255 const requestBody = await request.requestFormData();
2256
Jan Schefflerd6c1d402021-02-26 16:56:382257 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412258 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372259 referrer,
Blink Reformat4c46d092018-04-07 15:32:372260 body: requestBody,
2261 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372262 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372263 };
2264
Benedikt Meurer61b7a002024-09-04 08:02:312265 if (style === FetchStyle.NODE_JS) {
Jan Scheffler7c50d1f2019-12-17 13:33:292266 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462267 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532268 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462269 // following properties are not implemented in Node.js.
2270 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292271 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462272 extraHeaders['cookie'] = cookieHeader.value;
2273 }
2274 if (referrer) {
2275 delete fetchOptions.referrer;
2276 extraHeaders['Referer'] = referrer;
2277 }
Danil Somsikov59f4c612021-09-08 10:58:462278 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292279 fetchOptions.headers = {
2280 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462281 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292282 };
2283 }
2284 } else {
2285 fetchOptions.credentials = credentials;
2286 }
2287
Jan Scheffler172d5212020-01-02 14:42:562288 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372289 return `fetch(${url}, ${options});`;
2290 }
2291
Danil Somsikov59f4c612021-09-08 10:58:462292 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382293 Promise<string> {
2294 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462295 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132296 return commands.join(' ;\n');
2297 }
2298
Benedikt Meurer64b7e722023-12-15 09:03:582299 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'):
2300 Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382301 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362302 // Most of these headers are derived from the URL and are automatically added by cURL.
2303 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Barry Pollard0a176b42024-01-30 10:19:232304 const ignoredHeaders =
2305 new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version', 'authority', 'protocol']);
Blink Reformat4c46d092018-04-07 15:32:372306
Jan Schefflerd6c1d402021-02-26 16:56:382307 function escapeStringWin(str: string): string {
Danil Somsikovf4447112024-09-10 12:22:302308 /* Always escape the " characters so that we can use caret escaping.
Blink Reformat4c46d092018-04-07 15:32:372309
Jan Schefflerd6c1d402021-02-26 16:56:382310 Because cmd.exe parser and MS Crt arguments parsers use some of the
2311 same escape characters, they can interact with each other in
2312 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372313
Jan Schefflerd6c1d402021-02-26 16:56:382314 Replace \ with \\ first because it is an escape character for certain
2315 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372316
Jan Schefflerd6c1d402021-02-26 16:56:382317 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372318
Jan Schefflerd6c1d402021-02-26 16:56:382319 Then escape all characters we are not sure about with ^ to ensure it
2320 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372321
Jan Schefflerd6c1d402021-02-26 16:56:382322 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352323 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382324 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2325 parser); So we can get cmd.exe parser to escape the character after it,
2326 if it is followed by a valid beginning character of an ENV variable.
2327 This ensures we do not try and double escape another ^ if it was placed
2328 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372329
Jan Schefflerd6c1d402021-02-26 16:56:382330 Lastly we replace new lines with ^ and TWO new lines because the first
2331 new line is there to enact the escape command the second is the character
2332 to escape (in this case new line).
2333 */
Danil Somsikovf4447112024-09-10 12:22:302334 const encapsChars = '^"';
Blink Reformat4c46d092018-04-07 15:32:372335 return encapsChars +
2336 str.replace(/\\/g, '\\\\')
2337 .replace(/"/g, '\\"')
Danil Somsikovf4447112024-09-10 12:22:302338 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372339 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Danil Somsikov5381a522025-05-21 08:44:062340 .replace(/\r?\n|\r/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372341 encapsChars;
2342 }
2343
Jan Schefflerd6c1d402021-02-26 16:56:382344 function escapeStringPosix(str: string): string {
2345 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222346 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122347 let hexString = code.toString(16);
2348 // Zero pad to four digits to comply with ANSI-C Quoting:
2349 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342350 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122351 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342352 }
Joey Arhar2d21f712019-05-20 21:07:122353
2354 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372355 }
2356
Mathias Bynensf06e8c02020-02-28 13:58:282357 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372358 // Use ANSI-C quoting syntax.
2359 return '$\'' +
2360 str.replace(/\\/g, '\\\\')
2361 .replace(/\'/g, '\\\'')
2362 .replace(/\n/g, '\\n')
2363 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282364 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372365 '\'';
Blink Reformat4c46d092018-04-07 15:32:372366 }
Mathias Bynensf06e8c02020-02-28 13:58:282367 // Use single quote syntax.
2368 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372369 }
2370
2371 // cURL command expected to run on the same platform that DevTools run
2372 // (it may be different from the inspected page platform).
2373 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2374
2375 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2376
2377 let inferredMethod = 'GET';
2378 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372379 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082380 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272381 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532382 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272383 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372384 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372385 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372386 }
2387
2388 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292389 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372390 }
2391
2392 const requestHeaders = request.requestHeaders();
2393 for (let i = 0; i < requestHeaders.length; i++) {
2394 const header = requestHeaders[i];
2395 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372396 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372397 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342398 }
Benedikt Meurerb1bf2352024-12-16 13:38:492399 const value = header.value;
2400 if (!value.trim()) {
Wolfgang Beyer26b7e892022-08-16 11:02:352401 // A header passed with -H with no value or only whitespace as its
2402 // value tells curl to not set the header at all. To post an empty
2403 // header, you have to terminate it with a semicolon.
2404 command.push('-H ' + escapeString(name + ';'));
Benedikt Meurerb1bf2352024-12-16 13:38:492405 } else if (name.toLowerCase() === 'cookie') {
2406 command.push('-b ' + escapeString(value));
2407 } else {
2408 command.push('-H ' + escapeString(name + ': ' + value));
Wolfgang Beyer26b7e892022-08-16 11:02:352409 }
Blink Reformat4c46d092018-04-07 15:32:372410 }
2411 command = command.concat(data);
Blink Reformat4c46d092018-04-07 15:32:372412
Tim van der Lippe1d6e57a2019-09-30 11:55:342413 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372414 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342415 }
Jan Scheffler172d5212020-01-02 14:42:562416 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372417 }
2418
Benedikt Meurer64b7e722023-12-15 09:03:582419 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: 'unix'|'win'):
Jan Scheffler17b8fb42021-08-12 12:28:382420 Promise<string> {
2421 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352422 const commands =
2423 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342424 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132425 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342426 }
Mathias Bynensf06e8c02020-02-28 13:58:282427 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132428 }
2429
Jan Scheffler17b8fb42021-08-12 12:28:382430 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562431 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242432 const ignoredHeaders = new Set<string>([
2433 'host',
2434 'connection',
2435 'proxy-connection',
2436 'content-length',
2437 'expect',
2438 'range',
2439 'content-type',
2440 'user-agent',
2441 'cookie',
2442 ]);
Blink Reformat4c46d092018-04-07 15:32:372443
Jan Schefflerd6c1d402021-02-26 16:56:382444 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372445 return '"' +
2446 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2447 }
2448
Brandon Walderman153b8d72021-06-28 18:45:242449 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2450 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2451 // command does not allow setting these headers through the -Headers parameter. See docs at:
2452 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2453 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2454 const requestHeaders = request.requestHeaders();
2455 const props = [];
2456
2457 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2458 if (userAgentHeader) {
2459 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2460 }
2461
Shuran Huang670281e2024-02-15 16:29:542462 for (const includedCookie of request.includedRequestCookies()) {
2463 const name = escapeString(includedCookie.cookie.name());
2464 const value = escapeString(includedCookie.cookie.value());
2465 const domain = escapeString(includedCookie.cookie.domain());
Brandon Walderman153b8d72021-06-28 18:45:242466 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2467 }
2468
2469 if (props.length) {
2470 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2471 }
2472
2473 return null;
2474 }
2475
Jan Scheffler172d5212020-01-02 14:42:562476 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372477
2478 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562479 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372480 }
2481
Brandon Walderman153b8d72021-06-28 18:45:242482 const session = generatePowerShellSession(request);
2483 if (session) {
2484 command.push('-WebSession $session');
2485 }
2486
Blink Reformat4c46d092018-04-07 15:32:372487 const requestHeaders = request.requestHeaders();
2488 const headerNameValuePairs = [];
2489 for (const header of requestHeaders) {
2490 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342491 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372492 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342493 }
Blink Reformat4c46d092018-04-07 15:32:372494 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2495 }
2496 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562497 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372498 }
2499
2500 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2501 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562502 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372503 }
2504
2505 const formData = await request.requestFormData();
2506 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372507 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342508 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562509 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342510 } else {
Jan Scheffler172d5212020-01-02 14:42:562511 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342512 }
Blink Reformat4c46d092018-04-07 15:32:372513 }
2514
Brandon Walderman153b8d72021-06-28 18:45:242515 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2516 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2517 // compatibility only.
2518 const prelude = session || '';
2519 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372520 }
Harley Libcf41f92018-09-10 18:01:132521
Jan Scheffler17b8fb42021-08-12 12:28:382522 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2523 const nonBlobRequests = this.filterOutBlobRequests(requests);
2524 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132525 return commands.join(';\r\n');
2526 }
Joey Arhara86c14e2019-03-12 03:20:502527
Jan Schefflerd6c1d402021-02-26 16:56:382528 static getDCLEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142529 return '--sys-color-blue';
Joey Arhara86c14e2019-03-12 03:20:502530 }
2531
Jan Schefflerd6c1d402021-02-26 16:56:382532 static getLoadEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142533 return '--sys-color-error';
Joey Arhara86c14e2019-03-12 03:20:502534 }
Paul Lewis56509652019-12-06 12:51:582535}
Blink Reformat4c46d092018-04-07 15:32:372536
Jan Schefflerd6c1d402021-02-26 16:56:382537export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022538 let stackTraceText = '';
2539 for (const frame of stackTrace.callFrames) {
2540 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2541 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2542 }
2543 if (stackTrace.parent) {
2544 stackTraceText += computeStackTraceText(stackTrace.parent);
2545 }
2546 return stackTraceText;
2547}
2548
Jan Schefflerd6c1d402021-02-26 16:56:382549const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372550
Jan Schefflerd6c1d402021-02-26 16:56:382551export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372552 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222553}
2554
Paul Lewis56509652019-12-06 12:51:582555export const HTTPSchemas = {
Nikolay Vitkov47310242024-09-04 10:00:072556 http: true,
2557 https: true,
2558 ws: true,
2559 wss: true,
Blink Reformat4c46d092018-04-07 15:32:372560};
2561
Sigurd Schneider576ca9a2021-07-16 05:58:042562const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382563
2564export interface GroupLookupInterface {
2565 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2566 reset(): void;
2567}
2568
Jecelyn Yeen77c83462023-08-16 16:13:172569export const overrideFilter = {
2570 yes: 'yes',
2571 no: 'no',
2572 content: 'content',
2573 headers: 'headers',
2574};
2575
Nikolay Vitkov937f4632025-01-03 14:02:022576export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;
ioana forfota2c72e132023-09-22 12:11:482577
Danil Somsikov53d6f3e2025-02-24 12:31:272578export class MoreFiltersDropDownUI extends Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes>
2579 implements UI.FilterBar.FilterUI {
Silvia Eremia096e1202023-09-22 15:49:172580 private readonly filterElement: HTMLDivElement;
Danil Somsikov53d6f3e2025-02-24 12:31:272581 private readonly dropDownButton: UI.Toolbar.ToolbarMenuButton;
Silvia Eremia096e1202023-09-22 15:49:172582 private networkHideDataURLSetting: Common.Settings.Setting<boolean>;
2583 private networkHideChromeExtensionsSetting: Common.Settings.Setting<boolean>;
2584 private networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
2585 private networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
2586 private networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482587 private activeFiltersCount: HTMLElement;
2588 private activeFiltersCountAdorner: Adorners.Adorner.Adorner;
Silvia Eremia096e1202023-09-22 15:49:172589
Benedikt Meurer6b3ebf22024-01-12 10:00:512590 constructor() {
Silvia Eremia096e1202023-09-22 15:49:172591 super();
Silvia Eremia096e1202023-09-22 15:49:172592
Danil Somsikov74217e92024-01-30 07:01:122593 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
Silvia Eremia096e1202023-09-22 15:49:172594 this.networkHideChromeExtensionsSetting =
Danil Somsikov74217e92024-01-30 07:01:122595 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Silvia Eremia096e1202023-09-22 15:49:172596 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:122597 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172598 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:122599 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Silvia Eremia096e1202023-09-22 15:49:172600 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:122601 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172602
2603 this.filterElement = document.createElement('div');
2604 this.filterElement.setAttribute('aria-label', 'Show only/hide requests dropdown');
Danil Somsikov0cb97462024-01-30 15:11:292605 this.filterElement.setAttribute('jslog', `${VisualLogging.dropDown('more-filters').track({click: true})}`);
Kateryna Prokopenkod98e34c2023-09-25 18:08:482606
2607 this.activeFiltersCountAdorner = new Adorners.Adorner.Adorner();
2608 this.activeFiltersCount = document.createElement('span');
2609 this.activeFiltersCountAdorner.data = {
2610 name: 'countWrapper',
2611 content: this.activeFiltersCount,
2612 };
2613 this.activeFiltersCountAdorner.classList.add('active-filters-count');
2614 this.updateActiveFiltersCount();
2615
Danil Somsikov53d6f3e2025-02-24 12:31:272616 this.dropDownButton = new UI.Toolbar.ToolbarMenuButton(
2617 this.showMoreFiltersContextMenu.bind(this), /* isIconDropdown=*/ false, /* useSoftMenu=*/ true,
2618 /* jslogContext=*/ undefined, /* iconName=*/ undefined,
2619 /* keepOpen=*/ true);
2620 this.dropDownButton.setTitle(i18nString(UIStrings.showOnlyHideRequests));
Kateryna Prokopenko17cba892024-07-26 13:33:562621 this.dropDownButton.setText(i18nString(UIStrings.moreFilters));
2622 this.dropDownButton.setAdorner(this.activeFiltersCountAdorner);
Silvia Eremia096e1202023-09-22 15:49:172623 this.filterElement.appendChild(this.dropDownButton.element);
Silvia Eremia096e1202023-09-22 15:49:172624 this.dropDownButton.element.classList.add('dropdown-filterbar');
Kateryna Prokopenko5f434d42023-11-03 10:57:492625 this.updateTooltip();
Silvia Eremia096e1202023-09-22 15:49:172626 }
2627
Wolfgang Beyer3b382582023-11-16 12:40:022628 #onSettingChanged(): void {
Benedikt Meurerf08ab4a2024-09-03 09:37:352629 this.dispatchEventToListeners(UI.FilterBar.FilterUIEvents.FILTER_CHANGED);
Wolfgang Beyer3b382582023-11-16 12:40:022630 }
2631
Danil Somsikov53d6f3e2025-02-24 12:31:272632 showMoreFiltersContextMenu(contextMenu: UI.ContextMenu.ContextMenu): void {
Wolfgang Beyer3b382582023-11-16 12:40:022633 this.networkHideDataURLSetting.addChangeListener(this.#onSettingChanged.bind(this));
2634 this.networkHideChromeExtensionsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2635 this.networkShowBlockedCookiesOnlySetting.addChangeListener(this.#onSettingChanged.bind(this));
2636 this.networkOnlyBlockedRequestsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2637 this.networkOnlyThirdPartySetting.addChangeListener(this.#onSettingChanged.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172638
Danil Somsikov53d6f3e2025-02-24 12:31:272639 contextMenu.defaultSection().appendCheckboxItem(
Silvia Eremia096e1202023-09-22 15:49:172640 i18nString(UIStrings.hideDataUrls),
Danil Somsikov66fa2262024-02-22 13:02:492641 () => this.networkHideDataURLSetting.set(!this.networkHideDataURLSetting.get()), {
2642 checked: this.networkHideDataURLSetting.get(),
2643 tooltip: i18nString(UIStrings.hidesDataAndBlobUrls),
2644 jslogContext: 'hide-data-urls',
2645 });
Danil Somsikov53d6f3e2025-02-24 12:31:272646 contextMenu.defaultSection().appendCheckboxItem(
Silvia Eremia096e1202023-09-22 15:49:172647 i18nString(UIStrings.chromeExtensions),
Danil Somsikov66fa2262024-02-22 13:02:492648 () => this.networkHideChromeExtensionsSetting.set(!this.networkHideChromeExtensionsSetting.get()), {
2649 checked: this.networkHideChromeExtensionsSetting.get(),
2650 tooltip: i18nString(UIStrings.hideChromeExtension),
2651 jslogContext: 'hide-extension-urls',
2652 });
Danil Somsikov53d6f3e2025-02-24 12:31:272653 contextMenu.defaultSection().appendSeparator();
Kateryna Prokopenkod98e34c2023-09-25 18:08:482654
Danil Somsikov53d6f3e2025-02-24 12:31:272655 contextMenu.defaultSection().appendCheckboxItem(
Silvia Eremia096e1202023-09-22 15:49:172656 i18nString(UIStrings.hasBlockedCookies),
Danil Somsikov66fa2262024-02-22 13:02:492657 () => this.networkShowBlockedCookiesOnlySetting.set(!this.networkShowBlockedCookiesOnlySetting.get()), {
2658 checked: this.networkShowBlockedCookiesOnlySetting.get(),
2659 tooltip: i18nString(UIStrings.onlyShowRequestsWithBlockedCookies),
2660 jslogContext: 'only-blocked-response-cookies',
2661 });
Danil Somsikov53d6f3e2025-02-24 12:31:272662 contextMenu.defaultSection().appendCheckboxItem(
Silvia Eremia096e1202023-09-22 15:49:172663 i18nString(UIStrings.blockedRequests),
Danil Somsikov66fa2262024-02-22 13:02:492664 () => this.networkOnlyBlockedRequestsSetting.set(!this.networkOnlyBlockedRequestsSetting.get()), {
2665 checked: this.networkOnlyBlockedRequestsSetting.get(),
2666 tooltip: i18nString(UIStrings.onlyShowBlockedRequests),
2667 jslogContext: 'only-blocked-requests',
2668 });
Danil Somsikov53d6f3e2025-02-24 12:31:272669 contextMenu.defaultSection().appendCheckboxItem(
Silvia Eremia096e1202023-09-22 15:49:172670 i18nString(UIStrings.thirdParty),
Danil Somsikov66fa2262024-02-22 13:02:492671 () => this.networkOnlyThirdPartySetting.set(!this.networkOnlyThirdPartySetting.get()), {
2672 checked: this.networkOnlyThirdPartySetting.get(),
2673 tooltip: i18nString(UIStrings.onlyShowThirdPartyRequests),
2674 jslogContext: 'only-3rd-party-requests',
2675 });
Silvia Eremia096e1202023-09-22 15:49:172676 }
2677
Kateryna Prokopenko5f434d42023-11-03 10:57:492678 selectedFilters(): string[] {
2679 const filters = [
2680 ...this.networkHideDataURLSetting.get() ? [i18nString(UIStrings.hideDataUrls)] : [],
2681 ...this.networkHideChromeExtensionsSetting.get() ? [i18nString(UIStrings.chromeExtensions)] : [],
2682 ...this.networkShowBlockedCookiesOnlySetting.get() ? [i18nString(UIStrings.hasBlockedCookies)] : [],
2683 ...this.networkOnlyBlockedRequestsSetting.get() ? [i18nString(UIStrings.blockedRequests)] : [],
2684 ...this.networkOnlyThirdPartySetting.get() ? [i18nString(UIStrings.thirdParty)] : [],
Kateryna Prokopenkod98e34c2023-09-25 18:08:482685 ];
Kateryna Prokopenko5f434d42023-11-03 10:57:492686 return filters;
2687 }
2688
2689 updateActiveFiltersCount(): void {
2690 const count = this.selectedFilters().length;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482691 this.activeFiltersCount.textContent = count.toString();
2692 count ? this.activeFiltersCountAdorner.classList.remove('hidden') :
2693 this.activeFiltersCountAdorner.classList.add('hidden');
2694 }
2695
Kateryna Prokopenko5f434d42023-11-03 10:57:492696 updateTooltip(): void {
2697 if (this.selectedFilters().length) {
2698 this.dropDownButton.setTitle(this.selectedFilters().join(', '));
2699 } else {
TaegeonKim3ac28bb2025-03-09 06:06:472700 this.dropDownButton.setTitle(i18nString(UIStrings.showOnlyHideRequests));
Kateryna Prokopenko5f434d42023-11-03 10:57:492701 }
2702 }
2703
Silvia Eremia096e1202023-09-22 15:49:172704 isActive(): boolean {
Benedikt Meurer6b3ebf22024-01-12 10:00:512705 return this.selectedFilters().length !== 0;
Silvia Eremia096e1202023-09-22 15:49:172706 }
2707
2708 element(): HTMLDivElement {
2709 return this.filterElement;
2710 }
2711}