chore: do not accumulate protocol messages for debugging (#150)
This commit is contained in:
parent
929a5944bd
commit
b84d3c6cbe
|
|
@ -99,12 +99,9 @@ export class Connection extends EventEmitter {
|
||||||
_dispatchTargetMessageToSession(object: {method: string, params: any}) {
|
_dispatchTargetMessageToSession(object: {method: string, params: any}) {
|
||||||
if (object.method === 'Target.targetCreated') {
|
if (object.method === 'Target.targetCreated') {
|
||||||
const {targetId, type} = object.params.targetInfo;
|
const {targetId, type} = object.params.targetInfo;
|
||||||
// FIXME: this is a workaround for cross-origin navigation in WebKit.
|
|
||||||
// console.log(`[${targetId}] ${object.method}`);
|
|
||||||
const session = new TargetSession(this, type, targetId);
|
const session = new TargetSession(this, type, targetId);
|
||||||
this._sessions.set(targetId, session);
|
this._sessions.set(targetId, session);
|
||||||
} else if (object.method === 'Target.targetDestroyed') {
|
} else if (object.method === 'Target.targetDestroyed') {
|
||||||
// console.log(`[${object.params.targetId}] ${object.method}`);
|
|
||||||
const session = this._sessions.get(object.params.targetId);
|
const session = this._sessions.get(object.params.targetId);
|
||||||
if (session) {
|
if (session) {
|
||||||
// FIXME: this is a workaround for cross-origin navigation in WebKit.
|
// FIXME: this is a workaround for cross-origin navigation in WebKit.
|
||||||
|
|
@ -161,8 +158,6 @@ export class TargetSession extends EventEmitter {
|
||||||
private _callbacks = new Map<number, {resolve:(o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
|
private _callbacks = new Map<number, {resolve:(o: any) => void, reject: (e: Error) => void, error: Error, method: string}>();
|
||||||
private _targetType: string;
|
private _targetType: string;
|
||||||
private _sessionId: string;
|
private _sessionId: string;
|
||||||
private _out = [];
|
|
||||||
private _in = [];
|
|
||||||
on: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
on: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
||||||
addListener: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
addListener: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
||||||
off: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
off: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
|
||||||
|
|
@ -189,7 +184,6 @@ export class TargetSession extends EventEmitter {
|
||||||
params
|
params
|
||||||
};
|
};
|
||||||
debugWrappedMessage('SEND ► ' + JSON.stringify(messageObj, null, 2));
|
debugWrappedMessage('SEND ► ' + JSON.stringify(messageObj, null, 2));
|
||||||
this._out.push(messageObj);
|
|
||||||
// Serialize message before adding callback in case JSON throws.
|
// Serialize message before adding callback in case JSON throws.
|
||||||
const message = JSON.stringify(messageObj);
|
const message = JSON.stringify(messageObj);
|
||||||
const result = new Promise<Protocol.CommandReturnValues[T]>((resolve, reject) => {
|
const result = new Promise<Protocol.CommandReturnValues[T]>((resolve, reject) => {
|
||||||
|
|
@ -210,7 +204,6 @@ export class TargetSession extends EventEmitter {
|
||||||
_dispatchMessageFromTarget(message: string) {
|
_dispatchMessageFromTarget(message: string) {
|
||||||
const object = JSON.parse(message);
|
const object = JSON.parse(message);
|
||||||
debugWrappedMessage('◀ RECV ' + JSON.stringify(object, null, 2));
|
debugWrappedMessage('◀ RECV ' + JSON.stringify(object, null, 2));
|
||||||
this._in.push(object);
|
|
||||||
if (object.id && this._callbacks.has(object.id)) {
|
if (object.id && this._callbacks.has(object.id)) {
|
||||||
const callback = this._callbacks.get(object.id);
|
const callback = this._callbacks.get(object.id);
|
||||||
this._callbacks.delete(object.id);
|
this._callbacks.delete(object.id);
|
||||||
|
|
@ -220,7 +213,6 @@ export class TargetSession extends EventEmitter {
|
||||||
callback.resolve(object.result);
|
callback.resolve(object.result);
|
||||||
} else {
|
} else {
|
||||||
assert(!object.id);
|
assert(!object.id);
|
||||||
// console.log(`[${this._sessionId}] ${object.method}`);
|
|
||||||
this.emit(object.method, object.params);
|
this.emit(object.method, object.params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue