blob: f3dd746a7293a999d8dae2bcbcfbc2016b877058 [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';
Danil Somsikovf3b437f2023-03-23 16:15:3949import * as Coordinator from '../../ui/components/render_coordinator/render_coordinator.js';
Tim van der Lippe8499fe22021-04-12 16:42:4750import * as DataGrid from '../../ui/legacy/components/data_grid/data_grid.js';
Tim van der Lippe3167ffe2021-04-12 16:45:1451import * as PerfUI from '../../ui/legacy/components/perf_ui/perf_ui.js';
Tim van der Lippe339ad262021-04-21 12:23:3652import * as Components from '../../ui/legacy/components/utils/utils.js';
Tim van der Lippeaa61faf2021-04-07 15:32:0753import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippe0ed1d2b2020-02-04 13:45:1354
Kriti Sapra2d85f882021-08-18 09:01:3055import networkLogViewStyles from './networkLogView.css.js';
56
Jack Franklin3a802602022-07-13 08:39:4257import {
58 Events,
59 NetworkGroupNode,
60 NetworkRequestNode,
61 type NetworkLogViewInterface,
62 type NetworkNode,
63 type EventTypes,
64} from './NetworkDataGridNode.js';
Tim van der Lippe119690c2020-01-13 12:31:3065import {NetworkFrameGrouper} from './NetworkFrameGrouper.js';
66import {NetworkLogViewColumns} from './NetworkLogViewColumns.js';
Jack Franklin3a802602022-07-13 08:39:4267
Jack Frankline839c0c2022-05-03 08:47:4468import {
69 NetworkTimeBoundary,
70 NetworkTransferDurationCalculator,
71 NetworkTransferTimeCalculator,
Jack Franklin3a802602022-07-13 08:39:4272 type NetworkTimeCalculator,
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 */
Christy Chencac3f102021-02-03 10:07:5591 hidesDataAndBlobUrls: 'Hides data: and blob: URLs',
92 /**
Jack Franklinfd72c072022-12-21 11:45:0193 *@description Aria accessible name in Network Log View of the Network panel
94 */
Christy Chencac3f102021-02-03 10:07:5595 resourceTypesToInclude: 'Resource types to include',
96 /**
Wolfgang Beyerb9391362023-07-14 12:40:4597 *@description Label for a checkbox in the Network panel. When checked, only requests with
98 * blocked response cookies are shown.
Jack Franklinfd72c072022-12-21 11:45:0199 */
Wolfgang Beyerb9391362023-07-14 12:40:45100 hasBlockedCookies: 'Blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55101 /**
Jack Franklinfd72c072022-12-21 11:45:01102 *@description Tooltip for a checkbox in the Network panel. The response to a network request may include a
103 * cookie (https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). Such response cookies can
104 * be malformed or otherwise invalid and the browser may choose to ignore or not accept invalid cookies.
105 */
Wolfgang Beyer1cb5e772023-07-17 10:34:04106 onlyShowRequestsWithBlockedCookies: 'Show only the requests with blocked response cookies',
Christy Chencac3f102021-02-03 10:07:55107 /**
Jack Franklinfd72c072022-12-21 11:45:01108 *@description Label for a filter in the Network panel
109 */
Sofia Emelianova25f46422023-07-04 15:20:11110 blockedRequests: 'Blocked requests',
Christy Chencac3f102021-02-03 10:07:55111 /**
Jack Franklinfd72c072022-12-21 11:45:01112 *@description Tooltip for a filter in the Network panel
113 */
Sofia Emelianova25f46422023-07-04 15:20:11114 onlyShowBlockedRequests: 'Show only blocked requests',
Christy Chencac3f102021-02-03 10:07:55115 /**
Jack Franklinfd72c072022-12-21 11:45:01116 *@description Label for a filter in the Network panel
117 */
Danil Somsikov721956a2021-07-07 08:17:27118 thirdParty: '3rd-party requests',
119 /**
Jack Franklinfd72c072022-12-21 11:45:01120 *@description Tooltip for a filter in the Network panel
121 */
Sofia Emelianova25f46422023-07-04 15:20:11122 onlyShowThirdPartyRequests: 'Show only requests with origin different from page origin',
Danil Somsikov721956a2021-07-07 08:17:27123 /**
Jack Franklinfd72c072022-12-21 11:45:01124 *@description Text that appears when user drag and drop something (for example, a file) in Network Log View of the Network panel
125 */
Christy Chencac3f102021-02-03 10:07:55126 dropHarFilesHere: 'Drop HAR files here',
127 /**
Jack Franklinfd72c072022-12-21 11:45:01128 *@description Recording text text content in Network Log View of the Network panel
129 */
Christy Chencac3f102021-02-03 10:07:55130 recordingNetworkActivity: 'Recording network activity…',
131 /**
Jack Franklinfd72c072022-12-21 11:45:01132 *@description Text in Network Log View of the Network panel
133 *@example {Ctrl + R} PH1
134 */
Christy Chencac3f102021-02-03 10:07:55135 performARequestOrHitSToRecordThe: 'Perform a request or hit {PH1} to record the reload.',
136 /**
Jack Franklinfd72c072022-12-21 11:45:01137 *@description Shown in the Network Log View of the Network panel when the user has not yet
138 * recorded any network activity. This is an instruction to the user to start recording in order to
139 * show network activity in the current UI.
140 *@example {Ctrl + E} PH1
141 */
Wolfgang Beyerf4237472021-08-18 14:55:41142 recordToDisplayNetworkActivity: 'Record network log ({PH1}) to display network activity.',
Christy Chencac3f102021-02-03 10:07:55143 /**
Jack Franklinfd72c072022-12-21 11:45:01144 *@description Text that is usually a hyperlink to more documentation
145 */
Christy Chencac3f102021-02-03 10:07:55146 learnMore: 'Learn more',
147 /**
Jack Franklinfd72c072022-12-21 11:45:01148 *@description Text to announce to screen readers that network data is available.
149 */
Christy Chencac3f102021-02-03 10:07:55150 networkDataAvailable: 'Network Data Available',
151 /**
Jack Franklinfd72c072022-12-21 11:45:01152 *@description Text in Network Log View of the Network panel
153 *@example {3} PH1
154 *@example {5} PH2
155 */
Christy Chencac3f102021-02-03 10:07:55156 sSRequests: '{PH1} / {PH2} requests',
157 /**
Jack Franklinfd72c072022-12-21 11:45:01158 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of the
159 * resources transferred during a selected time frame over the compressed size of all resources transferred during
160 * the whole network log.
161 *@example {5 B} PH1
162 *@example {10 B} PH2
163 */
Christy Chencac3f102021-02-03 10:07:55164 sSTransferred: '{PH1} / {PH2} transferred',
165 /**
Jack Franklinfd72c072022-12-21 11:45:01166 *@description Message in a tooltip that shows the compressed size of the resources transferred during a selected
167 * time frame over the compressed size of all resources transferred during the whole network log.
168 *@example {10} PH1
169 *@example {15} PH2
170 */
Christy Chencac3f102021-02-03 10:07:55171 sBSBTransferredOverNetwork: '{PH1} B / {PH2} B transferred over network',
172 /**
Jack Franklinfd72c072022-12-21 11:45:01173 * @description Text in Network Log View of the Network panel. Appears when a particular network
174 * resource is selected by the user. Shows how large the selected resource was (PH1) out of the
175 * total size (PH2).
176 * @example {40MB} PH1
177 * @example {50MB} PH2
178 */
Christy Chencac3f102021-02-03 10:07:55179 sSResources: '{PH1} / {PH2} resources',
180 /**
Jack Franklinfd72c072022-12-21 11:45:01181 *@description Text in Network Log View of the Network panel
182 *@example {40} PH1
183 *@example {50} PH2
184 */
Christy Chencac3f102021-02-03 10:07:55185 sBSBResourcesLoadedByThePage: '{PH1} B / {PH2} B resources loaded by the page',
186 /**
Jack Franklinfd72c072022-12-21 11:45:01187 *@description Text in Network Log View of the Network panel
188 *@example {6} PH1
189 */
Christy Chencac3f102021-02-03 10:07:55190 sRequests: '{PH1} requests',
191 /**
Jack Franklinfd72c072022-12-21 11:45:01192 *@description Message in the summary toolbar at the bottom of the Network log that shows the compressed size of
193 * all resources transferred over network during a network activity log.
194 *@example {4 B} PH1
195 */
Christy Chencac3f102021-02-03 10:07:55196 sTransferred: '{PH1} transferred',
197 /**
Jack Franklinfd72c072022-12-21 11:45:01198 *@description Message in a tooltip that shows the compressed size of all resources transferred over network during
199 * a network activity log.
200 *@example {4} PH1
201 */
Christy Chencac3f102021-02-03 10:07:55202 sBTransferredOverNetwork: '{PH1} B transferred over network',
203 /**
Jack Franklinfd72c072022-12-21 11:45:01204 *@description Text in Network Log View of the Network panel
205 *@example {4} PH1
206 */
Christy Chencac3f102021-02-03 10:07:55207 sResources: '{PH1} resources',
208 /**
Jack Franklinfd72c072022-12-21 11:45:01209 *@description Text in Network Log View of the Network panel
210 *@example {10} PH1
211 */
Christy Chencac3f102021-02-03 10:07:55212 sBResourcesLoadedByThePage: '{PH1} B resources loaded by the page',
213 /**
Jack Franklinfd72c072022-12-21 11:45:01214 *@description Text in Network Log View of the Network panel
215 *@example {120ms} PH1
216 */
Christy Chencac3f102021-02-03 10:07:55217 finishS: 'Finish: {PH1}',
218 /**
Jack Franklinfd72c072022-12-21 11:45:01219 *@description Text in Network Log View of the Network panel
220 *@example {3000ms} PH1
221 */
Christy Chencac3f102021-02-03 10:07:55222 domcontentloadedS: 'DOMContentLoaded: {PH1}',
223 /**
Jack Franklinfd72c072022-12-21 11:45:01224 *@description Text in Network Log View of the Network panel
225 *@example {40ms} PH1
226 */
Christy Chencac3f102021-02-03 10:07:55227 loadS: 'Load: {PH1}',
228 /**
Jack Franklinfd72c072022-12-21 11:45:01229 *@description Text for copying
230 */
Christy Chencac3f102021-02-03 10:07:55231 copy: 'Copy',
232 /**
Jack Franklinfd72c072022-12-21 11:45:01233 *@description Text in Network Log View of the Network panel
234 */
Christy Chencac3f102021-02-03 10:07:55235 copyRequestHeaders: 'Copy request headers',
236 /**
Jack Franklinfd72c072022-12-21 11:45:01237 *@description Text in Network Log View of the Network panel
238 */
Christy Chencac3f102021-02-03 10:07:55239 copyResponseHeaders: 'Copy response headers',
240 /**
Jack Franklinfd72c072022-12-21 11:45:01241 *@description Text in Network Log View of the Network panel
242 */
Christy Chencac3f102021-02-03 10:07:55243 copyResponse: 'Copy response',
244 /**
Jack Franklinfd72c072022-12-21 11:45:01245 *@description Text in Network Log View of the Network panel
246 */
Peter Marshallf625dc82021-03-02 08:10:57247 copyStacktrace: 'Copy stack trace',
Christy Chencac3f102021-02-03 10:07:55248 /**
Jack Franklinfd72c072022-12-21 11:45:01249 * @description A context menu command in the Network panel, for copying to the clipboard.
250 * PowerShell refers to the format the data will be copied as.
251 */
Peter Marshallb8bd00f2021-02-24 08:25:18252 copyAsPowershell: 'Copy as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55253 /**
Jack Franklinfd72c072022-12-21 11:45:01254 *@description A context menu command in the Network panel, for copying to the clipboard. 'fetch'
255 * refers to the format the data will be copied as, which is compatible with the fetch web API.
256 */
Peter Marshallb8bd00f2021-02-24 08:25:18257 copyAsFetch: 'Copy as `fetch`',
Christy Chencac3f102021-02-03 10:07:55258 /**
Jack Franklinfd72c072022-12-21 11:45:01259 * @description Text in Network Log View of the Network panel. An action that copies a command to
260 * the developer's clipboard. The command allows the developer to replay this specific network
261 * request in Node.js, a desktop application/framework. 'Node.js fetch' is a noun phrase for the
262 * type of request that will be copied.
263 */
Peter Marshallb8bd00f2021-02-24 08:25:18264 copyAsNodejsFetch: 'Copy as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55265 /**
Jack Franklinfd72c072022-12-21 11:45:01266 *@description Text in Network Log View of the Network panel. An action that copies a command to
267 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
268 *translatable).
269 */
Peter Marshallb8bd00f2021-02-24 08:25:18270 copyAsCurlCmd: 'Copy as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55271 /**
Jack Franklinfd72c072022-12-21 11:45:01272 *@description Text in Network Log View of the Network panel. An action that copies a command to
273 *the clipboard. It will copy the command in the format compatible with a Bash script.
274 */
Peter Marshallb8bd00f2021-02-24 08:25:18275 copyAsCurlBash: 'Copy as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55276 /**
Jack Franklinfd72c072022-12-21 11:45:01277 *@description Text in Network Log View of the Network panel. An action that copies a command to
278 *the clipboard. It will copy the command in the format compatible with a PowerShell script.
279 */
Peter Marshallb8bd00f2021-02-24 08:25:18280 copyAllAsPowershell: 'Copy all as `PowerShell`',
Christy Chencac3f102021-02-03 10:07:55281 /**
Jack Franklinfd72c072022-12-21 11:45:01282 *@description Text in Network Log View of the Network panel. An action that copies a command to
283 *the clipboard. It will copy the command in the format compatible with a 'fetch' command (fetch
284 *should not be translated).
285 */
Peter Marshallb8bd00f2021-02-24 08:25:18286 copyAllAsFetch: 'Copy all as `fetch`',
Christy Chencac3f102021-02-03 10:07:55287 /**
Jack Franklinfd72c072022-12-21 11:45:01288 *@description Text in Network Log View of the Network panel. An action that copies a command to
289 *the clipboard. It will copy the command in the format compatible with a Node.js 'fetch' command
290 *(fetch and Node.js should not be translated).
291 */
Peter Marshallb8bd00f2021-02-24 08:25:18292 copyAllAsNodejsFetch: 'Copy all as `Node.js` `fetch`',
Christy Chencac3f102021-02-03 10:07:55293 /**
Jack Franklinfd72c072022-12-21 11:45:01294 *@description Text in Network Log View of the Network panel. An action that copies a command to
295 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
296 *translatable).
297 */
Peter Marshallb8bd00f2021-02-24 08:25:18298 copyAllAsCurlCmd: 'Copy all as `cURL` (`cmd`)',
Christy Chencac3f102021-02-03 10:07:55299 /**
Jack Franklinfd72c072022-12-21 11:45:01300 *@description Text in Network Log View of the Network panel. An action that copies a command to
301 *the clipboard. It will copy the command in the format compatible with a Bash script.
302 */
Peter Marshallb8bd00f2021-02-24 08:25:18303 copyAllAsCurlBash: 'Copy all as `cURL` (`bash`)',
Christy Chencac3f102021-02-03 10:07:55304 /**
Jack Franklinfd72c072022-12-21 11:45:01305 *@description Text in Network Log View of the Network panel. An action that copies a command to
306 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
307 *translatable).
308 */
Peter Marshallb8bd00f2021-02-24 08:25:18309 copyAsCurl: 'Copy as `cURL`',
Christy Chencac3f102021-02-03 10:07:55310 /**
Jack Franklinfd72c072022-12-21 11:45:01311 *@description Text in Network Log View of the Network panel. An action that copies a command to
312 *the clipboard. It will copy the command in the format compatible with cURL (a program, not
313 *translatable).
314 */
Peter Marshallb8bd00f2021-02-24 08:25:18315 copyAllAsCurl: 'Copy all as `cURL`',
Christy Chencac3f102021-02-03 10:07:55316 /**
Jack Franklinfd72c072022-12-21 11:45:01317 * @description Text in Network Log View of the Network panel. An action that copies data to the
318 * clipboard. It will copy the data in the HAR (not translatable) format. 'all' refers to every
319 * network request that is currently shown.
320 */
Peter Marshallb8bd00f2021-02-24 08:25:18321 copyAllAsHar: 'Copy all as `HAR`',
Christy Chencac3f102021-02-03 10:07:55322 /**
Jack Franklinfd72c072022-12-21 11:45:01323 *@description A context menu item in the Network Log View of the Network panel
324 */
Peter Marshallb8bd00f2021-02-24 08:25:18325 saveAllAsHarWithContent: 'Save all as `HAR` with content',
Christy Chencac3f102021-02-03 10:07:55326 /**
Jack Franklinfd72c072022-12-21 11:45:01327 *@description A context menu item in the Network Log View of the Network panel
328 */
Christy Chencac3f102021-02-03 10:07:55329 clearBrowserCache: 'Clear browser cache',
330 /**
Jack Franklinfd72c072022-12-21 11:45:01331 *@description A context menu item in the Network Log View of the Network panel
332 */
Christy Chencac3f102021-02-03 10:07:55333 clearBrowserCookies: 'Clear browser cookies',
334 /**
Jack Franklinfd72c072022-12-21 11:45:01335 *@description A context menu item in the Network Log View of the Network panel
336 */
Christy Chencac3f102021-02-03 10:07:55337 blockRequestUrl: 'Block request URL',
338 /**
Jack Franklinfd72c072022-12-21 11:45:01339 *@description A context menu item in the Network Log View of the Network panel
340 *@example {example.com} PH1
341 */
Christy Chencac3f102021-02-03 10:07:55342 unblockS: 'Unblock {PH1}',
343 /**
Jack Franklinfd72c072022-12-21 11:45:01344 *@description A context menu item in the Network Log View of the Network panel
345 */
Christy Chencac3f102021-02-03 10:07:55346 blockRequestDomain: 'Block request domain',
347 /**
Jack Franklinfd72c072022-12-21 11:45:01348 *@description Text to replay an XHR request
349 */
Christy Chencac3f102021-02-03 10:07:55350 replayXhr: 'Replay XHR',
351 /**
Jack Franklinfd72c072022-12-21 11:45:01352 *@description Text in Network Log View of the Network panel
353 */
Christy Chencac3f102021-02-03 10:07:55354 areYouSureYouWantToClearBrowser: 'Are you sure you want to clear browser cache?',
355 /**
Jack Franklinfd72c072022-12-21 11:45:01356 *@description Text in Network Log View of the Network panel
357 */
Christy Chencac3f102021-02-03 10:07:55358 areYouSureYouWantToClearBrowserCookies: 'Are you sure you want to clear browser cookies?',
Wolfgang Beyer5b433b02022-05-12 13:57:37359 /**
Jack Franklinfd72c072022-12-21 11:45:01360 *@description A context menu item in the Network Log View of the Network panel
361 * for creating a header override
362 */
Wolfgang Beyerc6fe2be2022-11-03 15:39:41363 overrideHeaders: 'Override headers',
Christy Chencac3f102021-02-03 10:07:55364};
Tim van der Lippef596ca02021-03-31 10:02:47365const str_ = i18n.i18n.registerUIStrings('panels/network/NetworkLogView.ts', UIStrings);
Christy Chencac3f102021-02-03 10:07:55366const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Danil Somsikov59f4c612021-09-08 10:58:46367
368const enum FetchStyle {
369 Browser = 0,
370 NodeJs = 1,
371}
372
Danil Somsikovf3b437f2023-03-23 16:15:39373const coordinator = Coordinator.RenderCoordinator.RenderCoordinator.instance();
374
Simon Zünd940cb1f2021-09-16 11:46:09375export class NetworkLogView extends Common.ObjectWrapper.eventMixin<EventTypes, typeof UI.Widget.VBox>(UI.Widget.VBox)
376 implements SDK.TargetManager.SDKModelObserver<SDK.NetworkManager.NetworkManager>, NetworkLogViewInterface {
Jack Franklin28577db2021-10-14 08:12:53377 private readonly networkInvertFilterSetting: Common.Settings.Setting<boolean>;
378 private readonly networkHideDataURLSetting: Common.Settings.Setting<boolean>;
Wolfgang Beyer1cb5e772023-07-17 10:34:04379 private readonly networkShowBlockedCookiesOnlySetting: Common.Settings.Setting<boolean>;
Jack Franklin28577db2021-10-14 08:12:53380 private readonly networkOnlyBlockedRequestsSetting: Common.Settings.Setting<boolean>;
381 private readonly networkOnlyThirdPartySetting: Common.Settings.Setting<boolean>;
382 private readonly networkResourceTypeFiltersSetting: Common.Settings.Setting<{[key: string]: boolean}>;
383 private rawRowHeight: number;
384 private readonly progressBarContainer: Element;
385 private readonly networkLogLargeRowsSetting: Common.Settings.Setting<boolean>;
386 private rowHeightInternal: number;
387 private readonly timeCalculatorInternal: NetworkTransferTimeCalculator;
388 private readonly durationCalculator: NetworkTransferDurationCalculator;
389 private calculatorInternal: NetworkTransferTimeCalculator;
Danil Somsikov2a4c4e02022-10-07 12:31:30390 private readonly columnsInternal: NetworkLogViewColumns;
Jack Franklin28577db2021-10-14 08:12:53391 private staleRequests: Set<SDK.NetworkRequest.NetworkRequest>;
392 private mainRequestLoadTime: number;
393 private mainRequestDOMContentLoadedTime: number;
394 private filters: Filter[];
395 private timeFilter: Filter|null;
396 private hoveredNodeInternal: NetworkNode|null;
397 private recordingHint: Element|null;
Jack Franklin28577db2021-10-14 08:12:53398 private highlightedNode: NetworkRequestNode|null;
399 private readonly linkifierInternal: Components.Linkifier.Linkifier;
400 private recording: boolean;
401 private needsRefresh: boolean;
402 private readonly headerHeightInternal: number;
403 private readonly groupLookups: Map<string, GroupLookupInterface>;
404 private activeGroupLookup: GroupLookupInterface|null;
405 private readonly textFilterUI: UI.FilterBar.TextFilterUI;
406 private readonly invertFilterUI: UI.FilterBar.CheckboxFilterUI;
407 private readonly dataURLFilterUI: UI.FilterBar.CheckboxFilterUI;
408 private resourceCategoryFilterUI: UI.FilterBar.NamedBitSetFilterUI;
Wolfgang Beyer1cb5e772023-07-17 10:34:04409 private readonly onlyBlockedResponseCookiesFilterUI: UI.FilterBar.CheckboxFilterUI;
Jack Franklin28577db2021-10-14 08:12:53410 private readonly onlyBlockedRequestsUI: UI.FilterBar.CheckboxFilterUI;
411 private readonly onlyThirdPartyFilterUI: UI.FilterBar.CheckboxFilterUI;
412 private readonly filterParser: TextUtils.TextUtils.FilterParser;
413 private readonly suggestionBuilder: UI.FilterSuggestionBuilder.FilterSuggestionBuilder;
414 private dataGrid: DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode>;
Wolfgang Beyer8fc262f2023-04-11 13:22:50415 private readonly summaryToolbarInternal: UI.Toolbar.Toolbar;
Jack Franklin28577db2021-10-14 08:12:53416 private readonly filterBar: UI.FilterBar.FilterBar;
417 private readonly textFilterSetting: Common.Settings.Setting<string>;
Jan Schefflerd6c1d402021-02-26 16:56:38418
419 constructor(
420 filterBar: UI.FilterBar.FilterBar, progressBarContainer: Element,
421 networkLogLargeRowsSetting: Common.Settings.Setting<boolean>) {
Blink Reformat4c46d092018-04-07 15:32:37422 super();
423 this.setMinimumSize(50, 64);
Blink Reformat4c46d092018-04-07 15:32:37424
425 this.element.id = 'network-container';
Brandon Goddard88d885a2019-10-31 16:11:05426 this.element.classList.add('no-node-selected');
Blink Reformat4c46d092018-04-07 15:32:37427
Jack Franklin28577db2021-10-14 08:12:53428 this.networkInvertFilterSetting = Common.Settings.Settings.instance().createSetting('networkInvertFilter', false);
429 this.networkHideDataURLSetting = Common.Settings.Settings.instance().createSetting('networkHideDataURL', false);
Wolfgang Beyer1cb5e772023-07-17 10:34:04430 this.networkShowBlockedCookiesOnlySetting =
431 Common.Settings.Settings.instance().createSetting('networkShowBlockedCookiesOnlySetting', false);
Jack Franklin28577db2021-10-14 08:12:53432 this.networkOnlyBlockedRequestsSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30433 Common.Settings.Settings.instance().createSetting('networkOnlyBlockedRequests', false);
Jack Franklin28577db2021-10-14 08:12:53434 this.networkOnlyThirdPartySetting =
Danil Somsikov721956a2021-07-07 08:17:27435 Common.Settings.Settings.instance().createSetting('networkOnlyThirdPartySetting', false);
Jack Franklin28577db2021-10-14 08:12:53436 this.networkResourceTypeFiltersSetting =
Paul Lewis2d7d65c2020-03-16 17:26:30437 Common.Settings.Settings.instance().createSetting('networkResourceTypeFilters', {});
Blink Reformat4c46d092018-04-07 15:32:37438
Jack Franklin28577db2021-10-14 08:12:53439 this.rawRowHeight = 0;
440 this.progressBarContainer = progressBarContainer;
441 this.networkLogLargeRowsSetting = networkLogLargeRowsSetting;
442 this.networkLogLargeRowsSetting.addChangeListener(updateRowHeight.bind(this), this);
Blink Reformat4c46d092018-04-07 15:32:37443
Jan Schefflerd6c1d402021-02-26 16:56:38444 function updateRowHeight(this: NetworkLogView): void {
Jack Franklin28577db2021-10-14 08:12:53445 this.rawRowHeight = Boolean(this.networkLogLargeRowsSetting.get()) ? 41 : 21;
446 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:37447 }
Jack Franklin28577db2021-10-14 08:12:53448 this.rawRowHeight = 0;
449 this.rowHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37450 updateRowHeight.call(this);
451
Jack Franklin28577db2021-10-14 08:12:53452 this.timeCalculatorInternal = new NetworkTransferTimeCalculator();
453 this.durationCalculator = new NetworkTransferDurationCalculator();
454 this.calculatorInternal = this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:37455
Danil Somsikov2a4c4e02022-10-07 12:31:30456 this.columnsInternal = new NetworkLogViewColumns(
Jack Franklin28577db2021-10-14 08:12:53457 this, this.timeCalculatorInternal, this.durationCalculator, networkLogLargeRowsSetting);
Danil Somsikov2a4c4e02022-10-07 12:31:30458 this.columnsInternal.show(this.element);
Blink Reformat4c46d092018-04-07 15:32:37459
Jack Franklin28577db2021-10-14 08:12:53460 this.staleRequests = new Set();
461 this.mainRequestLoadTime = -1;
462 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:37463
Jack Franklin28577db2021-10-14 08:12:53464 this.filters = [];
465 this.timeFilter = null;
466 this.hoveredNodeInternal = null;
467 this.recordingHint = null;
Jack Franklin28577db2021-10-14 08:12:53468 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:37469
Jack Franklin28577db2021-10-14 08:12:53470 this.linkifierInternal = new Components.Linkifier.Linkifier();
Blink Reformat4c46d092018-04-07 15:32:37471
Jack Franklin28577db2021-10-14 08:12:53472 this.recording = false;
473 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:37474
Jack Franklin28577db2021-10-14 08:12:53475 this.headerHeightInternal = 0;
Blink Reformat4c46d092018-04-07 15:32:37476
Jack Franklin28577db2021-10-14 08:12:53477 this.groupLookups = new Map();
478 this.groupLookups.set('Frame', new NetworkFrameGrouper(this));
Blink Reformat4c46d092018-04-07 15:32:37479
Jack Franklin28577db2021-10-14 08:12:53480 this.activeGroupLookup = null;
Blink Reformat4c46d092018-04-07 15:32:37481
Jack Franklin28577db2021-10-14 08:12:53482 this.textFilterUI = new UI.FilterBar.TextFilterUI();
483 this.textFilterUI.addEventListener(UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged, this);
484 filterBar.addFilter(this.textFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37485
Jack Franklin28577db2021-10-14 08:12:53486 this.invertFilterUI = new UI.FilterBar.CheckboxFilterUI(
487 'invert-filter', i18nString(UIStrings.invertFilter), true, this.networkInvertFilterSetting);
488 this.invertFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38489 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53490 UI.Tooltip.Tooltip.install(this.invertFilterUI.element(), i18nString(UIStrings.invertsFilter));
491 filterBar.addFilter(this.invertFilterUI);
Victor Porof66878d62021-07-16 13:12:37492
Jack Franklin28577db2021-10-14 08:12:53493 this.dataURLFilterUI = new UI.FilterBar.CheckboxFilterUI(
494 'hide-data-url', i18nString(UIStrings.hideDataUrls), true, this.networkHideDataURLSetting);
495 this.dataURLFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38496 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53497 UI.Tooltip.Tooltip.install(this.dataURLFilterUI.element(), i18nString(UIStrings.hidesDataAndBlobUrls));
498 filterBar.addFilter(this.dataURLFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37499
500 const filterItems =
Tim van der Lippe0ed1d2b2020-02-04 13:45:13501 Object.values(Common.ResourceType.resourceCategories)
Jan Schefflerd6c1d402021-02-26 16:56:38502 .map(
503 category =>
504 ({name: category.title(), label: (): string => category.shortTitle(), title: category.title()}));
Jack Franklin28577db2021-10-14 08:12:53505 this.resourceCategoryFilterUI =
506 new UI.FilterBar.NamedBitSetFilterUI(filterItems, this.networkResourceTypeFiltersSetting);
Elorm Cocha477cfb2023-06-08 17:58:08507 UI.ARIAUtils.setLabel(this.resourceCategoryFilterUI.element(), i18nString(UIStrings.resourceTypesToInclude));
Jack Franklin28577db2021-10-14 08:12:53508 this.resourceCategoryFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38509 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53510 filterBar.addFilter(this.resourceCategoryFilterUI);
Blink Reformat4c46d092018-04-07 15:32:37511
Wolfgang Beyer1cb5e772023-07-17 10:34:04512 this.onlyBlockedResponseCookiesFilterUI = new UI.FilterBar.CheckboxFilterUI(
513 'only-show-blocked-cookies', i18nString(UIStrings.hasBlockedCookies), true,
514 this.networkShowBlockedCookiesOnlySetting);
515 this.onlyBlockedResponseCookiesFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38516 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Wolfgang Beyer1cb5e772023-07-17 10:34:04517 UI.Tooltip.Tooltip.install(
518 this.onlyBlockedResponseCookiesFilterUI.element(), i18nString(UIStrings.onlyShowRequestsWithBlockedCookies));
519 filterBar.addFilter(this.onlyBlockedResponseCookiesFilterUI);
Jan Scheffler1ae7c9e2019-12-03 15:48:37520
Jack Franklin28577db2021-10-14 08:12:53521 this.onlyBlockedRequestsUI = new UI.FilterBar.CheckboxFilterUI(
Christy Chencac3f102021-02-03 10:07:55522 'only-show-blocked-requests', i18nString(UIStrings.blockedRequests), true,
Jack Franklin28577db2021-10-14 08:12:53523 this.networkOnlyBlockedRequestsSetting);
524 this.onlyBlockedRequestsUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38525 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53526 UI.Tooltip.Tooltip.install(this.onlyBlockedRequestsUI.element(), i18nString(UIStrings.onlyShowBlockedRequests));
527 filterBar.addFilter(this.onlyBlockedRequestsUI);
Sigurd Schneidera2afe0b2020-03-03 15:27:13528
Jack Franklin28577db2021-10-14 08:12:53529 this.onlyThirdPartyFilterUI = new UI.FilterBar.CheckboxFilterUI(
530 'only-show-third-party', i18nString(UIStrings.thirdParty), true, this.networkOnlyThirdPartySetting);
531 this.onlyThirdPartyFilterUI.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38532 UI.FilterBar.FilterUIEvents.FilterChanged, this.filterChanged.bind(this), this);
Jack Franklin28577db2021-10-14 08:12:53533 UI.Tooltip.Tooltip.install(this.onlyThirdPartyFilterUI.element(), i18nString(UIStrings.onlyShowThirdPartyRequests));
534 filterBar.addFilter(this.onlyThirdPartyFilterUI);
Danil Somsikov721956a2021-07-07 08:17:27535
Jack Franklin28577db2021-10-14 08:12:53536 this.filterParser = new TextUtils.TextUtils.FilterParser(searchKeys);
537 this.suggestionBuilder =
Jan Scheffler17b8fb42021-08-12 12:28:38538 new UI.FilterSuggestionBuilder.FilterSuggestionBuilder(searchKeys, NetworkLogView.sortSearchValues);
539 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:37540
Danil Somsikov2a4c4e02022-10-07 12:31:30541 this.dataGrid = this.columnsInternal.dataGrid();
Jan Scheffler17b8fb42021-08-12 12:28:38542 this.setupDataGrid();
Danil Somsikov2a4c4e02022-10-07 12:31:30543 this.columnsInternal.sortByCurrentColumn();
Erik Luo0187a022018-05-31 18:35:49544 filterBar.filterButton().addEventListener(
Jack Franklin28577db2021-10-14 08:12:53545 UI.Toolbar.ToolbarButton.Events.Click, this.dataGrid.scheduleUpdate.bind(this.dataGrid, true /* isFromUser */));
Blink Reformat4c46d092018-04-07 15:32:37546
Wolfgang Beyer8fc262f2023-04-11 13:22:50547 this.summaryToolbarInternal = new UI.Toolbar.Toolbar('network-summary-bar', this.element);
548 this.summaryToolbarInternal.element.setAttribute('role', 'status');
Blink Reformat4c46d092018-04-07 15:32:37549
Tim van der Lippe0ed1d2b2020-02-04 13:45:13550 new UI.DropTarget.DropTarget(
Jan Scheffler17b8fb42021-08-12 12:28:38551 this.element, [UI.DropTarget.Type.File], i18nString(UIStrings.dropHarFilesHere), this.handleDrop.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37552
Paul Lewis2d7d65c2020-03-16 17:26:30553 Common.Settings.Settings.instance()
554 .moduleSetting('networkColorCodeResourceTypes')
Jan Scheffler17b8fb42021-08-12 12:28:38555 .addChangeListener(this.invalidateAllItems.bind(this, false), this);
Blink Reformat4c46d092018-04-07 15:32:37556
Danil Somsikov62bc5782023-03-21 10:48:50557 SDK.TargetManager.TargetManager.instance().observeModels(SDK.NetworkManager.NetworkManager, this, {scoped: true});
Sigurd Schneidercf5b8302021-04-23 07:52:27558 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38559 Logs.NetworkLog.Events.RequestAdded, this.onRequestUpdated, this);
Sigurd Schneidercf5b8302021-04-23 07:52:27560 Logs.NetworkLog.NetworkLog.instance().addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38561 Logs.NetworkLog.Events.RequestUpdated, this.onRequestUpdated, this);
562 Logs.NetworkLog.NetworkLog.instance().addEventListener(Logs.NetworkLog.Events.Reset, this.reset, this);
Blink Reformat4c46d092018-04-07 15:32:37563
Jan Scheffler17b8fb42021-08-12 12:28:38564 this.updateGroupByFrame();
Paul Lewis2d7d65c2020-03-16 17:26:30565 Common.Settings.Settings.instance()
566 .moduleSetting('network.group-by-frame')
Jan Scheffler17b8fb42021-08-12 12:28:38567 .addChangeListener(() => this.updateGroupByFrame());
Blink Reformat4c46d092018-04-07 15:32:37568
Jack Franklin28577db2021-10-14 08:12:53569 this.filterBar = filterBar;
Jack Frankline3cb2802020-09-07 09:58:03570
Jack Franklin28577db2021-10-14 08:12:53571 this.textFilterSetting = Common.Settings.Settings.instance().createSetting('networkTextFilter', '');
572 if (this.textFilterSetting.get()) {
573 this.textFilterUI.setValue(this.textFilterSetting.get());
Jack Frankline3cb2802020-09-07 09:58:03574 }
Blink Reformat4c46d092018-04-07 15:32:37575 }
576
Jan Scheffler17b8fb42021-08-12 12:28:38577 private updateGroupByFrame(): void {
Paul Lewis2d7d65c2020-03-16 17:26:30578 const value = Common.Settings.Settings.instance().moduleSetting('network.group-by-frame').get();
Jan Scheffler17b8fb42021-08-12 12:28:38579 this.setGrouping(value ? 'Frame' : null);
Blink Reformat4c46d092018-04-07 15:32:37580 }
581
Jan Scheffler17b8fb42021-08-12 12:28:38582 private static sortSearchValues(key: string, values: string[]): void {
Sigurd Schneider30722582021-06-16 06:54:16583 if (key === NetworkForward.UIFilter.FilterType.Priority) {
Blink Reformat4c46d092018-04-07 15:32:37584 values.sort((a, b) => {
Jan Schefflerd6c1d402021-02-26 16:56:38585 const aPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(a) as Protocol.Network.ResourcePriority);
586 const bPriority = (PerfUI.NetworkPriorities.uiLabelToNetworkPriority(b) as Protocol.Network.ResourcePriority);
Tim van der Lippeded23fb2020-02-13 13:33:50587 return PerfUI.NetworkPriorities.networkPriorityWeight(aPriority) -
588 PerfUI.NetworkPriorities.networkPriorityWeight(bPriority);
Blink Reformat4c46d092018-04-07 15:32:37589 });
590 } else {
591 values.sort();
592 }
593 }
594
Jan Scheffler17b8fb42021-08-12 12:28:38595 private static negativeFilter(filter: Filter, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37596 return !filter(request);
597 }
598
Jan Scheffler17b8fb42021-08-12 12:28:38599 private static requestPathFilter(regex: RegExp|null, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34600 if (!regex) {
Blink Reformat4c46d092018-04-07 15:32:37601 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34602 }
Blink Reformat4c46d092018-04-07 15:32:37603
604 return regex.test(request.path() + '/' + request.name());
605 }
606
Jan Scheffler17b8fb42021-08-12 12:28:38607 private static subdomains(domain: string): string[] {
Blink Reformat4c46d092018-04-07 15:32:37608 const result = [domain];
609 let indexOfPeriod = domain.indexOf('.');
610 while (indexOfPeriod !== -1) {
611 result.push('*' + domain.substring(indexOfPeriod));
612 indexOfPeriod = domain.indexOf('.', indexOfPeriod + 1);
613 }
614 return result;
615 }
616
Jan Scheffler17b8fb42021-08-12 12:28:38617 private static createRequestDomainFilter(value: string): Filter {
Tim van der Lippebafa3bd2021-01-20 12:19:17618 const escapedPattern = value.split('*').map(Platform.StringUtilities.escapeForRegExp).join('.*');
Jan Scheffler17b8fb42021-08-12 12:28:38619 return NetworkLogView.requestDomainFilter.bind(null, new RegExp('^' + escapedPattern + '$', 'i'));
Blink Reformat4c46d092018-04-07 15:32:37620 }
621
Jan Scheffler17b8fb42021-08-12 12:28:38622 private static requestDomainFilter(regex: RegExp, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37623 return regex.test(request.domain);
624 }
625
Jan Scheffler17b8fb42021-08-12 12:28:38626 private static runningRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37627 return !request.finished;
628 }
629
Jan Scheffler17b8fb42021-08-12 12:28:38630 private static fromCacheRequestFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37631 return request.cached();
632 }
633
Jan Scheffler17b8fb42021-08-12 12:28:38634 private static interceptedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05635 return request.fetchedViaServiceWorker;
636 }
637
Jan Scheffler17b8fb42021-08-12 12:28:38638 private static initiatedByServiceWorkerFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Joey Arhard183e7e2019-02-28 03:37:05639 return request.initiatedByServiceWorker();
640 }
641
Jan Scheffler17b8fb42021-08-12 12:28:38642 private static requestResponseHeaderFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37643 return request.responseHeaderValue(value) !== undefined;
644 }
645
Jan Scheffler17b8fb42021-08-12 12:28:38646 private static requestResponseHeaderSetCookieFilter(value: string, request: SDK.NetworkRequest.NetworkRequest):
647 boolean {
Jack Franklin28577db2021-10-14 08:12:53648 // Multiple Set-Cookie headers in the request are concatenated via space. Only
Simon Zünd6dedde52021-08-03 09:04:51649 // filter via `includes` instead of strict equality.
650 return Boolean(request.responseHeaderValue('Set-Cookie')?.includes(value));
651 }
652
Jan Scheffler17b8fb42021-08-12 12:28:38653 private static requestMethodFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37654 return request.requestMethod === value;
655 }
656
Jan Scheffler17b8fb42021-08-12 12:28:38657 private static requestPriorityFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37658 return request.priority() === value;
659 }
660
Jan Scheffler17b8fb42021-08-12 12:28:38661 private static requestMimeTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37662 return request.mimeType === value;
663 }
664
Jan Scheffler17b8fb42021-08-12 12:28:38665 private static requestMixedContentFilter(
Sigurd Schneider30722582021-06-16 06:54:16666 value: NetworkForward.UIFilter.MixedContentFilterValues, request: SDK.NetworkRequest.NetworkRequest): boolean {
667 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Displayed) {
Blink Reformat4c46d092018-04-07 15:32:37668 return request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable;
Mathias Bynensf06e8c02020-02-28 13:58:28669 }
Sigurd Schneider30722582021-06-16 06:54:16670 if (value === NetworkForward.UIFilter.MixedContentFilterValues.Blocked) {
Blink Reformat4c46d092018-04-07 15:32:37671 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28672 }
Sigurd Schneider30722582021-06-16 06:54:16673 if (value === NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden) {
Blink Reformat4c46d092018-04-07 15:32:37674 return request.mixedContentType === Protocol.Security.MixedContentType.Blockable && !request.wasBlocked();
Mathias Bynensf06e8c02020-02-28 13:58:28675 }
Sigurd Schneider30722582021-06-16 06:54:16676 if (value === NetworkForward.UIFilter.MixedContentFilterValues.All) {
Blink Reformat4c46d092018-04-07 15:32:37677 return request.mixedContentType !== Protocol.Security.MixedContentType.None;
Tim van der Lippe1d6e57a2019-09-30 11:55:34678 }
Blink Reformat4c46d092018-04-07 15:32:37679
680 return false;
681 }
682
Jan Scheffler17b8fb42021-08-12 12:28:38683 private static requestSchemeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37684 return request.scheme === value;
685 }
686
Jan Scheffler17b8fb42021-08-12 12:28:38687 private static requestCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41688 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.domain() === value);
689 }
690
Jan Scheffler17b8fb42021-08-12 12:28:38691 private static requestCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41692 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.name() === value);
693 }
694
Jan Scheffler17b8fb42021-08-12 12:28:38695 private static requestCookiePathFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Simon Zündc9759102020-03-25 11:24:54696 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.path() === value);
697 }
698
Jan Scheffler17b8fb42021-08-12 12:28:38699 private static requestCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41700 return request.allCookiesIncludingBlockedOnes().some(cookie => cookie.value() === value);
701 }
702
Jan Scheffler17b8fb42021-08-12 12:28:38703 private static requestSetCookieDomainFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41704 return request.responseCookies.some(cookie => cookie.domain() === value);
Blink Reformat4c46d092018-04-07 15:32:37705 }
706
Jan Scheffler17b8fb42021-08-12 12:28:38707 private static requestSetCookieNameFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41708 return request.responseCookies.some(cookie => cookie.name() === value);
Blink Reformat4c46d092018-04-07 15:32:37709 }
710
Jan Scheffler17b8fb42021-08-12 12:28:38711 private static requestSetCookieValueFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Jan Scheffler341eea52019-12-12 09:08:41712 return request.responseCookies.some(cookie => cookie.value() === value);
Blink Reformat4c46d092018-04-07 15:32:37713 }
714
Jan Scheffler17b8fb42021-08-12 12:28:38715 private static requestSizeLargerThanFilter(value: number, request: SDK.NetworkRequest.NetworkRequest): boolean {
Blink Reformat4c46d092018-04-07 15:32:37716 return request.transferSize >= value;
717 }
718
Jan Scheffler17b8fb42021-08-12 12:28:38719 private static statusCodeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lipped7cfd142021-01-07 12:17:24720 return (String(request.statusCode)) === value;
Blink Reformat4c46d092018-04-07 15:32:37721 }
722
Sigurd Schneider576ca9a2021-07-16 05:58:04723 static getHTTPRequestsFilter(request: SDK.NetworkRequest.NetworkRequest): boolean {
Paul Lewis56509652019-12-06 12:51:58724 return request.parsedURL.isValid && (request.scheme in HTTPSchemas);
Blink Reformat4c46d092018-04-07 15:32:37725 }
726
Jan Scheffler17b8fb42021-08-12 12:28:38727 private static resourceTypeFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Sigurd Schneider464838b2020-08-24 13:53:03728 return request.resourceType().name() === value;
729 }
730
Jan Scheffler17b8fb42021-08-12 12:28:38731 private static requestUrlFilter(value: string, request: SDK.NetworkRequest.NetworkRequest): boolean {
Tim van der Lippebafa3bd2021-01-20 12:19:17732 const regex = new RegExp(Platform.StringUtilities.escapeForRegExp(value), 'i');
Julian Geppertf8ce40c2020-09-01 18:02:03733 return regex.test(request.url());
734 }
735
Jan Scheffler17b8fb42021-08-12 12:28:38736 private static requestTimeFilter(windowStart: number, windowEnd: number, request: SDK.NetworkRequest.NetworkRequest):
Jan Schefflerd6c1d402021-02-26 16:56:38737 boolean {
Tim van der Lippe1d6e57a2019-09-30 11:55:34738 if (request.issueTime() > windowEnd) {
Blink Reformat4c46d092018-04-07 15:32:37739 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34740 }
741 if (request.endTime !== -1 && request.endTime < windowStart) {
Blink Reformat4c46d092018-04-07 15:32:37742 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34743 }
Blink Reformat4c46d092018-04-07 15:32:37744 return true;
745 }
746
Jan Scheffler17b8fb42021-08-12 12:28:38747 private static copyRequestHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13748 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.requestHeadersText());
Blink Reformat4c46d092018-04-07 15:32:37749 }
750
Jan Scheffler17b8fb42021-08-12 12:28:38751 private static copyResponseHeaders(request: SDK.NetworkRequest.NetworkRequest): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13752 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(request.responseHeadersText);
Blink Reformat4c46d092018-04-07 15:32:37753 }
754
Jan Scheffler17b8fb42021-08-12 12:28:38755 private static async copyResponse(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Blink Reformat4c46d092018-04-07 15:32:37756 const contentData = await request.contentData();
Jan Schefflerd6c1d402021-02-26 16:56:38757 let content: (string|null)|string = contentData.content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:34758 if (!request.contentType().isTextType()) {
Tim van der Lippe18f04892020-03-17 11:39:40759 content = TextUtils.ContentProvider.contentAsDataURL(content, request.mimeType, contentData.encoded);
Tim van der Lippe224a8622020-09-23 12:14:37760 } else if (contentData.encoded && content) {
Ingvar Stepanyan1c771842018-10-10 14:35:08761 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:34762 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:13763 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(content);
Blink Reformat4c46d092018-04-07 15:32:37764 }
765
Jan Scheffler17b8fb42021-08-12 12:28:38766 private handleDrop(dataTransfer: DataTransfer): void {
Blink Reformat4c46d092018-04-07 15:32:37767 const items = dataTransfer.items;
Tim van der Lippe1d6e57a2019-09-30 11:55:34768 if (!items.length) {
Blink Reformat4c46d092018-04-07 15:32:37769 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34770 }
Simon Zünd99961242021-09-08 11:02:12771 const file = items[0].getAsFile();
772 if (file) {
Tim van der Lippe2d9a95c2022-01-04 15:18:03773 void this.onLoadFromFile(file);
Tim van der Lippe1d6e57a2019-09-30 11:55:34774 }
Blink Reformat4c46d092018-04-07 15:32:37775 }
776
Jan Schefflerd6c1d402021-02-26 16:56:38777 async onLoadFromFile(file: File): Promise<void> {
Tim van der Lippe0ed1d2b2020-02-04 13:45:13778 const outputStream = new Common.StringOutputStream.StringOutputStream();
779 const reader = new Bindings.FileUtils.ChunkedFileReader(file, /* chunkSize */ 10000000);
Blink Reformat4c46d092018-04-07 15:32:37780 const success = await reader.read(outputStream);
781 if (!success) {
Tim van der Lippe224a8622020-09-23 12:14:37782 const error = reader.error();
783 if (error) {
Jan Scheffler17b8fb42021-08-12 12:28:38784 this.harLoadFailed(error.message);
Tim van der Lippe224a8622020-09-23 12:14:37785 }
Blink Reformat4c46d092018-04-07 15:32:37786 return;
787 }
788 let harRoot;
789 try {
790 // HARRoot and JSON.parse might throw.
Sigurd Schneiderd66d0132021-04-28 13:57:56791 harRoot = new HAR.HARFormat.HARRoot(JSON.parse(outputStream.data()));
Blink Reformat4c46d092018-04-07 15:32:37792 } catch (e) {
Jan Scheffler17b8fb42021-08-12 12:28:38793 this.harLoadFailed(e);
Blink Reformat4c46d092018-04-07 15:32:37794 return;
795 }
Tim van der Lippe09cf5032021-04-29 15:08:09796 Logs.NetworkLog.NetworkLog.instance().importRequests(HAR.Importer.Importer.requestsFromHARLog(harRoot.log));
Blink Reformat4c46d092018-04-07 15:32:37797 }
798
Jan Scheffler17b8fb42021-08-12 12:28:38799 private harLoadFailed(message: string): void {
Paul Lewisa83ea612020-03-04 13:01:36800 Common.Console.Console.instance().error('Failed to load HAR file with following error: ' + message);
Blink Reformat4c46d092018-04-07 15:32:37801 }
802
Jan Scheffler17b8fb42021-08-12 12:28:38803 private setGrouping(groupKey: string|null): void {
Jack Franklin28577db2021-10-14 08:12:53804 if (this.activeGroupLookup) {
805 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:34806 }
Jack Franklin28577db2021-10-14 08:12:53807 const groupLookup = groupKey ? this.groupLookups.get(groupKey) || null : null;
808 this.activeGroupLookup = groupLookup;
Jan Scheffler17b8fb42021-08-12 12:28:38809 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:37810 }
811
Jan Scheffler17b8fb42021-08-12 12:28:38812 private computeRowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53813 return Math.round(this.rawRowHeight * window.devicePixelRatio) / window.devicePixelRatio;
Blink Reformat4c46d092018-04-07 15:32:37814 }
815
Jan Schefflerd6c1d402021-02-26 16:56:38816 nodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Tim van der Lippe224a8622020-09-23 12:14:37817 return networkRequestToNode.get(request) || null;
Blink Reformat4c46d092018-04-07 15:32:37818 }
819
Jan Schefflerd6c1d402021-02-26 16:56:38820 headerHeight(): number {
Jack Franklin28577db2021-10-14 08:12:53821 return this.headerHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:37822 }
823
Jan Schefflerd6c1d402021-02-26 16:56:38824 setRecording(recording: boolean): void {
Jack Franklin28577db2021-10-14 08:12:53825 this.recording = recording;
Jan Scheffler17b8fb42021-08-12 12:28:38826 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:37827 }
828
Danil Somsikov2a4c4e02022-10-07 12:31:30829 columns(): NetworkLogViewColumns {
830 return this.columnsInternal;
831 }
832
Wolfgang Beyer8fc262f2023-04-11 13:22:50833 summaryToolbar(): UI.Toolbar.Toolbar {
834 return this.summaryToolbarInternal;
835 }
836
Jan Schefflerd6c1d402021-02-26 16:56:38837 modelAdded(networkManager: SDK.NetworkManager.NetworkManager): void {
Blink Reformat4c46d092018-04-07 15:32:37838 // TODO(allada) Remove dependency on networkManager and instead use NetworkLog and PageLoad for needed data.
Danil Somsikov88384322023-03-22 13:53:22839 const target = networkManager.target();
840 if (target.outermostTarget() !== target) {
Blink Reformat4c46d092018-04-07 15:32:37841 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34842 }
Danil Somsikov88384322023-03-22 13:53:22843 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
Blink Reformat4c46d092018-04-07 15:32:37844 if (resourceTreeModel) {
Jan Scheffler17b8fb42021-08-12 12:28:38845 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37846 resourceTreeModel.addEventListener(
Jan Scheffler17b8fb42021-08-12 12:28:38847 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
Blink Reformat4c46d092018-04-07 15:32:37848 }
Danil Somsikov88384322023-03-22 13:53:22849 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Danil Somsikov123c3ef2023-06-14 10:07:04850 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:25851 this.refreshRequest(request);
852 }
Danil Somsikov88384322023-03-22 13:53:22853 }
Blink Reformat4c46d092018-04-07 15:32:37854 }
855
Jan Schefflerd6c1d402021-02-26 16:56:38856 modelRemoved(networkManager: SDK.NetworkManager.NetworkManager): void {
Danil Somsikov88384322023-03-22 13:53:22857 const target = networkManager.target();
858 if (target.outermostTarget() !== target) {
859 return;
860 }
861 const resourceTreeModel = target.model(SDK.ResourceTreeModel.ResourceTreeModel);
862 if (resourceTreeModel) {
863 resourceTreeModel.removeEventListener(SDK.ResourceTreeModel.Events.Load, this.loadEventFired, this);
864 resourceTreeModel.removeEventListener(
865 SDK.ResourceTreeModel.Events.DOMContentLoaded, this.domContentLoadedEventFired, this);
866 }
867 const preserveLog = Common.Settings.Settings.instance().moduleSetting('network_log.preserve-log').get();
868 if (!preserveLog) {
869 this.reset();
Blink Reformat4c46d092018-04-07 15:32:37870 }
871 }
872
Jan Schefflerd6c1d402021-02-26 16:56:38873 linkifier(): Components.Linkifier.Linkifier {
Jack Franklin28577db2021-10-14 08:12:53874 return this.linkifierInternal;
Simon Zündcdd72c92020-10-07 11:48:13875 }
876
Jan Schefflerd6c1d402021-02-26 16:56:38877 setWindow(start: number, end: number): void {
Blink Reformat4c46d092018-04-07 15:32:37878 if (!start && !end) {
Jack Franklin28577db2021-10-14 08:12:53879 this.timeFilter = null;
880 this.timeCalculatorInternal.setWindow(null);
Blink Reformat4c46d092018-04-07 15:32:37881 } else {
Jack Franklin28577db2021-10-14 08:12:53882 this.timeFilter = NetworkLogView.requestTimeFilter.bind(null, start, end);
883 this.timeCalculatorInternal.setWindow(new NetworkTimeBoundary(start, end));
Blink Reformat4c46d092018-04-07 15:32:37884 }
Jan Scheffler17b8fb42021-08-12 12:28:38885 this.filterRequests();
Blink Reformat4c46d092018-04-07 15:32:37886 }
887
Jan Schefflerd6c1d402021-02-26 16:56:38888 resetFocus(): void {
Jack Franklin28577db2021-10-14 08:12:53889 this.dataGrid.element.focus();
Blink Reformat4c46d092018-04-07 15:32:37890 }
891
Jan Scheffler17b8fb42021-08-12 12:28:38892 private resetSuggestionBuilder(): void {
Jack Franklin28577db2021-10-14 08:12:53893 this.suggestionBuilder.clear();
894 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.Running);
895 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16896 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.FromCache);
Jack Franklin28577db2021-10-14 08:12:53897 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16898 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted);
Jack Franklin28577db2021-10-14 08:12:53899 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:16900 NetworkForward.UIFilter.FilterType.Is, NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated);
Jack Franklin28577db2021-10-14 08:12:53901 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '100');
902 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '10k');
903 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.LargerThan, '1M');
904 this.textFilterUI.setSuggestionProvider(this.suggestionBuilder.completions.bind(this.suggestionBuilder));
Blink Reformat4c46d092018-04-07 15:32:37905 }
906
Simon Zünda2bae2e2021-09-16 07:57:13907 private filterChanged(): void {
Blink Reformat4c46d092018-04-07 15:32:37908 this.removeAllNodeHighlights();
Jack Franklin28577db2021-10-14 08:12:53909 this.parseFilterQuery(this.textFilterUI.value(), this.invertFilterUI.checked());
Jan Scheffler17b8fb42021-08-12 12:28:38910 this.filterRequests();
Jack Franklin28577db2021-10-14 08:12:53911 this.textFilterSetting.set(this.textFilterUI.value());
Blink Reformat4c46d092018-04-07 15:32:37912 }
913
Jan Schefflerd6c1d402021-02-26 16:56:38914 async resetFilter(): Promise<void> {
Jack Franklin28577db2021-10-14 08:12:53915 this.textFilterUI.clear();
Rajasekar Murugan3ad369e2020-02-19 18:20:12916 }
917
Jan Scheffler17b8fb42021-08-12 12:28:38918 private showRecordingHint(): void {
919 this.hideRecordingHint();
Jack Franklin28577db2021-10-14 08:12:53920 this.recordingHint = this.element.createChild('div', 'network-status-pane fill');
921 const hintText = this.recordingHint.createChild('div', 'recording-hint');
Joey Arhar0585e6f2018-10-30 23:11:18922
Jack Franklin28577db2021-10-14 08:12:53923 if (this.recording) {
Jan Schefflerd6c1d402021-02-26 16:56:38924 let reloadShortcutNode: Element|null = null;
Wolfgang Beyer5c385b92020-11-09 15:20:04925 const reloadShortcut =
926 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutsForAction('inspector_main.reload')[0];
927 if (reloadShortcut) {
Jack Franklin28577db2021-10-14 08:12:53928 reloadShortcutNode = this.recordingHint.createChild('b');
Wolfgang Beyer5c385b92020-11-09 15:20:04929 reloadShortcutNode.textContent = reloadShortcut.title();
930 }
931
Blink Reformat4c46d092018-04-07 15:32:37932 const recordingText = hintText.createChild('span');
Christy Chencac3f102021-02-03 10:07:55933 recordingText.textContent = i18nString(UIStrings.recordingNetworkActivity);
Joey Arhar0585e6f2018-10-30 23:11:18934 if (reloadShortcutNode) {
935 hintText.createChild('br');
Christy Chencac3f102021-02-03 10:07:55936 hintText.appendChild(i18n.i18n.getFormatLocalizedString(
937 str_, UIStrings.performARequestOrHitSToRecordThe, {PH1: reloadShortcutNode}));
Joey Arhar0585e6f2018-10-30 23:11:18938 }
Blink Reformat4c46d092018-04-07 15:32:37939 } else {
940 const recordNode = hintText.createChild('b');
Tim van der Lippe9c9fb122020-09-08 15:06:17941 recordNode.textContent =
Tim van der Lippe224a8622020-09-23 12:14:37942 UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction('network.toggle-recording') || '';
Christy Chencac3f102021-02-03 10:07:55943 hintText.appendChild(
Wolfgang Beyerf4237472021-08-18 14:55:41944 i18n.i18n.getFormatLocalizedString(str_, UIStrings.recordToDisplayNetworkActivity, {PH1: recordNode}));
Blink Reformat4c46d092018-04-07 15:32:37945 }
Kayce Basques5444c1b2019-02-15 20:32:53946 hintText.createChild('br');
Tim van der Lippe0ed1d2b2020-02-04 13:45:13947 hintText.appendChild(UI.XLink.XLink.create(
Jecelyn90c04162021-04-07 08:41:35948 'https://developer.chrome.com/docs/devtools/network/?utm_source=devtools&utm_campaign=2019Q1',
Christy Chencac3f102021-02-03 10:07:55949 i18nString(UIStrings.learnMore)));
Amanda Baker6761aae2019-11-05 18:59:11950
Jan Scheffler17b8fb42021-08-12 12:28:38951 this.setHidden(true);
Blink Reformat4c46d092018-04-07 15:32:37952 }
953
Jan Scheffler17b8fb42021-08-12 12:28:38954 private hideRecordingHint(): void {
955 this.setHidden(false);
Jack Franklin28577db2021-10-14 08:12:53956 if (this.recordingHint) {
957 this.recordingHint.remove();
Tim van der Lippe1d6e57a2019-09-30 11:55:34958 }
Michael Liao7322dee2021-04-07 18:33:30959 UI.ARIAUtils.alert(i18nString(UIStrings.networkDataAvailable));
Jack Franklin28577db2021-10-14 08:12:53960 this.recordingHint = null;
Blink Reformat4c46d092018-04-07 15:32:37961 }
962
Jan Scheffler17b8fb42021-08-12 12:28:38963 private setHidden(value: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:30964 this.columnsInternal.setHidden(value);
Wolfgang Beyer8fc262f2023-04-11 13:22:50965 UI.ARIAUtils.setHidden(this.summaryToolbarInternal.element, value);
Amanda Baker6761aae2019-11-05 18:59:11966 }
967
Randolf Jungffd14242023-04-19 00:32:25968 override elementsToRestoreScrollPositionsFor(): Element[] {
Jack Franklin28577db2021-10-14 08:12:53969 if (!this.dataGrid) // Not initialized yet.
Tim van der Lippe1d6e57a2019-09-30 11:55:34970 {
Blink Reformat4c46d092018-04-07 15:32:37971 return [];
Tim van der Lippe1d6e57a2019-09-30 11:55:34972 }
Jack Franklin28577db2021-10-14 08:12:53973 return [this.dataGrid.scrollContainer];
Blink Reformat4c46d092018-04-07 15:32:37974 }
975
Jan Schefflerd6c1d402021-02-26 16:56:38976 columnExtensionResolved(): void {
Jan Scheffler17b8fb42021-08-12 12:28:38977 this.invalidateAllItems(true);
Blink Reformat4c46d092018-04-07 15:32:37978 }
979
Jan Scheffler17b8fb42021-08-12 12:28:38980 private setupDataGrid(): DataGrid.SortableDataGrid.SortableDataGrid<NetworkNode> {
Jack Franklin28577db2021-10-14 08:12:53981 this.dataGrid.setRowContextMenuCallback((contextMenu, node) => {
Jan Schefflerd6c1d402021-02-26 16:56:38982 const request = (node as NetworkNode).request();
Tim van der Lippe1d6e57a2019-09-30 11:55:34983 if (request) {
Blink Reformat4c46d092018-04-07 15:32:37984 this.handleContextMenuForRequest(contextMenu, request);
Tim van der Lippe1d6e57a2019-09-30 11:55:34985 }
Blink Reformat4c46d092018-04-07 15:32:37986 });
Jack Franklin28577db2021-10-14 08:12:53987 this.dataGrid.setStickToBottom(true);
988 this.dataGrid.setName('networkLog');
989 this.dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last);
990 this.dataGrid.element.classList.add('network-log-grid');
991 this.dataGrid.element.addEventListener('mousedown', this.dataGridMouseDown.bind(this), true);
992 this.dataGrid.element.addEventListener('mousemove', this.dataGridMouseMove.bind(this), true);
993 this.dataGrid.element.addEventListener('mouseleave', () => this.setHoveredNode(null), true);
994 this.dataGrid.element.addEventListener('keydown', event => {
995 if (event.key === 'ArrowRight' && this.dataGrid.selectedNode) {
996 const initiatorLink = this.dataGrid.selectedNode.element().querySelector('span.devtools-link');
Olivia Flynn54728dd2021-05-21 20:15:43997 if (initiatorLink) {
998 (initiatorLink as HTMLElement).focus();
999 }
1000 }
ergunshee4a6132021-11-05 16:21:251001
Jack Franklin5e685be2022-10-17 14:27:091002 if (Platform.KeyboardUtilities.isEnterOrSpaceKey(event)) {
Jack Lynch29cc4f32020-07-22 21:52:051003 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: true, takeFocus: true});
Brandon Goddard88d885a2019-10-31 16:11:051004 event.consume(true);
1005 }
1006 });
ergunshee4a6132021-11-05 16:21:251007 this.dataGrid.element.addEventListener('keyup', event => {
1008 if ((event.key === 'r' || event.key === 'R') && this.dataGrid.selectedNode) {
1009 const request = (this.dataGrid.selectedNode as NetworkNode).request();
1010 if (!request) {
1011 return;
1012 }
1013
1014 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
1015 SDK.NetworkManager.NetworkManager.replayRequest(request);
1016 }
1017 }
1018 });
Jack Franklin28577db2021-10-14 08:12:531019 this.dataGrid.element.addEventListener('focus', this.onDataGridFocus.bind(this), true);
1020 this.dataGrid.element.addEventListener('blur', this.onDataGridBlur.bind(this), true);
1021 return this.dataGrid;
Blink Reformat4c46d092018-04-07 15:32:371022 }
1023
Jan Scheffler17b8fb42021-08-12 12:28:381024 private dataGridMouseMove(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381025 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531026 const node = (this.dataGrid.dataGridNodeFromNode((mouseEvent.target as Node)));
Tim van der Lippe224a8622020-09-23 12:14:371027 const highlightInitiatorChain = mouseEvent.shiftKey;
Jan Scheffler17b8fb42021-08-12 12:28:381028 this.setHoveredNode(node as NetworkNode, highlightInitiatorChain);
Blink Reformat4c46d092018-04-07 15:32:371029 }
1030
Jan Schefflerd6c1d402021-02-26 16:56:381031 hoveredNode(): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531032 return this.hoveredNodeInternal;
Blink Reformat4c46d092018-04-07 15:32:371033 }
1034
Jan Scheffler17b8fb42021-08-12 12:28:381035 private setHoveredNode(node: NetworkNode|null, highlightInitiatorChain?: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531036 if (this.hoveredNodeInternal) {
1037 this.hoveredNodeInternal.setHovered(false, false);
Tim van der Lippe1d6e57a2019-09-30 11:55:341038 }
Jack Franklin28577db2021-10-14 08:12:531039 this.hoveredNodeInternal = node;
1040 if (this.hoveredNodeInternal) {
1041 this.hoveredNodeInternal.setHovered(true, Boolean(highlightInitiatorChain));
Tim van der Lippe1d6e57a2019-09-30 11:55:341042 }
Blink Reformat4c46d092018-04-07 15:32:371043 }
1044
Jan Scheffler17b8fb42021-08-12 12:28:381045 private dataGridMouseDown(event: Event): void {
Jan Schefflerd6c1d402021-02-26 16:56:381046 const mouseEvent = (event as MouseEvent);
Jack Franklin28577db2021-10-14 08:12:531047 if (!this.dataGrid.selectedNode && mouseEvent.button) {
Tim van der Lippe224a8622020-09-23 12:14:371048 mouseEvent.consume();
Tim van der Lippe1d6e57a2019-09-30 11:55:341049 }
Blink Reformat4c46d092018-04-07 15:32:371050 }
1051
Jan Scheffler17b8fb42021-08-12 12:28:381052 private updateSummaryBar(): void {
1053 this.hideRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371054
1055 let transferSize = 0;
Dan Beam87466b52018-12-01 18:41:201056 let resourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371057 let selectedNodeNumber = 0;
1058 let selectedTransferSize = 0;
Dan Beam87466b52018-12-01 18:41:201059 let selectedResourceSize = 0;
Blink Reformat4c46d092018-04-07 15:32:371060 let baseTime = -1;
1061 let maxTime = -1;
1062
1063 let nodeCount = 0;
Sigurd Schneidercf5b8302021-04-23 07:52:271064 for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
Tim van der Lippe224a8622020-09-23 12:14:371065 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341066 if (!node) {
Blink Reformat4c46d092018-04-07 15:32:371067 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341068 }
Blink Reformat4c46d092018-04-07 15:32:371069 nodeCount++;
1070 const requestTransferSize = request.transferSize;
1071 transferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201072 const requestResourceSize = request.resourceSize;
1073 resourceSize += requestResourceSize;
Tim van der Lippe224a8622020-09-23 12:14:371074 if (!filteredNetworkRequests.has(node)) {
Blink Reformat4c46d092018-04-07 15:32:371075 selectedNodeNumber++;
1076 selectedTransferSize += requestTransferSize;
Dan Beam87466b52018-12-01 18:41:201077 selectedResourceSize += requestResourceSize;
Blink Reformat4c46d092018-04-07 15:32:371078 }
Tim van der Lippe0ed1d2b2020-02-04 13:45:131079 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
Blink Reformat4c46d092018-04-07 15:32:371080 // TODO(allada) inspectedURL should be stored in PageLoad used instead of target so HAR requests can have an
1081 // inspected url.
1082 if (networkManager && request.url() === networkManager.target().inspectedURL() &&
Tim van der Lippe0ed1d2b2020-02-04 13:45:131083 request.resourceType() === Common.ResourceType.resourceTypes.Document &&
Wolfgang Beyer8fc262f2023-04-11 13:22:501084 networkManager.target().parentTarget()?.type() !== SDK.Target.Type.Frame) {
Blink Reformat4c46d092018-04-07 15:32:371085 baseTime = request.startTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341086 }
1087 if (request.endTime > maxTime) {
Blink Reformat4c46d092018-04-07 15:32:371088 maxTime = request.endTime;
Tim van der Lippe1d6e57a2019-09-30 11:55:341089 }
Blink Reformat4c46d092018-04-07 15:32:371090 }
1091
1092 if (!nodeCount) {
Jan Scheffler17b8fb42021-08-12 12:28:381093 this.showRecordingHint();
Blink Reformat4c46d092018-04-07 15:32:371094 return;
1095 }
1096
Wolfgang Beyer8fc262f2023-04-11 13:22:501097 this.summaryToolbarInternal.removeToolbarItems();
Jan Schefflerd6c1d402021-02-26 16:56:381098 const appendChunk = (chunk: string, title?: string): HTMLDivElement => {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131099 const toolbarText = new UI.Toolbar.ToolbarText(chunk);
Joey Arhara86c14e2019-03-12 03:20:501100 toolbarText.setTitle(title ? title : chunk);
Wolfgang Beyer8fc262f2023-04-11 13:22:501101 this.summaryToolbarInternal.appendToolbarItem(toolbarText);
Jan Schefflerd6c1d402021-02-26 16:56:381102 return toolbarText.element as HTMLDivElement;
Joey Arhara86c14e2019-03-12 03:20:501103 };
Blink Reformat4c46d092018-04-07 15:32:371104
1105 if (selectedNodeNumber !== nodeCount) {
Christy Chencac3f102021-02-03 10:07:551106 appendChunk(i18nString(UIStrings.sSRequests, {PH1: selectedNodeNumber, PH2: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501107 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501108 appendChunk(
Christy Chencac3f102021-02-03 10:07:551109 i18nString(UIStrings.sSTransferred, {
1110 PH1: Platform.NumberUtilities.bytesToString(selectedTransferSize),
Jan Schefflerd6c1d402021-02-26 16:56:381111 PH2: Platform.NumberUtilities.bytesToString(transferSize),
Christy Chencac3f102021-02-03 10:07:551112 }),
1113 i18nString(UIStrings.sBSBTransferredOverNetwork, {PH1: selectedTransferSize, PH2: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501114 this.summaryToolbarInternal.appendSeparator();
Joey Arhara86c14e2019-03-12 03:20:501115 appendChunk(
Christy Chencac3f102021-02-03 10:07:551116 i18nString(UIStrings.sSResources, {
1117 PH1: Platform.NumberUtilities.bytesToString(selectedResourceSize),
Jan Schefflerd6c1d402021-02-26 16:56:381118 PH2: Platform.NumberUtilities.bytesToString(resourceSize),
Christy Chencac3f102021-02-03 10:07:551119 }),
1120 i18nString(UIStrings.sBSBResourcesLoadedByThePage, {PH1: selectedResourceSize, PH2: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371121 } else {
Christy Chencac3f102021-02-03 10:07:551122 appendChunk(i18nString(UIStrings.sRequests, {PH1: nodeCount}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501123 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251124 appendChunk(
Christy Chencac3f102021-02-03 10:07:551125 i18nString(UIStrings.sTransferred, {PH1: Platform.NumberUtilities.bytesToString(transferSize)}),
1126 i18nString(UIStrings.sBTransferredOverNetwork, {PH1: transferSize}));
Wolfgang Beyer8fc262f2023-04-11 13:22:501127 this.summaryToolbarInternal.appendSeparator();
Changhao Han9ec3f6e2019-11-12 18:43:251128 appendChunk(
Christy Chencac3f102021-02-03 10:07:551129 i18nString(UIStrings.sResources, {PH1: Platform.NumberUtilities.bytesToString(resourceSize)}),
1130 i18nString(UIStrings.sBResourcesLoadedByThePage, {PH1: resourceSize}));
Blink Reformat4c46d092018-04-07 15:32:371131 }
Dan Beam87466b52018-12-01 18:41:201132
Blink Reformat4c46d092018-04-07 15:32:371133 if (baseTime !== -1 && maxTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501134 this.summaryToolbarInternal.appendSeparator();
Simon Zündca90a4d2021-07-22 07:25:581135 appendChunk(i18nString(UIStrings.finishS, {PH1: i18n.TimeUtilities.secondsToString(maxTime - baseTime)}));
Jack Franklin28577db2021-10-14 08:12:531136 if (this.mainRequestDOMContentLoadedTime !== -1 && this.mainRequestDOMContentLoadedTime > baseTime) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501137 this.summaryToolbarInternal.appendSeparator();
Christy Chencac3f102021-02-03 10:07:551138 const domContentLoadedText = i18nString(
1139 UIStrings.domcontentloadedS,
Jack Franklin28577db2021-10-14 08:12:531140 {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestDOMContentLoadedTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381141 appendChunk(domContentLoadedText).style.color = `var(${NetworkLogView.getDCLEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371142 }
Jack Franklin28577db2021-10-14 08:12:531143 if (this.mainRequestLoadTime !== -1) {
Wolfgang Beyer8fc262f2023-04-11 13:22:501144 this.summaryToolbarInternal.appendSeparator();
Jack Franklin28577db2021-10-14 08:12:531145 const loadText =
1146 i18nString(UIStrings.loadS, {PH1: i18n.TimeUtilities.secondsToString(this.mainRequestLoadTime - baseTime)});
Benedikt Meurer0149ea02023-06-01 07:33:381147 appendChunk(loadText).style.color = `var(${NetworkLogView.getLoadEventColor()})`;
Blink Reformat4c46d092018-04-07 15:32:371148 }
1149 }
Blink Reformat4c46d092018-04-07 15:32:371150 }
1151
Jan Schefflerd6c1d402021-02-26 16:56:381152 scheduleRefresh(): void {
Jack Franklin28577db2021-10-14 08:12:531153 if (this.needsRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371154 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341155 }
Blink Reformat4c46d092018-04-07 15:32:371156
Jack Franklin28577db2021-10-14 08:12:531157 this.needsRefresh = true;
Blink Reformat4c46d092018-04-07 15:32:371158
Danil Somsikovf3b437f2023-03-23 16:15:391159 if (this.isShowing()) {
Simon Siefke03d72372023-06-26 14:44:461160 void coordinator.write('NetworkLogView.render', this.refresh.bind(this));
Tim van der Lippe1d6e57a2019-09-30 11:55:341161 }
Blink Reformat4c46d092018-04-07 15:32:371162 }
1163
Jan Schefflerd6c1d402021-02-26 16:56:381164 addFilmStripFrames(times: number[]): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301165 this.columnsInternal.addEventDividers(times, 'network-frame-divider');
Blink Reformat4c46d092018-04-07 15:32:371166 }
1167
Jan Schefflerd6c1d402021-02-26 16:56:381168 selectFilmStripFrame(time: number): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301169 this.columnsInternal.selectFilmStripFrame(time);
Blink Reformat4c46d092018-04-07 15:32:371170 }
1171
Jan Schefflerd6c1d402021-02-26 16:56:381172 clearFilmStripFrame(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301173 this.columnsInternal.clearFilmStripFrame();
Blink Reformat4c46d092018-04-07 15:32:371174 }
1175
Jan Scheffler17b8fb42021-08-12 12:28:381176 private refreshIfNeeded(): void {
Jack Franklin28577db2021-10-14 08:12:531177 if (this.needsRefresh) {
Jan Scheffler17b8fb42021-08-12 12:28:381178 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341179 }
Blink Reformat4c46d092018-04-07 15:32:371180 }
1181
Jan Scheffler17b8fb42021-08-12 12:28:381182 private invalidateAllItems(deferUpdate?: boolean): void {
Danil Somsikov123c3ef2023-06-14 10:07:041183 this.staleRequests = new Set(Logs.NetworkLog.NetworkLog.instance().requests().filter(this.isInScope));
Tim van der Lippe1d6e57a2019-09-30 11:55:341184 if (deferUpdate) {
Blink Reformat4c46d092018-04-07 15:32:371185 this.scheduleRefresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341186 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381187 this.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341188 }
Blink Reformat4c46d092018-04-07 15:32:371189 }
1190
Jan Schefflerd6c1d402021-02-26 16:56:381191 timeCalculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531192 return this.timeCalculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371193 }
1194
Jan Schefflerd6c1d402021-02-26 16:56:381195 calculator(): NetworkTimeCalculator {
Jack Franklin28577db2021-10-14 08:12:531196 return this.calculatorInternal;
Blink Reformat4c46d092018-04-07 15:32:371197 }
1198
Jan Schefflerd6c1d402021-02-26 16:56:381199 setCalculator(x: NetworkTimeCalculator): void {
Jack Franklin28577db2021-10-14 08:12:531200 if (!x || this.calculatorInternal === x) {
Blink Reformat4c46d092018-04-07 15:32:371201 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341202 }
Blink Reformat4c46d092018-04-07 15:32:371203
Jack Franklin28577db2021-10-14 08:12:531204 if (this.calculatorInternal !== x) {
1205 this.calculatorInternal = x;
Danil Somsikov2a4c4e02022-10-07 12:31:301206 this.columnsInternal.setCalculator(this.calculatorInternal);
Blink Reformat4c46d092018-04-07 15:32:371207 }
Jack Franklin28577db2021-10-14 08:12:531208 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371209
Jack Franklin28577db2021-10-14 08:12:531210 if (this.calculatorInternal.startAtZero) {
Danil Somsikov2a4c4e02022-10-07 12:31:301211 this.columnsInternal.hideEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341212 } else {
Danil Somsikov2a4c4e02022-10-07 12:31:301213 this.columnsInternal.showEventDividers();
Tim van der Lippe1d6e57a2019-09-30 11:55:341214 }
Blink Reformat4c46d092018-04-07 15:32:371215
Jan Scheffler17b8fb42021-08-12 12:28:381216 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371217 }
1218
Jan Scheffler17b8fb42021-08-12 12:28:381219 private loadEventFired(
Simon Zünd1a930492021-07-30 08:22:271220 event: Common.EventTarget
1221 .EventTargetEvent<{resourceTreeModel: SDK.ResourceTreeModel.ResourceTreeModel, loadTime: number}>): void {
Jack Franklin28577db2021-10-14 08:12:531222 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371223 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341224 }
Blink Reformat4c46d092018-04-07 15:32:371225
Simon Zünd1a930492021-07-30 08:22:271226 const time = event.data.loadTime;
Blink Reformat4c46d092018-04-07 15:32:371227 if (time) {
Jack Franklin28577db2021-10-14 08:12:531228 this.mainRequestLoadTime = time;
Danil Somsikov2a4c4e02022-10-07 12:31:301229 this.columnsInternal.addEventDividers([time], 'network-load-divider');
Blink Reformat4c46d092018-04-07 15:32:371230 }
1231 }
1232
Jan Scheffler17b8fb42021-08-12 12:28:381233 private domContentLoadedEventFired(event: Common.EventTarget.EventTargetEvent<number>): void {
Jack Franklin28577db2021-10-14 08:12:531234 if (!this.recording) {
Blink Reformat4c46d092018-04-07 15:32:371235 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341236 }
Simon Zünd1a930492021-07-30 08:22:271237 const {data} = event;
Blink Reformat4c46d092018-04-07 15:32:371238 if (data) {
Jack Franklin28577db2021-10-14 08:12:531239 this.mainRequestDOMContentLoadedTime = data;
Danil Somsikov2a4c4e02022-10-07 12:31:301240 this.columnsInternal.addEventDividers([data], 'network-dcl-divider');
Blink Reformat4c46d092018-04-07 15:32:371241 }
1242 }
1243
Randolf Jungffd14242023-04-19 00:32:251244 override wasShown(): void {
Jan Scheffler17b8fb42021-08-12 12:28:381245 this.refreshIfNeeded();
Kriti Sapra2d85f882021-08-18 09:01:301246 this.registerCSSFiles([networkLogViewStyles]);
Danil Somsikov2a4c4e02022-10-07 12:31:301247 this.columnsInternal.wasShown();
Blink Reformat4c46d092018-04-07 15:32:371248 }
1249
Randolf Jungffd14242023-04-19 00:32:251250 override willHide(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301251 this.columnsInternal.willHide();
Blink Reformat4c46d092018-04-07 15:32:371252 }
1253
Randolf Jungffd14242023-04-19 00:32:251254 override onResize(): void {
Jack Franklin28577db2021-10-14 08:12:531255 this.rowHeightInternal = this.computeRowHeight();
Blink Reformat4c46d092018-04-07 15:32:371256 }
1257
Jan Schefflerd6c1d402021-02-26 16:56:381258 flatNodesList(): NetworkNode[] {
1259 const rootNode =
Jack Franklin28577db2021-10-14 08:12:531260 (this.dataGrid.rootNode() as
Jan Schefflerd6c1d402021-02-26 16:56:381261 DataGrid.ViewportDataGrid.ViewportDataGridNode<DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>);
1262 return rootNode.flatChildren() as NetworkNode[];
Blink Reformat4c46d092018-04-07 15:32:371263 }
1264
Jan Scheffler17b8fb42021-08-12 12:28:381265 private onDataGridFocus(): void {
Jack Franklin28577db2021-10-14 08:12:531266 if (this.dataGrid.element.matches(':focus-visible')) {
Jack Lynch13d4daa2020-07-30 03:57:351267 this.element.classList.add('grid-focused');
Jack Lynchf3766732020-07-23 01:37:381268 }
Brandon Goddard44934902020-03-25 16:03:181269 this.updateNodeBackground();
1270 }
1271
Jan Scheffler17b8fb42021-08-12 12:28:381272 private onDataGridBlur(): void {
Brandon Goddard44934902020-03-25 16:03:181273 this.element.classList.remove('grid-focused');
1274 this.updateNodeBackground();
1275 }
1276
Jan Schefflerd6c1d402021-02-26 16:56:381277 updateNodeBackground(): void {
Jack Franklin28577db2021-10-14 08:12:531278 if (this.dataGrid.selectedNode) {
1279 (this.dataGrid.selectedNode as NetworkNode).updateBackgroundColor();
Brandon Goddard88d885a2019-10-31 16:11:051280 }
1281 }
1282
Jan Schefflerd6c1d402021-02-26 16:56:381283 updateNodeSelectedClass(isSelected: boolean): void {
Brandon Goddard88d885a2019-10-31 16:11:051284 if (isSelected) {
1285 this.element.classList.remove('no-node-selected');
1286 } else {
1287 this.element.classList.add('no-node-selected');
1288 }
1289 }
1290
Jan Schefflerd6c1d402021-02-26 16:56:381291 stylesChanged(): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301292 this.columnsInternal.scheduleRefresh();
Blink Reformat4c46d092018-04-07 15:32:371293 }
1294
Jan Scheffler17b8fb42021-08-12 12:28:381295 private refresh(): void {
Jack Franklin28577db2021-10-14 08:12:531296 this.needsRefresh = false;
Blink Reformat4c46d092018-04-07 15:32:371297
Blink Reformat4c46d092018-04-07 15:32:371298 this.removeAllNodeHighlights();
1299
Jack Franklin28577db2021-10-14 08:12:531300 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestLoadTime);
1301 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestLoadTime);
1302 this.timeCalculatorInternal.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
1303 this.durationCalculator.updateBoundariesForEventTime(this.mainRequestDOMContentLoadedTime);
Blink Reformat4c46d092018-04-07 15:32:371304
Jan Schefflerd6c1d402021-02-26 16:56:381305 const nodesToInsert = new Map<NetworkNode, NetworkNode>();
1306 const nodesToRefresh: NetworkNode[] = [];
Blink Reformat4c46d092018-04-07 15:32:371307
Jan Schefflerd6c1d402021-02-26 16:56:381308 const staleNodes = new Set<NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:371309
Jack Franklin28577db2021-10-14 08:12:531310 // While creating nodes it may add more entries into staleRequests because redirect request nodes update the parent
Blink Reformat4c46d092018-04-07 15:32:371311 // node so we loop until we have no more stale requests.
Jack Franklin28577db2021-10-14 08:12:531312 while (this.staleRequests.size) {
1313 const request = this.staleRequests.values().next().value;
1314 this.staleRequests.delete(request);
Tim van der Lippe224a8622020-09-23 12:14:371315 let node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341316 if (!node) {
Jan Scheffler17b8fb42021-08-12 12:28:381317 node = this.createNodeForRequest(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341318 }
Blink Reformat4c46d092018-04-07 15:32:371319 staleNodes.add(node);
1320 }
1321
1322 for (const node of staleNodes) {
Jan Scheffler17b8fb42021-08-12 12:28:381323 const isFilteredOut = !this.applyFilter(node);
Jack Franklin28577db2021-10-14 08:12:531324 if (isFilteredOut && node === this.hoveredNodeInternal) {
Jan Scheffler17b8fb42021-08-12 12:28:381325 this.setHoveredNode(null);
Tim van der Lippe1d6e57a2019-09-30 11:55:341326 }
Blink Reformat4c46d092018-04-07 15:32:371327
Tim van der Lippe1d6e57a2019-09-30 11:55:341328 if (!isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371329 nodesToRefresh.push(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341330 }
Blink Reformat4c46d092018-04-07 15:32:371331 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531332 this.timeCalculatorInternal.updateBoundaries(request);
1333 this.durationCalculator.updateBoundaries(request);
Jan Scheffler17b8fb42021-08-12 12:28:381334 const newParent = this.parentNodeForInsert(node);
Tim van der Lippe224a8622020-09-23 12:14:371335 const wasAlreadyFiltered = filteredNetworkRequests.has(node);
1336 if (wasAlreadyFiltered === isFilteredOut && node.parent === newParent) {
Blink Reformat4c46d092018-04-07 15:32:371337 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341338 }
Tim van der Lippe224a8622020-09-23 12:14:371339 if (isFilteredOut) {
1340 filteredNetworkRequests.add(node);
1341 } else {
1342 filteredNetworkRequests.delete(node);
1343 }
Blink Reformat4c46d092018-04-07 15:32:371344 const removeFromParent = node.parent && (isFilteredOut || node.parent !== newParent);
1345 if (removeFromParent) {
Jan Schefflerd6c1d402021-02-26 16:56:381346 let parent: NetworkNode|
1347 (DataGrid.DataGrid.DataGridNode<DataGrid.ViewportDataGrid.ViewportDataGridNode<
1348 DataGrid.SortableDataGrid.SortableDataGridNode<NetworkNode>>>|
1349 null) = node.parent;
Andres Olivares03d9c752020-10-01 15:08:111350 if (!parent) {
1351 continue;
1352 }
Blink Reformat4c46d092018-04-07 15:32:371353 parent.removeChild(node);
1354 while (parent && !parent.hasChildren() && parent.dataGrid && parent.dataGrid.rootNode() !== parent) {
Jan Schefflerd6c1d402021-02-26 16:56:381355 const grandparent = (parent.parent as NetworkNode);
Blink Reformat4c46d092018-04-07 15:32:371356 grandparent.removeChild(parent);
1357 parent = grandparent;
1358 }
1359 }
1360
Tim van der Lippe1d6e57a2019-09-30 11:55:341361 if (!newParent || isFilteredOut) {
Blink Reformat4c46d092018-04-07 15:32:371362 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:341363 }
Blink Reformat4c46d092018-04-07 15:32:371364
1365 if (!newParent.dataGrid && !nodesToInsert.has(newParent)) {
Jack Franklin28577db2021-10-14 08:12:531366 nodesToInsert.set(newParent, (this.dataGrid.rootNode() as NetworkNode));
Blink Reformat4c46d092018-04-07 15:32:371367 nodesToRefresh.push(newParent);
1368 }
1369 nodesToInsert.set(node, newParent);
1370 }
1371
Tim van der Lippe1d6e57a2019-09-30 11:55:341372 for (const node of nodesToInsert.keys()) {
Jan Schefflerd6c1d402021-02-26 16:56:381373 (nodesToInsert.get(node) as NetworkNode).appendChild(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341374 }
Blink Reformat4c46d092018-04-07 15:32:371375
Tim van der Lippe1d6e57a2019-09-30 11:55:341376 for (const node of nodesToRefresh) {
Blink Reformat4c46d092018-04-07 15:32:371377 node.refresh();
Tim van der Lippe1d6e57a2019-09-30 11:55:341378 }
Blink Reformat4c46d092018-04-07 15:32:371379
Jan Scheffler17b8fb42021-08-12 12:28:381380 this.updateSummaryBar();
Blink Reformat4c46d092018-04-07 15:32:371381
Tim van der Lippe1d6e57a2019-09-30 11:55:341382 if (nodesToInsert.size) {
Danil Somsikov2a4c4e02022-10-07 12:31:301383 this.columnsInternal.sortByCurrentColumn();
Tim van der Lippe1d6e57a2019-09-30 11:55:341384 }
Blink Reformat4c46d092018-04-07 15:32:371385
Jack Franklin28577db2021-10-14 08:12:531386 this.dataGrid.updateInstantly();
Jan Scheffler17b8fb42021-08-12 12:28:381387 this.didRefreshForTest();
Blink Reformat4c46d092018-04-07 15:32:371388 }
1389
Jan Scheffler17b8fb42021-08-12 12:28:381390 private didRefreshForTest(): void {
Blink Reformat4c46d092018-04-07 15:32:371391 }
1392
Jan Scheffler17b8fb42021-08-12 12:28:381393 private parentNodeForInsert(node: NetworkRequestNode): NetworkNode|null {
Jack Franklin28577db2021-10-14 08:12:531394 if (!this.activeGroupLookup) {
1395 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341396 }
Blink Reformat4c46d092018-04-07 15:32:371397
Jack Franklin28577db2021-10-14 08:12:531398 const groupNode = this.activeGroupLookup.groupNodeForRequest(node.request());
Tim van der Lippe1d6e57a2019-09-30 11:55:341399 if (!groupNode) {
Jack Franklin28577db2021-10-14 08:12:531400 return this.dataGrid.rootNode() as NetworkNode;
Tim van der Lippe1d6e57a2019-09-30 11:55:341401 }
Blink Reformat4c46d092018-04-07 15:32:371402 return groupNode;
1403 }
1404
Jan Scheffler17b8fb42021-08-12 12:28:381405 private reset(): void {
Simon Zünd98419832020-03-12 06:18:151406 this.dispatchEventToListeners(Events.RequestActivated, {showPanel: false});
Blink Reformat4c46d092018-04-07 15:32:371407
Jan Scheffler17b8fb42021-08-12 12:28:381408 this.setHoveredNode(null);
Danil Somsikov2a4c4e02022-10-07 12:31:301409 this.columnsInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371410
Jack Franklin28577db2021-10-14 08:12:531411 this.timeFilter = null;
1412 this.calculatorInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371413
Jack Franklin28577db2021-10-14 08:12:531414 this.timeCalculatorInternal.setWindow(null);
1415 this.linkifierInternal.reset();
Blink Reformat4c46d092018-04-07 15:32:371416
Jack Franklin28577db2021-10-14 08:12:531417 if (this.activeGroupLookup) {
1418 this.activeGroupLookup.reset();
Tim van der Lippe1d6e57a2019-09-30 11:55:341419 }
Jack Franklin28577db2021-10-14 08:12:531420 this.staleRequests.clear();
Jan Scheffler17b8fb42021-08-12 12:28:381421 this.resetSuggestionBuilder();
Blink Reformat4c46d092018-04-07 15:32:371422
Jack Franklin28577db2021-10-14 08:12:531423 this.mainRequestLoadTime = -1;
1424 this.mainRequestDOMContentLoadedTime = -1;
Blink Reformat4c46d092018-04-07 15:32:371425
Jack Franklin28577db2021-10-14 08:12:531426 this.dataGrid.rootNode().removeChildren();
Jan Scheffler17b8fb42021-08-12 12:28:381427 this.updateSummaryBar();
Jack Franklin28577db2021-10-14 08:12:531428 this.dataGrid.setStickToBottom(true);
Blink Reformat4c46d092018-04-07 15:32:371429 this.scheduleRefresh();
1430 }
1431
Jan Schefflerd6c1d402021-02-26 16:56:381432 setTextFilterValue(filterString: string): void {
Jack Franklin28577db2021-10-14 08:12:531433 this.textFilterUI.setValue(filterString);
1434 this.dataURLFilterUI.setChecked(false);
Wolfgang Beyer1cb5e772023-07-17 10:34:041435 this.onlyBlockedResponseCookiesFilterUI.setChecked(false);
Jack Franklin28577db2021-10-14 08:12:531436 this.onlyBlockedRequestsUI.setChecked(false);
1437 this.resourceCategoryFilterUI.reset();
Blink Reformat4c46d092018-04-07 15:32:371438 }
1439
Jan Scheffler17b8fb42021-08-12 12:28:381440 private createNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode {
Tim van der Lippe119690c2020-01-13 12:31:301441 const node = new NetworkRequestNode(this, request);
Tim van der Lippe224a8622020-09-23 12:14:371442 networkRequestToNode.set(request, node);
1443 filteredNetworkRequests.add(node);
Blink Reformat4c46d092018-04-07 15:32:371444
Tim van der Lippe1d6e57a2019-09-30 11:55:341445 for (let redirect = request.redirectSource(); redirect; redirect = redirect.redirectSource()) {
Jan Scheffler17b8fb42021-08-12 12:28:381446 this.refreshRequest(redirect);
Tim van der Lippe1d6e57a2019-09-30 11:55:341447 }
Blink Reformat4c46d092018-04-07 15:32:371448 return node;
1449 }
1450
Danil Somsikov123c3ef2023-06-14 10:07:041451 private isInScope(request: SDK.NetworkRequest.NetworkRequest): boolean {
1452 const networkManager = SDK.NetworkManager.NetworkManager.forRequest(request);
1453 return !networkManager || SDK.TargetManager.TargetManager.instance().isInScope(networkManager);
1454 }
1455
Kateryna Prokopenko460f5492021-08-27 08:20:281456 private onRequestUpdated(event: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void {
1457 const request = event.data;
Danil Somsikov123c3ef2023-06-14 10:07:041458 if (this.isInScope(request)) {
Danil Somsikova09c4de2023-03-27 10:35:251459 this.refreshRequest(request);
1460 }
Blink Reformat4c46d092018-04-07 15:32:371461 }
1462
Jan Scheffler17b8fb42021-08-12 12:28:381463 private refreshRequest(request: SDK.NetworkRequest.NetworkRequest): void {
1464 NetworkLogView.subdomains(request.domain)
Sigurd Schneider30722582021-06-16 06:54:161465 .forEach(
Jack Franklin28577db2021-10-14 08:12:531466 this.suggestionBuilder.addItem.bind(this.suggestionBuilder, NetworkForward.UIFilter.FilterType.Domain));
1467 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Method, request.requestMethod);
1468 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MimeType, request.mimeType);
1469 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Scheme, String(request.scheme));
1470 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.StatusCode, String(request.statusCode));
1471 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResourceType, request.resourceType().name());
1472 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.Url, request.securityOrigin());
Blink Reformat4c46d092018-04-07 15:32:371473
1474 const priority = request.priority();
1475 if (priority) {
Jack Franklin28577db2021-10-14 08:12:531476 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161477 NetworkForward.UIFilter.FilterType.Priority, PerfUI.NetworkPriorities.uiLabelForNetworkPriority(priority));
Blink Reformat4c46d092018-04-07 15:32:371478 }
1479
1480 if (request.mixedContentType !== Protocol.Security.MixedContentType.None) {
Jack Franklin28577db2021-10-14 08:12:531481 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161482 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.All);
Blink Reformat4c46d092018-04-07 15:32:371483 }
1484
1485 if (request.mixedContentType === Protocol.Security.MixedContentType.OptionallyBlockable) {
Jack Franklin28577db2021-10-14 08:12:531486 this.suggestionBuilder.addItem(
Sigurd Schneider30722582021-06-16 06:54:161487 NetworkForward.UIFilter.FilterType.MixedContent, NetworkForward.UIFilter.MixedContentFilterValues.Displayed);
Blink Reformat4c46d092018-04-07 15:32:371488 }
1489
1490 if (request.mixedContentType === Protocol.Security.MixedContentType.Blockable) {
Sigurd Schneider30722582021-06-16 06:54:161491 const suggestion = request.wasBlocked() ? NetworkForward.UIFilter.MixedContentFilterValues.Blocked :
1492 NetworkForward.UIFilter.MixedContentFilterValues.BlockOverridden;
Jack Franklin28577db2021-10-14 08:12:531493 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.MixedContent, suggestion);
Blink Reformat4c46d092018-04-07 15:32:371494 }
1495
1496 const responseHeaders = request.responseHeaders;
Simon Zünd6dedde52021-08-03 09:04:511497 for (const responseHeader of responseHeaders) {
Jack Franklin28577db2021-10-14 08:12:531498 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.HasResponseHeader, responseHeader.name);
Simon Zünd6dedde52021-08-03 09:04:511499 if (responseHeader.name === 'Set-Cookie') {
Jack Franklin28577db2021-10-14 08:12:531500 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie);
Simon Zünd6dedde52021-08-03 09:04:511501 }
Tim van der Lippe1d6e57a2019-09-30 11:55:341502 }
Jan Scheffler341eea52019-12-12 09:08:411503
1504 for (const cookie of request.responseCookies) {
Jack Franklin28577db2021-10-14 08:12:531505 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieDomain, cookie.domain());
1506 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieName, cookie.name());
1507 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.SetCookieValue, cookie.value());
Blink Reformat4c46d092018-04-07 15:32:371508 }
1509
Jan Scheffler341eea52019-12-12 09:08:411510 for (const cookie of request.allCookiesIncludingBlockedOnes()) {
Jack Franklin28577db2021-10-14 08:12:531511 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieDomain, cookie.domain());
1512 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieName, cookie.name());
1513 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookiePath, cookie.path());
1514 this.suggestionBuilder.addItem(NetworkForward.UIFilter.FilterType.CookieValue, cookie.value());
Jan Scheffler341eea52019-12-12 09:08:411515 }
1516
Jack Franklin28577db2021-10-14 08:12:531517 this.staleRequests.add(request);
Blink Reformat4c46d092018-04-07 15:32:371518 this.scheduleRefresh();
1519 }
1520
Jan Schefflerd6c1d402021-02-26 16:56:381521 rowHeight(): number {
Jack Franklin28577db2021-10-14 08:12:531522 return this.rowHeightInternal;
Blink Reformat4c46d092018-04-07 15:32:371523 }
1524
Jan Schefflerd6c1d402021-02-26 16:56:381525 switchViewMode(gridMode: boolean): void {
Danil Somsikov2a4c4e02022-10-07 12:31:301526 this.columnsInternal.switchViewMode(gridMode);
Blink Reformat4c46d092018-04-07 15:32:371527 }
1528
Jan Schefflerd6c1d402021-02-26 16:56:381529 handleContextMenuForRequest(contextMenu: UI.ContextMenu.ContextMenu, request: SDK.NetworkRequest.NetworkRequest):
1530 void {
Blink Reformat4c46d092018-04-07 15:32:371531 contextMenu.appendApplicableItems(request);
Christy Chencac3f102021-02-03 10:07:551532 let copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371533 const footerSection = copyMenu.footerSection();
1534 if (request) {
1535 copyMenu.defaultSection().appendItem(
Tim van der Lippe0ed1d2b2020-02-04 13:45:131536 UI.UIUtils.copyLinkAddressLabel(),
1537 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(
1538 Host.InspectorFrontendHost.InspectorFrontendHostInstance, request.contentURL()));
Blink Reformat4c46d092018-04-07 15:32:371539 if (request.requestHeadersText()) {
1540 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381541 i18nString(UIStrings.copyRequestHeaders), NetworkLogView.copyRequestHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371542 }
1543
1544 if (request.responseHeadersText) {
1545 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381546 i18nString(UIStrings.copyResponseHeaders), NetworkLogView.copyResponseHeaders.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371547 }
1548
1549 if (request.finished) {
1550 copyMenu.defaultSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381551 i18nString(UIStrings.copyResponse), NetworkLogView.copyResponse.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371552 }
1553
Tim van der Lippeb4faf5a2020-11-06 15:02:021554 const initiator = request.initiator();
1555
1556 if (initiator) {
1557 const stack = initiator.stack;
1558 if (stack) {
1559 // We proactively compute the stacktrace text, as we can't determine whether the stacktrace
Jack Franklin28577db2021-10-14 08:12:531560 // has any context solely based on the top frame. Sometimes, the top frame does not have
Tim van der Lippeb4faf5a2020-11-06 15:02:021561 // any callFrames, but its parent frames do.
1562 const stackTraceText = computeStackTraceText(stack);
1563 if (stackTraceText !== '') {
Christy Chencac3f102021-02-03 10:07:551564 copyMenu.defaultSection().appendItem(i18nString(UIStrings.copyStacktrace), () => {
Tim van der Lippeb4faf5a2020-11-06 15:02:021565 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(stackTraceText);
1566 });
1567 }
1568 }
1569 }
1570
Harley Libcf41f92018-09-10 18:01:131571 const disableIfBlob = request.isBlobRequest();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131572 if (Host.Platform.isWin()) {
Blink Reformat4c46d092018-04-07 15:32:371573 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381574 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371575 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461576 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1577 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291578 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461579 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1580 disableIfBlob);
Blink Reformat4c46d092018-04-07 15:32:371581 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381582 i18nString(UIStrings.copyAsCurlCmd), this.copyCurlCommand.bind(this, request, 'win'), disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131583 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381584 i18nString(UIStrings.copyAsCurlBash), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
1585 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461586 footerSection.appendItem(
1587 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1588 footerSection.appendItem(
1589 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381590 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlCmd), this.copyAllCurlCommand.bind(this, 'win'));
1591 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurlBash), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371592 } else {
Harley Libcf41f92018-09-10 18:01:131593 footerSection.appendItem(
Danil Somsikova4b089c2021-11-09 14:32:091594 i18nString(UIStrings.copyAsPowershell), this.copyPowerShellCommand.bind(this, request), disableIfBlob);
1595 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461596 i18nString(UIStrings.copyAsFetch), this.copyFetchCall.bind(this, request, FetchStyle.Browser),
1597 disableIfBlob);
Jan Scheffler7c50d1f2019-12-17 13:33:291598 footerSection.appendItem(
Danil Somsikov59f4c612021-09-08 10:58:461599 i18nString(UIStrings.copyAsNodejsFetch), this.copyFetchCall.bind(this, request, FetchStyle.NodeJs),
1600 disableIfBlob);
Harley Libcf41f92018-09-10 18:01:131601 footerSection.appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381602 i18nString(UIStrings.copyAsCurl), this.copyCurlCommand.bind(this, request, 'unix'), disableIfBlob);
Danil Somsikova4b089c2021-11-09 14:32:091603 footerSection.appendItem(i18nString(UIStrings.copyAllAsPowershell), this.copyAllPowerShellCommand.bind(this));
Danil Somsikov59f4c612021-09-08 10:58:461604 footerSection.appendItem(
1605 i18nString(UIStrings.copyAllAsFetch), this.copyAllFetchCall.bind(this, FetchStyle.Browser));
1606 footerSection.appendItem(
1607 i18nString(UIStrings.copyAllAsNodejsFetch), this.copyAllFetchCall.bind(this, FetchStyle.NodeJs));
Jan Scheffler17b8fb42021-08-12 12:28:381608 footerSection.appendItem(i18nString(UIStrings.copyAllAsCurl), this.copyAllCurlCommand.bind(this, 'unix'));
Blink Reformat4c46d092018-04-07 15:32:371609 }
1610 } else {
Christy Chencac3f102021-02-03 10:07:551611 copyMenu = contextMenu.clipboardSection().appendSubMenuItem(i18nString(UIStrings.copy));
Blink Reformat4c46d092018-04-07 15:32:371612 }
Jan Scheffler17b8fb42021-08-12 12:28:381613 footerSection.appendItem(i18nString(UIStrings.copyAllAsHar), this.copyAll.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371614
Christy Chencac3f102021-02-03 10:07:551615 contextMenu.saveSection().appendItem(i18nString(UIStrings.saveAllAsHarWithContent), this.exportAll.bind(this));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291616 if (Root.Runtime.experiments.isEnabled(Root.Runtime.ExperimentName.HEADER_OVERRIDES)) {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411617 contextMenu.saveSection().appendItem(
1618 i18nString(UIStrings.overrideHeaders), this.#handleCreateResponseHeaderOverrideClick.bind(this, request));
Wolfgang Beyer6a4cbb42022-05-16 13:02:291619 }
Wolfgang Beyerc6fe2be2022-11-03 15:39:411620
Jan Scheffler17b8fb42021-08-12 12:28:381621 contextMenu.editSection().appendItem(i18nString(UIStrings.clearBrowserCache), this.clearBrowserCache.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371622 contextMenu.editSection().appendItem(
Jan Scheffler17b8fb42021-08-12 12:28:381623 i18nString(UIStrings.clearBrowserCookies), this.clearBrowserCookies.bind(this));
Blink Reformat4c46d092018-04-07 15:32:371624
1625 if (request) {
1626 const maxBlockedURLLength = 20;
Tim van der Lippecd0bb372020-05-01 13:53:211627 const manager = SDK.NetworkManager.MultitargetNetworkManager.instance();
Blink Reformat4c46d092018-04-07 15:32:371628 let patterns = manager.blockedPatterns();
1629
Jan Schefflerd6c1d402021-02-26 16:56:381630 function addBlockedURL(url: string): void {
Kateryna Prokopenkoa2d72a52022-03-24 16:04:201631 patterns.push({enabled: true, url: url as Platform.DevToolsPath.UrlString});
Tim van der Lippeffa78622019-09-16 12:07:121632 manager.setBlockedPatterns(patterns);
1633 manager.setBlockingEnabled(true);
Tim van der Lippe2d9a95c2022-01-04 15:18:031634 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121635 }
1636
Jan Schefflerd6c1d402021-02-26 16:56:381637 function removeBlockedURL(url: string): void {
Tim van der Lippeffa78622019-09-16 12:07:121638 patterns = patterns.filter(pattern => pattern.url !== url);
1639 manager.setBlockedPatterns(patterns);
Tim van der Lippe2d9a95c2022-01-04 15:18:031640 void UI.ViewManager.ViewManager.instance().showView('network.blocked-urls');
Tim van der Lippeffa78622019-09-16 12:07:121641 }
1642
Blink Reformat4c46d092018-04-07 15:32:371643 const urlWithoutScheme = request.parsedURL.urlWithoutScheme();
1644 if (urlWithoutScheme && !patterns.find(pattern => pattern.url === urlWithoutScheme)) {
1645 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551646 i18nString(UIStrings.blockRequestUrl), addBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371647 } else if (urlWithoutScheme) {
Tim van der Lippe213266c2021-01-18 15:48:311648 const croppedURL = Platform.StringUtilities.trimMiddle(urlWithoutScheme, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371649 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551650 i18nString(UIStrings.unblockS, {PH1: croppedURL}), removeBlockedURL.bind(null, urlWithoutScheme));
Blink Reformat4c46d092018-04-07 15:32:371651 }
1652
1653 const domain = request.parsedURL.domain();
1654 if (domain && !patterns.find(pattern => pattern.url === domain)) {
1655 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551656 i18nString(UIStrings.blockRequestDomain), addBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371657 } else if (domain) {
Tim van der Lippe213266c2021-01-18 15:48:311658 const croppedDomain = Platform.StringUtilities.trimMiddle(domain, maxBlockedURLLength);
Blink Reformat4c46d092018-04-07 15:32:371659 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551660 i18nString(UIStrings.unblockS, {PH1: croppedDomain}), removeBlockedURL.bind(null, domain));
Blink Reformat4c46d092018-04-07 15:32:371661 }
1662
Tim van der Lippe0ed1d2b2020-02-04 13:45:131663 if (SDK.NetworkManager.NetworkManager.canReplayRequest(request)) {
Blink Reformat4c46d092018-04-07 15:32:371664 contextMenu.debugSection().appendItem(
Christy Chencac3f102021-02-03 10:07:551665 i18nString(UIStrings.replayXhr), SDK.NetworkManager.NetworkManager.replayRequest.bind(null, request));
Blink Reformat4c46d092018-04-07 15:32:371666 }
Blink Reformat4c46d092018-04-07 15:32:371667 }
1668 }
1669
Jan Scheffler17b8fb42021-08-12 12:28:381670 private harRequests(): SDK.NetworkRequest.NetworkRequest[] {
Sigurd Schneidercf5b8302021-04-23 07:52:271671 return Logs.NetworkLog.NetworkLog.instance()
1672 .requests()
Sigurd Schneider576ca9a2021-07-16 05:58:041673 .filter(NetworkLogView.getHTTPRequestsFilter)
Sigurd Schneidercf5b8302021-04-23 07:52:271674 .filter(request => {
1675 return request.finished ||
1676 (request.resourceType() === Common.ResourceType.resourceTypes.WebSocket && request.responseReceivedTime);
1677 });
Blink Reformat4c46d092018-04-07 15:32:371678 }
1679
Jan Scheffler17b8fb42021-08-12 12:28:381680 private async copyAll(): Promise<void> {
1681 const harArchive = {log: await HAR.Log.Log.build(this.harRequests())};
Tim van der Lippe0ed1d2b2020-02-04 13:45:131682 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(JSON.stringify(harArchive, null, 2));
Blink Reformat4c46d092018-04-07 15:32:371683 }
1684
Jan Scheffler17b8fb42021-08-12 12:28:381685 private async copyCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<void> {
Wolfgang Beyer26b7e892022-08-16 11:02:351686 const command = await NetworkLogView.generateCurlCommand(request, platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131687 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371688 }
1689
Jan Scheffler17b8fb42021-08-12 12:28:381690 private async copyAllCurlCommand(platform: string): Promise<void> {
1691 const commands = await this.generateAllCurlCommand(Logs.NetworkLog.NetworkLog.instance().requests(), platform);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131692 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371693 }
1694
Danil Somsikov59f4c612021-09-08 10:58:461695 private async copyFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<void> {
1696 const command = await this.generateFetchCall(request, style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131697 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371698 }
1699
Danil Somsikov59f4c612021-09-08 10:58:461700 private async copyAllFetchCall(style: FetchStyle): Promise<void> {
1701 const commands = await this.generateAllFetchCall(Logs.NetworkLog.NetworkLog.instance().requests(), style);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131702 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371703 }
1704
Jan Scheffler17b8fb42021-08-12 12:28:381705 private async copyPowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
1706 const command = await this.generatePowerShellCommand(request);
Tim van der Lippe0ed1d2b2020-02-04 13:45:131707 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(command);
Blink Reformat4c46d092018-04-07 15:32:371708 }
1709
Jan Scheffler17b8fb42021-08-12 12:28:381710 private async copyAllPowerShellCommand(): Promise<void> {
1711 const commands = await this.generateAllPowerShellCommand(Logs.NetworkLog.NetworkLog.instance().requests());
Tim van der Lippe0ed1d2b2020-02-04 13:45:131712 Host.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(commands);
Blink Reformat4c46d092018-04-07 15:32:371713 }
1714
Jan Schefflerd6c1d402021-02-26 16:56:381715 async exportAll(): Promise<void> {
Danil Somsikov62bc5782023-03-21 10:48:501716 const mainTarget = SDK.TargetManager.TargetManager.instance().scopeTarget();
Tim van der Lippe224a8622020-09-23 12:14:371717 if (!mainTarget) {
1718 return;
1719 }
1720 const url = mainTarget.inspectedURL();
Tim van der Lippe0ed1d2b2020-02-04 13:45:131721 const parsedURL = Common.ParsedURL.ParsedURL.fromString(url);
Kateryna Prokopenko380fdfa2022-03-16 16:39:321722 const filename = (parsedURL ? parsedURL.host : 'network-log') as Platform.DevToolsPath.RawPathString;
Tim van der Lippe0ed1d2b2020-02-04 13:45:131723 const stream = new Bindings.FileUtils.FileOutputStream();
Blink Reformat4c46d092018-04-07 15:32:371724
Kateryna Prokopenko380fdfa2022-03-16 16:39:321725 if (!await stream.open(Common.ParsedURL.ParsedURL.concatenate(filename, '.har'))) {
Blink Reformat4c46d092018-04-07 15:32:371726 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:341727 }
Blink Reformat4c46d092018-04-07 15:32:371728
Tim van der Lippe0ed1d2b2020-02-04 13:45:131729 const progressIndicator = new UI.ProgressIndicator.ProgressIndicator();
Jack Franklin28577db2021-10-14 08:12:531730 this.progressBarContainer.appendChild(progressIndicator.element);
Jan Scheffler17b8fb42021-08-12 12:28:381731 await HAR.Writer.Writer.write(stream, this.harRequests(), progressIndicator);
Blink Reformat4c46d092018-04-07 15:32:371732 progressIndicator.done();
Tim van der Lippe2d9a95c2022-01-04 15:18:031733 void stream.close();
Blink Reformat4c46d092018-04-07 15:32:371734 }
1735
Wolfgang Beyer5b433b02022-05-12 13:57:371736 async #handleCreateResponseHeaderOverrideClick(request: SDK.NetworkRequest.NetworkRequest): Promise<void> {
Wolfgang Beyerc6fe2be2022-11-03 15:39:411737 const requestLocation =
1738 NetworkForward.UIRequestLocation.UIRequestLocation.responseHeaderMatch(request, {name: '', value: ''});
Wolfgang Beyerc8f09372022-09-19 14:27:271739 const networkPersistanceManager = Persistence.NetworkPersistenceManager.NetworkPersistenceManager.instance();
1740 if (networkPersistanceManager.project()) {
Wolfgang Beyer1e62b692022-11-07 13:52:081741 Common.Settings.Settings.instance().moduleSetting('persistenceNetworkOverridesEnabled').set(true);
Wolfgang Beyerc8f09372022-09-19 14:27:271742 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411743 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371744 } else { // If folder for local overrides has not been provided yet
1745 UI.InspectorView.InspectorView.instance().displaySelectOverrideFolderInfobar(async(): Promise<void> => {
1746 await Sources.SourcesNavigator.OverridesNavigatorView.instance().setupNewWorkspace();
Wolfgang Beyerc8f09372022-09-19 14:27:271747 await networkPersistanceManager.getOrCreateHeadersUISourceCodeFromUrl(request.url());
Wolfgang Beyerc6fe2be2022-11-03 15:39:411748 await Common.Revealer.reveal(requestLocation);
Wolfgang Beyer5b433b02022-05-12 13:57:371749 });
1750 }
1751 }
1752
Jan Scheffler17b8fb42021-08-12 12:28:381753 private clearBrowserCache(): void {
Christy Chencac3f102021-02-03 10:07:551754 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowser))) {
Tim van der Lippecd0bb372020-05-01 13:53:211755 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCache();
Tim van der Lippe1d6e57a2019-09-30 11:55:341756 }
Blink Reformat4c46d092018-04-07 15:32:371757 }
1758
Jan Scheffler17b8fb42021-08-12 12:28:381759 private clearBrowserCookies(): void {
Christy Chencac3f102021-02-03 10:07:551760 if (confirm(i18nString(UIStrings.areYouSureYouWantToClearBrowserCookies))) {
Tim van der Lippecd0bb372020-05-01 13:53:211761 SDK.NetworkManager.MultitargetNetworkManager.instance().clearBrowserCookies();
Tim van der Lippe1d6e57a2019-09-30 11:55:341762 }
Blink Reformat4c46d092018-04-07 15:32:371763 }
1764
Jan Scheffler17b8fb42021-08-12 12:28:381765 private removeAllHighlights(): void {
Blink Reformat4c46d092018-04-07 15:32:371766 this.removeAllNodeHighlights();
Blink Reformat4c46d092018-04-07 15:32:371767 }
1768
Jan Scheffler17b8fb42021-08-12 12:28:381769 private applyFilter(node: NetworkRequestNode): boolean {
Blink Reformat4c46d092018-04-07 15:32:371770 const request = node.request();
Jack Franklin28577db2021-10-14 08:12:531771 if (this.timeFilter && !this.timeFilter(request)) {
Blink Reformat4c46d092018-04-07 15:32:371772 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341773 }
Christy Chen1825c612021-02-25 10:28:441774 const categoryName = request.resourceType().category().title();
Jack Franklin28577db2021-10-14 08:12:531775 if (!this.resourceCategoryFilterUI.accept(categoryName)) {
Blink Reformat4c46d092018-04-07 15:32:371776 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341777 }
Jack Franklin28577db2021-10-14 08:12:531778 if (this.dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL())) {
Blink Reformat4c46d092018-04-07 15:32:371779 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341780 }
Wolfgang Beyer1cb5e772023-07-17 10:34:041781 if (this.onlyBlockedResponseCookiesFilterUI.checked() && !request.blockedResponseCookies().length) {
Jan Scheffler1ae7c9e2019-12-03 15:48:371782 return false;
1783 }
Jack Franklin28577db2021-10-14 08:12:531784 if (this.onlyBlockedRequestsUI.checked() && !request.wasBlocked() && !request.corsErrorStatus()) {
Sigurd Schneidera2afe0b2020-03-03 15:27:131785 return false;
1786 }
Jack Franklin28577db2021-10-14 08:12:531787 if (this.onlyThirdPartyFilterUI.checked() && request.isSameSite()) {
Danil Somsikov721956a2021-07-07 08:17:271788 return false;
1789 }
Jack Franklin28577db2021-10-14 08:12:531790 for (let i = 0; i < this.filters.length; ++i) {
1791 if (!this.filters[i](request)) {
Blink Reformat4c46d092018-04-07 15:32:371792 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:341793 }
Blink Reformat4c46d092018-04-07 15:32:371794 }
1795 return true;
1796 }
1797
Danil Somsikov7a392fb2021-09-13 11:09:461798 private isValidUrl(url: string): boolean {
1799 try {
1800 new URL(url);
1801 return true;
1802 } catch (e) {
1803 return false;
1804 }
1805 }
1806
Jan Scheffler17b8fb42021-08-12 12:28:381807 private parseFilterQuery(query: string, invert: boolean): void {
Jack Franklin28577db2021-10-14 08:12:531808 // A query string can have multiple filters, some of them regular
1809 // expressions, some not. Each one of those filters can be negated with a
Victor Porof66878d62021-07-16 13:12:371810 // "-" prefix, including the regular expressions. The top-level `invert`
Jack Franklin28577db2021-10-14 08:12:531811 // checkbox therefore inverts each one of those individual filters.
1812 const descriptors = this.filterParser.parse(query);
1813 this.filters = descriptors.map(descriptor => {
Blink Reformat4c46d092018-04-07 15:32:371814 const key = descriptor.key;
1815 const text = descriptor.text || '';
1816 const regex = descriptor.regex;
1817 let filter;
1818 if (key) {
Tim van der Lippebafa3bd2021-01-20 12:19:171819 const defaultText = Platform.StringUtilities.escapeForRegExp(key + ':' + text);
Jan Scheffler17b8fb42021-08-12 12:28:381820 filter = this.createSpecialFilter((key as NetworkForward.UIFilter.FilterType), text) ||
1821 NetworkLogView.requestPathFilter.bind(null, new RegExp(defaultText, 'i'));
Blink Reformat4c46d092018-04-07 15:32:371822 } else if (descriptor.regex) {
Jan Scheffler17b8fb42021-08-12 12:28:381823 filter = NetworkLogView.requestPathFilter.bind(null, (regex as RegExp));
Danil Somsikov7a392fb2021-09-13 11:09:461824 } else if (this.isValidUrl(text)) {
1825 filter = NetworkLogView.requestUrlFilter.bind(null, text);
Blink Reformat4c46d092018-04-07 15:32:371826 } else {
Jan Scheffler17b8fb42021-08-12 12:28:381827 filter = NetworkLogView.requestPathFilter.bind(
Tim van der Lippebafa3bd2021-01-20 12:19:171828 null, new RegExp(Platform.StringUtilities.escapeForRegExp(text), 'i'));
Blink Reformat4c46d092018-04-07 15:32:371829 }
Victor Porof66878d62021-07-16 13:12:371830 if ((descriptor.negative && !invert) || (!descriptor.negative && invert)) {
Jan Scheffler17b8fb42021-08-12 12:28:381831 return NetworkLogView.negativeFilter.bind(null, filter);
Victor Porof66878d62021-07-16 13:12:371832 }
1833 return filter;
Blink Reformat4c46d092018-04-07 15:32:371834 });
1835 }
1836
Jan Scheffler17b8fb42021-08-12 12:28:381837 private createSpecialFilter(type: NetworkForward.UIFilter.FilterType, value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371838 switch (type) {
Sigurd Schneider30722582021-06-16 06:54:161839 case NetworkForward.UIFilter.FilterType.Domain:
Jan Scheffler17b8fb42021-08-12 12:28:381840 return NetworkLogView.createRequestDomainFilter(value);
Blink Reformat4c46d092018-04-07 15:32:371841
Sigurd Schneider30722582021-06-16 06:54:161842 case NetworkForward.UIFilter.FilterType.HasResponseHeader:
Jan Scheffler17b8fb42021-08-12 12:28:381843 return NetworkLogView.requestResponseHeaderFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371844
Simon Zünd6dedde52021-08-03 09:04:511845 case NetworkForward.UIFilter.FilterType.ResponseHeaderValueSetCookie:
Jan Scheffler17b8fb42021-08-12 12:28:381846 return NetworkLogView.requestResponseHeaderSetCookieFilter.bind(null, value);
Simon Zünd6dedde52021-08-03 09:04:511847
Sigurd Schneider30722582021-06-16 06:54:161848 case NetworkForward.UIFilter.FilterType.Is:
1849 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.Running) {
Jan Scheffler17b8fb42021-08-12 12:28:381850 return NetworkLogView.runningRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341851 }
Sigurd Schneider30722582021-06-16 06:54:161852 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.FromCache) {
Jan Scheffler17b8fb42021-08-12 12:28:381853 return NetworkLogView.fromCacheRequestFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341854 }
Sigurd Schneider30722582021-06-16 06:54:161855 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerIntercepted) {
Jan Scheffler17b8fb42021-08-12 12:28:381856 return NetworkLogView.interceptedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341857 }
Sigurd Schneider30722582021-06-16 06:54:161858 if (value.toLowerCase() === NetworkForward.UIFilter.IsFilterType.ServiceWorkerInitiated) {
Jan Scheffler17b8fb42021-08-12 12:28:381859 return NetworkLogView.initiatedByServiceWorkerFilter;
Tim van der Lippe1d6e57a2019-09-30 11:55:341860 }
Blink Reformat4c46d092018-04-07 15:32:371861 break;
1862
Sigurd Schneider30722582021-06-16 06:54:161863 case NetworkForward.UIFilter.FilterType.LargerThan:
Jan Scheffler17b8fb42021-08-12 12:28:381864 return this.createSizeFilter(value.toLowerCase());
Blink Reformat4c46d092018-04-07 15:32:371865
Sigurd Schneider30722582021-06-16 06:54:161866 case NetworkForward.UIFilter.FilterType.Method:
Jan Scheffler17b8fb42021-08-12 12:28:381867 return NetworkLogView.requestMethodFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371868
Sigurd Schneider30722582021-06-16 06:54:161869 case NetworkForward.UIFilter.FilterType.MimeType:
Jan Scheffler17b8fb42021-08-12 12:28:381870 return NetworkLogView.requestMimeTypeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371871
Sigurd Schneider30722582021-06-16 06:54:161872 case NetworkForward.UIFilter.FilterType.MixedContent:
Jan Scheffler17b8fb42021-08-12 12:28:381873 return NetworkLogView.requestMixedContentFilter.bind(
Sigurd Schneider30722582021-06-16 06:54:161874 null, (value as NetworkForward.UIFilter.MixedContentFilterValues));
Blink Reformat4c46d092018-04-07 15:32:371875
Sigurd Schneider30722582021-06-16 06:54:161876 case NetworkForward.UIFilter.FilterType.Scheme:
Jan Scheffler17b8fb42021-08-12 12:28:381877 return NetworkLogView.requestSchemeFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371878
Sigurd Schneider30722582021-06-16 06:54:161879 case NetworkForward.UIFilter.FilterType.SetCookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381880 return NetworkLogView.requestSetCookieDomainFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371881
Sigurd Schneider30722582021-06-16 06:54:161882 case NetworkForward.UIFilter.FilterType.SetCookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381883 return NetworkLogView.requestSetCookieNameFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371884
Sigurd Schneider30722582021-06-16 06:54:161885 case NetworkForward.UIFilter.FilterType.SetCookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381886 return NetworkLogView.requestSetCookieValueFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371887
Sigurd Schneider30722582021-06-16 06:54:161888 case NetworkForward.UIFilter.FilterType.CookieDomain:
Jan Scheffler17b8fb42021-08-12 12:28:381889 return NetworkLogView.requestCookieDomainFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411890
Sigurd Schneider30722582021-06-16 06:54:161891 case NetworkForward.UIFilter.FilterType.CookieName:
Jan Scheffler17b8fb42021-08-12 12:28:381892 return NetworkLogView.requestCookieNameFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411893
Sigurd Schneider30722582021-06-16 06:54:161894 case NetworkForward.UIFilter.FilterType.CookiePath:
Jan Scheffler17b8fb42021-08-12 12:28:381895 return NetworkLogView.requestCookiePathFilter.bind(null, value);
Simon Zündc9759102020-03-25 11:24:541896
Sigurd Schneider30722582021-06-16 06:54:161897 case NetworkForward.UIFilter.FilterType.CookieValue:
Jan Scheffler17b8fb42021-08-12 12:28:381898 return NetworkLogView.requestCookieValueFilter.bind(null, value);
Jan Scheffler341eea52019-12-12 09:08:411899
Sigurd Schneider30722582021-06-16 06:54:161900 case NetworkForward.UIFilter.FilterType.Priority:
Jan Scheffler17b8fb42021-08-12 12:28:381901 return NetworkLogView.requestPriorityFilter.bind(
Tim van der Lippeded23fb2020-02-13 13:33:501902 null, PerfUI.NetworkPriorities.uiLabelToNetworkPriority(value));
Blink Reformat4c46d092018-04-07 15:32:371903
Sigurd Schneider30722582021-06-16 06:54:161904 case NetworkForward.UIFilter.FilterType.StatusCode:
Jan Scheffler17b8fb42021-08-12 12:28:381905 return NetworkLogView.statusCodeFilter.bind(null, value);
Sigurd Schneider464838b2020-08-24 13:53:031906
Sigurd Schneider30722582021-06-16 06:54:161907 case NetworkForward.UIFilter.FilterType.ResourceType:
Jan Scheffler17b8fb42021-08-12 12:28:381908 return NetworkLogView.resourceTypeFilter.bind(null, value);
Julian Geppertf8ce40c2020-09-01 18:02:031909
Sigurd Schneider30722582021-06-16 06:54:161910 case NetworkForward.UIFilter.FilterType.Url:
Jan Scheffler17b8fb42021-08-12 12:28:381911 return NetworkLogView.requestUrlFilter.bind(null, value);
Blink Reformat4c46d092018-04-07 15:32:371912 }
1913 return null;
1914 }
1915
Jan Scheffler17b8fb42021-08-12 12:28:381916 private createSizeFilter(value: string): Filter|null {
Blink Reformat4c46d092018-04-07 15:32:371917 let multiplier = 1;
1918 if (value.endsWith('k')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541919 multiplier = 1000;
Blink Reformat4c46d092018-04-07 15:32:371920 value = value.substring(0, value.length - 1);
1921 } else if (value.endsWith('m')) {
Wolfgang Beyerd451ecd2020-10-23 08:35:541922 multiplier = 1000 * 1000;
Blink Reformat4c46d092018-04-07 15:32:371923 value = value.substring(0, value.length - 1);
1924 }
1925 const quantity = Number(value);
Tim van der Lippe1d6e57a2019-09-30 11:55:341926 if (isNaN(quantity)) {
Blink Reformat4c46d092018-04-07 15:32:371927 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341928 }
Jan Scheffler17b8fb42021-08-12 12:28:381929 return NetworkLogView.requestSizeLargerThanFilter.bind(null, quantity * multiplier);
Blink Reformat4c46d092018-04-07 15:32:371930 }
1931
Jan Scheffler17b8fb42021-08-12 12:28:381932 private filterRequests(): void {
1933 this.removeAllHighlights();
1934 this.invalidateAllItems();
Blink Reformat4c46d092018-04-07 15:32:371935 }
1936
Jan Scheffler17b8fb42021-08-12 12:28:381937 private reveal(request: SDK.NetworkRequest.NetworkRequest): NetworkRequestNode|null {
Blink Reformat4c46d092018-04-07 15:32:371938 this.removeAllNodeHighlights();
Tim van der Lippe224a8622020-09-23 12:14:371939 const node = networkRequestToNode.get(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341940 if (!node || !node.dataGrid) {
Blink Reformat4c46d092018-04-07 15:32:371941 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:341942 }
Brandon Goddard5e4244d2020-04-08 22:08:471943 // Viewport datagrid nodes do not reveal if not in the root node
Jack Franklin28577db2021-10-14 08:12:531944 // list of flatChildren. For children of grouped frame nodes:
Brandon Goddard5e4244d2020-04-08 22:08:471945 // reveal and expand parent to ensure child is revealable.
1946 if (node.parent && node.parent instanceof NetworkGroupNode) {
1947 node.parent.reveal();
1948 node.parent.expand();
1949 }
Blink Reformat4c46d092018-04-07 15:32:371950 node.reveal();
1951 return node;
1952 }
1953
Jan Schefflerd6c1d402021-02-26 16:56:381954 revealAndHighlightRequest(request: SDK.NetworkRequest.NetworkRequest): void {
Jan Scheffler17b8fb42021-08-12 12:28:381955 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341956 if (node) {
Jan Scheffler17b8fb42021-08-12 12:28:381957 this.highlightNode(node);
Tim van der Lippe1d6e57a2019-09-30 11:55:341958 }
Blink Reformat4c46d092018-04-07 15:32:371959 }
1960
Sigurd Schneider722301e2021-06-15 13:41:201961 revealAndHighlightRequestWithId(requestId: NetworkForward.NetworkRequestId.NetworkRequestId): void {
Danil Somsikov0c13d2d2021-06-10 15:02:071962 const request = Logs.NetworkLog.NetworkLog.instance().requestByManagerAndId(requestId.manager, requestId.requestId);
1963 if (request) {
1964 this.revealAndHighlightRequest(request);
1965 }
1966 }
1967
Sigurd Schneider14d3e9f2021-06-14 08:29:011968 selectRequest(request: SDK.NetworkRequest.NetworkRequest, options?: NetworkForward.UIRequestLocation.FilterOptions):
1969 void {
chait pinnamaneni6bc1c122020-10-30 17:30:521970 const defaultOptions = {clearFilter: true};
1971 const {clearFilter} = options || defaultOptions;
1972 if (clearFilter) {
1973 this.setTextFilterValue('');
1974 }
Jan Scheffler17b8fb42021-08-12 12:28:381975 const node = this.reveal(request);
Tim van der Lippe1d6e57a2019-09-30 11:55:341976 if (node) {
Blink Reformat4c46d092018-04-07 15:32:371977 node.select();
Tim van der Lippe1d6e57a2019-09-30 11:55:341978 }
Blink Reformat4c46d092018-04-07 15:32:371979 }
1980
Jan Schefflerd6c1d402021-02-26 16:56:381981 removeAllNodeHighlights(): void {
Jack Franklin28577db2021-10-14 08:12:531982 if (this.highlightedNode) {
1983 this.highlightedNode.element().classList.remove('highlighted-row');
1984 this.highlightedNode = null;
Blink Reformat4c46d092018-04-07 15:32:371985 }
1986 }
1987
Jan Scheffler17b8fb42021-08-12 12:28:381988 private highlightNode(node: NetworkRequestNode): void {
Tim van der Lippe0ed1d2b2020-02-04 13:45:131989 UI.UIUtils.runCSSAnimationOnce(node.element(), 'highlighted-row');
Jack Franklin28577db2021-10-14 08:12:531990 this.highlightedNode = node;
Blink Reformat4c46d092018-04-07 15:32:371991 }
1992
Jan Scheffler17b8fb42021-08-12 12:28:381993 private filterOutBlobRequests(requests: SDK.NetworkRequest.NetworkRequest[]): SDK.NetworkRequest.NetworkRequest[] {
Harley Libcf41f92018-09-10 18:01:131994 return requests.filter(request => !request.isBlobRequest());
1995 }
1996
Danil Somsikov59f4c612021-09-08 10:58:461997 private async generateFetchCall(request: SDK.NetworkRequest.NetworkRequest, style: FetchStyle): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:381998 const ignoredHeaders = new Set<string>([
Blink Reformat4c46d092018-04-07 15:32:371999 // Internal headers
Tim van der Lippe224a8622020-09-23 12:14:372000 'method',
2001 'path',
2002 'scheme',
2003 'version',
Blink Reformat4c46d092018-04-07 15:32:372004
2005 // Unsafe headers
2006 // Keep this list synchronized with src/net/http/http_util.cc
Tim van der Lippe224a8622020-09-23 12:14:372007 'accept-charset',
2008 'accept-encoding',
2009 'access-control-request-headers',
2010 'access-control-request-method',
2011 'connection',
2012 'content-length',
2013 'cookie',
2014 'cookie2',
2015 'date',
2016 'dnt',
2017 'expect',
2018 'host',
2019 'keep-alive',
2020 'origin',
2021 'referer',
2022 'te',
2023 'trailer',
2024 'transfer-encoding',
2025 'upgrade',
2026 'via',
Blink Reformat4c46d092018-04-07 15:32:372027 // TODO(phistuck) - remove this once crbug.com/571722 is fixed.
Tim van der Lippe224a8622020-09-23 12:14:372028 'user-agent',
2029 ]);
Blink Reformat4c46d092018-04-07 15:32:372030
Jan Schefflerd6c1d402021-02-26 16:56:382031 const credentialHeaders = new Set<string>(['cookie', 'authorization']);
Blink Reformat4c46d092018-04-07 15:32:372032
2033 const url = JSON.stringify(request.url());
2034
2035 const requestHeaders = request.requestHeaders();
Jan Schefflerd6c1d402021-02-26 16:56:382036 const headerData: Headers = requestHeaders.reduce((result, header) => {
Blink Reformat4c46d092018-04-07 15:32:372037 const name = header.name;
2038
Tim van der Lippe224a8622020-09-23 12:14:372039 if (!ignoredHeaders.has(name.toLowerCase()) && !name.includes(':')) {
Blink Reformat4c46d092018-04-07 15:32:372040 result.append(name, header.value);
Tim van der Lippe1d6e57a2019-09-30 11:55:342041 }
Blink Reformat4c46d092018-04-07 15:32:372042
2043 return result;
2044 }, new Headers());
2045
Jan Schefflerd6c1d402021-02-26 16:56:382046 const headers: HeadersInit = {};
Tim van der Lippe1d6e57a2019-09-30 11:55:342047 for (const headerArray of headerData) {
PhistucK6ed0a3e2018-08-04 06:28:412048 headers[headerArray[0]] = headerArray[1];
Tim van der Lippe1d6e57a2019-09-30 11:55:342049 }
Blink Reformat4c46d092018-04-07 15:32:372050
Sigurd Schneider0e88b912020-05-08 08:28:232051 const credentials = request.includedRequestCookies().length ||
Tim van der Lippe224a8622020-09-23 12:14:372052 requestHeaders.some(({name}) => credentialHeaders.has(name.toLowerCase())) ?
Jan Scheffler341eea52019-12-12 09:08:412053 'include' :
2054 'omit';
Blink Reformat4c46d092018-04-07 15:32:372055
2056 const referrerHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'referer');
2057
2058 const referrer = referrerHeader ? referrerHeader.value : void 0;
2059
2060 const referrerPolicy = request.referrerPolicy() || void 0;
2061
2062 const requestBody = await request.requestFormData();
2063
Jan Schefflerd6c1d402021-02-26 16:56:382064 const fetchOptions: RequestInit = {
PhistucK6ed0a3e2018-08-04 06:28:412065 headers: Object.keys(headers).length ? headers : void 0,
Blink Reformat4c46d092018-04-07 15:32:372066 referrer,
2067 referrerPolicy,
2068 body: requestBody,
2069 method: request.requestMethod,
Tim van der Lippe224a8622020-09-23 12:14:372070 mode: 'cors',
Blink Reformat4c46d092018-04-07 15:32:372071 };
2072
Danil Somsikov59f4c612021-09-08 10:58:462073 if (style === FetchStyle.NodeJs) {
Jan Scheffler7c50d1f2019-12-17 13:33:292074 const cookieHeader = requestHeaders.find(header => header.name.toLowerCase() === 'cookie');
Danil Somsikov59f4c612021-09-08 10:58:462075 const extraHeaders: HeadersInit = {};
Jack Franklin28577db2021-10-14 08:12:532076 // According to https://www.npmjs.com/package/node-fetch#class-request the
Danil Somsikov59f4c612021-09-08 10:58:462077 // following properties are not implemented in Node.js.
2078 delete fetchOptions.mode;
Jan Scheffler7c50d1f2019-12-17 13:33:292079 if (cookieHeader) {
Danil Somsikov59f4c612021-09-08 10:58:462080 extraHeaders['cookie'] = cookieHeader.value;
2081 }
2082 if (referrer) {
2083 delete fetchOptions.referrer;
2084 extraHeaders['Referer'] = referrer;
2085 }
2086 if (referrer) {
2087 delete fetchOptions.referrerPolicy;
2088 extraHeaders['Referrer-Policy'] = referrerPolicy as string;
2089 }
2090 if (Object.keys(extraHeaders).length) {
Jan Scheffler7c50d1f2019-12-17 13:33:292091 fetchOptions.headers = {
2092 ...headers,
Danil Somsikov59f4c612021-09-08 10:58:462093 ...extraHeaders,
Jan Scheffler7c50d1f2019-12-17 13:33:292094 };
2095 }
2096 } else {
2097 fetchOptions.credentials = credentials;
2098 }
2099
Jan Scheffler172d5212020-01-02 14:42:562100 const options = JSON.stringify(fetchOptions, null, 2);
Blink Reformat4c46d092018-04-07 15:32:372101 return `fetch(${url}, ${options});`;
2102 }
2103
Danil Somsikov59f4c612021-09-08 10:58:462104 private async generateAllFetchCall(requests: SDK.NetworkRequest.NetworkRequest[], style: FetchStyle):
Jan Scheffler17b8fb42021-08-12 12:28:382105 Promise<string> {
2106 const nonBlobRequests = this.filterOutBlobRequests(requests);
Danil Somsikov59f4c612021-09-08 10:58:462107 const commands = await Promise.all(nonBlobRequests.map(request => this.generateFetchCall(request, style)));
Harley Libcf41f92018-09-10 18:01:132108 return commands.join(' ;\n');
2109 }
2110
Wolfgang Beyer26b7e892022-08-16 11:02:352111 static async generateCurlCommand(request: SDK.NetworkRequest.NetworkRequest, platform: string): Promise<string> {
Jan Schefflerd6c1d402021-02-26 16:56:382112 let command: string[] = [];
Eric Lawrence7a7b3682019-10-17 23:06:362113 // Most of these headers are derived from the URL and are automatically added by cURL.
2114 // The |Accept-Encoding| header is ignored to prevent decompression errors. crbug.com/1015321
Jan Schefflerd6c1d402021-02-26 16:56:382115 const ignoredHeaders = new Set<string>(['accept-encoding', 'host', 'method', 'path', 'scheme', 'version']);
Blink Reformat4c46d092018-04-07 15:32:372116
Jan Schefflerd6c1d402021-02-26 16:56:382117 function escapeStringWin(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372118 /* If there are no new line characters do not escape the " characters
Jan Schefflerd6c1d402021-02-26 16:56:382119 since it only uglifies the command.
Blink Reformat4c46d092018-04-07 15:32:372120
Jan Schefflerd6c1d402021-02-26 16:56:382121 Because cmd.exe parser and MS Crt arguments parsers use some of the
2122 same escape characters, they can interact with each other in
2123 horrible ways, the order of operations is critical.
Blink Reformat4c46d092018-04-07 15:32:372124
Jan Schefflerd6c1d402021-02-26 16:56:382125 Replace \ with \\ first because it is an escape character for certain
2126 conditions in both parsers.
Blink Reformat4c46d092018-04-07 15:32:372127
Jan Schefflerd6c1d402021-02-26 16:56:382128 Replace all " with \" to ensure the first parser does not remove it.
Blink Reformat4c46d092018-04-07 15:32:372129
Jan Schefflerd6c1d402021-02-26 16:56:382130 Then escape all characters we are not sure about with ^ to ensure it
2131 gets to MS Crt parser safely.
Blink Reformat4c46d092018-04-07 15:32:372132
Jan Schefflerd6c1d402021-02-26 16:56:382133 The % character is special because MS Crt parser will try and look for
Wolfgang Beyer26b7e892022-08-16 11:02:352134 ENV variables and fill them in its place. We cannot escape them with %
Jan Schefflerd6c1d402021-02-26 16:56:382135 and cannot escape them with ^ (because it's cmd.exe's escape not MS Crt
2136 parser); So we can get cmd.exe parser to escape the character after it,
2137 if it is followed by a valid beginning character of an ENV variable.
2138 This ensures we do not try and double escape another ^ if it was placed
2139 by the previous replace.
Blink Reformat4c46d092018-04-07 15:32:372140
Jan Schefflerd6c1d402021-02-26 16:56:382141 Lastly we replace new lines with ^ and TWO new lines because the first
2142 new line is there to enact the escape command the second is the character
2143 to escape (in this case new line).
2144 */
Blink Reformat4c46d092018-04-07 15:32:372145 const encapsChars = /[\r\n]/.test(str) ? '^"' : '"';
2146 return encapsChars +
2147 str.replace(/\\/g, '\\\\')
2148 .replace(/"/g, '\\"')
Jan Scheffler747b8a12020-11-03 17:41:542149 .replace(/[^a-zA-Z0-9\s_\-:=+~'\/.',?;()*`&]/g, '^$&')
Blink Reformat4c46d092018-04-07 15:32:372150 .replace(/%(?=[a-zA-Z0-9_])/g, '%^')
Jan Scheffler747b8a12020-11-03 17:41:542151 .replace(/\r?\n/g, '^\n\n') +
Blink Reformat4c46d092018-04-07 15:32:372152 encapsChars;
2153 }
2154
Jan Schefflerd6c1d402021-02-26 16:56:382155 function escapeStringPosix(str: string): string {
2156 function escapeCharacter(x: string): string {
Erik Luoaa676752018-08-21 05:52:222157 const code = x.charCodeAt(0);
Joey Arhar2d21f712019-05-20 21:07:122158 let hexString = code.toString(16);
2159 // Zero pad to four digits to comply with ANSI-C Quoting:
2160 // http://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html
Tim van der Lippe1d6e57a2019-09-30 11:55:342161 while (hexString.length < 4) {
Joey Arhar2d21f712019-05-20 21:07:122162 hexString = '0' + hexString;
Tim van der Lippe1d6e57a2019-09-30 11:55:342163 }
Joey Arhar2d21f712019-05-20 21:07:122164
2165 return '\\u' + hexString;
Blink Reformat4c46d092018-04-07 15:32:372166 }
2167
Mathias Bynensf06e8c02020-02-28 13:58:282168 if (/[\0-\x1F\x7F-\x9F!]|\'/.test(str)) {
Blink Reformat4c46d092018-04-07 15:32:372169 // Use ANSI-C quoting syntax.
2170 return '$\'' +
2171 str.replace(/\\/g, '\\\\')
2172 .replace(/\'/g, '\\\'')
2173 .replace(/\n/g, '\\n')
2174 .replace(/\r/g, '\\r')
Mathias Bynensf06e8c02020-02-28 13:58:282175 .replace(/[\0-\x1F\x7F-\x9F!]/g, escapeCharacter) +
Blink Reformat4c46d092018-04-07 15:32:372176 '\'';
Blink Reformat4c46d092018-04-07 15:32:372177 }
Mathias Bynensf06e8c02020-02-28 13:58:282178 // Use single quote syntax.
2179 return '\'' + str + '\'';
Blink Reformat4c46d092018-04-07 15:32:372180 }
2181
2182 // cURL command expected to run on the same platform that DevTools run
2183 // (it may be different from the inspected page platform).
2184 const escapeString = platform === 'win' ? escapeStringWin : escapeStringPosix;
2185
2186 command.push(escapeString(request.url()).replace(/[[{}\]]/g, '\\$&'));
2187
2188 let inferredMethod = 'GET';
2189 const data = [];
Blink Reformat4c46d092018-04-07 15:32:372190 const formData = await request.requestFormData();
Michael Brüningca6b1ce2021-04-14 16:27:082191 if (formData) {
Jan Scheffler441bb6a2020-02-11 11:46:272192 // Note that formData is not necessarily urlencoded because it might for example
Jack Franklin28577db2021-10-14 08:12:532193 // come from a fetch request made with an explicitly unencoded body.
Jan Scheffler441bb6a2020-02-11 11:46:272194 data.push('--data-raw ' + escapeString(formData));
Tim van der Lippe224a8622020-09-23 12:14:372195 ignoredHeaders.add('content-length');
Blink Reformat4c46d092018-04-07 15:32:372196 inferredMethod = 'POST';
Blink Reformat4c46d092018-04-07 15:32:372197 }
2198
2199 if (request.requestMethod !== inferredMethod) {
Jan Schefflera4e536a2020-01-09 08:51:292200 command.push('-X ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372201 }
2202
2203 const requestHeaders = request.requestHeaders();
2204 for (let i = 0; i < requestHeaders.length; i++) {
2205 const header = requestHeaders[i];
2206 const name = header.name.replace(/^:/, ''); // Translate SPDY v3 headers to HTTP headers.
Tim van der Lippe224a8622020-09-23 12:14:372207 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372208 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342209 }
Wolfgang Beyer26b7e892022-08-16 11:02:352210 if (header.value.trim()) {
2211 command.push('-H ' + escapeString(name + ': ' + header.value));
2212 } else {
2213 // A header passed with -H with no value or only whitespace as its
2214 // value tells curl to not set the header at all. To post an empty
2215 // header, you have to terminate it with a semicolon.
2216 command.push('-H ' + escapeString(name + ';'));
2217 }
Blink Reformat4c46d092018-04-07 15:32:372218 }
2219 command = command.concat(data);
2220 command.push('--compressed');
2221
Tim van der Lippe1d6e57a2019-09-30 11:55:342222 if (request.securityState() === Protocol.Security.SecurityState.Insecure) {
Blink Reformat4c46d092018-04-07 15:32:372223 command.push('--insecure');
Tim van der Lippe1d6e57a2019-09-30 11:55:342224 }
Jan Scheffler172d5212020-01-02 14:42:562225 return 'curl ' + command.join(command.length >= 3 ? (platform === 'win' ? ' ^\n ' : ' \\\n ') : ' ');
Blink Reformat4c46d092018-04-07 15:32:372226 }
2227
Jan Scheffler17b8fb42021-08-12 12:28:382228 private async generateAllCurlCommand(requests: SDK.NetworkRequest.NetworkRequest[], platform: string):
2229 Promise<string> {
2230 const nonBlobRequests = this.filterOutBlobRequests(requests);
Wolfgang Beyer26b7e892022-08-16 11:02:352231 const commands =
2232 await Promise.all(nonBlobRequests.map(request => NetworkLogView.generateCurlCommand(request, platform)));
Tim van der Lippe1d6e57a2019-09-30 11:55:342233 if (platform === 'win') {
Harley Libcf41f92018-09-10 18:01:132234 return commands.join(' &\r\n');
Tim van der Lippe1d6e57a2019-09-30 11:55:342235 }
Mathias Bynensf06e8c02020-02-28 13:58:282236 return commands.join(' ;\n');
Harley Libcf41f92018-09-10 18:01:132237 }
2238
Jan Scheffler17b8fb42021-08-12 12:28:382239 private async generatePowerShellCommand(request: SDK.NetworkRequest.NetworkRequest): Promise<string> {
Jan Scheffler172d5212020-01-02 14:42:562240 const command = [];
Brandon Walderman153b8d72021-06-28 18:45:242241 const ignoredHeaders = new Set<string>([
2242 'host',
2243 'connection',
2244 'proxy-connection',
2245 'content-length',
2246 'expect',
2247 'range',
2248 'content-type',
2249 'user-agent',
2250 'cookie',
2251 ]);
Blink Reformat4c46d092018-04-07 15:32:372252
Jan Schefflerd6c1d402021-02-26 16:56:382253 function escapeString(str: string): string {
Blink Reformat4c46d092018-04-07 15:32:372254 return '"' +
2255 str.replace(/[`\$"]/g, '`$&').replace(/[^\x20-\x7E]/g, char => '$([char]' + char.charCodeAt(0) + ')') + '"';
2256 }
2257
Brandon Walderman153b8d72021-06-28 18:45:242258 // Generate a WebRequestSession object with the UserAgent and Cookie header values.
2259 // This is used to pass the user-agent and cookie headers to Invoke-WebRequest because the Invoke-WebRequest
2260 // command does not allow setting these headers through the -Headers parameter. See docs at:
2261 // https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#parameters
2262 function generatePowerShellSession(request: SDK.NetworkRequest.NetworkRequest): string|null {
2263 const requestHeaders = request.requestHeaders();
2264 const props = [];
2265
2266 const userAgentHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'user-agent');
2267 if (userAgentHeader) {
2268 props.push(`$session.UserAgent = ${escapeString(userAgentHeader.value)}`);
2269 }
2270
2271 for (const cookie of request.includedRequestCookies()) {
2272 const name = escapeString(cookie.name());
2273 const value = escapeString(cookie.value());
2274 const domain = escapeString(cookie.domain());
2275 props.push(`$session.Cookies.Add((New-Object System.Net.Cookie(${name}, ${value}, "/", ${domain})))`);
2276 }
2277
2278 if (props.length) {
2279 return '$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession\n' + props.join('\n') + '\n';
2280 }
2281
2282 return null;
2283 }
2284
Jan Scheffler172d5212020-01-02 14:42:562285 command.push('-Uri ' + escapeString(request.url()));
Blink Reformat4c46d092018-04-07 15:32:372286
2287 if (request.requestMethod !== 'GET') {
Jan Scheffler172d5212020-01-02 14:42:562288 command.push('-Method ' + escapeString(request.requestMethod));
Blink Reformat4c46d092018-04-07 15:32:372289 }
2290
Brandon Walderman153b8d72021-06-28 18:45:242291 const session = generatePowerShellSession(request);
2292 if (session) {
2293 command.push('-WebSession $session');
2294 }
2295
Blink Reformat4c46d092018-04-07 15:32:372296 const requestHeaders = request.requestHeaders();
2297 const headerNameValuePairs = [];
2298 for (const header of requestHeaders) {
2299 const name = header.name.replace(/^:/, ''); // Translate h2 headers to HTTP headers.
Tim van der Lippe1d6e57a2019-09-30 11:55:342300 if (ignoredHeaders.has(name.toLowerCase())) {
Blink Reformat4c46d092018-04-07 15:32:372301 continue;
Tim van der Lippe1d6e57a2019-09-30 11:55:342302 }
Blink Reformat4c46d092018-04-07 15:32:372303 headerNameValuePairs.push(escapeString(name) + '=' + escapeString(header.value));
2304 }
2305 if (headerNameValuePairs.length) {
Jan Scheffler172d5212020-01-02 14:42:562306 command.push('-Headers @{\n' + headerNameValuePairs.join('\n ') + '\n}');
Blink Reformat4c46d092018-04-07 15:32:372307 }
2308
2309 const contentTypeHeader = requestHeaders.find(({name}) => name.toLowerCase() === 'content-type');
2310 if (contentTypeHeader) {
Jan Scheffler172d5212020-01-02 14:42:562311 command.push('-ContentType ' + escapeString(contentTypeHeader.value));
Blink Reformat4c46d092018-04-07 15:32:372312 }
2313
2314 const formData = await request.requestFormData();
2315 if (formData) {
Blink Reformat4c46d092018-04-07 15:32:372316 const body = escapeString(formData);
Tim van der Lippe1d6e57a2019-09-30 11:55:342317 if (/[^\x20-\x7E]/.test(formData)) {
Jan Scheffler172d5212020-01-02 14:42:562318 command.push('-Body ([System.Text.Encoding]::UTF8.GetBytes(' + body + '))');
Tim van der Lippe1d6e57a2019-09-30 11:55:342319 } else {
Jan Scheffler172d5212020-01-02 14:42:562320 command.push('-Body ' + body);
Tim van der Lippe1d6e57a2019-09-30 11:55:342321 }
Blink Reformat4c46d092018-04-07 15:32:372322 }
2323
Brandon Walderman153b8d72021-06-28 18:45:242324 // The -UseBasicParsing parameter prevents Invoke-WebRequest from using the IE engine for parsing. Basic
2325 // parsing is the default behavior in PowerShell 6.0.0+ and the parameter is included here for backwards
2326 // compatibility only.
2327 const prelude = session || '';
2328 return prelude + 'Invoke-WebRequest -UseBasicParsing ' + command.join(command.length >= 3 ? ' `\n' : ' ');
Blink Reformat4c46d092018-04-07 15:32:372329 }
Harley Libcf41f92018-09-10 18:01:132330
Jan Scheffler17b8fb42021-08-12 12:28:382331 private async generateAllPowerShellCommand(requests: SDK.NetworkRequest.NetworkRequest[]): Promise<string> {
2332 const nonBlobRequests = this.filterOutBlobRequests(requests);
2333 const commands = await Promise.all(nonBlobRequests.map(request => this.generatePowerShellCommand(request)));
Harley Libcf41f92018-09-10 18:01:132334 return commands.join(';\r\n');
2335 }
Joey Arhara86c14e2019-03-12 03:20:502336
Jan Schefflerd6c1d402021-02-26 16:56:382337 static getDCLEventColor(): string {
Benedikt Meurer0149ea02023-06-01 07:33:382338 return '--color-syntax-3';
Joey Arhara86c14e2019-03-12 03:20:502339 }
2340
Jan Schefflerd6c1d402021-02-26 16:56:382341 static getLoadEventColor(): string {
Benedikt Meurer0149ea02023-06-01 07:33:382342 return '--color-syntax-1';
Joey Arhara86c14e2019-03-12 03:20:502343 }
Paul Lewis56509652019-12-06 12:51:582344}
Blink Reformat4c46d092018-04-07 15:32:372345
Jan Schefflerd6c1d402021-02-26 16:56:382346export function computeStackTraceText(stackTrace: Protocol.Runtime.StackTrace): string {
Tim van der Lippeb4faf5a2020-11-06 15:02:022347 let stackTraceText = '';
2348 for (const frame of stackTrace.callFrames) {
2349 const functionName = UI.UIUtils.beautifyFunctionName(frame.functionName);
2350 stackTraceText += `${functionName} @ ${frame.url}:${frame.lineNumber + 1}\n`;
2351 }
2352 if (stackTrace.parent) {
2353 stackTraceText += computeStackTraceText(stackTrace.parent);
2354 }
2355 return stackTraceText;
2356}
2357
Jan Schefflerd6c1d402021-02-26 16:56:382358const filteredNetworkRequests = new WeakSet<NetworkRequestNode>();
2359const networkRequestToNode = new WeakMap<SDK.NetworkRequest.NetworkRequest, NetworkRequestNode>();
Blink Reformat4c46d092018-04-07 15:32:372360
Jan Schefflerd6c1d402021-02-26 16:56:382361export function isRequestFilteredOut(request: NetworkRequestNode): boolean {
Tim van der Lippe224a8622020-09-23 12:14:372362 return filteredNetworkRequests.has(request);
Tim van der Lippe3dc5fd62020-09-22 13:12:222363}
2364
Paul Lewis56509652019-12-06 12:51:582365export const HTTPSchemas = {
Blink Reformat4c46d092018-04-07 15:32:372366 'http': true,
2367 'https': true,
2368 'ws': true,
Jan Schefflerd6c1d402021-02-26 16:56:382369 'wss': true,
Blink Reformat4c46d092018-04-07 15:32:372370};
2371
Sigurd Schneider576ca9a2021-07-16 05:58:042372const searchKeys: string[] = Object.values(NetworkForward.UIFilter.FilterType);
Jan Schefflerd6c1d402021-02-26 16:56:382373
2374export interface GroupLookupInterface {
2375 groupNodeForRequest(request: SDK.NetworkRequest.NetworkRequest): NetworkGroupNode|null;
2376 reset(): void;
2377}
2378
2379export type Filter = (request: SDK.NetworkRequest.NetworkRequest) => boolean;