blob: 344f94af4a2270acc1d2ffef9baa12fcae6602d6 [file] [log] [blame]
Jan Schefflerd6c1d402021-02-26 16:56:381// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Blink Reformat4c46d092018-04-07 15:32:375/*
6 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Tim van der Lippe76961572021-04-06 10:48:0735import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3036import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2837import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2738import * as Platform from '../../core/platform/platform.js';
Wolfgang Beyer6a4cbb42022-05-16 13:02:2939import * as Root from '../../core/root/root.js';
Tim van der Lippee00b92f2021-03-31 16:52:1740import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0541import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5942import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5643import * as HAR from '../../models/har/har.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2744import * as Logs from '../../models/logs/logs.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3745import * as Persistence from '../../models/persistence/persistence.js';
Tim van der Lippefca98ed2021-04-08 14:10:1446import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1647import * as NetworkForward from '../../panels/network/forward/forward.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3748import * as Sources from '../../panels/sources/sources.js';
Kateryna Prokopenkod98e34c2023-09-25 18:08:4849import * as Adorners from '../../ui/components/adorners/adorners.js';
Benedikt Meurer328b3a72025-01-02 10:38:5550import * as RenderCoordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4751import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1452import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3653import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0754import * as UI from '../../ui/legacy/legacy.js';
Wolfgang Beyer8ad25a72024-01-03 12:44:2955import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1356
Jack Franklin3a802602022-07-13 08:39:4257import {
58 Events,
ioana forfota2c72e132023-09-22 12:11:4859 type EventTypes,
Jack Franklin3a802602022-07-13 08:39:4260 NetworkGroupNode,
Jack Franklin3a802602022-07-13 08:39:4261 type NetworkLogViewInterface,
62 type NetworkNode,
ioana forfota2c72e132023-09-22 12:11:4863 NetworkRequestNode,
Jack Franklin3a802602022-07-13 08:39:4264} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3065import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
ioana forfota2c72e132023-09-22 12:11:4866import networkLogViewStyles from './networkLogView.css.js';
Tim van der Lippe119690c2020-01-13 12:31:3067import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Frankline839c0c2022-05-03 08:47:4468import {
69 NetworkTimeBoundary,
ioana forfota2c72e132023-09-22 12:11:4870 type NetworkTimeCalculator,
Jack Frankline839c0c2022-05-03 08:47:4471 NetworkTransferDurationCalculator,
72 NetworkTransferTimeCalculator,
73} from './NetworkTimeCalculator.js';
Tim van der Lippe119690c2020-01-13 12:31:3074
Simon Zünd34490692021-03-01 08:25:1875const UIStrings = {
Christy Chencac3f102021-02-03 10:07:5576 /**
Jack Franklinfd72c072022-12-21 11:45:0177 *@description Text in Network Log View of the Network panel
78 */
Victor Porof66878d62021-07-16 13:12:3779 invertFilter: 'Invert',
80 /**
Jack Franklinfd72c072022-12-21 11:45:0181 *@description Tooltip for the 'invert' checkbox in the Network panel.
82 */
Victor Porof66878d62021-07-16 13:12:3783 invertsFilter: 'Inverts the search filter',
84 /**
Jack Franklinfd72c072022-12-21 11:45:0185 *@description Text in Network Log View of the Network panel
86 */
Christy Chencac3f102021-02-03 10:07:5587 hideDataUrls: 'Hide data URLs',
88 /**
Jack Franklinfd72c072022-12-21 11:45:0189 *@description Data urlfilter ui element title in Network Log View of the Network panel
90 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:5591 hidesDataAndBlobUrls: 'Hide \'data:\' and \'blob:\' URLs',
Christy Chencac3f102021-02-03 10:07:5592 /**
ioana forfota45b44152023-07-21 14:20:5393 * @description Label for a filter in the Network panel
94 */
ioana forfotaaf54bd12023-07-28 09:46:2995 chromeExtensions: 'Hide extension URLs',
ioana forfota45b44152023-07-21 14:20:5396 /**
97 * @description Tooltip for a filter in the Network panel
98 */
Jecelyn Yeen82a2c9c2023-08-09 10:40:5599 hideChromeExtension: 'Hide \'chrome-extension://\' URLs',
ioana forfota45b44152023-07-21 14:20:53100 /**
Jack Franklinfd72c072022-12-21 11:45:01101 *@description Aria accessible name in Network Log View of the Network panel
102 */
ioana forfota2c72e132023-09-22 12:11:48103 requestTypesToInclude: 'Request types to include',
104 /**
Wolfgang Beyerb9391362023-07-14 12:40:45105 *@description Label for a checkbox in the Network panel. When checked, only requests with
106 * blocked response cookies are shown.
Jack Franklinfd72c072022-12-21 11:45:01107 */
Wolfgang Beyerb9391362023-07-14 12:40:45108 hasBlockedCookies: 'Blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55109 /**
Jack Franklinfd72c072022-12-21 11:45:01110 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
111 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
112 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
113 */
Kateryna Prokopenko5f434d42023-11-03 10:57:49114 onlyShowRequestsWithBlockedCookies: 'Show only requests with blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55115 /**
Jack Franklinfd72c072022-12-21 11:45:01116 *@description Label for a filter in the Network panel
117 */
Sofia Emelianova25f46422023-07-04 15:20:11118 blockedRequests: 'Blocked requests',
Christy Chencac3f102021-02-03 10:07:55119 /**
Jack Franklinfd72c072022-12-21 11:45:01120 *@description Tooltip for a filter in the Network panel
121 */
Sofia Emelianova25f46422023-07-04 15:20:11122 onlyShowBlockedRequests: 'Show only blocked requests',
Christy Chencac3f102021-02-03 10:07:55123 /**
Jack Franklinfd72c072022-12-21 11:45:01124 *@description Label for a filter in the Network panel
125 */
Danil Somsikov721956a2021-07-07 08:17:27126 thirdParty: '3rd-party requests',
127 /**
Jack Franklinfd72c072022-12-21 11:45:01128 *@description Tooltip for a filter in the Network panel
129 */
Sofia Emelianova25f46422023-07-04 15:20:11130 onlyShowThirdPartyRequests: 'Show only requests with origin different from page origin',
Danil Somsikov721956a2021-07-07 08:17:27131 /**
Jack Franklinfd72c072022-12-21 11:45:01132 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
133 */
Christy Chencac3f102021-02-03 10:07:55134 dropHarFilesHere: 'Drop HAR files here',
135 /**
Jack Franklinfd72c072022-12-21 11:45:01136 *@description Recording text text content in Network Log View of the Network panel
137 */
Christy Chencac3f102021-02-03 10:07:55138 recordingNetworkActivity: 'Recording network activity…',
139 /**
Jack Franklinfd72c072022-12-21 11:45:01140 *@description Text in Network Log View of the Network panel
141 *@example {Ctrl + R} PH1
142 */
Christy Chencac3f102021-02-03 10:07:55143 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
144 /**
Jack Franklinfd72c072022-12-21 11:45:01145 *@description Shown in the Network Log View of the Network panel when the user has not yet
146 * recorded any network activity. This is an instruction to the user to start recording in order to
147 * show network activity in the current UI.
148 *@example {Ctrl + E} PH1
149 */
Wolfgang Beyerf4237472021-08-18 14:55:41150 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55151 /**
Jack Franklinfd72c072022-12-21 11:45:01152 *@description Text that is usually a hyperlink to more documentation
153 */
Christy Chencac3f102021-02-03 10:07:55154 learnMore: 'Learn more',
155 /**
Jack Franklinfd72c072022-12-21 11:45:01156 *@description Text to announce to screen readers that network data is available.
157 */
Christy Chencac3f102021-02-03 10:07:55158 networkDataAvailable: 'Network Data Available',
159 /**
Jack Franklinfd72c072022-12-21 11:45:01160 *@description Text in Network Log View of the Network panel
161 *@example {3} PH1
162 *@example {5} PH2
163 */
Christy Chencac3f102021-02-03 10:07:55164 sSRequests: '{PH1} / {PH2} requests',
165 /**
Jack Franklinfd72c072022-12-21 11:45:01166 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
167 * resources transferred during a selected time frame over the compressed size of all resources transferred during
168 * the whole network log.
169 *@example {5 B} PH1
170 *@example {10 B} PH2
171 */
Christy Chencac3f102021-02-03 10:07:55172 sSTransferred: '{PH1} / {PH2} transferred',
173 /**
Jack Franklinfd72c072022-12-21 11:45:01174 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
175 * time frame over the compressed size of all resources transferred during the whole network log.
176 *@example {10} PH1
177 *@example {15} PH2
178 */
Christy Chencac3f102021-02-03 10:07:55179 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
180 /**
Jack Franklinfd72c072022-12-21 11:45:01181 * @description Text in Network Log View of the Network panel. Appears when a particular network
182 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
183 * total size (PH2).
184 * @example {40MB} PH1
185 * @example {50MB} PH2
186 */
Christy Chencac3f102021-02-03 10:07:55187 sSResources: '{PH1} / {PH2} resources',
188 /**
Jack Franklinfd72c072022-12-21 11:45:01189 *@description Text in Network Log View of the Network panel
190 *@example {40} PH1
191 *@example {50} PH2
192 */
Christy Chencac3f102021-02-03 10:07:55193 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
194 /**
Jack Franklinfd72c072022-12-21 11:45:01195 *@description Text in Network Log View of the Network panel
196 *@example {6} PH1
197 */
Christy Chencac3f102021-02-03 10:07:55198 sRequests: '{PH1} requests',
199 /**
Jack Franklinfd72c072022-12-21 11:45:01200 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
201 * all resources transferred over network during a network activity log.
202 *@example {4 B} PH1
203 */
Christy Chencac3f102021-02-03 10:07:55204 sTransferred: '{PH1} transferred',
205 /**
Jack Franklinfd72c072022-12-21 11:45:01206 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
207 * a network activity log.
208 *@example {4} PH1
209 */
Christy Chencac3f102021-02-03 10:07:55210 sBTransferredOverNetwork: '{PH1} B transferred over network',
211 /**
Jack Franklinfd72c072022-12-21 11:45:01212 *@description Text in Network Log View of the Network panel
213 *@example {4} PH1
214 */
Christy Chencac3f102021-02-03 10:07:55215 sResources: '{PH1} resources',
216 /**
Jack Franklinfd72c072022-12-21 11:45:01217 *@description Text in Network Log View of the Network panel
218 *@example {10} PH1
219 */
Christy Chencac3f102021-02-03 10:07:55220 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
221 /**
Jack Franklinfd72c072022-12-21 11:45:01222 *@description Text in Network Log View of the Network panel
223 *@example {120ms} PH1
224 */
Christy Chencac3f102021-02-03 10:07:55225 finishS: 'Finish: {PH1}',
226 /**
Jack Franklinfd72c072022-12-21 11:45:01227 *@description Text in Network Log View of the Network panel
228 *@example {3000ms} PH1
229 */
Christy Chencac3f102021-02-03 10:07:55230 domcontentloadedS: 'DOMContentLoaded: {PH1}',
231 /**
Jack Franklinfd72c072022-12-21 11:45:01232 *@description Text in Network Log View of the Network panel
233 *@example {40ms} PH1
234 */
Christy Chencac3f102021-02-03 10:07:55235 loadS: 'Load: {PH1}',
236 /**
Jack Franklinfd72c072022-12-21 11:45:01237 *@description Text for copying
238 */
Christy Chencac3f102021-02-03 10:07:55239 copy: 'Copy',
240 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51241 *@description A context menu command in the Network panel, for copying the URL of the selected request to the clipboard.
242 */
243 copyURL: 'Copy URL',
244 /**
Jack Franklinfd72c072022-12-21 11:45:01245 *@description Text in Network Log View of the Network panel
246 */
Christy Chencac3f102021-02-03 10:07:55247 copyRequestHeaders: 'Copy request headers',
248 /**
Jack Franklinfd72c072022-12-21 11:45:01249 *@description Text in Network Log View of the Network panel
250 */
Christy Chencac3f102021-02-03 10:07:55251 copyResponseHeaders: 'Copy response headers',
252 /**
Jack Franklinfd72c072022-12-21 11:45:01253 *@description Text in Network Log View of the Network panel
254 */
Christy Chencac3f102021-02-03 10:07:55255 copyResponse: 'Copy response',
256 /**
Jack Franklinfd72c072022-12-21 11:45:01257 *@description Text in Network Log View of the Network panel
258 */
Peter Marshallf625dc82021-03-02 08:10:57259 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55260 /**
Jack Franklinfd72c072022-12-21 11:45:01261 * @description A context menu command in the Network panel, for copying to the clipboard.
262 * PowerShell refers to the format the data will be copied as.
263 */
Peter Marshallb8bd00f2021-02-24 08:25:18264 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55265 /**
Jack Franklinfd72c072022-12-21 11:45:01266 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
267 * refers to the format the data will be copied as, which is compatible with the fetch web API.
268 */
Peter Marshallb8bd00f2021-02-24 08:25:18269 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55270 /**
Jack Franklinfd72c072022-12-21 11:45:01271 * @description Text in Network Log View of the Network panel. An action that copies a command to
272 * the developer's clipboard. The command allows the developer to replay this specific network
273 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
274 * type of request that will be copied.
275 */
Benedikt Meurer8f0fee62023-12-27 12:36:51276 copyAsNodejsFetch: 'Copy as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55277 /**
Jack Franklinfd72c072022-12-21 11:45:01278 *@description Text in Network Log View of the Network panel. An action that copies a command to
279 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
280 *translatable).
281 */
Peter Marshallb8bd00f2021-02-24 08:25:18282 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55283 /**
Jack Franklinfd72c072022-12-21 11:45:01284 *@description Text in Network Log View of the Network panel. An action that copies a command to
285 *the clipboard. It will copy the command in the format compatible with a Bash script.
286 */
Peter Marshallb8bd00f2021-02-24 08:25:18287 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55288 /**
Benedikt Meurer8f0fee62023-12-27 12:36:51289 *@description A context menu command in the Network panel, for copying the URLs of all requestes to the clipboard.
290 */
291 copyAllURLs: 'Copy all URLs',
292 /**
Yang Guo6d1361f2024-07-11 08:23:48293 *@description A context menu command in the Network panel, for copying the URLs of all requestes
294 (after applying the Network filter) to the clipboard.
295 */
Yang Guo80af52f2024-07-16 12:06:26296 copyAllListedURLs: 'Copy all listed URLs',
Yang Guo6d1361f2024-07-11 08:23:48297 /**
Jack Franklinfd72c072022-12-21 11:45:01298 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48299 *the clipboard. It will copy the command in the format compatible with a PowerShell script to
300 *represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01301 */
Peter Marshallb8bd00f2021-02-24 08:25:18302 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55303 /**
Jack Franklinfd72c072022-12-21 11:45:01304 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48305 *the clipboard. It will copy the command in the format compatible with a PowerShell script to
306 *represent all network requests (after applying the Network filter).
307 */
Yang Guo80af52f2024-07-16 12:06:26308 copyAllListedAsPowershell: 'Copy all listed as `PowerShell`',
Yang Guo6d1361f2024-07-11 08:23:48309 /**
310 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01311 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
Yang Guo6d1361f2024-07-11 08:23:48312 *should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01313 */
Peter Marshallb8bd00f2021-02-24 08:25:18314 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55315 /**
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 'fetch' command (fetch
318 *should not be translated) to represent all network requests (after applying the Network filter).
319 */
Yang Guo80af52f2024-07-16 12:06:26320 copyAllListedAsFetch: 'Copy all listed as `fetch`',
Yang Guo6d1361f2024-07-11 08:23:48321 /**
322 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01323 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
Yang Guo6d1361f2024-07-11 08:23:48324 *(fetch and Node.js should not be translated) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01325 */
Benedikt Meurer8f0fee62023-12-27 12:36:51326 copyAllAsNodejsFetch: 'Copy all as `fetch` (`Node.js`)',
Christy Chencac3f102021-02-03 10:07:55327 /**
Jack Franklinfd72c072022-12-21 11:45:01328 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48329 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
330 *(fetch and Node.js should not be translated) to represent all network requests (after applying
331 *the Network filter).
332 */
Yang Guo80af52f2024-07-16 12:06:26333 copyAllListedAsNodejsFetch: 'Copy all listed as `fetch` (`Node.js`)',
Yang Guo6d1361f2024-07-11 08:23:48334 /**
335 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01336 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48337 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01338 */
Peter Marshallb8bd00f2021-02-24 08:25:18339 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55340 /**
Jack Franklinfd72c072022-12-21 11:45:01341 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48342 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
343 *translatable) to represent all network requests (after applying the Network filter).
344 */
Yang Guo80af52f2024-07-16 12:06:26345 copyAllListedAsCurlCmd: 'Copy all listed as `cURL` (`cmd`)',
Yang Guo6d1361f2024-07-11 08:23:48346 /**
347 *@description Text in Network Log View of the Network panel. An action that copies a command to
348 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
349 *all network requests.
Jack Franklinfd72c072022-12-21 11:45:01350 */
Peter Marshallb8bd00f2021-02-24 08:25:18351 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55352 /**
Jack Franklinfd72c072022-12-21 11:45:01353 *@description Text in Network Log View of the Network panel. An action that copies a command to
Yang Guo6d1361f2024-07-11 08:23:48354 *the clipboard. It will copy the command in the format compatible with a Bash script to represent
355 *all network requests (after applying the Network filter).
356 */
Yang Guo80af52f2024-07-16 12:06:26357 copyAllListedAsCurlBash: 'Copy all listed as `cURL` (`bash`)',
Yang Guo6d1361f2024-07-11 08:23:48358 /**
359 *@description Text in Network Log View of the Network panel. An action that copies a command to
Jack Franklinfd72c072022-12-21 11:45:01360 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
361 *translatable).
362 */
Peter Marshallb8bd00f2021-02-24 08:25:18363 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55364 /**
Jack Franklinfd72c072022-12-21 11:45:01365 *@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 cURL (a program, not
Yang Guo6d1361f2024-07-11 08:23:48367 *translatable) to represent all network requests.
Jack Franklinfd72c072022-12-21 11:45:01368 */
Peter Marshallb8bd00f2021-02-24 08:25:18369 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55370 /**
Yang Guo6d1361f2024-07-11 08:23:48371 *@description Text in Network Log View of the Network panel. An action that copies a command to
372 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
373 *translatable) to represent all network requests (after applying the Network filter).
374 */
Yang Guo80af52f2024-07-16 12:06:26375 copyAllListedAsCurl: 'Copy all listed as `cURL`',
Yang Guo6d1361f2024-07-11 08:23:48376 /**
Jack Franklinfd72c072022-12-21 11:45:01377 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24378 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
379 * sensitive data from the network requests. 'all' refers to every network request that is currently
380 * shown.
Jack Franklinfd72c072022-12-21 11:45:01381 */
Benedikt Meureracd96a62024-09-10 07:25:24382 copyAllAsHarSanitized: 'Copy all as `HAR` (sanitized)',
Christy Chencac3f102021-02-03 10:07:55383 /**
Yang Guo6d1361f2024-07-11 08:23:48384 * @description Text in Network Log View of the Network panel. An action that copies data to the
Benedikt Meureracd96a62024-09-10 07:25:24385 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
386 * sensitive data from the network requests. 'all' refers to every network request that is currently
387 * shown.
Yang Guo6d1361f2024-07-11 08:23:48388 */
Benedikt Meureracd96a62024-09-10 07:25:24389 copyAllAsHarWithSensitiveData: 'Copy all as `HAR` (with sensitive data)',
390 /**
391 * @description Text in Network Log View of the Network panel. An action that copies data to the
392 * clipboard. It will copy the data in the HAR (not translatable) format and scrub all potentially
393 * sensitive data from the network requests. 'all' refers to every network request that is currently
394 * shown (after applying the Network filter).
395 */
396 copyAllListedAsHarSanitized: 'Copy all listed as `HAR` (sanitized)',
397 /**
398 * @description Text in Network Log View of the Network panel. An action that copies data to the
399 * clipboard. It will copy the data in the HAR (not translatable) format and include potentially
400 * sensitive data from the network requests. 'all' refers to every network request that is currently
401 * shown (after applying the Network filter).
402 */
403 copyAllListedAsHarWithSensitiveData: 'Copy all listed as `HAR` (with sensitive data)',
Yang Guo6d1361f2024-07-11 08:23:48404 /**
Jack Franklinfd72c072022-12-21 11:45:01405 *@description A context menu item in the Network Log View of the Network panel
406 */
Christy Chencac3f102021-02-03 10:07:55407 clearBrowserCache: 'Clear browser cache',
408 /**
Jack Franklinfd72c072022-12-21 11:45:01409 *@description A context menu item in the Network Log View of the Network panel
410 */
Christy Chencac3f102021-02-03 10:07:55411 clearBrowserCookies: 'Clear browser cookies',
412 /**
Jack Franklinfd72c072022-12-21 11:45:01413 *@description A context menu item in the Network Log View of the Network panel
414 */
Christy Chencac3f102021-02-03 10:07:55415 blockRequestUrl: 'Block request URL',
416 /**
Jack Franklinfd72c072022-12-21 11:45:01417 *@description A context menu item in the Network Log View of the Network panel
418 *@example {example.com} PH1
419 */
Christy Chencac3f102021-02-03 10:07:55420 unblockS: 'Unblock {PH1}',
421 /**
Jack Franklinfd72c072022-12-21 11:45:01422 *@description A context menu item in the Network Log View of the Network panel
423 */
Christy Chencac3f102021-02-03 10:07:55424 blockRequestDomain: 'Block request domain',
425 /**
Jack Franklinfd72c072022-12-21 11:45:01426 *@description Text to replay an XHR request
427 */
Christy Chencac3f102021-02-03 10:07:55428 replayXhr: 'Replay XHR',
429 /**
Jack Franklinfd72c072022-12-21 11:45:01430 *@description Text in Network Log View of the Network panel
431 */
Christy Chencac3f102021-02-03 10:07:55432 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
433 /**
Jack Franklinfd72c072022-12-21 11:45:01434 *@description Text in Network Log View of the Network panel
435 */
Christy Chencac3f102021-02-03 10:07:55436 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37437 /**
Jack Franklinfd72c072022-12-21 11:45:01438 *@description A context menu item in the Network Log View of the Network panel
439 * for creating a header override
440 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41441 overrideHeaders: 'Override headers',
Silvia Eremia096e1202023-09-22 15:49:17442 /**
443 * @description Tooltip for the Show only/Hide requests dropdown of the filterbar
444 */
445 showOnlyHideRequests: 'Show only/hide requests',
446 /**
447 * @description Text for the Show only/Hide requests dropdown button of the filterbar
448 */
449 moreFilters: 'More filters',
Christy Chencac3f102021-02-03 10:07:55450};
Tim van der Lippef596ca02021-03-31 10:02:47451const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55452const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46453
454const enum FetchStyle {
Benedikt Meurer61b7a002024-09-04 08:02:31455 BROWSER = 0,
456 NODE_JS = 1,
Danil Somsikov59f4c612021-09-08 10:58:46457}
458
Simon Zünd940cb1f2021-09-16 11:46:09459export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
460 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53461 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
462 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
ioana forfota45b44152023-07-21 14:20:53463 private readonly networkHideChromeExtensions: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04464 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53465 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
466 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
467 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
Benedikt Meureracd96a62024-09-10 07:25:24468 private readonly networkShowOptionsToGenerateHarWithSensitiveData: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53469 private rawRowHeight: number;
470 private readonly progressBarContainer: Element;
471 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
472 private rowHeightInternal: number;
473 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
474 private readonly durationCalculator: NetworkTransferDurationCalculator;
475 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30476 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53477 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
478 private mainRequestLoadTime: number;
479 private mainRequestDOMContentLoadedTime: number;
480 private filters: Filter[];
481 private timeFilter: Filter|null;
482 private hoveredNodeInternal: NetworkNode|null;
483 private recordingHint: Element|null;
Jack Franklin28577db2021-10-14 08:12:53484 private highlightedNode: NetworkRequestNode|null;
485 private readonly linkifierInternal: Components.Linkifier.Linkifier;
486 private recording: boolean;
487 private needsRefresh: boolean;
488 private readonly headerHeightInternal: number;
489 private readonly groupLookups: Map<string, GroupLookupInterface>;
490 private activeGroupLookup: GroupLookupInterface|null;
491 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
492 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
Silvia Eremia096e1202023-09-22 15:49:17493 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
494 private readonly moreFiltersDropDownUI: MoreFiltersDropDownUI|undefined;
495 private readonly onlyBlockedResponseCookiesFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
496 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI|undefined;
497 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
498 private readonly hideChromeExtensionsUI: UI.FilterBar.CheckboxFilterUI|undefined;
Kateryna Prokopenko24c28f92024-08-30 15:09:28499 private readonly resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
Jack Franklin28577db2021-10-14 08:12:53500 private readonly filterParser: TextUtils.TextUtils.FilterParser;
501 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
502 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50503 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53504 private readonly filterBar: UI.FilterBar.FilterBar;
505 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38506
507 constructor(
508 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
509 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37510 super();
511 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37512
513 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05514 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37515
Danil Somsikov74217e92024-01-30 07:01:12516 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('network-invert-filter', false);
517 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
ioana forfota45b44152023-07-21 14:20:53518 this.networkHideChromeExtensions =
Danil Somsikov74217e92024-01-30 07:01:12519 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04520 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:12521 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Jack Franklin28577db2021-10-14 08:12:53522 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:12523 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Jack Franklin28577db2021-10-14 08:12:53524 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:12525 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Jack Franklin28577db2021-10-14 08:12:53526 this.networkResourceTypeFiltersSetting =
Danil Somsikov74217e92024-01-30 07:01:12527 Common.Settings.Settings.instance().createSetting('network-resource-type-filters', {});
Benedikt Meureracd96a62024-09-10 07:25:24528 this.networkShowOptionsToGenerateHarWithSensitiveData = Common.Settings.Settings.instance().createSetting(
529 'network.show-options-to-generate-har-with-sensitive-data', false);
Blink Reformat4c46d092018-04-07 15:32:37530
Jack Franklin28577db2021-10-14 08:12:53531 this.rawRowHeight = 0;
532 this.progressBarContainer = progressBarContainer;
533 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
534 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37535
Jan Schefflerd6c1d402021-02-26 16:56:38536 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53537 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
538 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37539 }
Jack Franklin28577db2021-10-14 08:12:53540 this.rawRowHeight = 0;
541 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37542 updateRowHeight.call(this);
543
Jack Franklin28577db2021-10-14 08:12:53544 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
545 this.durationCalculator = new NetworkTransferDurationCalculator();
546 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37547
Danil Somsikov2a4c4e02022-10-07 12:31:30548 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53549 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30550 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37551
Jack Franklin28577db2021-10-14 08:12:53552 this.staleRequests = new Set();
553 this.mainRequestLoadTime = -1;
554 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37555
Jack Franklin28577db2021-10-14 08:12:53556 this.filters = [];
557 this.timeFilter = null;
558 this.hoveredNodeInternal = null;
559 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53560 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37561
Jack Franklin28577db2021-10-14 08:12:53562 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37563
Jack Franklin28577db2021-10-14 08:12:53564 this.recording = false;
565 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37566
Jack Franklin28577db2021-10-14 08:12:53567 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37568
Jack Franklin28577db2021-10-14 08:12:53569 this.groupLookups = new Map();
570 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37571
Jack Franklin28577db2021-10-14 08:12:53572 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37573
Jack Franklin28577db2021-10-14 08:12:53574 this.textFilterUI = new UI.FilterBar.TextFilterUI();
Benedikt Meurerf08ab4a2024-09-03 09:37:35575 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
Jack Franklin28577db2021-10-14 08:12:53576 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37577
Jack Franklin28577db2021-10-14 08:12:53578 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyercda33c92023-12-21 16:04:32579 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting, 'invert-filter');
Jack Franklin28577db2021-10-14 08:12:53580 this.invertFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35581 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53582 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
583 filterBar.addFilter(this.invertFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00584 filterBar.addDivider();
Victor Porof66878d62021-07-16 13:12:37585
Blink Reformat4c46d092018-04-07 15:32:37586 const filterItems =
Danil Somsikovf90908e2024-02-29 15:40:36587 Object.entries(Common.ResourceType.resourceCategories).map(([key, category]) => ({
Simon Zünd9112a772024-10-17 07:02:51588 name: category.name,
Danil Somsikovf90908e2024-02-29 15:40:36589 label: () => category.shortTitle(),
590 title: category.title(),
591 jslogContext:
592 Platform.StringUtilities.toKebabCase(key),
593 }));
ioana forfota2c72e132023-09-22 12:11:48594
595 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
Kateryna Prokopenko24c28f92024-08-30 15:09:28596 this.moreFiltersDropDownUI = new MoreFiltersDropDownUI();
Benedikt Meurerf08ab4a2024-09-03 09:37:35597 this.moreFiltersDropDownUI.addEventListener(UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged, this);
Kateryna Prokopenko24c28f92024-08-30 15:09:28598 filterBar.addFilter(this.moreFiltersDropDownUI);
599
600 this.resourceCategoryFilterUI =
601 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17602 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
603 this.resourceCategoryFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35604 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17605 filterBar.addFilter(this.resourceCategoryFilterUI);
ioana forfota2c72e132023-09-22 12:11:48606 } else {
Silvia Eremia096e1202023-09-22 15:49:17607 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20608 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting, 'hide-data-urls');
Silvia Eremia096e1202023-09-22 15:49:17609 this.dataURLFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35610 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17611 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
612 filterBar.addFilter(this.dataURLFilterUI);
613
614 this.hideChromeExtensionsUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20615 'chrome-extension', i18nString(UIStrings.chromeExtensions), true, this.networkHideChromeExtensions,
616 'hide-extension-urls');
Silvia Eremia096e1202023-09-22 15:49:17617 this.hideChromeExtensionsUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35618 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17619 UI.Tooltip.Tooltip.install(this.hideChromeExtensionsUI.element(), i18nString(UIStrings.hideChromeExtension));
620 filterBar.addFilter(this.hideChromeExtensionsUI);
621
ioana forfota2c72e132023-09-22 12:11:48622 this.resourceCategoryFilterUI =
623 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17624 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
625 this.resourceCategoryFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35626 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17627 filterBar.addFilter(this.resourceCategoryFilterUI);
628
629 this.onlyBlockedResponseCookiesFilterUI = new UI.FilterBar.CheckboxFilterUI(
630 'only-show-blocked-cookies', i18nString(UIStrings.hasBlockedCookies), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20631 this.networkShowBlockedCookiesOnlySetting, 'only-show-blocked-cookies');
Silvia Eremia096e1202023-09-22 15:49:17632 this.onlyBlockedResponseCookiesFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35633 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17634 UI.Tooltip.Tooltip.install(
635 this.onlyBlockedResponseCookiesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
636 filterBar.addFilter(this.onlyBlockedResponseCookiesFilterUI);
637
638 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
639 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20640 this.networkOnlyBlockedRequestsSetting, 'only-show-blocked-requests');
Silvia Eremia096e1202023-09-22 15:49:17641 this.onlyBlockedRequestsUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35642 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17643 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
644 filterBar.addFilter(this.onlyBlockedRequestsUI);
645
646 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20647 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting,
648 'only-show-third-party');
Silvia Eremia096e1202023-09-22 15:49:17649 this.onlyThirdPartyFilterUI.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35650 UI.FilterBar.FilterUIEvents.FILTER_CHANGED, this.filterChanged.bind(this), this);
Silvia Eremia096e1202023-09-22 15:49:17651 UI.Tooltip.Tooltip.install(
652 this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
653 filterBar.addFilter(this.onlyThirdPartyFilterUI);
ioana forfota2c72e132023-09-22 12:11:48654 }
Danil Somsikov721956a2021-07-07 08:17:27655
Jack Franklin28577db2021-10-14 08:12:53656 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
657 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38658 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
659 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37660
Danil Somsikov2a4c4e02022-10-07 12:31:30661 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38662 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30663 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49664 filterBar.filterButton().addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:35665 UI.Toolbar.ToolbarButton.Events.CLICK, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37666
Wolfgang Beyer8fc262f2023-04-11 13:22:50667 this.summaryToolbarInternal = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
668 this.summaryToolbarInternal.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37669
Tim van der Lippe0ed1d2b2020-02-04 13:45:13670 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38671 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37672
Paul Lewis2d7d65c2020-03-16 17:26:30673 Common.Settings.Settings.instance()
Danil Somsikov74217e92024-01-30 07:01:12674 .moduleSetting('network-color-code-resource-types')
Jan Scheffler17b8fb42021-08-12 12:28:38675 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37676
Danil Somsikov62bc5782023-03-21 10:48:50677 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27678 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38679 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27680 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38681 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
Wolfgang Beyer51f2f252023-07-27 17:09:51682 Logs.NetworkLog.NetworkLog.instance().addEventListener(
683 Logs.NetworkLog.Events.RequestRemoved, this.onRequestRemoved, this);
Jan Scheffler17b8fb42021-08-12 12:28:38684 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37685
Jan Scheffler17b8fb42021-08-12 12:28:38686 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30687 Common.Settings.Settings.instance()
688 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38689 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37690
Jack Franklin28577db2021-10-14 08:12:53691 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03692
Danil Somsikov74217e92024-01-30 07:01:12693 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('network-text-filter', '');
Jack Franklin28577db2021-10-14 08:12:53694 if (this.textFilterSetting.get()) {
695 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03696 }
Blink Reformat4c46d092018-04-07 15:32:37697 }
698
Silvia Eremia096e1202023-09-22 15:49:17699 getMoreFiltersDropdown(): MoreFiltersDropDownUI|undefined {
700 return this.moreFiltersDropDownUI;
701 }
702
Jan Scheffler17b8fb42021-08-12 12:28:38703 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30704 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38705 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37706 }
707
Jan Scheffler17b8fb42021-08-12 12:28:38708 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16709 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37710 values.sort((a, b) => {
Paul Irisha8a15972024-04-30 15:14:19711 const aPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a);
712 const bPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b);
Tim van der Lippeded23fb2020-02-13 13:33:50713 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
714 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37715 });
716 } else {
717 values.sort();
718 }
719 }
720
Jan Scheffler17b8fb42021-08-12 12:28:38721 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37722 return !filter(request);
723 }
724
Jan Scheffler17b8fb42021-08-12 12:28:38725 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34726 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37727 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34728 }
Blink Reformat4c46d092018-04-07 15:32:37729
730 return regex.test(request.path() + '/' + request.name());
731 }
732
Jan Scheffler17b8fb42021-08-12 12:28:38733 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37734 const result = [domain];
735 let indexOfPeriod = domain.indexOf('.');
736 while (indexOfPeriod !== -1) {
737 result.push('*' + domain.substring(indexOfPeriod));
738 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
739 }
740 return result;
741 }
742
Jan Scheffler17b8fb42021-08-12 12:28:38743 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17744 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38745 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37746 }
747
Jan Scheffler17b8fb42021-08-12 12:28:38748 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37749 return regex.test(request.domain);
750 }
751
Jan Scheffler17b8fb42021-08-12 12:28:38752 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37753 return !request.finished;
754 }
755
Jan Scheffler17b8fb42021-08-12 12:28:38756 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37757 return request.cached();
758 }
759
Jan Scheffler17b8fb42021-08-12 12:28:38760 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05761 return request.fetchedViaServiceWorker;
762 }
763
Jan Scheffler17b8fb42021-08-12 12:28:38764 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05765 return request.initiatedByServiceWorker();
766 }
767
Jan Scheffler17b8fb42021-08-12 12:28:38768 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37769 return request.responseHeaderValue(value) !== undefined;
770 }
771
Jan Scheffler17b8fb42021-08-12 12:28:38772 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
773 boolean {
Jack Franklin28577db2021-10-14 08:12:53774 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51775 // filter via `includes` instead of strict equality.
776 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
777 }
778
Jan Scheffler17b8fb42021-08-12 12:28:38779 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37780 return request.requestMethod === value;
781 }
782
Jan Scheffler17b8fb42021-08-12 12:28:38783 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37784 return request.priority() === value;
785 }
786
Jan Scheffler17b8fb42021-08-12 12:28:38787 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37788 return request.mimeType === value;
789 }
790
Jan Scheffler17b8fb42021-08-12 12:28:38791 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16792 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
Benedikt Meurer61b7a002024-09-04 08:02:31793 if (value === NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED) {
Blink Reformat4c46d092018-04-07 15:32:37794 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28795 }
Benedikt Meurer61b7a002024-09-04 08:02:31796 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED) {
Blink Reformat4c46d092018-04-07 15:32:37797 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28798 }
Benedikt Meurer61b7a002024-09-04 08:02:31799 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN) {
Blink Reformat4c46d092018-04-07 15:32:37800 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28801 }
Benedikt Meurer61b7a002024-09-04 08:02:31802 if (value === NetworkForward.UIFilter.MixedContentFilterValues.ALL) {
Blink Reformat4c46d092018-04-07 15:32:37803 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34804 }
Blink Reformat4c46d092018-04-07 15:32:37805
806 return false;
807 }
808
Jan Scheffler17b8fb42021-08-12 12:28:38809 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37810 return request.scheme === value;
811 }
812
Jan Scheffler17b8fb42021-08-12 12:28:38813 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41814 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
815 }
816
Jan Scheffler17b8fb42021-08-12 12:28:38817 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41818 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
819 }
820
Jan Scheffler17b8fb42021-08-12 12:28:38821 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54822 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
823 }
824
Jan Scheffler17b8fb42021-08-12 12:28:38825 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41826 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
827 }
828
Jan Scheffler17b8fb42021-08-12 12:28:38829 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41830 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37831 }
832
Jan Scheffler17b8fb42021-08-12 12:28:38833 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41834 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37835 }
836
Jan Scheffler17b8fb42021-08-12 12:28:38837 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41838 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37839 }
840
Jan Scheffler17b8fb42021-08-12 12:28:38841 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37842 return request.transferSize >= value;
843 }
844
Jan Scheffler17b8fb42021-08-12 12:28:38845 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24846 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37847 }
848
Jecelyn Yeen77c83462023-08-16 16:13:17849 private static hasOverridesFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
850 if (!value) {
851 return false;
852 }
853
854 if (value === overrideFilter.no) {
855 return request.overrideTypes.length === 0;
856 }
857
858 if (value === overrideFilter.yes) {
859 return request.overrideTypes.length > 0;
860 }
861
862 if (value === overrideFilter.content) {
863 return request.overrideTypes.includes('content');
864 }
865
866 if (value === overrideFilter.headers) {
867 return request.overrideTypes.includes('headers');
868 }
869
870 return request.overrideTypes.join(',').includes(value);
871 }
872
Sigurd Schneider576ca9a2021-07-16 05:58:04873 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58874 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37875 }
876
Jan Scheffler17b8fb42021-08-12 12:28:38877 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03878 return request.resourceType().name() === value;
879 }
880
Jan Scheffler17b8fb42021-08-12 12:28:38881 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17882 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03883 return regex.test(request.url());
884 }
885
Jan Scheffler17b8fb42021-08-12 12:28:38886 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38887 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34888 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37889 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34890 }
891 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37892 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34893 }
Blink Reformat4c46d092018-04-07 15:32:37894 return true;
895 }
896
Jan Scheffler17b8fb42021-08-12 12:28:38897 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13898 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37899 }
900
Jan Scheffler17b8fb42021-08-12 12:28:38901 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13902 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37903 }
904
Jan Scheffler17b8fb42021-08-12 12:28:38905 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Simon Zünd0d87db62024-05-27 07:26:27906 const contentData = await request.requestContentData();
Simon Zünd3b583882023-12-22 05:23:43907 let content: string;
Simon Zünd7fb55c02024-01-29 12:00:27908 if (TextUtils.ContentData.ContentData.isError(contentData)) {
Simon Zünd3b583882023-12-22 05:23:43909 content = '';
Simon Zündebe01922024-01-18 10:11:58910 } else if (!contentData.isTextContent) {
Simon Zünd3b583882023-12-22 05:23:43911 content = contentData.asDataUrl() ?? '';
912 } else {
913 content = contentData.text;
Tim van der Lippe1d6e57a2019-09-30 11:55:34914 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13915 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37916 }
917
Jan Scheffler17b8fb42021-08-12 12:28:38918 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37919 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34920 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37921 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34922 }
Simon Zünd99961242021-09-08 11:02:12923 const file = items[0].getAsFile();
924 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03925 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34926 }
Blink Reformat4c46d092018-04-07 15:32:37927 }
928
Jan Schefflerd6c1d402021-02-26 16:56:38929 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13930 const outputStream = new Common.StringOutputStream.StringOutputStream();
931 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37932 const success = await reader.read(outputStream);
933 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37934 const error = reader.error();
935 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38936 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37937 }
Blink Reformat4c46d092018-04-07 15:32:37938 return;
939 }
940 let harRoot;
941 try {
942 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56943 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37944 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38945 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37946 return;
947 }
Tim van der Lippe09cf5032021-04-29 15:08:09948 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37949 }
950
Jan Scheffler17b8fb42021-08-12 12:28:38951 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36952 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37953 }
954
Jan Scheffler17b8fb42021-08-12 12:28:38955 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53956 if (this.activeGroupLookup) {
957 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34958 }
Jack Franklin28577db2021-10-14 08:12:53959 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
960 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38961 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37962 }
963
Jan Scheffler17b8fb42021-08-12 12:28:38964 private computeRowHeight(): number {
Benedikt Meurera0d809e2024-02-28 14:20:54965 return this.rawRowHeight;
Blink Reformat4c46d092018-04-07 15:32:37966 }
967
Jan Schefflerd6c1d402021-02-26 16:56:38968 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37969 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37970 }
971
Jan Schefflerd6c1d402021-02-26 16:56:38972 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53973 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37974 }
975
Jan Schefflerd6c1d402021-02-26 16:56:38976 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53977 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38978 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37979 }
980
Danil Somsikov2a4c4e02022-10-07 12:31:30981 columns(): NetworkLogViewColumns {
982 return this.columnsInternal;
983 }
984
Wolfgang Beyer8fc262f2023-04-11 13:22:50985 summaryToolbar(): UI.Toolbar.Toolbar {
986 return this.summaryToolbarInternal;
987 }
988
Jan Schefflerd6c1d402021-02-26 16:56:38989 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37990 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22991 const target = networkManager.target();
992 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37993 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34994 }
Danil Somsikov88384322023-03-22 13:53:22995 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37996 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38997 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37998 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38999 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:371000 }
Danil Somsikov88384322023-03-22 13:53:221001 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:041002 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:251003 this.refreshRequest(request);
1004 }
Danil Somsikov88384322023-03-22 13:53:221005 }
Blink Reformat4c46d092018-04-07 15:32:371006 }
1007
Jan Schefflerd6c1d402021-02-26 16:56:381008 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:221009 const target = networkManager.target();
1010 if (target.outermostTarget() !== target) {
1011 return;
1012 }
1013 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
1014 if (resourceTreeModel) {
1015 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
1016 resourceTreeModel.removeEventListener(
1017 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
1018 }
Danil Somsikovac291c82024-01-30 13:47:461019 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network-log.preserve-log').get();
Danil Somsikov88384322023-03-22 13:53:221020 if (!preserveLog) {
1021 this.reset();
Blink Reformat4c46d092018-04-07 15:32:371022 }
1023 }
1024
Jan Schefflerd6c1d402021-02-26 16:56:381025 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:531026 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:131027 }
1028
Jan Schefflerd6c1d402021-02-26 16:56:381029 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:371030 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:531031 this.timeFilter = null;
1032 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:371033 } else {
Jack Franklin28577db2021-10-14 08:12:531034 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
1035 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:371036 }
Jan Scheffler17b8fb42021-08-12 12:28:381037 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:371038 }
1039
Jan Schefflerd6c1d402021-02-26 16:56:381040 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531041 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:371042 }
1043
Jan Scheffler17b8fb42021-08-12 12:28:381044 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:531045 this.suggestionBuilder.clear();
Benedikt Meurer61b7a002024-09-04 08:02:311046 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.RUNNING);
Jack Franklin28577db2021-10-14 08:12:531047 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311048 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FROM_CACHE);
Jack Franklin28577db2021-10-14 08:12:531049 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311050 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED);
Jack Franklin28577db2021-10-14 08:12:531051 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311052 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED);
Jack Franklin28577db2021-10-14 08:12:531053 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
1054 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
1055 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
1056 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Jecelyn Yeen77c83462023-08-16 16:13:171057 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.yes);
1058 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.no);
1059 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.content);
1060 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.headers);
Blink Reformat4c46d092018-04-07 15:32:371061 }
1062
Simon Zünda2bae2e2021-09-16 07:57:131063 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371064 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:531065 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:381066 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:531067 this.textFilterSetting.set(this.textFilterUI.value());
Kateryna Prokopenkod98e34c2023-09-25 18:08:481068 this.moreFiltersDropDownUI?.updateActiveFiltersCount();
Kateryna Prokopenko5f434d42023-11-03 10:57:491069 this.moreFiltersDropDownUI?.updateTooltip();
Blink Reformat4c46d092018-04-07 15:32:371070 }
1071
Jan Schefflerd6c1d402021-02-26 16:56:381072 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:531073 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:121074 }
1075
Jan Scheffler17b8fb42021-08-12 12:28:381076 private showRecordingHint(): void {
1077 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:531078 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
1079 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:181080
Jack Franklin28577db2021-10-14 08:12:531081 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:381082 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:041083 const reloadShortcut =
Benedikt Meurere0b4b922024-01-15 13:33:531084 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector-main.reload')[0];
Wolfgang Beyer5c385b92020-11-09 15:20:041085 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:531086 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:041087 reloadShortcutNode.textContent = reloadShortcut.title();
1088 }
1089
Blink Reformat4c46d092018-04-07 15:32:371090 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:551091 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:181092 if (reloadShortcutNode) {
1093 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:551094 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
1095 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:181096 }
Blink Reformat4c46d092018-04-07 15:32:371097 } else {
1098 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:171099 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:371100 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:551101 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:411102 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:371103 }
Kayce Basques5444c1b2019-02-15 20:32:531104 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:131105 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:351106 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Kateryna Prokopenko1a4e2612023-12-21 13:23:451107 i18nString(UIStrings.learnMore), undefined, undefined, 'learn-more'));
Amanda Baker6761aae2019-11-05 18:59:111108
Jan Scheffler17b8fb42021-08-12 12:28:381109 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:371110 }
1111
Jan Scheffler17b8fb42021-08-12 12:28:381112 private hideRecordingHint(): void {
1113 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:531114 if (this.recordingHint) {
1115 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:341116 }
Michael Liao7322dee2021-04-07 18:33:301117 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:531118 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:371119 }
1120
Jan Scheffler17b8fb42021-08-12 12:28:381121 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301122 this.columnsInternal.setHidden(value);
Wolfgang Beyer8fc262f2023-04-11 13:22:501123 UI.ARIAUtils.setHidden(this.summaryToolbarInternal.element, value);
Amanda Baker6761aae2019-11-05 18:59:111124 }
1125
Randolf Jungffd14242023-04-19 00:32:251126 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:531127 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:341128 {
Blink Reformat4c46d092018-04-07 15:32:371129 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:341130 }
Jack Franklin28577db2021-10-14 08:12:531131 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:371132 }
1133
Jan Schefflerd6c1d402021-02-26 16:56:381134 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381135 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:371136 }
1137
Jan Scheffler17b8fb42021-08-12 12:28:381138 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:531139 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:381140 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341141 if (request) {
Blink Reformat4c46d092018-04-07 15:32:371142 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341143 }
Blink Reformat4c46d092018-04-07 15:32:371144 });
Paul Irishf2ff58b2024-11-06 23:52:001145 this.dataGrid.setEnableAutoScrollToBottom(true);
Danil Somsikova6ce6ed2024-01-31 08:10:121146 this.dataGrid.setName('network-log');
Benedikt Meurerf08ab4a2024-09-03 09:37:351147 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.LAST);
Jack Franklin28577db2021-10-14 08:12:531148 this.dataGrid.element.classList.add('network-log-grid');
1149 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
1150 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
1151 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
1152 this.dataGrid.element.addEventListener('keydown', event => {
1153 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
Danil Somsikove10a94c2024-03-11 08:31:321154 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('button.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:431155 if (initiatorLink) {
1156 (initiatorLink as HTMLElement).focus();
1157 }
1158 }
ergunshee4a6132021-11-05 16:21:251159
Jack Franklin5e685be2022-10-17 14:27:091160 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051161 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051162 event.consume(true);
1163 }
1164 });
ergunshee4a6132021-11-05 16:21:251165 this.dataGrid.element.addEventListener('keyup', event => {
1166 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1167 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1168 if (!request) {
1169 return;
1170 }
1171
1172 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1173 SDK.NetworkManager.NetworkManager.replayRequest(request);
Danil Somsikov1a4a3322024-03-11 16:27:271174 void VisualLogging.logKeyDown(this.dataGrid.selectedNode.element(), event, 'replay-xhr');
ergunshee4a6132021-11-05 16:21:251175 }
1176 }
1177 });
Jack Franklin28577db2021-10-14 08:12:531178 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1179 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1180 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371181 }
1182
Jan Scheffler17b8fb42021-08-12 12:28:381183 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381184 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531185 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371186 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381187 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371188 }
1189
Jan Schefflerd6c1d402021-02-26 16:56:381190 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531191 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371192 }
1193
Jan Scheffler17b8fb42021-08-12 12:28:381194 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531195 if (this.hoveredNodeInternal) {
1196 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341197 }
Jack Franklin28577db2021-10-14 08:12:531198 this.hoveredNodeInternal = node;
1199 if (this.hoveredNodeInternal) {
1200 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341201 }
Blink Reformat4c46d092018-04-07 15:32:371202 }
1203
Jan Scheffler17b8fb42021-08-12 12:28:381204 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381205 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531206 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371207 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341208 }
Blink Reformat4c46d092018-04-07 15:32:371209 }
1210
Jan Scheffler17b8fb42021-08-12 12:28:381211 private updateSummaryBar(): void {
1212 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371213
1214 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201215 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371216 let selectedNodeNumber = 0;
1217 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201218 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371219 let baseTime = -1;
1220 let maxTime = -1;
1221
1222 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271223 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371224 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341225 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371226 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341227 }
Blink Reformat4c46d092018-04-07 15:32:371228 nodeCount++;
1229 const requestTransferSize = request.transferSize;
1230 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201231 const requestResourceSize = request.resourceSize;
1232 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371233 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371234 selectedNodeNumber++;
1235 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201236 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371237 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131238 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371239 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1240 // inspected url.
1241 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131242 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Benedikt Meurerb7d85042024-08-23 13:38:321243 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.FRAME) {
Adithya Srinivasan77770382024-05-17 20:22:091244 // If the primary main frame's document was fetched from the prefetch cache,
1245 // we should use the issueTime (i.e. when the navigation request was about to start)
1246 // instead of startTime, which is when the prefetch network request started
1247 // (which is typically well before the navigation starts).
1248 baseTime = request.fromPrefetchCache() ? request.issueTime() : request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341249 }
1250 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371251 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341252 }
Blink Reformat4c46d092018-04-07 15:32:371253 }
1254
1255 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381256 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371257 return;
1258 }
1259
Wolfgang Beyer8fc262f2023-04-11 13:22:501260 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381261 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131262 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501263 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501264 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381265 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501266 };
Blink Reformat4c46d092018-04-07 15:32:371267
1268 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551269 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501270 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501271 appendChunk(
Christy Chencac3f102021-02-03 10:07:551272 i18nString(UIStrings.sSTransferred, {
Connor Clarkcc5008a2024-11-08 23:17:001273 PH1: i18n.ByteUtilities.bytesToString(selectedTransferSize),
1274 PH2: i18n.ByteUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551275 }),
1276 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501277 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501278 appendChunk(
Christy Chencac3f102021-02-03 10:07:551279 i18nString(UIStrings.sSResources, {
Connor Clarkcc5008a2024-11-08 23:17:001280 PH1: i18n.ByteUtilities.bytesToString(selectedResourceSize),
1281 PH2: i18n.ByteUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551282 }),
1283 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371284 } else {
Christy Chencac3f102021-02-03 10:07:551285 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501286 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251287 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001288 i18nString(UIStrings.sTransferred, {PH1: i18n.ByteUtilities.bytesToString(transferSize)}),
Christy Chencac3f102021-02-03 10:07:551289 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501290 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251291 appendChunk(
Connor Clarkcc5008a2024-11-08 23:17:001292 i18nString(UIStrings.sResources, {PH1: i18n.ByteUtilities.bytesToString(resourceSize)}),
Christy Chencac3f102021-02-03 10:07:551293 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371294 }
Dan Beam87466b52018-12-01 18:41:201295
Blink Reformat4c46d092018-04-07 15:32:371296 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501297 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581298 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531299 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501300 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551301 const domContentLoadedText = i18nString(
1302 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531303 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381304 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371305 }
Jack Franklin28577db2021-10-14 08:12:531306 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501307 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531308 const loadText =
1309 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381310 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371311 }
1312 }
Blink Reformat4c46d092018-04-07 15:32:371313 }
1314
Jan Schefflerd6c1d402021-02-26 16:56:381315 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531316 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371317 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341318 }
Blink Reformat4c46d092018-04-07 15:32:371319
Jack Franklin28577db2021-10-14 08:12:531320 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371321
Danil Somsikovf3b437f2023-03-23 16:15:391322 if (this.isShowing()) {
Benedikt Meurer328b3a72025-01-02 10:38:551323 void RenderCoordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341324 }
Blink Reformat4c46d092018-04-07 15:32:371325 }
1326
Jan Schefflerd6c1d402021-02-26 16:56:381327 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301328 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371329 }
1330
Jan Schefflerd6c1d402021-02-26 16:56:381331 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301332 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371333 }
1334
Jan Schefflerd6c1d402021-02-26 16:56:381335 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301336 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371337 }
1338
Jan Scheffler17b8fb42021-08-12 12:28:381339 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531340 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381341 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341342 }
Blink Reformat4c46d092018-04-07 15:32:371343 }
1344
Jan Scheffler17b8fb42021-08-12 12:28:381345 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041346 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341347 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371348 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341349 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381350 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341351 }
Blink Reformat4c46d092018-04-07 15:32:371352 }
1353
Jan Schefflerd6c1d402021-02-26 16:56:381354 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531355 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371356 }
1357
Jan Schefflerd6c1d402021-02-26 16:56:381358 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531359 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371360 }
1361
Jan Schefflerd6c1d402021-02-26 16:56:381362 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531363 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371364 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341365 }
Blink Reformat4c46d092018-04-07 15:32:371366
Jack Franklin28577db2021-10-14 08:12:531367 if (this.calculatorInternal !== x) {
1368 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301369 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371370 }
Jack Franklin28577db2021-10-14 08:12:531371 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371372
Jack Franklin28577db2021-10-14 08:12:531373 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301374 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341375 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301376 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341377 }
Blink Reformat4c46d092018-04-07 15:32:371378
Jan Scheffler17b8fb42021-08-12 12:28:381379 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381
Jan Scheffler17b8fb42021-08-12 12:28:381382 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271383 event: Common.EventTarget
1384 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531385 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371386 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341387 }
Blink Reformat4c46d092018-04-07 15:32:371388
Simon Zünd1a930492021-07-30 08:22:271389 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371390 if (time) {
Jack Franklin28577db2021-10-14 08:12:531391 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301392 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371393 }
1394 }
1395
Jan Scheffler17b8fb42021-08-12 12:28:381396 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531397 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371398 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341399 }
Simon Zünd1a930492021-07-30 08:22:271400 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371401 if (data) {
Jack Franklin28577db2021-10-14 08:12:531402 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301403 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371404 }
1405 }
1406
Randolf Jungffd14242023-04-19 00:32:251407 override wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381408 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301409 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301410 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371411 }
1412
Randolf Jungffd14242023-04-19 00:32:251413 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301414 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371415 }
1416
Randolf Jungffd14242023-04-19 00:32:251417 override onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531418 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371419 }
1420
Jan Schefflerd6c1d402021-02-26 16:56:381421 flatNodesList(): NetworkNode[] {
1422 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531423 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381424 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1425 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371426 }
1427
Jan Scheffler17b8fb42021-08-12 12:28:381428 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531429 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351430 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381431 }
Brandon Goddard44934902020-03-25 16:03:181432 this.updateNodeBackground();
1433 }
1434
Jan Scheffler17b8fb42021-08-12 12:28:381435 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181436 this.element.classList.remove('grid-focused');
1437 this.updateNodeBackground();
1438 }
1439
Jan Schefflerd6c1d402021-02-26 16:56:381440 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531441 if (this.dataGrid.selectedNode) {
1442 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051443 }
1444 }
1445
Jan Schefflerd6c1d402021-02-26 16:56:381446 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051447 if (isSelected) {
1448 this.element.classList.remove('no-node-selected');
1449 } else {
1450 this.element.classList.add('no-node-selected');
1451 }
1452 }
1453
Jan Schefflerd6c1d402021-02-26 16:56:381454 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301455 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371456 }
1457
Wolfgang Beyer51f2f252023-07-27 17:09:511458 private removeNodeAndMaybeAncestors(node: NetworkRequestNode): void {
1459 let parent: NetworkNode|
1460 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1461 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1462 null) = node.parent;
1463 if (!parent) {
1464 return;
1465 }
1466 parent.removeChild(node);
1467 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1468 const grandparent = (parent.parent as NetworkNode);
1469 grandparent.removeChild(parent);
1470 parent = grandparent;
1471 }
1472 }
1473
Jan Scheffler17b8fb42021-08-12 12:28:381474 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531475 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371476
Blink Reformat4c46d092018-04-07 15:32:371477 this.removeAllNodeHighlights();
1478
Jack Franklin28577db2021-10-14 08:12:531479 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1480 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1481 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1482 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371483
Jan Schefflerd6c1d402021-02-26 16:56:381484 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1485 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371486
Jan Schefflerd6c1d402021-02-26 16:56:381487 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371488
Jack Franklin28577db2021-10-14 08:12:531489 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371490 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531491 while (this.staleRequests.size) {
Simon Zündf0d3b5c2024-10-10 06:28:021492 const request = this.staleRequests.values().next().value as SDK.NetworkRequest.NetworkRequest;
Jack Franklin28577db2021-10-14 08:12:531493 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371494 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341495 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381496 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341497 }
Blink Reformat4c46d092018-04-07 15:32:371498 staleNodes.add(node);
1499 }
1500
1501 for (const node of staleNodes) {
Yang Guo6d1361f2024-07-11 08:23:481502 const request = node.request();
1503 const isFilteredOut = !this.applyFilter(request);
Benedikt Meurere4391232024-06-07 10:47:251504 if (isFilteredOut) {
1505 if (node === this.hoveredNodeInternal) {
1506 this.setHoveredNode(null);
1507 }
1508 node.selected = false;
1509 } else {
Blink Reformat4c46d092018-04-07 15:32:371510 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341511 }
Jack Franklin28577db2021-10-14 08:12:531512 this.timeCalculatorInternal.updateBoundaries(request);
1513 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381514 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371515 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1516 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371517 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341518 }
Tim van der Lippe224a8622020-09-23 12:14:371519 if (isFilteredOut) {
1520 filteredNetworkRequests.add(node);
1521 } else {
1522 filteredNetworkRequests.delete(node);
1523 }
Blink Reformat4c46d092018-04-07 15:32:371524 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1525 if (removeFromParent) {
Wolfgang Beyer51f2f252023-07-27 17:09:511526 this.removeNodeAndMaybeAncestors(node);
Blink Reformat4c46d092018-04-07 15:32:371527 }
1528
Tim van der Lippe1d6e57a2019-09-30 11:55:341529 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371530 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341531 }
Blink Reformat4c46d092018-04-07 15:32:371532
1533 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531534 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371535 nodesToRefresh.push(newParent);
1536 }
1537 nodesToInsert.set(node, newParent);
1538 }
1539
Tim van der Lippe1d6e57a2019-09-30 11:55:341540 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381541 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341542 }
Blink Reformat4c46d092018-04-07 15:32:371543
Tim van der Lippe1d6e57a2019-09-30 11:55:341544 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371545 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341546 }
Blink Reformat4c46d092018-04-07 15:32:371547
Jan Scheffler17b8fb42021-08-12 12:28:381548 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371549
Tim van der Lippe1d6e57a2019-09-30 11:55:341550 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301551 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341552 }
Blink Reformat4c46d092018-04-07 15:32:371553
Jack Franklin28577db2021-10-14 08:12:531554 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381555 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371556 }
1557
Jan Scheffler17b8fb42021-08-12 12:28:381558 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371559 }
1560
Jan Scheffler17b8fb42021-08-12 12:28:381561 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531562 if (!this.activeGroupLookup) {
1563 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341564 }
Blink Reformat4c46d092018-04-07 15:32:371565
Jack Franklin28577db2021-10-14 08:12:531566 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341567 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531568 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341569 }
Blink Reformat4c46d092018-04-07 15:32:371570 return groupNode;
1571 }
1572
Jan Scheffler17b8fb42021-08-12 12:28:381573 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151574 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371575
Jan Scheffler17b8fb42021-08-12 12:28:381576 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301577 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371578
Jack Franklin28577db2021-10-14 08:12:531579 this.timeFilter = null;
1580 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371581
Jack Franklin28577db2021-10-14 08:12:531582 this.timeCalculatorInternal.setWindow(null);
1583 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371584
Jack Franklin28577db2021-10-14 08:12:531585 if (this.activeGroupLookup) {
1586 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341587 }
Jack Franklin28577db2021-10-14 08:12:531588 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381589 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371590
Jack Franklin28577db2021-10-14 08:12:531591 this.mainRequestLoadTime = -1;
1592 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371593
Jack Franklin28577db2021-10-14 08:12:531594 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381595 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371596 this.scheduleRefresh();
1597 }
1598
Silvia Eremia096e1202023-09-22 15:49:171599 // TODO(crbug.com/1477668)
Jan Schefflerd6c1d402021-02-26 16:56:381600 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531601 this.textFilterUI.setValue(filterString);
Silvia Eremia096e1202023-09-22 15:49:171602 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
1603 this.networkHideDataURLSetting.set(false);
1604 this.networkShowBlockedCookiesOnlySetting.set(false);
1605 this.networkOnlyBlockedRequestsSetting.set(false);
1606 this.networkOnlyThirdPartySetting.set(false);
1607 this.networkHideChromeExtensions.set(false);
1608 } else {
1609 this.dataURLFilterUI?.setChecked(false);
1610 this.onlyBlockedResponseCookiesFilterUI?.setChecked(false);
1611 this.onlyBlockedRequestsUI?.setChecked(false);
1612 this.onlyThirdPartyFilterUI?.setChecked(false);
1613 this.hideChromeExtensionsUI?.setChecked(false);
1614 }
Jack Franklin28577db2021-10-14 08:12:531615 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371616 }
1617
Jan Scheffler17b8fb42021-08-12 12:28:381618 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301619 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371620 networkRequestToNode.set(request, node);
1621 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371622
Tim van der Lippe1d6e57a2019-09-30 11:55:341623 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381624 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341625 }
Blink Reformat4c46d092018-04-07 15:32:371626 return node;
1627 }
1628
Danil Somsikov123c3ef2023-06-14 10:07:041629 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1630 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1631 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1632 }
1633
Wolfgang Beyer393dc2b2024-01-05 15:07:401634 private onRequestUpdated(
1635 event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest, preserveLog?: boolean}>):
1636 void {
1637 const {request, preserveLog} = event.data;
1638 if (this.isInScope(request) || preserveLog) {
Danil Somsikova09c4de2023-03-27 10:35:251639 this.refreshRequest(request);
1640 }
Blink Reformat4c46d092018-04-07 15:32:371641 }
1642
Wolfgang Beyer393dc2b2024-01-05 15:07:401643 private onRequestRemoved(event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest}>):
1644 void {
1645 const {request} = event.data;
Wolfgang Beyer51f2f252023-07-27 17:09:511646 this.staleRequests.delete(request);
1647 const node = networkRequestToNode.get(request);
1648 if (node) {
1649 this.removeNodeAndMaybeAncestors(node);
1650 }
1651 }
1652
Jan Scheffler17b8fb42021-08-12 12:28:381653 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1654 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161655 .forEach(
Jack Franklin28577db2021-10-14 08:12:531656 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1657 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1658 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1659 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1660 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1661 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1662 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371663
1664 const priority = request.priority();
1665 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531666 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161667 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371668 }
1669
1670 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531671 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311672 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.ALL);
Blink Reformat4c46d092018-04-07 15:32:371673 }
1674
1675 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531676 this.suggestionBuilder.addItem(
Benedikt Meurer61b7a002024-09-04 08:02:311677 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.DISPLAYED);
Blink Reformat4c46d092018-04-07 15:32:371678 }
1679
1680 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Benedikt Meurer61b7a002024-09-04 08:02:311681 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.BLOCKED :
1682 NetworkForward.UIFilter.MixedContentFilterValues.BLOCK_OVERRIDDEN;
Jack Franklin28577db2021-10-14 08:12:531683 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371684 }
1685
1686 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511687 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531688 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511689 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531690 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511691 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341692 }
Jan Scheffler341eea52019-12-12 09:08:411693
1694 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531695 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1696 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1697 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371698 }
1699
Jan Scheffler341eea52019-12-12 09:08:411700 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531701 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1702 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1703 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1704 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411705 }
1706
Jack Franklin28577db2021-10-14 08:12:531707 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371708 this.scheduleRefresh();
1709 }
1710
Jan Schefflerd6c1d402021-02-26 16:56:381711 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531712 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371713 }
1714
Jan Schefflerd6c1d402021-02-26 16:56:381715 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301716 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371717 }
1718
Jan Schefflerd6c1d402021-02-26 16:56:381719 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1720 void {
Blink Reformat4c46d092018-04-07 15:32:371721 contextMenu.appendApplicableItems(request);
Yang Guo6d1361f2024-07-11 08:23:481722 const filtered = this.filterBar.hasActiveFilter();
Danil Somsikov23eacf62024-02-23 08:46:301723 const copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy), false, 'copy');
Blink Reformat4c46d092018-04-07 15:32:371724 if (request) {
Samiya Caurb2be2652024-09-12 05:50:541725 if (UI.ActionRegistry.ActionRegistry.instance().hasAction('drjones.network-panel-context')) {
Samiya Caur7618ee12024-09-20 14:22:221726 UI.Context.Context.instance().setFlavor(SDK.NetworkRequest.NetworkRequest, request);
Samiya Caurb2be2652024-09-12 05:50:541727 contextMenu.headerSection().appendAction(
1728 'drjones.network-panel-context',
1729 );
1730 }
Blink Reformat4c46d092018-04-07 15:32:371731 copyMenu.defaultSection().appendItem(
Benedikt Meurer8f0fee62023-12-27 12:36:511732 i18nString(UIStrings.copyURL),
Tim van der Lippe0ed1d2b2020-02-04 13:45:131733 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
Danil Somsikov23eacf62024-02-23 08:46:301734 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()),
1735 {jslogContext: 'copy-url'});
1736 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261737 filtered ? i18nString(UIStrings.copyAllListedURLs) : i18nString(UIStrings.copyAllURLs),
Yang Guo6d1361f2024-07-11 08:23:481738 this.copyAllURLs.bind(this), {jslogContext: 'copy-all-urls'});
Blink Reformat4c46d092018-04-07 15:32:371739 if (request.requestHeadersText()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511740 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301741 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request),
1742 {jslogContext: 'copy-request-headers'});
Blink Reformat4c46d092018-04-07 15:32:371743 }
1744
1745 if (request.responseHeadersText) {
Benedikt Meurer8f0fee62023-12-27 12:36:511746 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301747 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request),
1748 {jslogContext: 'copy-response-headers'});
Blink Reformat4c46d092018-04-07 15:32:371749 }
1750
1751 if (request.finished) {
Benedikt Meurer8f0fee62023-12-27 12:36:511752 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301753 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request),
1754 {jslogContext: 'copy-response'});
Blink Reformat4c46d092018-04-07 15:32:371755 }
1756
Tim van der Lippeb4faf5a2020-11-06 15:02:021757 const initiator = request.initiator();
1758
1759 if (initiator) {
1760 const stack = initiator.stack;
1761 if (stack) {
1762 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531763 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021764 // any callFrames, but its parent frames do.
1765 const stackTraceText = computeStackTraceText(stack);
1766 if (stackTraceText !== '') {
Benedikt Meurer8f0fee62023-12-27 12:36:511767 copyMenu.saveSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021768 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
Danil Somsikov23eacf62024-02-23 08:46:301769 }, {jslogContext: 'copy-stacktrace'});
Tim van der Lippeb4faf5a2020-11-06 15:02:021770 }
1771 }
1772 }
1773
Harley Libcf41f92018-09-10 18:01:131774 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131775 if (Host.Platform.isWin()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511776 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391777 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'),
Danil Somsikov23eacf62024-02-23 08:46:301778 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511779 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391780 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301781 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-bash'});
Blink Reformat4c46d092018-04-07 15:32:371782 } else {
Benedikt Meurer8f0fee62023-12-27 12:36:511783 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391784 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301785 {disabled: disableIfBlob, jslogContext: 'copy-as-curl'});
Blink Reformat4c46d092018-04-07 15:32:371786 }
Benedikt Meurer8f0fee62023-12-27 12:36:511787 copyMenu.defaultSection().appendItem(
1788 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
Danil Somsikov23eacf62024-02-23 08:46:301789 {disabled: disableIfBlob, jslogContext: 'copy-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511790 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311791 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.BROWSER),
Danil Somsikov23eacf62024-02-23 08:46:301792 {disabled: disableIfBlob, jslogContext: 'copy-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511793 copyMenu.defaultSection().appendItem(
Benedikt Meurer61b7a002024-09-04 08:02:311794 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NODE_JS),
Danil Somsikov23eacf62024-02-23 08:46:301795 {disabled: disableIfBlob, jslogContext: 'copy-as-nodejs-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511796
1797 if (Host.Platform.isWin()) {
1798 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261799 filtered ? i18nString(UIStrings.copyAllListedAsCurlCmd) : i18nString(UIStrings.copyAllAsCurlCmd),
Yang Guo6d1361f2024-07-11 08:23:481800 this.copyAllCurlCommand.bind(this, 'win'), {jslogContext: 'copy-all-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511801 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261802 filtered ? i18nString(UIStrings.copyAllListedAsCurlBash) : i18nString(UIStrings.copyAllAsCurlBash),
Yang Guo6d1361f2024-07-11 08:23:481803 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl-bash'});
Benedikt Meurer8f0fee62023-12-27 12:36:511804 } else {
1805 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261806 filtered ? i18nString(UIStrings.copyAllListedAsCurl) : i18nString(UIStrings.copyAllAsCurl),
Yang Guo6d1361f2024-07-11 08:23:481807 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl'});
Benedikt Meurer8f0fee62023-12-27 12:36:511808 }
1809 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261810 filtered ? i18nString(UIStrings.copyAllListedAsPowershell) : i18nString(UIStrings.copyAllAsPowershell),
Yang Guo6d1361f2024-07-11 08:23:481811 this.copyAllPowerShellCommand.bind(this), {jslogContext: 'copy-all-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511812 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261813 filtered ? i18nString(UIStrings.copyAllListedAsFetch) : i18nString(UIStrings.copyAllAsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311814 this.copyAllFetchCall.bind(this, FetchStyle.BROWSER), {jslogContext: 'copy-all-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511815 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261816 filtered ? i18nString(UIStrings.copyAllListedAsNodejsFetch) : i18nString(UIStrings.copyAllAsNodejsFetch),
Benedikt Meurer61b7a002024-09-04 08:02:311817 this.copyAllFetchCall.bind(this, FetchStyle.NODE_JS), {jslogContext: 'copy-all-as-nodejs-fetch'});
Blink Reformat4c46d092018-04-07 15:32:371818 }
Danil Somsikov23eacf62024-02-23 08:46:301819 copyMenu.footerSection().appendItem(
Benedikt Meureracd96a62024-09-10 07:25:241820 filtered ? i18nString(UIStrings.copyAllListedAsHarSanitized) : i18nString(UIStrings.copyAllAsHarSanitized),
1821 this.copyAllAsHAR.bind(this, {sanitize: true}), {jslogContext: 'copy-all-as-har'});
Benedikt Meurerd553c502024-10-17 19:07:181822 if (this.networkShowOptionsToGenerateHarWithSensitiveData.get()) {
Benedikt Meureracd96a62024-09-10 07:25:241823 copyMenu.footerSection().appendItem(
1824 filtered ? i18nString(UIStrings.copyAllListedAsHarWithSensitiveData) :
1825 i18nString(UIStrings.copyAllAsHarWithSensitiveData),
1826 this.copyAllAsHAR.bind(this, {sanitize: false}), {jslogContext: 'copy-all-as-har-with-sensitive-data'});
1827 }
Blink Reformat4c46d092018-04-07 15:32:371828
Wolfgang Beyer650e9572023-11-29 12:45:081829 contextMenu.overrideSection().appendItem(
Wolfgang Beyer9d9affb2024-05-08 10:14:441830 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request), {
1831 disabled:
1832 Persistence.NetworkPersistenceManager.NetworkPersistenceManager.isForbiddenNetworkUrl(request.url()),
1833 jslogContext: 'override-headers',
1834 });
Wolfgang Beyerc6fe2be2022-11-03 15:39:411835
Blink Reformat4c46d092018-04-07 15:32:371836 contextMenu.editSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301837 i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this),
1838 {jslogContext: 'clear-browser-cache'});
1839 contextMenu.editSection().appendItem(
1840 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this),
1841 {jslogContext: 'clear-browser-cookies'});
Blink Reformat4c46d092018-04-07 15:32:371842
1843 if (request) {
1844 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211845 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371846 let patterns = manager.blockedPatterns();
1847
Jan Schefflerd6c1d402021-02-26 16:56:381848 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201849 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121850 manager.setBlockedPatterns(patterns);
1851 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031852 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121853 }
1854
Jan Schefflerd6c1d402021-02-26 16:56:381855 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121856 patterns = patterns.filter(pattern => pattern.url !== url);
1857 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031858 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121859 }
1860
Blink Reformat4c46d092018-04-07 15:32:371861 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1862 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1863 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301864 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme),
1865 {jslogContext: 'block-request-url'});
Blink Reformat4c46d092018-04-07 15:32:371866 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311867 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371868 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301869 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme),
1870 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371871 }
1872
1873 const domain = request.parsedURL.domain();
1874 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1875 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301876 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain),
1877 {jslogContext: 'block-request-domain'});
Blink Reformat4c46d092018-04-07 15:32:371878 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311879 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371880 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301881 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain),
1882 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371883 }
1884
Tim van der Lippe0ed1d2b2020-02-04 13:45:131885 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371886 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301887 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request),
1888 {jslogContext: 'replay-xhr'});
Blink Reformat4c46d092018-04-07 15:32:371889 }
Blink Reformat4c46d092018-04-07 15:32:371890 }
1891 }
1892
Jan Scheffler17b8fb42021-08-12 12:28:381893 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Yang Guo6d1361f2024-07-11 08:23:481894 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1895 return requests.filter(NetworkLogView.getHTTPRequestsFilter).filter(request => {
1896 return request.finished ||
1897 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1898 });
Blink Reformat4c46d092018-04-07 15:32:371899 }
1900
Benedikt Meureracd96a62024-09-10 07:25:241901 private async copyAllAsHAR(options: HAR.Log.BuildOptions): Promise<void> {
1902 const harArchive = {log: await HAR.Log.Log.build(this.harRequests(), options)};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131903 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371904 }
1905
Benedikt Meurer8f0fee62023-12-27 12:36:511906 private copyAllURLs(): void {
Yang Guo6d1361f2024-07-11 08:23:481907 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1908 const nonBlobRequests = this.filterOutBlobRequests(requests);
Benedikt Meurer8f0fee62023-12-27 12:36:511909 const urls = nonBlobRequests.map(request => request.url());
1910 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(urls.join('\n'));
1911 }
1912
Benedikt Meurer64b7e722023-12-15 09:03:581913 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351914 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131915 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371916 }
1917
Benedikt Meurer64b7e722023-12-15 09:03:581918 private async copyAllCurlCommand(platform: 'unix'|'win'): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481919 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1920 const commands = await this.generateAllCurlCommand(requests, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131921 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371922 }
1923
Danil Somsikov59f4c612021-09-08 10:58:461924 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1925 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131926 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371927 }
1928
Danil Somsikov59f4c612021-09-08 10:58:461929 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481930 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1931 const commands = await this.generateAllFetchCall(requests, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131932 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371933 }
1934
Jan Scheffler17b8fb42021-08-12 12:28:381935 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1936 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131937 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371938 }
1939
Jan Scheffler17b8fb42021-08-12 12:28:381940 private async copyAllPowerShellCommand(): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481941 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1942 const commands = await this.generateAllPowerShellCommand(requests);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131943 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371944 }
1945
Benedikt Meureracd96a62024-09-10 07:25:241946 async exportAll(options: HAR.Log.BuildOptions): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501947 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371948 if (!mainTarget) {
1949 return;
1950 }
1951 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131952 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321953 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131954 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371955
Kateryna Prokopenko380fdfa2022-03-16 16:39:321956 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371957 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341958 }
Blink Reformat4c46d092018-04-07 15:32:371959
Tim van der Lippe0ed1d2b2020-02-04 13:45:131960 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531961 this.progressBarContainer.appendChild(progressIndicator.element);
Benedikt Meureracd96a62024-09-10 07:25:241962 await HAR.Writer.Writer.write(stream, this.harRequests(), options, progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371963 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031964 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371965 }
1966
Wolfgang Beyer5b433b02022-05-12 13:57:371967 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411968 const requestLocation =
1969 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271970 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1971 if (networkPersistanceManager.project()) {
Danil Somsikovde84fb52024-01-30 13:53:091972 Common.Settings.Settings.instance().moduleSetting('persistence-network-overrides-enabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271973 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411974 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371975 } else { // If folder for local overrides has not been provided yet
Danil Somsikovacd635c2024-02-09 12:56:511976 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async () => {
Wolfgang Beyer5b433b02022-05-12 13:57:371977 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271978 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411979 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371980 });
1981 }
1982 }
1983
Jan Scheffler17b8fb42021-08-12 12:28:381984 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551985 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211986 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341987 }
Blink Reformat4c46d092018-04-07 15:32:371988 }
1989
Jan Scheffler17b8fb42021-08-12 12:28:381990 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551991 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211992 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341993 }
Blink Reformat4c46d092018-04-07 15:32:371994 }
1995
Yang Guo6d1361f2024-07-11 08:23:481996 private applyFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Jack Franklin28577db2021-10-14 08:12:531997 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371998 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341999 }
Simon Zündb3042fb2024-12-11 06:43:062000 const categoryName = request.resourceType().category().name;
Jack Franklin28577db2021-10-14 08:12:532001 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:372002 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342003 }
Silvia Eremia096e1202023-09-22 15:49:172004 const [hideDataURL, blockedCookies, blockedRequests, thirdParty, hideExtensionURL] =
2005 Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN) ?
2006 [
2007 this.networkHideDataURLSetting.get(),
2008 this.networkShowBlockedCookiesOnlySetting.get(),
2009 this.networkOnlyBlockedRequestsSetting.get(),
2010 this.networkOnlyThirdPartySetting.get(),
2011 this.networkHideChromeExtensions.get(),
2012 ] :
2013 [
2014 this.dataURLFilterUI?.checked(),
2015 this.onlyBlockedResponseCookiesFilterUI?.checked(),
2016 this.onlyBlockedRequestsUI?.checked(),
2017 this.onlyThirdPartyFilterUI?.checked(),
2018 this.hideChromeExtensionsUI?.checked(),
2019 ];
2020
2021 if (hideDataURL && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:372022 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342023 }
Silvia Eremia096e1202023-09-22 15:49:172024 if (blockedCookies && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:372025 return false;
2026 }
Silvia Eremia096e1202023-09-22 15:49:172027 if (blockedRequests && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:132028 return false;
2029 }
Silvia Eremia096e1202023-09-22 15:49:172030 if (thirdParty && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:272031 return false;
2032 }
Silvia Eremia096e1202023-09-22 15:49:172033 if (hideExtensionURL && request.scheme === 'chrome-extension') {
ioana forfota45b44152023-07-21 14:20:532034 return false;
2035 }
Jack Franklin28577db2021-10-14 08:12:532036 for (let i = 0; i < this.filters.length; ++i) {
2037 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:372038 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342039 }
Blink Reformat4c46d092018-04-07 15:32:372040 }
2041 return true;
2042 }
2043
Danil Somsikov7a392fb2021-09-13 11:09:462044 private isValidUrl(url: string): boolean {
2045 try {
2046 new URL(url);
2047 return true;
2048 } catch (e) {
2049 return false;
2050 }
2051 }
2052
Jan Scheffler17b8fb42021-08-12 12:28:382053 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:532054 // A query string can have multiple filters, some of them regular
2055 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:372056 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:532057 // checkbox therefore inverts each one of those individual filters.
2058 const descriptors = this.filterParser.parse(query);
2059 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:372060 const key = descriptor.key;
2061 const text = descriptor.text || '';
2062 const regex = descriptor.regex;
2063 let filter;
2064 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:172065 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:382066 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
2067 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:372068 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:382069 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:462070 } else if (this.isValidUrl(text)) {
2071 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:372072 } else {
Jan Scheffler17b8fb42021-08-12 12:28:382073 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:172074 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:372075 }
Victor Porof66878d62021-07-16 13:12:372076 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:382077 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:372078 }
2079 return filter;
Blink Reformat4c46d092018-04-07 15:32:372080 });
2081 }
2082
Jan Scheffler17b8fb42021-08-12 12:28:382083 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372084 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:162085 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:382086 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:372087
Sigurd Schneider30722582021-06-16 06:54:162088 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:382089 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372090
Simon Zünd6dedde52021-08-03 09:04:512091 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:382092 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:512093
Sigurd Schneider30722582021-06-16 06:54:162094 case NetworkForward.UIFilter.FilterType.Is:
Benedikt Meurer61b7a002024-09-04 08:02:312095 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.RUNNING) {
Jan Scheffler17b8fb42021-08-12 12:28:382096 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342097 }
Benedikt Meurer61b7a002024-09-04 08:02:312098 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FROM_CACHE) {
Jan Scheffler17b8fb42021-08-12 12:28:382099 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342100 }
Benedikt Meurer61b7a002024-09-04 08:02:312101 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INTERCEPTED) {
Jan Scheffler17b8fb42021-08-12 12:28:382102 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342103 }
Benedikt Meurer61b7a002024-09-04 08:02:312104 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.SERVICE_WORKER_INITIATED) {
Jan Scheffler17b8fb42021-08-12 12:28:382105 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342106 }
Blink Reformat4c46d092018-04-07 15:32:372107 break;
2108
Sigurd Schneider30722582021-06-16 06:54:162109 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:382110 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:372111
Sigurd Schneider30722582021-06-16 06:54:162112 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:382113 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372114
Sigurd Schneider30722582021-06-16 06:54:162115 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:382116 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372117
Sigurd Schneider30722582021-06-16 06:54:162118 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:382119 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:162120 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:372121
Sigurd Schneider30722582021-06-16 06:54:162122 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:382123 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372124
Sigurd Schneider30722582021-06-16 06:54:162125 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382126 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372127
Sigurd Schneider30722582021-06-16 06:54:162128 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382129 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372130
Sigurd Schneider30722582021-06-16 06:54:162131 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382132 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372133
Sigurd Schneider30722582021-06-16 06:54:162134 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382135 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412136
Sigurd Schneider30722582021-06-16 06:54:162137 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382138 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412139
Sigurd Schneider30722582021-06-16 06:54:162140 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:382141 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:542142
Sigurd Schneider30722582021-06-16 06:54:162143 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382144 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412145
Sigurd Schneider30722582021-06-16 06:54:162146 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:382147 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:502148 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:372149
Sigurd Schneider30722582021-06-16 06:54:162150 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:382151 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:032152
Jecelyn Yeen77c83462023-08-16 16:13:172153 case NetworkForward.UIFilter.FilterType.HasOverrides:
2154 return NetworkLogView.hasOverridesFilter.bind(null, value);
2155
Sigurd Schneider30722582021-06-16 06:54:162156 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:382157 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:032158
Sigurd Schneider30722582021-06-16 06:54:162159 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:382160 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372161 }
2162 return null;
2163 }
2164
Jan Scheffler17b8fb42021-08-12 12:28:382165 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372166 let multiplier = 1;
2167 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542168 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:372169 value = value.substring(0, value.length - 1);
2170 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542171 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:372172 value = value.substring(0, value.length - 1);
2173 }
2174 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342175 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:372176 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342177 }
Jan Scheffler17b8fb42021-08-12 12:28:382178 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:372179 }
2180
Jan Scheffler17b8fb42021-08-12 12:28:382181 private filterRequests(): void {
Nancy Liffb3c7e2024-08-01 14:58:152182 this.removeAllNodeHighlights();
Jan Scheffler17b8fb42021-08-12 12:28:382183 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:372184 }
2185
Jan Scheffler17b8fb42021-08-12 12:28:382186 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:372187 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:372188 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342189 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:372190 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342191 }
Brandon Goddard5e4244d2020-04-08 22:08:472192 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:532193 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:472194 // reveal and expand parent to ensure child is revealable.
2195 if (node.parent && node.parent instanceof NetworkGroupNode) {
2196 node.parent.reveal();
2197 node.parent.expand();
2198 }
Blink Reformat4c46d092018-04-07 15:32:372199 node.reveal();
2200 return node;
2201 }
2202
Jan Schefflerd6c1d402021-02-26 16:56:382203 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:382204 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342205 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:382206 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:342207 }
Blink Reformat4c46d092018-04-07 15:32:372208 }
2209
Sigurd Schneider722301e2021-06-15 13:41:202210 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:072211 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
2212 if (request) {
2213 this.revealAndHighlightRequest(request);
2214 }
2215 }
2216
Sigurd Schneider14d3e9f2021-06-14 08:29:012217 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
2218 void {
chait pinnamaneni6bc1c122020-10-30 17:30:522219 const defaultOptions = {clearFilter: true};
2220 const {clearFilter} = options || defaultOptions;
2221 if (clearFilter) {
2222 this.setTextFilterValue('');
2223 }
Jan Scheffler17b8fb42021-08-12 12:28:382224 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342225 if (node) {
Blink Reformat4c46d092018-04-07 15:32:372226 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:342227 }
Blink Reformat4c46d092018-04-07 15:32:372228 }
2229
Jan Schefflerd6c1d402021-02-26 16:56:382230 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:532231 if (this.highlightedNode) {
2232 this.highlightedNode.element().classList.remove('highlighted-row');
2233 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:372234 }
2235 }
2236
Jan Scheffler17b8fb42021-08-12 12:28:382237 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132238 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:532239 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:372240 }
2241
Jan Scheffler17b8fb42021-08-12 12:28:382242 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:132243 return requests.filter(request => !request.isBlobRequest());
2244 }
2245
Danil Somsikov59f4c612021-09-08 10:58:462246 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382247 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:372248 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372249 'method',
2250 'path',
2251 'scheme',
2252 'version',
Blink Reformat4c46d092018-04-07 15:32:372253
2254 // Unsafe headers
2255 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372256 'accept-charset',
2257 'accept-encoding',
2258 'access-control-request-headers',
2259 'access-control-request-method',
2260 'connection',
2261 'content-length',
2262 'cookie',
2263 'cookie2',
2264 'date',
2265 'dnt',
2266 'expect',
2267 'host',
2268 'keep-alive',
2269 'origin',
2270 'referer',
2271 'te',
2272 'trailer',
2273 'transfer-encoding',
2274 'upgrade',
2275 'via',
Blink Reformat4c46d092018-04-07 15:32:372276 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372277 'user-agent',
2278 ]);
Blink Reformat4c46d092018-04-07 15:32:372279
Jan Schefflerd6c1d402021-02-26 16:56:382280 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372281
2282 const url = JSON.stringify(request.url());
2283
2284 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382285 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372286 const name = header.name;
2287
Tim van der Lippe224a8622020-09-23 12:14:372288 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372289 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342290 }
Blink Reformat4c46d092018-04-07 15:32:372291
2292 return result;
2293 }, new Headers());
2294
Jan Schefflerd6c1d402021-02-26 16:56:382295 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342296 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412297 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342298 }
Blink Reformat4c46d092018-04-07 15:32:372299
Sigurd Schneider0e88b912020-05-08 08:28:232300 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372301 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412302 'include' :
2303 'omit';
Blink Reformat4c46d092018-04-07 15:32:372304
2305 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2306
2307 const referrer = referrerHeader ? referrerHeader.value : void 0;
2308
2309 const referrerPolicy = request.referrerPolicy() || void 0;
2310
2311 const requestBody = await request.requestFormData();
2312
Jan Schefflerd6c1d402021-02-26 16:56:382313 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412314 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372315 referrer,
2316 referrerPolicy,
2317 body: requestBody,
2318 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372319 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372320 };
2321
Benedikt Meurer61b7a002024-09-04 08:02:312322 if (style === FetchStyle.NODE_JS) {
Jan Scheffler7c50d1f2019-12-17 13:33:292323 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462324 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532325 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462326 // following properties are not implemented in Node.js.
2327 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292328 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462329 extraHeaders['cookie'] = cookieHeader.value;
2330 }
2331 if (referrer) {
2332 delete fetchOptions.referrer;
2333 extraHeaders['Referer'] = referrer;
2334 }
2335 if (referrer) {
2336 delete fetchOptions.referrerPolicy;
2337 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2338 }
2339 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292340 fetchOptions.headers = {
2341 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462342 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292343 };
2344 }
2345 } else {
2346 fetchOptions.credentials = credentials;
2347 }
2348
Jan Scheffler172d5212020-01-02 14:42:562349 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372350 return `fetch(${url}, ${options});`;
2351 }
2352
Danil Somsikov59f4c612021-09-08 10:58:462353 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382354 Promise<string> {
2355 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462356 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132357 return commands.join(' ;\n');
2358 }
2359
Benedikt Meurer64b7e722023-12-15 09:03:582360 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'):
2361 Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382362 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362363 // Most of these headers are derived from the URL and are automatically added by cURL.
2364 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Barry Pollard0a176b42024-01-30 10:19:232365 const ignoredHeaders =
2366 new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version', 'authority', 'protocol']);
Blink Reformat4c46d092018-04-07 15:32:372367
Jan Schefflerd6c1d402021-02-26 16:56:382368 function escapeStringWin(str: string): string {
Danil Somsikovf4447112024-09-10 12:22:302369 /* Always escape the " characters so that we can use caret escaping.
Blink Reformat4c46d092018-04-07 15:32:372370
Jan Schefflerd6c1d402021-02-26 16:56:382371 Because cmd.exe parser and MS Crt arguments parsers use some of the
2372 same escape characters, they can interact with each other in
2373 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372374
Jan Schefflerd6c1d402021-02-26 16:56:382375 Replace \ with \\ first because it is an escape character for certain
2376 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372377
Jan Schefflerd6c1d402021-02-26 16:56:382378 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372379
Jan Schefflerd6c1d402021-02-26 16:56:382380 Then escape all characters we are not sure about with ^ to ensure it
2381 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372382
Jan Schefflerd6c1d402021-02-26 16:56:382383 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352384 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382385 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2386 parser); So we can get cmd.exe parser to escape the character after it,
2387 if it is followed by a valid beginning character of an ENV variable.
2388 This ensures we do not try and double escape another ^ if it was placed
2389 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372390
Jan Schefflerd6c1d402021-02-26 16:56:382391 Lastly we replace new lines with ^ and TWO new lines because the first
2392 new line is there to enact the escape command the second is the character
2393 to escape (in this case new line).
2394 */
Danil Somsikovf4447112024-09-10 12:22:302395 const encapsChars = '^"';
Blink Reformat4c46d092018-04-07 15:32:372396 return encapsChars +
2397 str.replace(/\\/g, '\\\\')
2398 .replace(/"/g, '\\"')
Danil Somsikovf4447112024-09-10 12:22:302399 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372400 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542401 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372402 encapsChars;
2403 }
2404
Jan Schefflerd6c1d402021-02-26 16:56:382405 function escapeStringPosix(str: string): string {
2406 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222407 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122408 let hexString = code.toString(16);
2409 // Zero pad to four digits to comply with ANSI-C Quoting:
2410 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342411 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122412 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342413 }
Joey Arhar2d21f712019-05-20 21:07:122414
2415 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372416 }
2417
Mathias Bynensf06e8c02020-02-28 13:58:282418 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372419 // Use ANSI-C quoting syntax.
2420 return '$\'' +
2421 str.replace(/\\/g, '\\\\')
2422 .replace(/\'/g, '\\\'')
2423 .replace(/\n/g, '\\n')
2424 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282425 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372426 '\'';
Blink Reformat4c46d092018-04-07 15:32:372427 }
Mathias Bynensf06e8c02020-02-28 13:58:282428 // Use single quote syntax.
2429 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372430 }
2431
2432 // cURL command expected to run on the same platform that DevTools run
2433 // (it may be different from the inspected page platform).
2434 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2435
2436 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2437
2438 let inferredMethod = 'GET';
2439 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372440 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082441 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272442 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532443 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272444 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372445 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372446 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372447 }
2448
2449 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292450 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372451 }
2452
2453 const requestHeaders = request.requestHeaders();
2454 for (let i = 0; i < requestHeaders.length; i++) {
2455 const header = requestHeaders[i];
2456 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372457 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372458 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342459 }
Benedikt Meurerb1bf2352024-12-16 13:38:492460 const value = header.value;
2461 if (!value.trim()) {
Wolfgang Beyer26b7e892022-08-16 11:02:352462 // A header passed with -H with no value or only whitespace as its
2463 // value tells curl to not set the header at all. To post an empty
2464 // header, you have to terminate it with a semicolon.
2465 command.push('-H ' + escapeString(name + ';'));
Benedikt Meurerb1bf2352024-12-16 13:38:492466 } else if (name.toLowerCase() === 'cookie') {
2467 command.push('-b ' + escapeString(value));
2468 } else {
2469 command.push('-H ' + escapeString(name + ': ' + value));
Wolfgang Beyer26b7e892022-08-16 11:02:352470 }
Blink Reformat4c46d092018-04-07 15:32:372471 }
2472 command = command.concat(data);
Blink Reformat4c46d092018-04-07 15:32:372473
Tim van der Lippe1d6e57a2019-09-30 11:55:342474 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372475 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342476 }
Jan Scheffler172d5212020-01-02 14:42:562477 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372478 }
2479
Benedikt Meurer64b7e722023-12-15 09:03:582480 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: 'unix'|'win'):
Jan Scheffler17b8fb42021-08-12 12:28:382481 Promise<string> {
2482 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352483 const commands =
2484 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342485 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132486 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342487 }
Mathias Bynensf06e8c02020-02-28 13:58:282488 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132489 }
2490
Jan Scheffler17b8fb42021-08-12 12:28:382491 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562492 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242493 const ignoredHeaders = new Set<string>([
2494 'host',
2495 'connection',
2496 'proxy-connection',
2497 'content-length',
2498 'expect',
2499 'range',
2500 'content-type',
2501 'user-agent',
2502 'cookie',
2503 ]);
Blink Reformat4c46d092018-04-07 15:32:372504
Jan Schefflerd6c1d402021-02-26 16:56:382505 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372506 return '"' +
2507 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2508 }
2509
Brandon Walderman153b8d72021-06-28 18:45:242510 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2511 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2512 // command does not allow setting these headers through the -Headers parameter. See docs at:
2513 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2514 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2515 const requestHeaders = request.requestHeaders();
2516 const props = [];
2517
2518 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2519 if (userAgentHeader) {
2520 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2521 }
2522
Shuran Huang670281e2024-02-15 16:29:542523 for (const includedCookie of request.includedRequestCookies()) {
2524 const name = escapeString(includedCookie.cookie.name());
2525 const value = escapeString(includedCookie.cookie.value());
2526 const domain = escapeString(includedCookie.cookie.domain());
Brandon Walderman153b8d72021-06-28 18:45:242527 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2528 }
2529
2530 if (props.length) {
2531 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2532 }
2533
2534 return null;
2535 }
2536
Jan Scheffler172d5212020-01-02 14:42:562537 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372538
2539 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562540 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372541 }
2542
Brandon Walderman153b8d72021-06-28 18:45:242543 const session = generatePowerShellSession(request);
2544 if (session) {
2545 command.push('-WebSession $session');
2546 }
2547
Blink Reformat4c46d092018-04-07 15:32:372548 const requestHeaders = request.requestHeaders();
2549 const headerNameValuePairs = [];
2550 for (const header of requestHeaders) {
2551 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342552 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372553 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342554 }
Blink Reformat4c46d092018-04-07 15:32:372555 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2556 }
2557 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562558 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372559 }
2560
2561 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2562 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562563 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372564 }
2565
2566 const formData = await request.requestFormData();
2567 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372568 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342569 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562570 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342571 } else {
Jan Scheffler172d5212020-01-02 14:42:562572 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342573 }
Blink Reformat4c46d092018-04-07 15:32:372574 }
2575
Brandon Walderman153b8d72021-06-28 18:45:242576 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2577 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2578 // compatibility only.
2579 const prelude = session || '';
2580 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372581 }
Harley Libcf41f92018-09-10 18:01:132582
Jan Scheffler17b8fb42021-08-12 12:28:382583 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2584 const nonBlobRequests = this.filterOutBlobRequests(requests);
2585 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132586 return commands.join(';\r\n');
2587 }
Joey Arhara86c14e2019-03-12 03:20:502588
Jan Schefflerd6c1d402021-02-26 16:56:382589 static getDCLEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142590 return '--sys-color-blue';
Joey Arhara86c14e2019-03-12 03:20:502591 }
2592
Jan Schefflerd6c1d402021-02-26 16:56:382593 static getLoadEventColor(): string {
Saiv-kodesdf8bada2024-12-19 09:05:142594 return '--sys-color-error';
Joey Arhara86c14e2019-03-12 03:20:502595 }
Paul Lewis56509652019-12-06 12:51:582596}
Blink Reformat4c46d092018-04-07 15:32:372597
Jan Schefflerd6c1d402021-02-26 16:56:382598export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022599 let stackTraceText = '';
2600 for (const frame of stackTrace.callFrames) {
2601 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2602 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2603 }
2604 if (stackTrace.parent) {
2605 stackTraceText += computeStackTraceText(stackTrace.parent);
2606 }
2607 return stackTraceText;
2608}
2609
Jan Schefflerd6c1d402021-02-26 16:56:382610const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2611const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372612
Jan Schefflerd6c1d402021-02-26 16:56:382613export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372614 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222615}
2616
Paul Lewis56509652019-12-06 12:51:582617export const HTTPSchemas = {
Nikolay Vitkov47310242024-09-04 10:00:072618 http: true,
2619 https: true,
2620 ws: true,
2621 wss: true,
Blink Reformat4c46d092018-04-07 15:32:372622};
2623
Sigurd Schneider576ca9a2021-07-16 05:58:042624const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382625
2626export interface GroupLookupInterface {
2627 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2628 reset(): void;
2629}
2630
Jecelyn Yeen77c83462023-08-16 16:13:172631export const overrideFilter = {
2632 yes: 'yes',
2633 no: 'no',
2634 content: 'content',
2635 headers: 'headers',
2636};
2637
Jan Schefflerd6c1d402021-02-26 16:56:382638export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;
ioana forfota2c72e132023-09-22 12:11:482639
Silvia Eremia096e1202023-09-22 15:49:172640export class MoreFiltersDropDownUI extends
2641 Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes> implements UI.FilterBar.FilterUI {
2642 private readonly filterElement: HTMLDivElement;
Kateryna Prokopenko17cba892024-07-26 13:33:562643 private readonly dropDownButton: UI.Toolbar.ToolbarCombobox;
Silvia Eremia096e1202023-09-22 15:49:172644 private networkHideDataURLSetting: Common.Settings.Setting<boolean>;
2645 private networkHideChromeExtensionsSetting: Common.Settings.Setting<boolean>;
2646 private networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
2647 private networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
2648 private networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
2649 private contextMenu?: UI.ContextMenu.ContextMenu;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482650 private activeFiltersCount: HTMLElement;
2651 private activeFiltersCountAdorner: Adorners.Adorner.Adorner;
Silvia Eremia096e1202023-09-22 15:49:172652
Benedikt Meurer6b3ebf22024-01-12 10:00:512653 constructor() {
Silvia Eremia096e1202023-09-22 15:49:172654 super();
Silvia Eremia096e1202023-09-22 15:49:172655
Danil Somsikov74217e92024-01-30 07:01:122656 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
Silvia Eremia096e1202023-09-22 15:49:172657 this.networkHideChromeExtensionsSetting =
Danil Somsikov74217e92024-01-30 07:01:122658 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Silvia Eremia096e1202023-09-22 15:49:172659 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:122660 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172661 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:122662 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Silvia Eremia096e1202023-09-22 15:49:172663 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:122664 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172665
2666 this.filterElement = document.createElement('div');
2667 this.filterElement.setAttribute('aria-label', 'Show only/hide requests dropdown');
Danil Somsikov0cb97462024-01-30 15:11:292668 this.filterElement.setAttribute('jslog', `${VisualLogging.dropDown('more-filters').track({click: true})}`);
Kateryna Prokopenkod98e34c2023-09-25 18:08:482669
2670 this.activeFiltersCountAdorner = new Adorners.Adorner.Adorner();
2671 this.activeFiltersCount = document.createElement('span');
2672 this.activeFiltersCountAdorner.data = {
2673 name: 'countWrapper',
2674 content: this.activeFiltersCount,
2675 };
2676 this.activeFiltersCountAdorner.classList.add('active-filters-count');
2677 this.updateActiveFiltersCount();
2678
Kateryna Prokopenko17cba892024-07-26 13:33:562679 this.dropDownButton = new UI.Toolbar.ToolbarCombobox(i18nString(UIStrings.showOnlyHideRequests));
2680 this.dropDownButton.setText(i18nString(UIStrings.moreFilters));
2681 this.dropDownButton.setAdorner(this.activeFiltersCountAdorner);
Silvia Eremia096e1202023-09-22 15:49:172682 this.filterElement.appendChild(this.dropDownButton.element);
Silvia Eremia096e1202023-09-22 15:49:172683 this.dropDownButton.element.classList.add('dropdown-filterbar');
2684 this.dropDownButton.addEventListener(
Benedikt Meurerf08ab4a2024-09-03 09:37:352685 UI.Toolbar.ToolbarButton.Events.CLICK, this.showMoreFiltersContextMenu.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172686 UI.ARIAUtils.markAsMenuButton(this.dropDownButton.element);
Kateryna Prokopenko5f434d42023-11-03 10:57:492687 this.updateTooltip();
Silvia Eremia096e1202023-09-22 15:49:172688 }
2689
Wolfgang Beyer3b382582023-11-16 12:40:022690 #onSettingChanged(): void {
Benedikt Meurerf08ab4a2024-09-03 09:37:352691 this.dispatchEventToListeners(UI.FilterBar.FilterUIEvents.FILTER_CHANGED);
Wolfgang Beyer3b382582023-11-16 12:40:022692 }
2693
Silvia Eremia096e1202023-09-22 15:49:172694 showMoreFiltersContextMenu(event: Common.EventTarget.EventTargetEvent<Event>): void {
2695 const mouseEvent = event.data;
2696
Wolfgang Beyer3b382582023-11-16 12:40:022697 this.networkHideDataURLSetting.addChangeListener(this.#onSettingChanged.bind(this));
2698 this.networkHideChromeExtensionsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2699 this.networkShowBlockedCookiesOnlySetting.addChangeListener(this.#onSettingChanged.bind(this));
2700 this.networkOnlyBlockedRequestsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2701 this.networkOnlyThirdPartySetting.addChangeListener(this.#onSettingChanged.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172702 this.contextMenu = new UI.ContextMenu.ContextMenu(mouseEvent, {
2703 useSoftMenu: true,
2704 keepOpen: true,
2705 x: this.dropDownButton.element.getBoundingClientRect().left,
2706 y: this.dropDownButton.element.getBoundingClientRect().top +
2707 (this.dropDownButton.element as HTMLElement).offsetHeight,
2708 });
2709
2710 this.contextMenu.defaultSection().appendCheckboxItem(
2711 i18nString(UIStrings.hideDataUrls),
Danil Somsikov66fa2262024-02-22 13:02:492712 () => this.networkHideDataURLSetting.set(!this.networkHideDataURLSetting.get()), {
2713 checked: this.networkHideDataURLSetting.get(),
2714 tooltip: i18nString(UIStrings.hidesDataAndBlobUrls),
2715 jslogContext: 'hide-data-urls',
2716 });
Silvia Eremia096e1202023-09-22 15:49:172717 this.contextMenu.defaultSection().appendCheckboxItem(
2718 i18nString(UIStrings.chromeExtensions),
Danil Somsikov66fa2262024-02-22 13:02:492719 () => this.networkHideChromeExtensionsSetting.set(!this.networkHideChromeExtensionsSetting.get()), {
2720 checked: this.networkHideChromeExtensionsSetting.get(),
2721 tooltip: i18nString(UIStrings.hideChromeExtension),
2722 jslogContext: 'hide-extension-urls',
2723 });
Silvia Eremia096e1202023-09-22 15:49:172724 this.contextMenu.defaultSection().appendSeparator();
Kateryna Prokopenkod98e34c2023-09-25 18:08:482725
Silvia Eremia096e1202023-09-22 15:49:172726 this.contextMenu.defaultSection().appendCheckboxItem(
2727 i18nString(UIStrings.hasBlockedCookies),
Danil Somsikov66fa2262024-02-22 13:02:492728 () => this.networkShowBlockedCookiesOnlySetting.set(!this.networkShowBlockedCookiesOnlySetting.get()), {
2729 checked: this.networkShowBlockedCookiesOnlySetting.get(),
2730 tooltip: i18nString(UIStrings.onlyShowRequestsWithBlockedCookies),
2731 jslogContext: 'only-blocked-response-cookies',
2732 });
Silvia Eremia096e1202023-09-22 15:49:172733 this.contextMenu.defaultSection().appendCheckboxItem(
2734 i18nString(UIStrings.blockedRequests),
Danil Somsikov66fa2262024-02-22 13:02:492735 () => this.networkOnlyBlockedRequestsSetting.set(!this.networkOnlyBlockedRequestsSetting.get()), {
2736 checked: this.networkOnlyBlockedRequestsSetting.get(),
2737 tooltip: i18nString(UIStrings.onlyShowBlockedRequests),
2738 jslogContext: 'only-blocked-requests',
2739 });
Silvia Eremia096e1202023-09-22 15:49:172740 this.contextMenu.defaultSection().appendCheckboxItem(
2741 i18nString(UIStrings.thirdParty),
Danil Somsikov66fa2262024-02-22 13:02:492742 () => this.networkOnlyThirdPartySetting.set(!this.networkOnlyThirdPartySetting.get()), {
2743 checked: this.networkOnlyThirdPartySetting.get(),
2744 tooltip: i18nString(UIStrings.onlyShowThirdPartyRequests),
2745 jslogContext: 'only-3rd-party-requests',
2746 });
Silvia Eremia096e1202023-09-22 15:49:172747
2748 void this.contextMenu.show();
2749 }
2750
Kateryna Prokopenko5f434d42023-11-03 10:57:492751 selectedFilters(): string[] {
2752 const filters = [
2753 ...this.networkHideDataURLSetting.get() ? [i18nString(UIStrings.hideDataUrls)] : [],
2754 ...this.networkHideChromeExtensionsSetting.get() ? [i18nString(UIStrings.chromeExtensions)] : [],
2755 ...this.networkShowBlockedCookiesOnlySetting.get() ? [i18nString(UIStrings.hasBlockedCookies)] : [],
2756 ...this.networkOnlyBlockedRequestsSetting.get() ? [i18nString(UIStrings.blockedRequests)] : [],
2757 ...this.networkOnlyThirdPartySetting.get() ? [i18nString(UIStrings.thirdParty)] : [],
Kateryna Prokopenkod98e34c2023-09-25 18:08:482758 ];
Kateryna Prokopenko5f434d42023-11-03 10:57:492759 return filters;
2760 }
2761
2762 updateActiveFiltersCount(): void {
2763 const count = this.selectedFilters().length;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482764 this.activeFiltersCount.textContent = count.toString();
2765 count ? this.activeFiltersCountAdorner.classList.remove('hidden') :
2766 this.activeFiltersCountAdorner.classList.add('hidden');
2767 }
2768
Kateryna Prokopenko5f434d42023-11-03 10:57:492769 updateTooltip(): void {
2770 if (this.selectedFilters().length) {
2771 this.dropDownButton.setTitle(this.selectedFilters().join(', '));
2772 } else {
2773 this.dropDownButton.setTitle(UIStrings.showOnlyHideRequests);
2774 }
2775 }
2776
Silvia Eremia096e1202023-09-22 15:49:172777 discard(): void {
2778 if (this.contextMenu) {
2779 this.contextMenu.discard();
2780 }
2781 }
2782
2783 isActive(): boolean {
Benedikt Meurer6b3ebf22024-01-12 10:00:512784 return this.selectedFilters().length !== 0;
Silvia Eremia096e1202023-09-22 15:49:172785 }
2786
2787 element(): HTMLDivElement {
2788 return this.filterElement;
2789 }
2790}