log large cdp messages

Summary:
Running with
```
DEBUG=Metro:InspectorProxy DEV=1 js1 run --no-tty-print
```
When a message larger than 100kb is send over the cdp, log it.

Changelog: [Internal]

Reviewed By: huntie

Differential Revision: D75000887

fbshipit-source-id: 6f426ed4db7ac1996c4f26461a6e0d13c096e5cd
This commit is contained in:
Vitali Zaidman
2025-05-21 06:53:25 -07:00
committed by Facebook GitHub Bot
parent 36df97f500
commit c97853aeb1
@@ -72,6 +72,28 @@ export default class CDPMessagesLogging {
let timeout: Timeout | null = null;
this.#cdpMessagesLoggingBatchingFn[destination] = (message: string) => {
if (message.length > 1024 * 100) {
const messagePreview = JSON.stringify(
JSON.parse(message, (key, value) => {
if (Array.isArray(value)) {
return '[ARRAY]';
}
if (typeof value === 'string' && value.length > 50) {
return value.slice(0, 50) + '...';
}
return value;
}),
null,
2,
);
debug(
'%s A large message (%s MB) was %s- %s',
getCDPLogPrefix(destination),
(message.length / (1024 * 1024)).toFixed(2),
destination.startsWith('Proxy') ? ' sent ' : 'received',
messagePreview,
);
}
if (timeout == null) {
timeout = setTimeout<$ReadOnlyArray<CDPMessageDestination>>(() => {
debug(