chore: strip out injected script from protocol logs (#1054)

This commit is contained in:
Dmitry Gozman 2020-02-18 19:56:59 -08:00 committed by GitHub
parent 1805acd5d5
commit 223685ee7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 7 deletions

View file

@ -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]}`;
}

View file

@ -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]}`;
}

View file

@ -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}}`;
}