fix(connection): separate send/receive debug logging (#6017)
This PR splits the logging for send and receive messages in to separate debug channels. This way it is easier to filter and takes advantage of debug's automated coloring to make it easier to visually parse on the command line
This commit is contained in:
parent
c701ea194a
commit
6e060ce0fd
@ -16,7 +16,8 @@
|
|||||||
import { assert } from './helper';
|
import { assert } from './helper';
|
||||||
import { Events } from './Events';
|
import { Events } from './Events';
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
const debugProtocol = debug('puppeteer:protocol');
|
const debugProtocolSend = debug('puppeteer:protocol:SEND ►');
|
||||||
|
const debugProtocolReceive = debug('puppeteer:protocol:RECV ◀');
|
||||||
|
|
||||||
import Protocol from './protocol';
|
import Protocol from './protocol';
|
||||||
import { ConnectionTransport } from './ConnectionTransport';
|
import { ConnectionTransport } from './ConnectionTransport';
|
||||||
@ -78,14 +79,14 @@ export class Connection extends EventEmitter {
|
|||||||
_rawSend(message: {}): number {
|
_rawSend(message: {}): number {
|
||||||
const id = ++this._lastId;
|
const id = ++this._lastId;
|
||||||
message = JSON.stringify(Object.assign({}, message, { id }));
|
message = JSON.stringify(Object.assign({}, message, { id }));
|
||||||
debugProtocol('SEND ► ' + message);
|
debugProtocolSend(message);
|
||||||
this._transport.send(message);
|
this._transport.send(message);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onMessage(message: string): Promise<void> {
|
async _onMessage(message: string): Promise<void> {
|
||||||
if (this._delay) await new Promise((f) => setTimeout(f, this._delay));
|
if (this._delay) await new Promise((f) => setTimeout(f, this._delay));
|
||||||
debugProtocol('◀ RECV ' + message);
|
debugProtocolReceive(message);
|
||||||
const object = JSON.parse(message);
|
const object = JSON.parse(message);
|
||||||
if (object.method === 'Target.attachedToTarget') {
|
if (object.method === 'Target.attachedToTarget') {
|
||||||
const sessionId = object.params.sessionId;
|
const sessionId = object.params.sessionId;
|
||||||
|
Loading…
Reference in New Issue
Block a user