feat(logging): log the API calls (#464)
This commit is contained in:
parent
c2d95a3530
commit
a8b9920a14
|
|
@ -20,7 +20,7 @@ import { ConnectionTransport } from '../transport';
|
|||
import { assert } from '../helper';
|
||||
import { Protocol } from './protocol';
|
||||
|
||||
const debugProtocol = platform.debug('playwright:protocol');
|
||||
const debugProtocol = platform.debug('pw:protocol');
|
||||
|
||||
export const ConnectionEvents = {
|
||||
Disconnected: Symbol('ConnectionEvents.Disconnected')
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
|||
constructor(context: FrameExecutionContext, remoteObject: any) {
|
||||
super(context, remoteObject);
|
||||
this._page = context.frame._page;
|
||||
return helper.logPublicApiCalls('handle', this);
|
||||
}
|
||||
|
||||
asElement(): ElementHandle<T> | null {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import * as platform from '../platform';
|
|||
import { ConnectionTransport } from '../transport';
|
||||
import { Protocol } from './protocol';
|
||||
|
||||
const debugProtocol = platform.debug('playwright:protocol');
|
||||
const debugProtocol = platform.debug('pw:protocol');
|
||||
|
||||
export const ConnectionEvents = {
|
||||
Disconnected: Symbol('Disconnected'),
|
||||
|
|
|
|||
|
|
@ -293,6 +293,8 @@ export class Frame {
|
|||
|
||||
if (this._parentFrame)
|
||||
this._parentFrame._childFrames.add(this);
|
||||
|
||||
return helper.logPublicApiCalls('frame', this);
|
||||
}
|
||||
|
||||
async goto(url: string, options?: GotoOptions): Promise<network.Response | null> {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
import { TimeoutError } from './errors';
|
||||
import * as platform from './platform';
|
||||
|
||||
export const debugError = platform.debug(`playwright:error`);
|
||||
export const debugError = platform.debug(`pw:error`);
|
||||
|
||||
export type RegisteredListener = {
|
||||
emitter: platform.EventEmitterType;
|
||||
|
|
@ -60,6 +60,26 @@ class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
static logPublicApiCalls(className: string, object: any): any {
|
||||
const log = platform.debug('pw:api');
|
||||
if (!log.enabled)
|
||||
return object;
|
||||
return new Proxy(object, {
|
||||
get(target, key: string) {
|
||||
const value = target[key];
|
||||
if (typeof key === 'string' && key.startsWith('_') || typeof value !== 'function')
|
||||
return value;
|
||||
return function(...args: any) {
|
||||
if (args.length)
|
||||
log(`${className}.${key} %o`, args);
|
||||
else
|
||||
log(`${className}.${key}`);
|
||||
return value.apply(this, args);
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static addEventListener(
|
||||
emitter: platform.EventEmitterType,
|
||||
eventName: (string | symbol),
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import * as types from './types';
|
||||
import * as dom from './dom';
|
||||
import { helper } from './helper';
|
||||
|
||||
export interface ExecutionContextDelegate {
|
||||
evaluate(context: ExecutionContext, returnByValue: boolean, pageFunction: string | Function, ...args: any[]): Promise<any>;
|
||||
|
|
@ -57,6 +58,7 @@ export class JSHandle<T = any> {
|
|||
constructor(context: ExecutionContext, remoteObject: any) {
|
||||
this._context = context;
|
||||
this._remoteObject = remoteObject;
|
||||
return helper.logPublicApiCalls('handle', this);
|
||||
}
|
||||
|
||||
evaluate: types.EvaluateOn<T> = (pageFunction, ...args) => {
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ export class Page extends platform.EventEmitter {
|
|||
if (delegate.pdf)
|
||||
this.pdf = delegate.pdf.bind(delegate);
|
||||
this.coverage = delegate.coverage();
|
||||
return helper.logPublicApiCalls('page', this);
|
||||
}
|
||||
|
||||
_didClose() {
|
||||
|
|
@ -537,7 +538,9 @@ export class Worker {
|
|||
constructor(url: string) {
|
||||
this._url = url;
|
||||
this._executionContextPromise = new Promise(x => this._executionContextCallback = x);
|
||||
return helper.logPublicApiCalls('worker', this);
|
||||
}
|
||||
|
||||
_createExecutionContext(delegate: js.ExecutionContextDelegate) {
|
||||
this._existingExecutionContext = new js.ExecutionContext(delegate);
|
||||
this._executionContextCallback(this._existingExecutionContext);
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import * as platform from '../platform';
|
|||
import { ConnectionTransport } from '../transport';
|
||||
import { Protocol } from './protocol';
|
||||
|
||||
const debugProtocol = platform.debug('playwright:protocol');
|
||||
const debugWrappedMessage = platform.debug('wrapped');
|
||||
const debugProtocol = platform.debug('pw:protocol');
|
||||
const debugWrappedMessage = platform.debug('pw:wrapped');
|
||||
|
||||
// WKBrowserServer uses this special id to issue Browser.close command which we
|
||||
// should ignore.
|
||||
|
|
|
|||
Loading…
Reference in a new issue