blob: a1f5e413983b7b7efb8dfe6ae42bcd8dd9ce55bd [file] [log] [blame]
Jan Schefflerd6c1d402021-02-26 16:56:381// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Blink Reformat4c46d092018-04-07 15:32:375/*
6 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Anthony Ricaud <[email protected]>
8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
20 * its contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
27 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Tim van der Lippe76961572021-04-06 10:48:0735import * as Common from '../../core/common/common.js';
Tim van der Lippee0247312021-04-01 14:25:3036import * as Host from '../../core/host/host.js';
Tim van der Lippebb352e62021-04-01 17:57:2837import * as i18n from '../../core/i18n/i18n.js';
Tim van der Lippeaa1ed7a2021-03-31 14:38:2738import * as Platform from '../../core/platform/platform.js';
Wolfgang Beyer6a4cbb42022-05-16 13:02:2939import * as Root from '../../core/root/root.js';
Tim van der Lippee00b92f2021-03-31 16:52:1740import * as SDK from '../../core/sdk/sdk.js';
Tim van der Lippe229a54f2021-05-14 16:59:0541import * as Protocol from '../../generated/protocol.js';
Tim van der Lippe959b6f02021-04-07 09:07:5942import * as Bindings from '../../models/bindings/bindings.js';
Sigurd Schneiderd66d0132021-04-28 13:57:5643import * as HAR from '../../models/har/har.js';
Sigurd Schneidercf5b8302021-04-23 07:52:2744import * as Logs from '../../models/logs/logs.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3745import * as Persistence from '../../models/persistence/persistence.js';
Tim van der Lippefca98ed2021-04-08 14:10:1446import * as TextUtils from '../../models/text_utils/text_utils.js';
Sigurd Schneider30722582021-06-16 06:54:1647import * as NetworkForward from '../../panels/network/forward/forward.js';
Wolfgang Beyer5b433b02022-05-12 13:57:3748import * as Sources from '../../panels/sources/sources.js';
Kateryna Prokopenkod98e34c2023-09-25 18:08:4849import * as Adorners from '../../ui/components/adorners/adorners.js';
Danil Somsikovf3b437f2023-03-23 16:15:3950import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4751import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1452import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3653import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0754import * as UI from '../../ui/legacy/legacy.js';
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,
Jack Frankline839c0c2022-05-03 08:47:4473} 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
378 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
379 * network request that is currently shown.
380 */
Peter Marshallb8bd00f2021-02-24 08:25:18381 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55382 /**
Yang Guo6d1361f2024-07-11 08:23:48383 * @description Text in Network Log View of the Network panel. An action that copies data to the
384 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
385 * network request that is currently shown (after applying the Network filter).
386 */
Yang Guo80af52f2024-07-16 12:06:26387 copyAllListedAsHar: 'Copy all listed as `HAR`',
Yang Guo6d1361f2024-07-11 08:23:48388 /**
Jack Franklinfd72c072022-12-21 11:45:01389 *@description A context menu item in the Network Log View of the Network panel
390 */
Peter Marshallb8bd00f2021-02-24 08:25:18391 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55392 /**
Jack Franklinfd72c072022-12-21 11:45:01393 *@description A context menu item in the Network Log View of the Network panel
394 */
Christy Chencac3f102021-02-03 10:07:55395 clearBrowserCache: 'Clear browser cache',
396 /**
Jack Franklinfd72c072022-12-21 11:45:01397 *@description A context menu item in the Network Log View of the Network panel
398 */
Christy Chencac3f102021-02-03 10:07:55399 clearBrowserCookies: 'Clear browser cookies',
400 /**
Jack Franklinfd72c072022-12-21 11:45:01401 *@description A context menu item in the Network Log View of the Network panel
402 */
Christy Chencac3f102021-02-03 10:07:55403 blockRequestUrl: 'Block request URL',
404 /**
Jack Franklinfd72c072022-12-21 11:45:01405 *@description A context menu item in the Network Log View of the Network panel
406 *@example {example.com} PH1
407 */
Christy Chencac3f102021-02-03 10:07:55408 unblockS: 'Unblock {PH1}',
409 /**
Jack Franklinfd72c072022-12-21 11:45:01410 *@description A context menu item in the Network Log View of the Network panel
411 */
Christy Chencac3f102021-02-03 10:07:55412 blockRequestDomain: 'Block request domain',
413 /**
Jack Franklinfd72c072022-12-21 11:45:01414 *@description Text to replay an XHR request
415 */
Christy Chencac3f102021-02-03 10:07:55416 replayXhr: 'Replay XHR',
417 /**
Jack Franklinfd72c072022-12-21 11:45:01418 *@description Text in Network Log View of the Network panel
419 */
Christy Chencac3f102021-02-03 10:07:55420 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
421 /**
Jack Franklinfd72c072022-12-21 11:45:01422 *@description Text in Network Log View of the Network panel
423 */
Christy Chencac3f102021-02-03 10:07:55424 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37425 /**
Jack Franklinfd72c072022-12-21 11:45:01426 *@description A context menu item in the Network Log View of the Network panel
427 * for creating a header override
428 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41429 overrideHeaders: 'Override headers',
Silvia Eremia096e1202023-09-22 15:49:17430 /**
431 * @description Tooltip for the Show only/Hide requests dropdown of the filterbar
432 */
433 showOnlyHideRequests: 'Show only/hide requests',
434 /**
435 * @description Text for the Show only/Hide requests dropdown button of the filterbar
436 */
437 moreFilters: 'More filters',
Christy Chencac3f102021-02-03 10:07:55438};
Tim van der Lippef596ca02021-03-31 10:02:47439const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55440const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46441
442const enum FetchStyle {
443 Browser = 0,
444 NodeJs = 1,
445}
446
Danil Somsikovf3b437f2023-03-23 16:15:39447const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
448
Simon Zünd940cb1f2021-09-16 11:46:09449export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
450 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53451 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
452 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
ioana forfota45b44152023-07-21 14:20:53453 private readonly networkHideChromeExtensions: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04454 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53455 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
456 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
457 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
458 private rawRowHeight: number;
459 private readonly progressBarContainer: Element;
460 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
461 private rowHeightInternal: number;
462 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
463 private readonly durationCalculator: NetworkTransferDurationCalculator;
464 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30465 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53466 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
467 private mainRequestLoadTime: number;
468 private mainRequestDOMContentLoadedTime: number;
469 private filters: Filter[];
470 private timeFilter: Filter|null;
471 private hoveredNodeInternal: NetworkNode|null;
472 private recordingHint: Element|null;
Jack Franklin28577db2021-10-14 08:12:53473 private highlightedNode: NetworkRequestNode|null;
474 private readonly linkifierInternal: Components.Linkifier.Linkifier;
475 private recording: boolean;
476 private needsRefresh: boolean;
477 private readonly headerHeightInternal: number;
478 private readonly groupLookups: Map<string, GroupLookupInterface>;
479 private activeGroupLookup: GroupLookupInterface|null;
480 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
481 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
Silvia Eremia096e1202023-09-22 15:49:17482 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
483 private readonly moreFiltersDropDownUI: MoreFiltersDropDownUI|undefined;
484 private readonly onlyBlockedResponseCookiesFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
485 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI|undefined;
486 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI|undefined;
487 private readonly hideChromeExtensionsUI: UI.FilterBar.CheckboxFilterUI|undefined;
Kateryna Prokopenko24c28f92024-08-30 15:09:28488 private readonly resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
Jack Franklin28577db2021-10-14 08:12:53489 private readonly filterParser: TextUtils.TextUtils.FilterParser;
490 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
491 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50492 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53493 private readonly filterBar: UI.FilterBar.FilterBar;
494 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38495
496 constructor(
497 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
498 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37499 super();
500 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37501
502 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05503 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37504
Danil Somsikov74217e92024-01-30 07:01:12505 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('network-invert-filter', false);
506 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
ioana forfota45b44152023-07-21 14:20:53507 this.networkHideChromeExtensions =
Danil Somsikov74217e92024-01-30 07:01:12508 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04509 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:12510 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Jack Franklin28577db2021-10-14 08:12:53511 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:12512 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Jack Franklin28577db2021-10-14 08:12:53513 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:12514 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Jack Franklin28577db2021-10-14 08:12:53515 this.networkResourceTypeFiltersSetting =
Danil Somsikov74217e92024-01-30 07:01:12516 Common.Settings.Settings.instance().createSetting('network-resource-type-filters', {});
Blink Reformat4c46d092018-04-07 15:32:37517
Jack Franklin28577db2021-10-14 08:12:53518 this.rawRowHeight = 0;
519 this.progressBarContainer = progressBarContainer;
520 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
521 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37522
Jan Schefflerd6c1d402021-02-26 16:56:38523 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53524 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
525 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37526 }
Jack Franklin28577db2021-10-14 08:12:53527 this.rawRowHeight = 0;
528 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37529 updateRowHeight.call(this);
530
Jack Franklin28577db2021-10-14 08:12:53531 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
532 this.durationCalculator = new NetworkTransferDurationCalculator();
533 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37534
Danil Somsikov2a4c4e02022-10-07 12:31:30535 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53536 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30537 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37538
Jack Franklin28577db2021-10-14 08:12:53539 this.staleRequests = new Set();
540 this.mainRequestLoadTime = -1;
541 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37542
Jack Franklin28577db2021-10-14 08:12:53543 this.filters = [];
544 this.timeFilter = null;
545 this.hoveredNodeInternal = null;
546 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53547 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37548
Jack Franklin28577db2021-10-14 08:12:53549 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37550
Jack Franklin28577db2021-10-14 08:12:53551 this.recording = false;
552 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37553
Jack Franklin28577db2021-10-14 08:12:53554 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37555
Jack Franklin28577db2021-10-14 08:12:53556 this.groupLookups = new Map();
557 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37558
Jack Franklin28577db2021-10-14 08:12:53559 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37560
Jack Franklin28577db2021-10-14 08:12:53561 this.textFilterUI = new UI.FilterBar.TextFilterUI();
562 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
563 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37564
Jack Franklin28577db2021-10-14 08:12:53565 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyercda33c92023-12-21 16:04:32566 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting, 'invert-filter');
Jack Franklin28577db2021-10-14 08:12:53567 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38568 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53569 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
570 filterBar.addFilter(this.invertFilterUI);
Kateryna Prokopenko862a31e2023-09-25 21:06:00571 filterBar.addDivider();
Victor Porof66878d62021-07-16 13:12:37572
Blink Reformat4c46d092018-04-07 15:32:37573 const filterItems =
Danil Somsikovf90908e2024-02-29 15:40:36574 Object.entries(Common.ResourceType.resourceCategories).map(([key, category]) => ({
575 name: category.title(),
576 label: () => category.shortTitle(),
577 title: category.title(),
578 jslogContext:
579 Platform.StringUtilities.toKebabCase(key),
580 }));
ioana forfota2c72e132023-09-22 12:11:48581
582 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
Kateryna Prokopenko24c28f92024-08-30 15:09:28583 this.moreFiltersDropDownUI = new MoreFiltersDropDownUI();
584 this.moreFiltersDropDownUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
585 filterBar.addFilter(this.moreFiltersDropDownUI);
586
587 this.resourceCategoryFilterUI =
588 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17589 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
590 this.resourceCategoryFilterUI.addEventListener(
591 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
592 filterBar.addFilter(this.resourceCategoryFilterUI);
ioana forfota2c72e132023-09-22 12:11:48593 } else {
Silvia Eremia096e1202023-09-22 15:49:17594 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20595 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting, 'hide-data-urls');
Silvia Eremia096e1202023-09-22 15:49:17596 this.dataURLFilterUI.addEventListener(
597 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
598 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
599 filterBar.addFilter(this.dataURLFilterUI);
600
601 this.hideChromeExtensionsUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20602 'chrome-extension', i18nString(UIStrings.chromeExtensions), true, this.networkHideChromeExtensions,
603 'hide-extension-urls');
Silvia Eremia096e1202023-09-22 15:49:17604 this.hideChromeExtensionsUI.addEventListener(
605 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
606 UI.Tooltip.Tooltip.install(this.hideChromeExtensionsUI.element(), i18nString(UIStrings.hideChromeExtension));
607 filterBar.addFilter(this.hideChromeExtensionsUI);
608
ioana forfota2c72e132023-09-22 12:11:48609 this.resourceCategoryFilterUI =
610 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Silvia Eremia096e1202023-09-22 15:49:17611 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.requestTypesToInclude));
612 this.resourceCategoryFilterUI.addEventListener(
613 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
614 filterBar.addFilter(this.resourceCategoryFilterUI);
615
616 this.onlyBlockedResponseCookiesFilterUI = new UI.FilterBar.CheckboxFilterUI(
617 'only-show-blocked-cookies', i18nString(UIStrings.hasBlockedCookies), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20618 this.networkShowBlockedCookiesOnlySetting, 'only-show-blocked-cookies');
Silvia Eremia096e1202023-09-22 15:49:17619 this.onlyBlockedResponseCookiesFilterUI.addEventListener(
620 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
621 UI.Tooltip.Tooltip.install(
622 this.onlyBlockedResponseCookiesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
623 filterBar.addFilter(this.onlyBlockedResponseCookiesFilterUI);
624
625 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
626 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Wolfgang Beyer6d388da2024-04-29 11:24:20627 this.networkOnlyBlockedRequestsSetting, 'only-show-blocked-requests');
Silvia Eremia096e1202023-09-22 15:49:17628 this.onlyBlockedRequestsUI.addEventListener(
629 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
630 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
631 filterBar.addFilter(this.onlyBlockedRequestsUI);
632
633 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
Wolfgang Beyer6d388da2024-04-29 11:24:20634 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting,
635 'only-show-third-party');
Silvia Eremia096e1202023-09-22 15:49:17636 this.onlyThirdPartyFilterUI.addEventListener(
637 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
638 UI.Tooltip.Tooltip.install(
639 this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
640 filterBar.addFilter(this.onlyThirdPartyFilterUI);
ioana forfota2c72e132023-09-22 12:11:48641 }
Danil Somsikov721956a2021-07-07 08:17:27642
Jack Franklin28577db2021-10-14 08:12:53643 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
644 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38645 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
646 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37647
Danil Somsikov2a4c4e02022-10-07 12:31:30648 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38649 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30650 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49651 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53652 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37653
Wolfgang Beyer8fc262f2023-04-11 13:22:50654 this.summaryToolbarInternal = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
655 this.summaryToolbarInternal.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37656
Tim van der Lippe0ed1d2b2020-02-04 13:45:13657 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38658 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37659
Paul Lewis2d7d65c2020-03-16 17:26:30660 Common.Settings.Settings.instance()
Danil Somsikov74217e92024-01-30 07:01:12661 .moduleSetting('network-color-code-resource-types')
Jan Scheffler17b8fb42021-08-12 12:28:38662 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37663
Danil Somsikov62bc5782023-03-21 10:48:50664 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27665 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38666 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27667 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38668 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
Wolfgang Beyer51f2f252023-07-27 17:09:51669 Logs.NetworkLog.NetworkLog.instance().addEventListener(
670 Logs.NetworkLog.Events.RequestRemoved, this.onRequestRemoved, this);
Jan Scheffler17b8fb42021-08-12 12:28:38671 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37672
Jan Scheffler17b8fb42021-08-12 12:28:38673 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30674 Common.Settings.Settings.instance()
675 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38676 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37677
Jack Franklin28577db2021-10-14 08:12:53678 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03679
Danil Somsikov74217e92024-01-30 07:01:12680 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('network-text-filter', '');
Jack Franklin28577db2021-10-14 08:12:53681 if (this.textFilterSetting.get()) {
682 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03683 }
Blink Reformat4c46d092018-04-07 15:32:37684 }
685
Silvia Eremia096e1202023-09-22 15:49:17686 getMoreFiltersDropdown(): MoreFiltersDropDownUI|undefined {
687 return this.moreFiltersDropDownUI;
688 }
689
Jan Scheffler17b8fb42021-08-12 12:28:38690 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30691 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38692 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37693 }
694
Jan Scheffler17b8fb42021-08-12 12:28:38695 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16696 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37697 values.sort((a, b) => {
Paul Irisha8a15972024-04-30 15:14:19698 const aPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a);
699 const bPriority = PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b);
Tim van der Lippeded23fb2020-02-13 13:33:50700 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
701 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37702 });
703 } else {
704 values.sort();
705 }
706 }
707
Jan Scheffler17b8fb42021-08-12 12:28:38708 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37709 return !filter(request);
710 }
711
Jan Scheffler17b8fb42021-08-12 12:28:38712 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34713 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37714 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34715 }
Blink Reformat4c46d092018-04-07 15:32:37716
717 return regex.test(request.path() + '/' + request.name());
718 }
719
Jan Scheffler17b8fb42021-08-12 12:28:38720 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37721 const result = [domain];
722 let indexOfPeriod = domain.indexOf('.');
723 while (indexOfPeriod !== -1) {
724 result.push('*' + domain.substring(indexOfPeriod));
725 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
726 }
727 return result;
728 }
729
Jan Scheffler17b8fb42021-08-12 12:28:38730 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17731 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38732 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37733 }
734
Jan Scheffler17b8fb42021-08-12 12:28:38735 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37736 return regex.test(request.domain);
737 }
738
Jan Scheffler17b8fb42021-08-12 12:28:38739 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37740 return !request.finished;
741 }
742
Jan Scheffler17b8fb42021-08-12 12:28:38743 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37744 return request.cached();
745 }
746
Jan Scheffler17b8fb42021-08-12 12:28:38747 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05748 return request.fetchedViaServiceWorker;
749 }
750
Jan Scheffler17b8fb42021-08-12 12:28:38751 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05752 return request.initiatedByServiceWorker();
753 }
754
Jan Scheffler17b8fb42021-08-12 12:28:38755 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37756 return request.responseHeaderValue(value) !== undefined;
757 }
758
Jan Scheffler17b8fb42021-08-12 12:28:38759 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
760 boolean {
Jack Franklin28577db2021-10-14 08:12:53761 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51762 // filter via `includes` instead of strict equality.
763 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
764 }
765
Jan Scheffler17b8fb42021-08-12 12:28:38766 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37767 return request.requestMethod === value;
768 }
769
Jan Scheffler17b8fb42021-08-12 12:28:38770 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37771 return request.priority() === value;
772 }
773
Jan Scheffler17b8fb42021-08-12 12:28:38774 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37775 return request.mimeType === value;
776 }
777
Jan Scheffler17b8fb42021-08-12 12:28:38778 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16779 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
780 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37781 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28782 }
Sigurd Schneider30722582021-06-16 06:54:16783 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37784 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28785 }
Sigurd Schneider30722582021-06-16 06:54:16786 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37787 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28788 }
Sigurd Schneider30722582021-06-16 06:54:16789 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37790 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34791 }
Blink Reformat4c46d092018-04-07 15:32:37792
793 return false;
794 }
795
Jan Scheffler17b8fb42021-08-12 12:28:38796 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37797 return request.scheme === value;
798 }
799
Jan Scheffler17b8fb42021-08-12 12:28:38800 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41801 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
802 }
803
Jan Scheffler17b8fb42021-08-12 12:28:38804 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41805 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
806 }
807
Jan Scheffler17b8fb42021-08-12 12:28:38808 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54809 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
810 }
811
Jan Scheffler17b8fb42021-08-12 12:28:38812 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41813 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
814 }
815
Jan Scheffler17b8fb42021-08-12 12:28:38816 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41817 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37818 }
819
Jan Scheffler17b8fb42021-08-12 12:28:38820 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41821 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37822 }
823
Jan Scheffler17b8fb42021-08-12 12:28:38824 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41825 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37826 }
827
Jan Scheffler17b8fb42021-08-12 12:28:38828 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37829 return request.transferSize >= value;
830 }
831
Jan Scheffler17b8fb42021-08-12 12:28:38832 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24833 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37834 }
835
Jecelyn Yeen77c83462023-08-16 16:13:17836 private static hasOverridesFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
837 if (!value) {
838 return false;
839 }
840
841 if (value === overrideFilter.no) {
842 return request.overrideTypes.length === 0;
843 }
844
845 if (value === overrideFilter.yes) {
846 return request.overrideTypes.length > 0;
847 }
848
849 if (value === overrideFilter.content) {
850 return request.overrideTypes.includes('content');
851 }
852
853 if (value === overrideFilter.headers) {
854 return request.overrideTypes.includes('headers');
855 }
856
857 return request.overrideTypes.join(',').includes(value);
858 }
859
Sigurd Schneider576ca9a2021-07-16 05:58:04860 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58861 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37862 }
863
Jan Scheffler17b8fb42021-08-12 12:28:38864 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03865 return request.resourceType().name() === value;
866 }
867
Jan Scheffler17b8fb42021-08-12 12:28:38868 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17869 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03870 return regex.test(request.url());
871 }
872
Jan Scheffler17b8fb42021-08-12 12:28:38873 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38874 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34875 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37876 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34877 }
878 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37879 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34880 }
Blink Reformat4c46d092018-04-07 15:32:37881 return true;
882 }
883
Jan Scheffler17b8fb42021-08-12 12:28:38884 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13885 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37886 }
887
Jan Scheffler17b8fb42021-08-12 12:28:38888 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13889 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37890 }
891
Jan Scheffler17b8fb42021-08-12 12:28:38892 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Simon Zünd0d87db62024-05-27 07:26:27893 const contentData = await request.requestContentData();
Simon Zünd3b583882023-12-22 05:23:43894 let content: string;
Simon Zünd7fb55c02024-01-29 12:00:27895 if (TextUtils.ContentData.ContentData.isError(contentData)) {
Simon Zünd3b583882023-12-22 05:23:43896 content = '';
Simon Zündebe01922024-01-18 10:11:58897 } else if (!contentData.isTextContent) {
Simon Zünd3b583882023-12-22 05:23:43898 content = contentData.asDataUrl() ?? '';
899 } else {
900 content = contentData.text;
Tim van der Lippe1d6e57a2019-09-30 11:55:34901 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13902 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37903 }
904
Jan Scheffler17b8fb42021-08-12 12:28:38905 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37906 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34907 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37908 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34909 }
Simon Zünd99961242021-09-08 11:02:12910 const file = items[0].getAsFile();
911 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03912 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34913 }
Blink Reformat4c46d092018-04-07 15:32:37914 }
915
Jan Schefflerd6c1d402021-02-26 16:56:38916 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13917 const outputStream = new Common.StringOutputStream.StringOutputStream();
918 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37919 const success = await reader.read(outputStream);
920 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37921 const error = reader.error();
922 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38923 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37924 }
Blink Reformat4c46d092018-04-07 15:32:37925 return;
926 }
927 let harRoot;
928 try {
929 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56930 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37931 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38932 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37933 return;
934 }
Tim van der Lippe09cf5032021-04-29 15:08:09935 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37936 }
937
Jan Scheffler17b8fb42021-08-12 12:28:38938 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36939 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37940 }
941
Jan Scheffler17b8fb42021-08-12 12:28:38942 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53943 if (this.activeGroupLookup) {
944 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34945 }
Jack Franklin28577db2021-10-14 08:12:53946 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
947 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38948 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37949 }
950
Jan Scheffler17b8fb42021-08-12 12:28:38951 private computeRowHeight(): number {
Benedikt Meurera0d809e2024-02-28 14:20:54952 return this.rawRowHeight;
Blink Reformat4c46d092018-04-07 15:32:37953 }
954
Jan Schefflerd6c1d402021-02-26 16:56:38955 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37956 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37957 }
958
Jan Schefflerd6c1d402021-02-26 16:56:38959 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53960 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37961 }
962
Jan Schefflerd6c1d402021-02-26 16:56:38963 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53964 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38965 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37966 }
967
Danil Somsikov2a4c4e02022-10-07 12:31:30968 columns(): NetworkLogViewColumns {
969 return this.columnsInternal;
970 }
971
Wolfgang Beyer8fc262f2023-04-11 13:22:50972 summaryToolbar(): UI.Toolbar.Toolbar {
973 return this.summaryToolbarInternal;
974 }
975
Jan Schefflerd6c1d402021-02-26 16:56:38976 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37977 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22978 const target = networkManager.target();
979 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37980 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34981 }
Danil Somsikov88384322023-03-22 13:53:22982 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37983 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38984 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37985 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38986 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37987 }
Danil Somsikov88384322023-03-22 13:53:22988 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:04989 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:25990 this.refreshRequest(request);
991 }
Danil Somsikov88384322023-03-22 13:53:22992 }
Blink Reformat4c46d092018-04-07 15:32:37993 }
994
Jan Schefflerd6c1d402021-02-26 16:56:38995 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:22996 const target = networkManager.target();
997 if (target.outermostTarget() !== target) {
998 return;
999 }
1000 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
1001 if (resourceTreeModel) {
1002 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
1003 resourceTreeModel.removeEventListener(
1004 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
1005 }
Danil Somsikovac291c82024-01-30 13:47:461006 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network-log.preserve-log').get();
Danil Somsikov88384322023-03-22 13:53:221007 if (!preserveLog) {
1008 this.reset();
Blink Reformat4c46d092018-04-07 15:32:371009 }
1010 }
1011
Jan Schefflerd6c1d402021-02-26 16:56:381012 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:531013 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:131014 }
1015
Jan Schefflerd6c1d402021-02-26 16:56:381016 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:371017 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:531018 this.timeFilter = null;
1019 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:371020 } else {
Jack Franklin28577db2021-10-14 08:12:531021 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
1022 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:371023 }
Jan Scheffler17b8fb42021-08-12 12:28:381024 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:371025 }
1026
Jan Schefflerd6c1d402021-02-26 16:56:381027 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531028 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:371029 }
1030
Jan Scheffler17b8fb42021-08-12 12:28:381031 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:531032 this.suggestionBuilder.clear();
1033 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
1034 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161035 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:531036 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161037 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:531038 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161039 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:531040 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
1041 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
1042 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
1043 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Jecelyn Yeen77c83462023-08-16 16:13:171044 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.yes);
1045 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.no);
1046 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.content);
1047 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasOverrides, overrideFilter.headers);
Blink Reformat4c46d092018-04-07 15:32:371048 }
1049
Simon Zünda2bae2e2021-09-16 07:57:131050 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:371051 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:531052 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:381053 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:531054 this.textFilterSetting.set(this.textFilterUI.value());
Kateryna Prokopenkod98e34c2023-09-25 18:08:481055 this.moreFiltersDropDownUI?.updateActiveFiltersCount();
Kateryna Prokopenko5f434d42023-11-03 10:57:491056 this.moreFiltersDropDownUI?.updateTooltip();
Blink Reformat4c46d092018-04-07 15:32:371057 }
1058
Jan Schefflerd6c1d402021-02-26 16:56:381059 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:531060 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:121061 }
1062
Jan Scheffler17b8fb42021-08-12 12:28:381063 private showRecordingHint(): void {
1064 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:531065 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
1066 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:181067
Jack Franklin28577db2021-10-14 08:12:531068 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:381069 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:041070 const reloadShortcut =
Benedikt Meurere0b4b922024-01-15 13:33:531071 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector-main.reload')[0];
Wolfgang Beyer5c385b92020-11-09 15:20:041072 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:531073 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:041074 reloadShortcutNode.textContent = reloadShortcut.title();
1075 }
1076
Blink Reformat4c46d092018-04-07 15:32:371077 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:551078 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:181079 if (reloadShortcutNode) {
1080 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:551081 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
1082 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:181083 }
Blink Reformat4c46d092018-04-07 15:32:371084 } else {
1085 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:171086 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:371087 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:551088 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:411089 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:371090 }
Kayce Basques5444c1b2019-02-15 20:32:531091 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:131092 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:351093 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Kateryna Prokopenko1a4e2612023-12-21 13:23:451094 i18nString(UIStrings.learnMore), undefined, undefined, 'learn-more'));
Amanda Baker6761aae2019-11-05 18:59:111095
Jan Scheffler17b8fb42021-08-12 12:28:381096 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:371097 }
1098
Jan Scheffler17b8fb42021-08-12 12:28:381099 private hideRecordingHint(): void {
1100 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:531101 if (this.recordingHint) {
1102 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:341103 }
Michael Liao7322dee2021-04-07 18:33:301104 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:531105 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:371106 }
1107
Jan Scheffler17b8fb42021-08-12 12:28:381108 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301109 this.columnsInternal.setHidden(value);
Wolfgang Beyer8fc262f2023-04-11 13:22:501110 UI.ARIAUtils.setHidden(this.summaryToolbarInternal.element, value);
Amanda Baker6761aae2019-11-05 18:59:111111 }
1112
Randolf Jungffd14242023-04-19 00:32:251113 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:531114 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:341115 {
Blink Reformat4c46d092018-04-07 15:32:371116 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:341117 }
Jack Franklin28577db2021-10-14 08:12:531118 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:371119 }
1120
Jan Schefflerd6c1d402021-02-26 16:56:381121 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381122 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:371123 }
1124
Jan Scheffler17b8fb42021-08-12 12:28:381125 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:531126 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:381127 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:341128 if (request) {
Blink Reformat4c46d092018-04-07 15:32:371129 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341130 }
Blink Reformat4c46d092018-04-07 15:32:371131 });
Jack Franklin28577db2021-10-14 08:12:531132 this.dataGrid.setStickToBottom(true);
Danil Somsikova6ce6ed2024-01-31 08:10:121133 this.dataGrid.setName('network-log');
Jack Franklin28577db2021-10-14 08:12:531134 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
1135 this.dataGrid.element.classList.add('network-log-grid');
1136 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
1137 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
1138 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
1139 this.dataGrid.element.addEventListener('keydown', event => {
1140 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
Danil Somsikove10a94c2024-03-11 08:31:321141 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('button.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:431142 if (initiatorLink) {
1143 (initiatorLink as HTMLElement).focus();
1144 }
1145 }
ergunshee4a6132021-11-05 16:21:251146
Jack Franklin5e685be2022-10-17 14:27:091147 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051148 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051149 event.consume(true);
1150 }
1151 });
ergunshee4a6132021-11-05 16:21:251152 this.dataGrid.element.addEventListener('keyup', event => {
1153 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1154 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1155 if (!request) {
1156 return;
1157 }
1158
1159 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1160 SDK.NetworkManager.NetworkManager.replayRequest(request);
Danil Somsikov1a4a3322024-03-11 16:27:271161 void VisualLogging.logKeyDown(this.dataGrid.selectedNode.element(), event, 'replay-xhr');
ergunshee4a6132021-11-05 16:21:251162 }
1163 }
1164 });
Jack Franklin28577db2021-10-14 08:12:531165 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1166 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1167 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371168 }
1169
Jan Scheffler17b8fb42021-08-12 12:28:381170 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381171 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531172 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371173 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381174 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371175 }
1176
Jan Schefflerd6c1d402021-02-26 16:56:381177 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531178 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371179 }
1180
Jan Scheffler17b8fb42021-08-12 12:28:381181 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531182 if (this.hoveredNodeInternal) {
1183 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341184 }
Jack Franklin28577db2021-10-14 08:12:531185 this.hoveredNodeInternal = node;
1186 if (this.hoveredNodeInternal) {
1187 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341188 }
Blink Reformat4c46d092018-04-07 15:32:371189 }
1190
Jan Scheffler17b8fb42021-08-12 12:28:381191 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381192 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531193 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371194 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341195 }
Blink Reformat4c46d092018-04-07 15:32:371196 }
1197
Jan Scheffler17b8fb42021-08-12 12:28:381198 private updateSummaryBar(): void {
1199 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371200
1201 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201202 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371203 let selectedNodeNumber = 0;
1204 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201205 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371206 let baseTime = -1;
1207 let maxTime = -1;
1208
1209 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271210 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371211 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341212 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371213 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341214 }
Blink Reformat4c46d092018-04-07 15:32:371215 nodeCount++;
1216 const requestTransferSize = request.transferSize;
1217 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201218 const requestResourceSize = request.resourceSize;
1219 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371220 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371221 selectedNodeNumber++;
1222 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201223 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371224 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131225 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371226 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1227 // inspected url.
1228 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131229 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Benedikt Meurerb7d85042024-08-23 13:38:321230 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.FRAME) {
Adithya Srinivasan77770382024-05-17 20:22:091231 // If the primary main frame's document was fetched from the prefetch cache,
1232 // we should use the issueTime (i.e. when the navigation request was about to start)
1233 // instead of startTime, which is when the prefetch network request started
1234 // (which is typically well before the navigation starts).
1235 baseTime = request.fromPrefetchCache() ? request.issueTime() : request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341236 }
1237 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371238 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341239 }
Blink Reformat4c46d092018-04-07 15:32:371240 }
1241
1242 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381243 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371244 return;
1245 }
1246
Wolfgang Beyer8fc262f2023-04-11 13:22:501247 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381248 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131249 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501250 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501251 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381252 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501253 };
Blink Reformat4c46d092018-04-07 15:32:371254
1255 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551256 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501257 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501258 appendChunk(
Christy Chencac3f102021-02-03 10:07:551259 i18nString(UIStrings.sSTransferred, {
1260 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381261 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551262 }),
1263 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501264 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501265 appendChunk(
Christy Chencac3f102021-02-03 10:07:551266 i18nString(UIStrings.sSResources, {
1267 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381268 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551269 }),
1270 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371271 } else {
Christy Chencac3f102021-02-03 10:07:551272 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501273 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251274 appendChunk(
Christy Chencac3f102021-02-03 10:07:551275 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1276 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501277 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251278 appendChunk(
Christy Chencac3f102021-02-03 10:07:551279 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1280 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371281 }
Dan Beam87466b52018-12-01 18:41:201282
Blink Reformat4c46d092018-04-07 15:32:371283 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501284 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581285 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531286 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501287 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551288 const domContentLoadedText = i18nString(
1289 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531290 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381291 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371292 }
Jack Franklin28577db2021-10-14 08:12:531293 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501294 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531295 const loadText =
1296 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381297 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371298 }
1299 }
Blink Reformat4c46d092018-04-07 15:32:371300 }
1301
Jan Schefflerd6c1d402021-02-26 16:56:381302 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531303 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371304 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341305 }
Blink Reformat4c46d092018-04-07 15:32:371306
Jack Franklin28577db2021-10-14 08:12:531307 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371308
Danil Somsikovf3b437f2023-03-23 16:15:391309 if (this.isShowing()) {
Simon Siefke03d72372023-06-26 14:44:461310 void coordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341311 }
Blink Reformat4c46d092018-04-07 15:32:371312 }
1313
Jan Schefflerd6c1d402021-02-26 16:56:381314 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301315 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371316 }
1317
Jan Schefflerd6c1d402021-02-26 16:56:381318 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301319 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371320 }
1321
Jan Schefflerd6c1d402021-02-26 16:56:381322 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301323 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371324 }
1325
Jan Scheffler17b8fb42021-08-12 12:28:381326 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531327 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381328 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341329 }
Blink Reformat4c46d092018-04-07 15:32:371330 }
1331
Jan Scheffler17b8fb42021-08-12 12:28:381332 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041333 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341334 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371335 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341336 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381337 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341338 }
Blink Reformat4c46d092018-04-07 15:32:371339 }
1340
Jan Schefflerd6c1d402021-02-26 16:56:381341 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531342 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371343 }
1344
Jan Schefflerd6c1d402021-02-26 16:56:381345 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531346 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371347 }
1348
Jan Schefflerd6c1d402021-02-26 16:56:381349 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531350 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371351 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341352 }
Blink Reformat4c46d092018-04-07 15:32:371353
Jack Franklin28577db2021-10-14 08:12:531354 if (this.calculatorInternal !== x) {
1355 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301356 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371357 }
Jack Franklin28577db2021-10-14 08:12:531358 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371359
Jack Franklin28577db2021-10-14 08:12:531360 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301361 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341362 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301363 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341364 }
Blink Reformat4c46d092018-04-07 15:32:371365
Jan Scheffler17b8fb42021-08-12 12:28:381366 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371367 }
1368
Jan Scheffler17b8fb42021-08-12 12:28:381369 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271370 event: Common.EventTarget
1371 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531372 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371373 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341374 }
Blink Reformat4c46d092018-04-07 15:32:371375
Simon Zünd1a930492021-07-30 08:22:271376 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371377 if (time) {
Jack Franklin28577db2021-10-14 08:12:531378 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301379 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371380 }
1381 }
1382
Jan Scheffler17b8fb42021-08-12 12:28:381383 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531384 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371385 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341386 }
Simon Zünd1a930492021-07-30 08:22:271387 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371388 if (data) {
Jack Franklin28577db2021-10-14 08:12:531389 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301390 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371391 }
1392 }
1393
Randolf Jungffd14242023-04-19 00:32:251394 override wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381395 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301396 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301397 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371398 }
1399
Randolf Jungffd14242023-04-19 00:32:251400 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301401 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371402 }
1403
Randolf Jungffd14242023-04-19 00:32:251404 override onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531405 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371406 }
1407
Jan Schefflerd6c1d402021-02-26 16:56:381408 flatNodesList(): NetworkNode[] {
1409 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531410 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381411 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1412 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371413 }
1414
Jan Scheffler17b8fb42021-08-12 12:28:381415 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531416 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351417 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381418 }
Brandon Goddard44934902020-03-25 16:03:181419 this.updateNodeBackground();
1420 }
1421
Jan Scheffler17b8fb42021-08-12 12:28:381422 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181423 this.element.classList.remove('grid-focused');
1424 this.updateNodeBackground();
1425 }
1426
Jan Schefflerd6c1d402021-02-26 16:56:381427 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531428 if (this.dataGrid.selectedNode) {
1429 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051430 }
1431 }
1432
Jan Schefflerd6c1d402021-02-26 16:56:381433 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051434 if (isSelected) {
1435 this.element.classList.remove('no-node-selected');
1436 } else {
1437 this.element.classList.add('no-node-selected');
1438 }
1439 }
1440
Jan Schefflerd6c1d402021-02-26 16:56:381441 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301442 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371443 }
1444
Wolfgang Beyer51f2f252023-07-27 17:09:511445 private removeNodeAndMaybeAncestors(node: NetworkRequestNode): void {
1446 let parent: NetworkNode|
1447 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1448 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1449 null) = node.parent;
1450 if (!parent) {
1451 return;
1452 }
1453 parent.removeChild(node);
1454 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
1455 const grandparent = (parent.parent as NetworkNode);
1456 grandparent.removeChild(parent);
1457 parent = grandparent;
1458 }
1459 }
1460
Jan Scheffler17b8fb42021-08-12 12:28:381461 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531462 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371463
Blink Reformat4c46d092018-04-07 15:32:371464 this.removeAllNodeHighlights();
1465
Jack Franklin28577db2021-10-14 08:12:531466 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1467 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1468 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1469 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371470
Jan Schefflerd6c1d402021-02-26 16:56:381471 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1472 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371473
Jan Schefflerd6c1d402021-02-26 16:56:381474 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371475
Jack Franklin28577db2021-10-14 08:12:531476 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371477 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531478 while (this.staleRequests.size) {
1479 const request = this.staleRequests.values().next().value;
1480 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371481 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341482 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381483 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341484 }
Blink Reformat4c46d092018-04-07 15:32:371485 staleNodes.add(node);
1486 }
1487
1488 for (const node of staleNodes) {
Yang Guo6d1361f2024-07-11 08:23:481489 const request = node.request();
1490 const isFilteredOut = !this.applyFilter(request);
Benedikt Meurere4391232024-06-07 10:47:251491 if (isFilteredOut) {
1492 if (node === this.hoveredNodeInternal) {
1493 this.setHoveredNode(null);
1494 }
1495 node.selected = false;
1496 } else {
Blink Reformat4c46d092018-04-07 15:32:371497 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341498 }
Jack Franklin28577db2021-10-14 08:12:531499 this.timeCalculatorInternal.updateBoundaries(request);
1500 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381501 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371502 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1503 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371504 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341505 }
Tim van der Lippe224a8622020-09-23 12:14:371506 if (isFilteredOut) {
1507 filteredNetworkRequests.add(node);
1508 } else {
1509 filteredNetworkRequests.delete(node);
1510 }
Blink Reformat4c46d092018-04-07 15:32:371511 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1512 if (removeFromParent) {
Wolfgang Beyer51f2f252023-07-27 17:09:511513 this.removeNodeAndMaybeAncestors(node);
Blink Reformat4c46d092018-04-07 15:32:371514 }
1515
Tim van der Lippe1d6e57a2019-09-30 11:55:341516 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371517 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341518 }
Blink Reformat4c46d092018-04-07 15:32:371519
1520 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531521 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371522 nodesToRefresh.push(newParent);
1523 }
1524 nodesToInsert.set(node, newParent);
1525 }
1526
Tim van der Lippe1d6e57a2019-09-30 11:55:341527 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381528 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341529 }
Blink Reformat4c46d092018-04-07 15:32:371530
Tim van der Lippe1d6e57a2019-09-30 11:55:341531 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371532 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341533 }
Blink Reformat4c46d092018-04-07 15:32:371534
Jan Scheffler17b8fb42021-08-12 12:28:381535 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371536
Tim van der Lippe1d6e57a2019-09-30 11:55:341537 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301538 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341539 }
Blink Reformat4c46d092018-04-07 15:32:371540
Jack Franklin28577db2021-10-14 08:12:531541 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381542 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371543 }
1544
Jan Scheffler17b8fb42021-08-12 12:28:381545 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371546 }
1547
Jan Scheffler17b8fb42021-08-12 12:28:381548 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531549 if (!this.activeGroupLookup) {
1550 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341551 }
Blink Reformat4c46d092018-04-07 15:32:371552
Jack Franklin28577db2021-10-14 08:12:531553 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341554 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531555 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341556 }
Blink Reformat4c46d092018-04-07 15:32:371557 return groupNode;
1558 }
1559
Jan Scheffler17b8fb42021-08-12 12:28:381560 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151561 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371562
Jan Scheffler17b8fb42021-08-12 12:28:381563 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301564 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371565
Jack Franklin28577db2021-10-14 08:12:531566 this.timeFilter = null;
1567 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371568
Jack Franklin28577db2021-10-14 08:12:531569 this.timeCalculatorInternal.setWindow(null);
1570 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371571
Jack Franklin28577db2021-10-14 08:12:531572 if (this.activeGroupLookup) {
1573 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341574 }
Jack Franklin28577db2021-10-14 08:12:531575 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381576 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371577
Jack Franklin28577db2021-10-14 08:12:531578 this.mainRequestLoadTime = -1;
1579 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371580
Jack Franklin28577db2021-10-14 08:12:531581 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381582 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531583 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371584 this.scheduleRefresh();
1585 }
1586
Silvia Eremia096e1202023-09-22 15:49:171587 // TODO(crbug.com/1477668)
Jan Schefflerd6c1d402021-02-26 16:56:381588 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531589 this.textFilterUI.setValue(filterString);
Silvia Eremia096e1202023-09-22 15:49:171590 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN)) {
1591 this.networkHideDataURLSetting.set(false);
1592 this.networkShowBlockedCookiesOnlySetting.set(false);
1593 this.networkOnlyBlockedRequestsSetting.set(false);
1594 this.networkOnlyThirdPartySetting.set(false);
1595 this.networkHideChromeExtensions.set(false);
1596 } else {
1597 this.dataURLFilterUI?.setChecked(false);
1598 this.onlyBlockedResponseCookiesFilterUI?.setChecked(false);
1599 this.onlyBlockedRequestsUI?.setChecked(false);
1600 this.onlyThirdPartyFilterUI?.setChecked(false);
1601 this.hideChromeExtensionsUI?.setChecked(false);
1602 }
Jack Franklin28577db2021-10-14 08:12:531603 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371604 }
1605
Jan Scheffler17b8fb42021-08-12 12:28:381606 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301607 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371608 networkRequestToNode.set(request, node);
1609 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371610
Tim van der Lippe1d6e57a2019-09-30 11:55:341611 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381612 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341613 }
Blink Reformat4c46d092018-04-07 15:32:371614 return node;
1615 }
1616
Danil Somsikov123c3ef2023-06-14 10:07:041617 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1618 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1619 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1620 }
1621
Wolfgang Beyer393dc2b2024-01-05 15:07:401622 private onRequestUpdated(
1623 event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest, preserveLog?: boolean}>):
1624 void {
1625 const {request, preserveLog} = event.data;
1626 if (this.isInScope(request) || preserveLog) {
Danil Somsikova09c4de2023-03-27 10:35:251627 this.refreshRequest(request);
1628 }
Blink Reformat4c46d092018-04-07 15:32:371629 }
1630
Wolfgang Beyer393dc2b2024-01-05 15:07:401631 private onRequestRemoved(event: Common.EventTarget.EventTargetEvent<{request: SDK.NetworkRequest.NetworkRequest}>):
1632 void {
1633 const {request} = event.data;
Wolfgang Beyer51f2f252023-07-27 17:09:511634 this.staleRequests.delete(request);
1635 const node = networkRequestToNode.get(request);
1636 if (node) {
1637 this.removeNodeAndMaybeAncestors(node);
1638 }
1639 }
1640
Jan Scheffler17b8fb42021-08-12 12:28:381641 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1642 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161643 .forEach(
Jack Franklin28577db2021-10-14 08:12:531644 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1645 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1646 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1647 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1648 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1649 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1650 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371651
1652 const priority = request.priority();
1653 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531654 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161655 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371656 }
1657
1658 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531659 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161660 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371661 }
1662
1663 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531664 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161665 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371666 }
1667
1668 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161669 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1670 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531671 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371672 }
1673
1674 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511675 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531676 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511677 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531678 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511679 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341680 }
Jan Scheffler341eea52019-12-12 09:08:411681
1682 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531683 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1684 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1685 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371686 }
1687
Jan Scheffler341eea52019-12-12 09:08:411688 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531689 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1690 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1691 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1692 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411693 }
1694
Jack Franklin28577db2021-10-14 08:12:531695 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371696 this.scheduleRefresh();
1697 }
1698
Jan Schefflerd6c1d402021-02-26 16:56:381699 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531700 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371701 }
1702
Jan Schefflerd6c1d402021-02-26 16:56:381703 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301704 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371705 }
1706
Jan Schefflerd6c1d402021-02-26 16:56:381707 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1708 void {
Blink Reformat4c46d092018-04-07 15:32:371709 contextMenu.appendApplicableItems(request);
Yang Guo6d1361f2024-07-11 08:23:481710 const filtered = this.filterBar.hasActiveFilter();
Danil Somsikov23eacf62024-02-23 08:46:301711 const copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy), false, 'copy');
Blink Reformat4c46d092018-04-07 15:32:371712 if (request) {
1713 copyMenu.defaultSection().appendItem(
Benedikt Meurer8f0fee62023-12-27 12:36:511714 i18nString(UIStrings.copyURL),
Tim van der Lippe0ed1d2b2020-02-04 13:45:131715 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
Danil Somsikov23eacf62024-02-23 08:46:301716 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()),
1717 {jslogContext: 'copy-url'});
1718 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261719 filtered ? i18nString(UIStrings.copyAllListedURLs) : i18nString(UIStrings.copyAllURLs),
Yang Guo6d1361f2024-07-11 08:23:481720 this.copyAllURLs.bind(this), {jslogContext: 'copy-all-urls'});
Blink Reformat4c46d092018-04-07 15:32:371721 if (request.requestHeadersText()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511722 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301723 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request),
1724 {jslogContext: 'copy-request-headers'});
Blink Reformat4c46d092018-04-07 15:32:371725 }
1726
1727 if (request.responseHeadersText) {
Benedikt Meurer8f0fee62023-12-27 12:36:511728 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301729 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request),
1730 {jslogContext: 'copy-response-headers'});
Blink Reformat4c46d092018-04-07 15:32:371731 }
1732
1733 if (request.finished) {
Benedikt Meurer8f0fee62023-12-27 12:36:511734 copyMenu.saveSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301735 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request),
1736 {jslogContext: 'copy-response'});
Blink Reformat4c46d092018-04-07 15:32:371737 }
1738
Tim van der Lippeb4faf5a2020-11-06 15:02:021739 const initiator = request.initiator();
1740
1741 if (initiator) {
1742 const stack = initiator.stack;
1743 if (stack) {
1744 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531745 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021746 // any callFrames, but its parent frames do.
1747 const stackTraceText = computeStackTraceText(stack);
1748 if (stackTraceText !== '') {
Benedikt Meurer8f0fee62023-12-27 12:36:511749 copyMenu.saveSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021750 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
Danil Somsikov23eacf62024-02-23 08:46:301751 }, {jslogContext: 'copy-stacktrace'});
Tim van der Lippeb4faf5a2020-11-06 15:02:021752 }
1753 }
1754 }
1755
Harley Libcf41f92018-09-10 18:01:131756 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131757 if (Host.Platform.isWin()) {
Benedikt Meurer8f0fee62023-12-27 12:36:511758 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391759 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'),
Danil Somsikov23eacf62024-02-23 08:46:301760 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511761 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391762 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301763 {disabled: disableIfBlob, jslogContext: 'copy-as-curl-bash'});
Blink Reformat4c46d092018-04-07 15:32:371764 } else {
Benedikt Meurer8f0fee62023-12-27 12:36:511765 copyMenu.defaultSection().appendItem(
Danil Somsikov712aaa52023-11-09 16:43:391766 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'),
Danil Somsikov23eacf62024-02-23 08:46:301767 {disabled: disableIfBlob, jslogContext: 'copy-as-curl'});
Blink Reformat4c46d092018-04-07 15:32:371768 }
Benedikt Meurer8f0fee62023-12-27 12:36:511769 copyMenu.defaultSection().appendItem(
1770 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request),
Danil Somsikov23eacf62024-02-23 08:46:301771 {disabled: disableIfBlob, jslogContext: 'copy-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511772 copyMenu.defaultSection().appendItem(
1773 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
Danil Somsikov23eacf62024-02-23 08:46:301774 {disabled: disableIfBlob, jslogContext: 'copy-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511775 copyMenu.defaultSection().appendItem(
1776 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
Danil Somsikov23eacf62024-02-23 08:46:301777 {disabled: disableIfBlob, jslogContext: 'copy-as-nodejs-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511778
1779 if (Host.Platform.isWin()) {
1780 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261781 filtered ? i18nString(UIStrings.copyAllListedAsCurlCmd) : i18nString(UIStrings.copyAllAsCurlCmd),
Yang Guo6d1361f2024-07-11 08:23:481782 this.copyAllCurlCommand.bind(this, 'win'), {jslogContext: 'copy-all-as-curl-cmd'});
Benedikt Meurer8f0fee62023-12-27 12:36:511783 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261784 filtered ? i18nString(UIStrings.copyAllListedAsCurlBash) : i18nString(UIStrings.copyAllAsCurlBash),
Yang Guo6d1361f2024-07-11 08:23:481785 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl-bash'});
Benedikt Meurer8f0fee62023-12-27 12:36:511786 } else {
1787 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261788 filtered ? i18nString(UIStrings.copyAllListedAsCurl) : i18nString(UIStrings.copyAllAsCurl),
Yang Guo6d1361f2024-07-11 08:23:481789 this.copyAllCurlCommand.bind(this, 'unix'), {jslogContext: 'copy-all-as-curl'});
Benedikt Meurer8f0fee62023-12-27 12:36:511790 }
1791 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261792 filtered ? i18nString(UIStrings.copyAllListedAsPowershell) : i18nString(UIStrings.copyAllAsPowershell),
Yang Guo6d1361f2024-07-11 08:23:481793 this.copyAllPowerShellCommand.bind(this), {jslogContext: 'copy-all-as-powershell'});
Benedikt Meurer8f0fee62023-12-27 12:36:511794 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261795 filtered ? i18nString(UIStrings.copyAllListedAsFetch) : i18nString(UIStrings.copyAllAsFetch),
Yang Guo6d1361f2024-07-11 08:23:481796 this.copyAllFetchCall.bind(this, FetchStyle.Browser), {jslogContext: 'copy-all-as-fetch'});
Benedikt Meurer8f0fee62023-12-27 12:36:511797 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261798 filtered ? i18nString(UIStrings.copyAllListedAsNodejsFetch) : i18nString(UIStrings.copyAllAsNodejsFetch),
Yang Guo6d1361f2024-07-11 08:23:481799 this.copyAllFetchCall.bind(this, FetchStyle.NodeJs), {jslogContext: 'copy-all-as-nodejs-fetch'});
Blink Reformat4c46d092018-04-07 15:32:371800 }
Danil Somsikov23eacf62024-02-23 08:46:301801 copyMenu.footerSection().appendItem(
Yang Guo80af52f2024-07-16 12:06:261802 filtered ? i18nString(UIStrings.copyAllListedAsHar) : i18nString(UIStrings.copyAllAsHar),
Yang Guo6d1361f2024-07-11 08:23:481803 this.copyAllAsHAR.bind(this), {jslogContext: 'copy-all-as-har'});
Blink Reformat4c46d092018-04-07 15:32:371804
Danil Somsikov23eacf62024-02-23 08:46:301805 contextMenu.saveSection().appendItem(
1806 i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this),
1807 {jslogContext: 'save-all-as-har-with-content'});
Wolfgang Beyer650e9572023-11-29 12:45:081808 contextMenu.overrideSection().appendItem(
Wolfgang Beyer9d9affb2024-05-08 10:14:441809 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request), {
1810 disabled:
1811 Persistence.NetworkPersistenceManager.NetworkPersistenceManager.isForbiddenNetworkUrl(request.url()),
1812 jslogContext: 'override-headers',
1813 });
Wolfgang Beyerc6fe2be2022-11-03 15:39:411814
Blink Reformat4c46d092018-04-07 15:32:371815 contextMenu.editSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301816 i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this),
1817 {jslogContext: 'clear-browser-cache'});
1818 contextMenu.editSection().appendItem(
1819 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this),
1820 {jslogContext: 'clear-browser-cookies'});
Blink Reformat4c46d092018-04-07 15:32:371821
1822 if (request) {
1823 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211824 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371825 let patterns = manager.blockedPatterns();
1826
Jan Schefflerd6c1d402021-02-26 16:56:381827 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201828 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121829 manager.setBlockedPatterns(patterns);
1830 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031831 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121832 }
1833
Jan Schefflerd6c1d402021-02-26 16:56:381834 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121835 patterns = patterns.filter(pattern => pattern.url !== url);
1836 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031837 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121838 }
1839
Blink Reformat4c46d092018-04-07 15:32:371840 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1841 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1842 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301843 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme),
1844 {jslogContext: 'block-request-url'});
Blink Reformat4c46d092018-04-07 15:32:371845 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311846 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371847 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301848 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme),
1849 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371850 }
1851
1852 const domain = request.parsedURL.domain();
1853 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1854 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301855 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain),
1856 {jslogContext: 'block-request-domain'});
Blink Reformat4c46d092018-04-07 15:32:371857 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311858 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371859 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301860 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain),
1861 {jslogContext: 'unblock'});
Blink Reformat4c46d092018-04-07 15:32:371862 }
1863
Tim van der Lippe0ed1d2b2020-02-04 13:45:131864 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371865 contextMenu.debugSection().appendItem(
Danil Somsikov23eacf62024-02-23 08:46:301866 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request),
1867 {jslogContext: 'replay-xhr'});
Blink Reformat4c46d092018-04-07 15:32:371868 }
Blink Reformat4c46d092018-04-07 15:32:371869 }
1870 }
1871
Jan Scheffler17b8fb42021-08-12 12:28:381872 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Yang Guo6d1361f2024-07-11 08:23:481873 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1874 return requests.filter(NetworkLogView.getHTTPRequestsFilter).filter(request => {
1875 return request.finished ||
1876 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1877 });
Blink Reformat4c46d092018-04-07 15:32:371878 }
1879
Benedikt Meurer8f0fee62023-12-27 12:36:511880 private async copyAllAsHAR(): Promise<void> {
Jan Scheffler17b8fb42021-08-12 12:28:381881 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131882 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371883 }
1884
Benedikt Meurer8f0fee62023-12-27 12:36:511885 private copyAllURLs(): void {
Yang Guo6d1361f2024-07-11 08:23:481886 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1887 const nonBlobRequests = this.filterOutBlobRequests(requests);
Benedikt Meurer8f0fee62023-12-27 12:36:511888 const urls = nonBlobRequests.map(request => request.url());
1889 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(urls.join('\n'));
1890 }
1891
Benedikt Meurer64b7e722023-12-15 09:03:581892 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351893 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131894 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371895 }
1896
Benedikt Meurer64b7e722023-12-15 09:03:581897 private async copyAllCurlCommand(platform: 'unix'|'win'): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481898 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1899 const commands = await this.generateAllCurlCommand(requests, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131900 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371901 }
1902
Danil Somsikov59f4c612021-09-08 10:58:461903 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1904 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131905 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371906 }
1907
Danil Somsikov59f4c612021-09-08 10:58:461908 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481909 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1910 const commands = await this.generateAllFetchCall(requests, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131911 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371912 }
1913
Jan Scheffler17b8fb42021-08-12 12:28:381914 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1915 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131916 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371917 }
1918
Jan Scheffler17b8fb42021-08-12 12:28:381919 private async copyAllPowerShellCommand(): Promise<void> {
Yang Guo6d1361f2024-07-11 08:23:481920 const requests = Logs.NetworkLog.NetworkLog.instance().requests().filter(request => this.applyFilter(request));
1921 const commands = await this.generateAllPowerShellCommand(requests);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131922 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371923 }
1924
Jan Schefflerd6c1d402021-02-26 16:56:381925 async exportAll(): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501926 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371927 if (!mainTarget) {
1928 return;
1929 }
1930 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131931 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321932 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131933 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371934
Kateryna Prokopenko380fdfa2022-03-16 16:39:321935 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371936 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341937 }
Blink Reformat4c46d092018-04-07 15:32:371938
Tim van der Lippe0ed1d2b2020-02-04 13:45:131939 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531940 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381941 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371942 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031943 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371944 }
1945
Wolfgang Beyer5b433b02022-05-12 13:57:371946 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411947 const requestLocation =
1948 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271949 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1950 if (networkPersistanceManager.project()) {
Danil Somsikovde84fb52024-01-30 13:53:091951 Common.Settings.Settings.instance().moduleSetting('persistence-network-overrides-enabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271952 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411953 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371954 } else { // If folder for local overrides has not been provided yet
Danil Somsikovacd635c2024-02-09 12:56:511955 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async () => {
Wolfgang Beyer5b433b02022-05-12 13:57:371956 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271957 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411958 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371959 });
1960 }
1961 }
1962
Jan Scheffler17b8fb42021-08-12 12:28:381963 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551964 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211965 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341966 }
Blink Reformat4c46d092018-04-07 15:32:371967 }
1968
Jan Scheffler17b8fb42021-08-12 12:28:381969 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551970 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211971 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341972 }
Blink Reformat4c46d092018-04-07 15:32:371973 }
1974
Yang Guo6d1361f2024-07-11 08:23:481975 private applyFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Jack Franklin28577db2021-10-14 08:12:531976 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371977 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341978 }
Christy Chen1825c612021-02-25 10:28:441979 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531980 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371981 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341982 }
Silvia Eremia096e1202023-09-22 15:49:171983 const [hideDataURL, blockedCookies, blockedRequests, thirdParty, hideExtensionURL] =
1984 Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.NETWORK_PANEL_FILTER_BAR_REDESIGN) ?
1985 [
1986 this.networkHideDataURLSetting.get(),
1987 this.networkShowBlockedCookiesOnlySetting.get(),
1988 this.networkOnlyBlockedRequestsSetting.get(),
1989 this.networkOnlyThirdPartySetting.get(),
1990 this.networkHideChromeExtensions.get(),
1991 ] :
1992 [
1993 this.dataURLFilterUI?.checked(),
1994 this.onlyBlockedResponseCookiesFilterUI?.checked(),
1995 this.onlyBlockedRequestsUI?.checked(),
1996 this.onlyThirdPartyFilterUI?.checked(),
1997 this.hideChromeExtensionsUI?.checked(),
1998 ];
1999
2000 if (hideDataURL && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:372001 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342002 }
Silvia Eremia096e1202023-09-22 15:49:172003 if (blockedCookies && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:372004 return false;
2005 }
Silvia Eremia096e1202023-09-22 15:49:172006 if (blockedRequests && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:132007 return false;
2008 }
Silvia Eremia096e1202023-09-22 15:49:172009 if (thirdParty && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:272010 return false;
2011 }
Silvia Eremia096e1202023-09-22 15:49:172012 if (hideExtensionURL && request.scheme === 'chrome-extension') {
ioana forfota45b44152023-07-21 14:20:532013 return false;
2014 }
Jack Franklin28577db2021-10-14 08:12:532015 for (let i = 0; i < this.filters.length; ++i) {
2016 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:372017 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:342018 }
Blink Reformat4c46d092018-04-07 15:32:372019 }
2020 return true;
2021 }
2022
Danil Somsikov7a392fb2021-09-13 11:09:462023 private isValidUrl(url: string): boolean {
2024 try {
2025 new URL(url);
2026 return true;
2027 } catch (e) {
2028 return false;
2029 }
2030 }
2031
Jan Scheffler17b8fb42021-08-12 12:28:382032 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:532033 // A query string can have multiple filters, some of them regular
2034 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:372035 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:532036 // checkbox therefore inverts each one of those individual filters.
2037 const descriptors = this.filterParser.parse(query);
2038 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:372039 const key = descriptor.key;
2040 const text = descriptor.text || '';
2041 const regex = descriptor.regex;
2042 let filter;
2043 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:172044 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:382045 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
2046 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:372047 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:382048 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:462049 } else if (this.isValidUrl(text)) {
2050 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:372051 } else {
Jan Scheffler17b8fb42021-08-12 12:28:382052 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:172053 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:372054 }
Victor Porof66878d62021-07-16 13:12:372055 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:382056 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:372057 }
2058 return filter;
Blink Reformat4c46d092018-04-07 15:32:372059 });
2060 }
2061
Jan Scheffler17b8fb42021-08-12 12:28:382062 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372063 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:162064 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:382065 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:372066
Sigurd Schneider30722582021-06-16 06:54:162067 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:382068 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372069
Simon Zünd6dedde52021-08-03 09:04:512070 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:382071 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:512072
Sigurd Schneider30722582021-06-16 06:54:162073 case NetworkForward.UIFilter.FilterType.Is:
2074 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:382075 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342076 }
Sigurd Schneider30722582021-06-16 06:54:162077 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:382078 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342079 }
Sigurd Schneider30722582021-06-16 06:54:162080 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:382081 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342082 }
Sigurd Schneider30722582021-06-16 06:54:162083 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:382084 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:342085 }
Blink Reformat4c46d092018-04-07 15:32:372086 break;
2087
Sigurd Schneider30722582021-06-16 06:54:162088 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:382089 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:372090
Sigurd Schneider30722582021-06-16 06:54:162091 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:382092 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372093
Sigurd Schneider30722582021-06-16 06:54:162094 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:382095 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372096
Sigurd Schneider30722582021-06-16 06:54:162097 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:382098 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:162099 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:372100
Sigurd Schneider30722582021-06-16 06:54:162101 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:382102 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372103
Sigurd Schneider30722582021-06-16 06:54:162104 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382105 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372106
Sigurd Schneider30722582021-06-16 06:54:162107 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382108 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372109
Sigurd Schneider30722582021-06-16 06:54:162110 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382111 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372112
Sigurd Schneider30722582021-06-16 06:54:162113 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:382114 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412115
Sigurd Schneider30722582021-06-16 06:54:162116 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:382117 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412118
Sigurd Schneider30722582021-06-16 06:54:162119 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:382120 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:542121
Sigurd Schneider30722582021-06-16 06:54:162122 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:382123 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:412124
Sigurd Schneider30722582021-06-16 06:54:162125 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:382126 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:502127 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:372128
Sigurd Schneider30722582021-06-16 06:54:162129 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:382130 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:032131
Jecelyn Yeen77c83462023-08-16 16:13:172132 case NetworkForward.UIFilter.FilterType.HasOverrides:
2133 return NetworkLogView.hasOverridesFilter.bind(null, value);
2134
Sigurd Schneider30722582021-06-16 06:54:162135 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:382136 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:032137
Sigurd Schneider30722582021-06-16 06:54:162138 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:382139 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:372140 }
2141 return null;
2142 }
2143
Jan Scheffler17b8fb42021-08-12 12:28:382144 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:372145 let multiplier = 1;
2146 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542147 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:372148 value = value.substring(0, value.length - 1);
2149 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:542150 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:372151 value = value.substring(0, value.length - 1);
2152 }
2153 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342154 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:372155 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342156 }
Jan Scheffler17b8fb42021-08-12 12:28:382157 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:372158 }
2159
Jan Scheffler17b8fb42021-08-12 12:28:382160 private filterRequests(): void {
Nancy Liffb3c7e2024-08-01 14:58:152161 this.removeAllNodeHighlights();
Jan Scheffler17b8fb42021-08-12 12:28:382162 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:372163 }
2164
Jan Scheffler17b8fb42021-08-12 12:28:382165 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:372166 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:372167 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342168 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:372169 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:342170 }
Brandon Goddard5e4244d2020-04-08 22:08:472171 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:532172 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:472173 // reveal and expand parent to ensure child is revealable.
2174 if (node.parent && node.parent instanceof NetworkGroupNode) {
2175 node.parent.reveal();
2176 node.parent.expand();
2177 }
Blink Reformat4c46d092018-04-07 15:32:372178 node.reveal();
2179 return node;
2180 }
2181
Jan Schefflerd6c1d402021-02-26 16:56:382182 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:382183 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342184 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:382185 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:342186 }
Blink Reformat4c46d092018-04-07 15:32:372187 }
2188
Sigurd Schneider722301e2021-06-15 13:41:202189 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:072190 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
2191 if (request) {
2192 this.revealAndHighlightRequest(request);
2193 }
2194 }
2195
Sigurd Schneider14d3e9f2021-06-14 08:29:012196 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
2197 void {
chait pinnamaneni6bc1c122020-10-30 17:30:522198 const defaultOptions = {clearFilter: true};
2199 const {clearFilter} = options || defaultOptions;
2200 if (clearFilter) {
2201 this.setTextFilterValue('');
2202 }
Jan Scheffler17b8fb42021-08-12 12:28:382203 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:342204 if (node) {
Blink Reformat4c46d092018-04-07 15:32:372205 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:342206 }
Blink Reformat4c46d092018-04-07 15:32:372207 }
2208
Jan Schefflerd6c1d402021-02-26 16:56:382209 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:532210 if (this.highlightedNode) {
2211 this.highlightedNode.element().classList.remove('highlighted-row');
2212 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:372213 }
2214 }
2215
Jan Scheffler17b8fb42021-08-12 12:28:382216 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:132217 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:532218 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:372219 }
2220
Jan Scheffler17b8fb42021-08-12 12:28:382221 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:132222 return requests.filter(request => !request.isBlobRequest());
2223 }
2224
Danil Somsikov59f4c612021-09-08 10:58:462225 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382226 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:372227 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372228 'method',
2229 'path',
2230 'scheme',
2231 'version',
Blink Reformat4c46d092018-04-07 15:32:372232
2233 // Unsafe headers
2234 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372235 'accept-charset',
2236 'accept-encoding',
2237 'access-control-request-headers',
2238 'access-control-request-method',
2239 'connection',
2240 'content-length',
2241 'cookie',
2242 'cookie2',
2243 'date',
2244 'dnt',
2245 'expect',
2246 'host',
2247 'keep-alive',
2248 'origin',
2249 'referer',
2250 'te',
2251 'trailer',
2252 'transfer-encoding',
2253 'upgrade',
2254 'via',
Blink Reformat4c46d092018-04-07 15:32:372255 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372256 'user-agent',
2257 ]);
Blink Reformat4c46d092018-04-07 15:32:372258
Jan Schefflerd6c1d402021-02-26 16:56:382259 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372260
2261 const url = JSON.stringify(request.url());
2262
2263 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382264 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372265 const name = header.name;
2266
Tim van der Lippe224a8622020-09-23 12:14:372267 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372268 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342269 }
Blink Reformat4c46d092018-04-07 15:32:372270
2271 return result;
2272 }, new Headers());
2273
Jan Schefflerd6c1d402021-02-26 16:56:382274 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342275 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412276 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342277 }
Blink Reformat4c46d092018-04-07 15:32:372278
Sigurd Schneider0e88b912020-05-08 08:28:232279 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372280 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412281 'include' :
2282 'omit';
Blink Reformat4c46d092018-04-07 15:32:372283
2284 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2285
2286 const referrer = referrerHeader ? referrerHeader.value : void 0;
2287
2288 const referrerPolicy = request.referrerPolicy() || void 0;
2289
2290 const requestBody = await request.requestFormData();
2291
Jan Schefflerd6c1d402021-02-26 16:56:382292 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412293 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372294 referrer,
2295 referrerPolicy,
2296 body: requestBody,
2297 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372298 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372299 };
2300
Danil Somsikov59f4c612021-09-08 10:58:462301 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292302 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462303 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532304 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462305 // following properties are not implemented in Node.js.
2306 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292307 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462308 extraHeaders['cookie'] = cookieHeader.value;
2309 }
2310 if (referrer) {
2311 delete fetchOptions.referrer;
2312 extraHeaders['Referer'] = referrer;
2313 }
2314 if (referrer) {
2315 delete fetchOptions.referrerPolicy;
2316 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2317 }
2318 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292319 fetchOptions.headers = {
2320 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462321 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292322 };
2323 }
2324 } else {
2325 fetchOptions.credentials = credentials;
2326 }
2327
Jan Scheffler172d5212020-01-02 14:42:562328 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372329 return `fetch(${url}, ${options});`;
2330 }
2331
Danil Somsikov59f4c612021-09-08 10:58:462332 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382333 Promise<string> {
2334 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462335 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132336 return commands.join(' ;\n');
2337 }
2338
Benedikt Meurer64b7e722023-12-15 09:03:582339 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: 'unix'|'win'):
2340 Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382341 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362342 // Most of these headers are derived from the URL and are automatically added by cURL.
2343 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Barry Pollard0a176b42024-01-30 10:19:232344 const ignoredHeaders =
2345 new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version', 'authority', 'protocol']);
Blink Reformat4c46d092018-04-07 15:32:372346
Jan Schefflerd6c1d402021-02-26 16:56:382347 function escapeStringWin(str: string): string {
Benedikt Meurer64b7e722023-12-15 09:03:582348 /* Only escape the " characters when necessary.
Blink Reformat4c46d092018-04-07 15:32:372349
Jan Schefflerd6c1d402021-02-26 16:56:382350 Because cmd.exe parser and MS Crt arguments parsers use some of the
2351 same escape characters, they can interact with each other in
2352 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372353
Jan Schefflerd6c1d402021-02-26 16:56:382354 Replace \ with \\ first because it is an escape character for certain
2355 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372356
Jan Schefflerd6c1d402021-02-26 16:56:382357 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372358
Jan Schefflerd6c1d402021-02-26 16:56:382359 Then escape all characters we are not sure about with ^ to ensure it
2360 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372361
Jan Schefflerd6c1d402021-02-26 16:56:382362 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352363 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382364 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2365 parser); So we can get cmd.exe parser to escape the character after it,
2366 if it is followed by a valid beginning character of an ENV variable.
2367 This ensures we do not try and double escape another ^ if it was placed
2368 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372369
Jan Schefflerd6c1d402021-02-26 16:56:382370 Lastly we replace new lines with ^ and TWO new lines because the first
2371 new line is there to enact the escape command the second is the character
2372 to escape (in this case new line).
2373 */
Benedikt Meurer64b7e722023-12-15 09:03:582374 const encapsChars = /[\r\n]|[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/.test(str) ? '^"' : '"';
Blink Reformat4c46d092018-04-07 15:32:372375 return encapsChars +
2376 str.replace(/\\/g, '\\\\')
2377 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542378 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372379 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542380 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372381 encapsChars;
2382 }
2383
Jan Schefflerd6c1d402021-02-26 16:56:382384 function escapeStringPosix(str: string): string {
2385 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222386 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122387 let hexString = code.toString(16);
2388 // Zero pad to four digits to comply with ANSI-C Quoting:
2389 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342390 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122391 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342392 }
Joey Arhar2d21f712019-05-20 21:07:122393
2394 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372395 }
2396
Mathias Bynensf06e8c02020-02-28 13:58:282397 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372398 // Use ANSI-C quoting syntax.
2399 return '$\'' +
2400 str.replace(/\\/g, '\\\\')
2401 .replace(/\'/g, '\\\'')
2402 .replace(/\n/g, '\\n')
2403 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282404 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372405 '\'';
Blink Reformat4c46d092018-04-07 15:32:372406 }
Mathias Bynensf06e8c02020-02-28 13:58:282407 // Use single quote syntax.
2408 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372409 }
2410
2411 // cURL command expected to run on the same platform that DevTools run
2412 // (it may be different from the inspected page platform).
2413 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2414
2415 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2416
2417 let inferredMethod = 'GET';
2418 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372419 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082420 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272421 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532422 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272423 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372424 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372425 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372426 }
2427
2428 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292429 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372430 }
2431
2432 const requestHeaders = request.requestHeaders();
2433 for (let i = 0; i < requestHeaders.length; i++) {
2434 const header = requestHeaders[i];
2435 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372436 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372437 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342438 }
Wolfgang Beyer26b7e892022-08-16 11:02:352439 if (header.value.trim()) {
2440 command.push('-H ' + escapeString(name + ': ' + header.value));
2441 } else {
2442 // A header passed with -H with no value or only whitespace as its
2443 // value tells curl to not set the header at all. To post an empty
2444 // header, you have to terminate it with a semicolon.
2445 command.push('-H ' + escapeString(name + ';'));
2446 }
Blink Reformat4c46d092018-04-07 15:32:372447 }
2448 command = command.concat(data);
Blink Reformat4c46d092018-04-07 15:32:372449
Tim van der Lippe1d6e57a2019-09-30 11:55:342450 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372451 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342452 }
Jan Scheffler172d5212020-01-02 14:42:562453 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372454 }
2455
Benedikt Meurer64b7e722023-12-15 09:03:582456 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: 'unix'|'win'):
Jan Scheffler17b8fb42021-08-12 12:28:382457 Promise<string> {
2458 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352459 const commands =
2460 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342461 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132462 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342463 }
Mathias Bynensf06e8c02020-02-28 13:58:282464 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132465 }
2466
Jan Scheffler17b8fb42021-08-12 12:28:382467 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562468 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242469 const ignoredHeaders = new Set<string>([
2470 'host',
2471 'connection',
2472 'proxy-connection',
2473 'content-length',
2474 'expect',
2475 'range',
2476 'content-type',
2477 'user-agent',
2478 'cookie',
2479 ]);
Blink Reformat4c46d092018-04-07 15:32:372480
Jan Schefflerd6c1d402021-02-26 16:56:382481 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372482 return '"' +
2483 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2484 }
2485
Brandon Walderman153b8d72021-06-28 18:45:242486 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2487 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2488 // command does not allow setting these headers through the -Headers parameter. See docs at:
2489 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2490 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2491 const requestHeaders = request.requestHeaders();
2492 const props = [];
2493
2494 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2495 if (userAgentHeader) {
2496 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2497 }
2498
Shuran Huang670281e2024-02-15 16:29:542499 for (const includedCookie of request.includedRequestCookies()) {
2500 const name = escapeString(includedCookie.cookie.name());
2501 const value = escapeString(includedCookie.cookie.value());
2502 const domain = escapeString(includedCookie.cookie.domain());
Brandon Walderman153b8d72021-06-28 18:45:242503 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2504 }
2505
2506 if (props.length) {
2507 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2508 }
2509
2510 return null;
2511 }
2512
Jan Scheffler172d5212020-01-02 14:42:562513 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372514
2515 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562516 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372517 }
2518
Brandon Walderman153b8d72021-06-28 18:45:242519 const session = generatePowerShellSession(request);
2520 if (session) {
2521 command.push('-WebSession $session');
2522 }
2523
Blink Reformat4c46d092018-04-07 15:32:372524 const requestHeaders = request.requestHeaders();
2525 const headerNameValuePairs = [];
2526 for (const header of requestHeaders) {
2527 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342528 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372529 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342530 }
Blink Reformat4c46d092018-04-07 15:32:372531 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2532 }
2533 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562534 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372535 }
2536
2537 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2538 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562539 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372540 }
2541
2542 const formData = await request.requestFormData();
2543 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372544 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342545 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562546 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342547 } else {
Jan Scheffler172d5212020-01-02 14:42:562548 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342549 }
Blink Reformat4c46d092018-04-07 15:32:372550 }
2551
Brandon Walderman153b8d72021-06-28 18:45:242552 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2553 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2554 // compatibility only.
2555 const prelude = session || '';
2556 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372557 }
Harley Libcf41f92018-09-10 18:01:132558
Jan Scheffler17b8fb42021-08-12 12:28:382559 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2560 const nonBlobRequests = this.filterOutBlobRequests(requests);
2561 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132562 return commands.join(';\r\n');
2563 }
Joey Arhara86c14e2019-03-12 03:20:502564
Jan Schefflerd6c1d402021-02-26 16:56:382565 static getDCLEventColor(): string {
Kateryna Prokopenkof85f4d12023-10-05 14:24:402566 return '--sys-color-token-attribute-value';
Joey Arhara86c14e2019-03-12 03:20:502567 }
2568
Jan Schefflerd6c1d402021-02-26 16:56:382569 static getLoadEventColor(): string {
Kateryna Prokopenkof85f4d12023-10-05 14:24:402570 return '--sys-color-token-property-special';
Joey Arhara86c14e2019-03-12 03:20:502571 }
Paul Lewis56509652019-12-06 12:51:582572}
Blink Reformat4c46d092018-04-07 15:32:372573
Jan Schefflerd6c1d402021-02-26 16:56:382574export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022575 let stackTraceText = '';
2576 for (const frame of stackTrace.callFrames) {
2577 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2578 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2579 }
2580 if (stackTrace.parent) {
2581 stackTraceText += computeStackTraceText(stackTrace.parent);
2582 }
2583 return stackTraceText;
2584}
2585
Jan Schefflerd6c1d402021-02-26 16:56:382586const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2587const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372588
Jan Schefflerd6c1d402021-02-26 16:56:382589export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372590 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222591}
2592
Paul Lewis56509652019-12-06 12:51:582593export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372594 'http': true,
2595 'https': true,
2596 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382597 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372598};
2599
Sigurd Schneider576ca9a2021-07-16 05:58:042600const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382601
2602export interface GroupLookupInterface {
2603 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2604 reset(): void;
2605}
2606
Jecelyn Yeen77c83462023-08-16 16:13:172607export const overrideFilter = {
2608 yes: 'yes',
2609 no: 'no',
2610 content: 'content',
2611 headers: 'headers',
2612};
2613
Jan Schefflerd6c1d402021-02-26 16:56:382614export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;
ioana forfota2c72e132023-09-22 12:11:482615
Silvia Eremia096e1202023-09-22 15:49:172616export class MoreFiltersDropDownUI extends
2617 Common.ObjectWrapper.ObjectWrapper<UI.FilterBar.FilterUIEventTypes> implements UI.FilterBar.FilterUI {
2618 private readonly filterElement: HTMLDivElement;
Kateryna Prokopenko17cba892024-07-26 13:33:562619 private readonly dropDownButton: UI.Toolbar.ToolbarCombobox;
Silvia Eremia096e1202023-09-22 15:49:172620 private networkHideDataURLSetting: Common.Settings.Setting<boolean>;
2621 private networkHideChromeExtensionsSetting: Common.Settings.Setting<boolean>;
2622 private networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
2623 private networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
2624 private networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
2625 private contextMenu?: UI.ContextMenu.ContextMenu;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482626 private activeFiltersCount: HTMLElement;
2627 private activeFiltersCountAdorner: Adorners.Adorner.Adorner;
Wolfgang Beyer3b382582023-11-16 12:40:022628 private hasChanged = false;
Silvia Eremia096e1202023-09-22 15:49:172629
Benedikt Meurer6b3ebf22024-01-12 10:00:512630 constructor() {
Silvia Eremia096e1202023-09-22 15:49:172631 super();
Silvia Eremia096e1202023-09-22 15:49:172632
Danil Somsikov74217e92024-01-30 07:01:122633 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('network-hide-data-url', false);
Silvia Eremia096e1202023-09-22 15:49:172634 this.networkHideChromeExtensionsSetting =
Danil Somsikov74217e92024-01-30 07:01:122635 Common.Settings.Settings.instance().createSetting('network-hide-chrome-extensions', false);
Silvia Eremia096e1202023-09-22 15:49:172636 this.networkShowBlockedCookiesOnlySetting =
Danil Somsikov74217e92024-01-30 07:01:122637 Common.Settings.Settings.instance().createSetting('network-show-blocked-cookies-only-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172638 this.networkOnlyBlockedRequestsSetting =
Danil Somsikov74217e92024-01-30 07:01:122639 Common.Settings.Settings.instance().createSetting('network-only-blocked-requests', false);
Silvia Eremia096e1202023-09-22 15:49:172640 this.networkOnlyThirdPartySetting =
Danil Somsikov74217e92024-01-30 07:01:122641 Common.Settings.Settings.instance().createSetting('network-only-third-party-setting', false);
Silvia Eremia096e1202023-09-22 15:49:172642
2643 this.filterElement = document.createElement('div');
2644 this.filterElement.setAttribute('aria-label', 'Show only/hide requests dropdown');
Danil Somsikov0cb97462024-01-30 15:11:292645 this.filterElement.setAttribute('jslog', `${VisualLogging.dropDown('more-filters').track({click: true})}`);
Kateryna Prokopenkod98e34c2023-09-25 18:08:482646
2647 this.activeFiltersCountAdorner = new Adorners.Adorner.Adorner();
2648 this.activeFiltersCount = document.createElement('span');
2649 this.activeFiltersCountAdorner.data = {
2650 name: 'countWrapper',
2651 content: this.activeFiltersCount,
2652 };
2653 this.activeFiltersCountAdorner.classList.add('active-filters-count');
2654 this.updateActiveFiltersCount();
2655
Kateryna Prokopenko17cba892024-07-26 13:33:562656 this.dropDownButton = new UI.Toolbar.ToolbarCombobox(i18nString(UIStrings.showOnlyHideRequests));
2657 this.dropDownButton.setText(i18nString(UIStrings.moreFilters));
2658 this.dropDownButton.setAdorner(this.activeFiltersCountAdorner);
Silvia Eremia096e1202023-09-22 15:49:172659 this.filterElement.appendChild(this.dropDownButton.element);
Silvia Eremia096e1202023-09-22 15:49:172660 this.dropDownButton.element.classList.add('dropdown-filterbar');
2661 this.dropDownButton.addEventListener(
2662 UI.Toolbar.ToolbarButton.Events.Click, this.showMoreFiltersContextMenu.bind(this));
2663 UI.ARIAUtils.markAsMenuButton(this.dropDownButton.element);
Kateryna Prokopenko5f434d42023-11-03 10:57:492664 this.updateTooltip();
Silvia Eremia096e1202023-09-22 15:49:172665 }
2666
Wolfgang Beyer3b382582023-11-16 12:40:022667 emitUMA(): void {
2668 if (this.hasChanged) {
2669 const selectedFilters = this.selectedFilters();
2670 Host.userMetrics.networkPanelMoreFiltersNumberOfSelectedChanged(selectedFilters.length);
2671 for (const selectedFilter of selectedFilters) {
2672 Host.userMetrics.networkPanelMoreFiltersItemSelected(selectedFilter);
2673 }
2674 }
2675 }
2676
2677 #onSettingChanged(): void {
2678 this.hasChanged = true;
Benedikt Meurer6b3ebf22024-01-12 10:00:512679 this.dispatchEventToListeners(UI.FilterBar.FilterUIEvents.FilterChanged);
Wolfgang Beyer3b382582023-11-16 12:40:022680 }
2681
Silvia Eremia096e1202023-09-22 15:49:172682 showMoreFiltersContextMenu(event: Common.EventTarget.EventTargetEvent<Event>): void {
2683 const mouseEvent = event.data;
Wolfgang Beyer3b382582023-11-16 12:40:022684 this.hasChanged = false;
Silvia Eremia096e1202023-09-22 15:49:172685
Wolfgang Beyer3b382582023-11-16 12:40:022686 this.networkHideDataURLSetting.addChangeListener(this.#onSettingChanged.bind(this));
2687 this.networkHideChromeExtensionsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2688 this.networkShowBlockedCookiesOnlySetting.addChangeListener(this.#onSettingChanged.bind(this));
2689 this.networkOnlyBlockedRequestsSetting.addChangeListener(this.#onSettingChanged.bind(this));
2690 this.networkOnlyThirdPartySetting.addChangeListener(this.#onSettingChanged.bind(this));
Silvia Eremia096e1202023-09-22 15:49:172691 this.contextMenu = new UI.ContextMenu.ContextMenu(mouseEvent, {
2692 useSoftMenu: true,
2693 keepOpen: true,
2694 x: this.dropDownButton.element.getBoundingClientRect().left,
2695 y: this.dropDownButton.element.getBoundingClientRect().top +
2696 (this.dropDownButton.element as HTMLElement).offsetHeight,
Wolfgang Beyer3b382582023-11-16 12:40:022697 onSoftMenuClosed: this.emitUMA.bind(this),
Silvia Eremia096e1202023-09-22 15:49:172698 });
2699
2700 this.contextMenu.defaultSection().appendCheckboxItem(
2701 i18nString(UIStrings.hideDataUrls),
Danil Somsikov66fa2262024-02-22 13:02:492702 () => this.networkHideDataURLSetting.set(!this.networkHideDataURLSetting.get()), {
2703 checked: this.networkHideDataURLSetting.get(),
2704 tooltip: i18nString(UIStrings.hidesDataAndBlobUrls),
2705 jslogContext: 'hide-data-urls',
2706 });
Silvia Eremia096e1202023-09-22 15:49:172707 this.contextMenu.defaultSection().appendCheckboxItem(
2708 i18nString(UIStrings.chromeExtensions),
Danil Somsikov66fa2262024-02-22 13:02:492709 () => this.networkHideChromeExtensionsSetting.set(!this.networkHideChromeExtensionsSetting.get()), {
2710 checked: this.networkHideChromeExtensionsSetting.get(),
2711 tooltip: i18nString(UIStrings.hideChromeExtension),
2712 jslogContext: 'hide-extension-urls',
2713 });
Silvia Eremia096e1202023-09-22 15:49:172714 this.contextMenu.defaultSection().appendSeparator();
Kateryna Prokopenkod98e34c2023-09-25 18:08:482715
Silvia Eremia096e1202023-09-22 15:49:172716 this.contextMenu.defaultSection().appendCheckboxItem(
2717 i18nString(UIStrings.hasBlockedCookies),
Danil Somsikov66fa2262024-02-22 13:02:492718 () => this.networkShowBlockedCookiesOnlySetting.set(!this.networkShowBlockedCookiesOnlySetting.get()), {
2719 checked: this.networkShowBlockedCookiesOnlySetting.get(),
2720 tooltip: i18nString(UIStrings.onlyShowRequestsWithBlockedCookies),
2721 jslogContext: 'only-blocked-response-cookies',
2722 });
Silvia Eremia096e1202023-09-22 15:49:172723 this.contextMenu.defaultSection().appendCheckboxItem(
2724 i18nString(UIStrings.blockedRequests),
Danil Somsikov66fa2262024-02-22 13:02:492725 () => this.networkOnlyBlockedRequestsSetting.set(!this.networkOnlyBlockedRequestsSetting.get()), {
2726 checked: this.networkOnlyBlockedRequestsSetting.get(),
2727 tooltip: i18nString(UIStrings.onlyShowBlockedRequests),
2728 jslogContext: 'only-blocked-requests',
2729 });
Silvia Eremia096e1202023-09-22 15:49:172730 this.contextMenu.defaultSection().appendCheckboxItem(
2731 i18nString(UIStrings.thirdParty),
Danil Somsikov66fa2262024-02-22 13:02:492732 () => this.networkOnlyThirdPartySetting.set(!this.networkOnlyThirdPartySetting.get()), {
2733 checked: this.networkOnlyThirdPartySetting.get(),
2734 tooltip: i18nString(UIStrings.onlyShowThirdPartyRequests),
2735 jslogContext: 'only-3rd-party-requests',
2736 });
Silvia Eremia096e1202023-09-22 15:49:172737
2738 void this.contextMenu.show();
2739 }
2740
Kateryna Prokopenko5f434d42023-11-03 10:57:492741 selectedFilters(): string[] {
2742 const filters = [
2743 ...this.networkHideDataURLSetting.get() ? [i18nString(UIStrings.hideDataUrls)] : [],
2744 ...this.networkHideChromeExtensionsSetting.get() ? [i18nString(UIStrings.chromeExtensions)] : [],
2745 ...this.networkShowBlockedCookiesOnlySetting.get() ? [i18nString(UIStrings.hasBlockedCookies)] : [],
2746 ...this.networkOnlyBlockedRequestsSetting.get() ? [i18nString(UIStrings.blockedRequests)] : [],
2747 ...this.networkOnlyThirdPartySetting.get() ? [i18nString(UIStrings.thirdParty)] : [],
Kateryna Prokopenkod98e34c2023-09-25 18:08:482748 ];
Kateryna Prokopenko5f434d42023-11-03 10:57:492749 return filters;
2750 }
2751
2752 updateActiveFiltersCount(): void {
2753 const count = this.selectedFilters().length;
Kateryna Prokopenkod98e34c2023-09-25 18:08:482754 this.activeFiltersCount.textContent = count.toString();
2755 count ? this.activeFiltersCountAdorner.classList.remove('hidden') :
2756 this.activeFiltersCountAdorner.classList.add('hidden');
2757 }
2758
Kateryna Prokopenko5f434d42023-11-03 10:57:492759 updateTooltip(): void {
2760 if (this.selectedFilters().length) {
2761 this.dropDownButton.setTitle(this.selectedFilters().join(', '));
2762 } else {
2763 this.dropDownButton.setTitle(UIStrings.showOnlyHideRequests);
2764 }
2765 }
2766
Silvia Eremia096e1202023-09-22 15:49:172767 discard(): void {
2768 if (this.contextMenu) {
2769 this.contextMenu.discard();
2770 }
2771 }
2772
2773 isActive(): boolean {
Benedikt Meurer6b3ebf22024-01-12 10:00:512774 return this.selectedFilters().length !== 0;
Silvia Eremia096e1202023-09-22 15:49:172775 }
2776
2777 element(): HTMLDivElement {
2778 return this.filterElement;
2779 }
2780}