diff --git a/packages/playwright-core/src/server/helper.ts b/packages/playwright-core/src/server/helper.ts index 51f1bf61d2..ab59987a40 100644 --- a/packages/playwright-core/src/server/helper.ts +++ b/packages/playwright-core/src/server/helper.ts @@ -22,6 +22,8 @@ import { debugLogger } from '../common/debugLogger'; import type { RegisteredListener } from '../utils/eventsHelper'; import { eventsHelper } from '../utils/eventsHelper'; +const MAX_LOG_LENGTH = process.env.MAX_LOG_LENGTH ? +process.env.MAX_LOG_LENGTH : Infinity; + class Helper { static completeUserURL(urlString: string): string { if (urlString.startsWith('localhost') || urlString.startsWith('127.0.0.1')) @@ -84,8 +86,12 @@ class Helper { return (direction: 'send' | 'receive', message: object) => { if (protocolLogger) protocolLogger(direction, message); - if (debugLogger.isEnabled('protocol')) - debugLogger.log('protocol', (direction === 'send' ? 'SEND ► ' : '◀ RECV ') + JSON.stringify(message)); + if (debugLogger.isEnabled('protocol')) { + let text = JSON.stringify(message); + if (text.length > MAX_LOG_LENGTH) + text = text.substring(0, MAX_LOG_LENGTH / 2) + ' <<<<<( LOG TRUNCATED )>>>>> ' + text.substring(text.length - MAX_LOG_LENGTH / 2); + debugLogger.log('protocol', (direction === 'send' ? 'SEND ► ' : '◀ RECV ') + text); + } }; }