From 2f6ce8ee6a71432a0109a5527ab0d250181bd474 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 18 Feb 2020 11:22:08 -0800 Subject: [PATCH] chore: strip out injected script from protocol logs --- src/chromium/crConnection.ts | 9 ++++++++- src/firefox/ffConnection.ts | 13 ++++++++++--- src/webkit/wkConnection.ts | 13 ++++++++++--- test/page.spec.js | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/chromium/crConnection.ts b/src/chromium/crConnection.ts index a3d703a054..e542ba87fd 100644 --- a/src/chromium/crConnection.ts +++ b/src/chromium/crConnection.ts @@ -60,7 +60,7 @@ export class CRConnection extends platform.EventEmitter { if (sessionId) message.sessionId = sessionId; const data = JSON.stringify(message); - this._debugProtocol('SEND ► ' + data); + this._debugProtocol('SEND ► ' + (rewriteInjectedScriptEvaluationLog(message) || data)); this._transport.send(data); return id; } @@ -192,3 +192,10 @@ function rewriteError(error: Error, message: string): Error { error.message = message; return error; } + +function rewriteInjectedScriptEvaluationLog(message: any): string | undefined { + // Injected script is very long and clutters protocol logs. + // To increase development velocity, we skip replace it with short description in the log. + if (message.method === 'Runtime.evaluate' && message.params && message.params.expression && message.params.expression.includes('src/injected/injected.ts')) + return `{"id":${message.id} [evaluate injected script]}`; +} diff --git a/src/firefox/ffConnection.ts b/src/firefox/ffConnection.ts index 09db9df2b7..1b3b83d10b 100644 --- a/src/firefox/ffConnection.ts +++ b/src/firefox/ffConnection.ts @@ -84,9 +84,9 @@ export class FFConnection extends platform.EventEmitter { } _rawSend(message: any) { - message = JSON.stringify(message); - this._debugProtocol('SEND ► ' + message); - this._transport.send(message); + const data = JSON.stringify(message); + this._debugProtocol('SEND ► ' + (rewriteInjectedScriptEvaluationLog(message) || data)); + this._transport.send(data); } async _onMessage(message: string) { @@ -226,3 +226,10 @@ function rewriteError(error: Error, message: string): Error { error.message = message; return error; } + +function rewriteInjectedScriptEvaluationLog(message: any): string | undefined { + // Injected script is very long and clutters protocol logs. + // To increase development velocity, we skip replace it with short description in the log. + if (message.method === 'Runtime.evaluate' && message.params && message.params.expression && message.params.expression.includes('src/injected/injected.ts')) + return `{"id":${message.id} [evaluate injected script]}`; +} diff --git a/src/webkit/wkConnection.ts b/src/webkit/wkConnection.ts index 2fc51a9624..7e7c5ec98b 100644 --- a/src/webkit/wkConnection.ts +++ b/src/webkit/wkConnection.ts @@ -53,9 +53,9 @@ export class WKConnection { } rawSend(message: any) { - message = JSON.stringify(message); - this._debugFunction('SEND ► ' + message); - this._transport.send(message); + const data = JSON.stringify(message); + this._debugFunction('SEND ► ' + (rewriteInjectedScriptEvaluationLog(message) || data)); + this._transport.send(data); } private _dispatchMessage(message: string) { @@ -177,3 +177,10 @@ export function rewriteError(error: Error, message: string): Error { export function isSwappedOutError(e: Error) { return e.message.includes('Target was swapped out.'); } + +function rewriteInjectedScriptEvaluationLog(message: any): string | undefined { + // Injected script is very long and clutters protocol logs. + // To increase development velocity, we skip replace it with short description in the log. + if (message.params && message.params.message && message.params.message.includes('Runtime.evaluate') && message.params.message.includes('src/injected/injected.ts')) + return `{"id":${message.id},"method":"${message.method}","params":{"message":[evaluate injected script],"targetId":"${message.params.targetId}"},"pageProxyId":${message.pageProxyId}}`; +} diff --git a/test/page.spec.js b/test/page.spec.js index 9c9a122003..721750e9f9 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -1044,7 +1044,7 @@ module.exports.describe = function({testRunner, expect, headless, playwright, FF await page.fill('body', 'some value'); expect(await page.evaluate(() => document.body.textContent)).toBe('some value'); }); - it('should be able to fill when focus is in the wrong frame', async({page}) => { + fit('should be able to fill when focus is in the wrong frame', async({page}) => { await page.setContent(`