Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: no pw:api logs from internal playwright instance (#39747)

Dmitry Gozman33c0d8f37079
diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts
index 344463e328..27c1e1046f 100644
--- a/packages/playwright-core/src/server/frames.ts
+++ b/packages/playwright-core/src/server/frames.ts
@@ -29,7 +29,6 @@ import { isAbortError, ProgressController } from './progress';
import * as types from './types';
import { LongStandingScope, asLocator, assert, constructURLBasedOnBaseURL, makeWaitForNextTask, renderTitleForCall } from '../utils';
import { isSessionClosedError } from './protocolError';
-import { debugLogger } from './utils/debugLogger';
import { eventsHelper } from './utils/eventsHelper';
import { isInvalidSelectorError } from '../utils/isomorphic/selectorParser';
import { ManualPromise } from '../utils/isomorphic/manualPromise';
@@ -245,7 +244,7 @@ export class FrameManager {
const navigationEvent: NavigationEvent = { url, name, newDocument: frame._currentDocument, isPublic: true };
this._fireInternalFrameNavigation(frame, navigationEvent);
if (!initial) {
- debugLogger.log('api', ` navigated to "${url}"`);
+ frame.apiLog(` navigated to "${url}"`);
this._page.frameNavigatedToNewDocument(frame);
}
// Restore pending if any - see comments above about keepPending.
@@ -264,7 +263,7 @@ export class FrameManager {
frame._url = url;
const navigationEvent: NavigationEvent = { url, name: frame._name, isPublic: true };
this._fireInternalFrameNavigation(frame, navigationEvent);
- debugLogger.log('api', ` navigated to "${url}"`);
+ frame.apiLog(` navigated to "${url}"`);
}
frameAbortedNavigation(frameId: string, errorText: string, documentId?: string) {
@@ -510,7 +509,7 @@ export class Frame extends SdkObject<FrameEventMap> {
this._firedLifecycleEvents.add(event);
this.emit(Frame.Events.AddLifecycle, event);
if (this === this._page.mainFrame() && this._url !== 'about:blank')
- debugLogger.log('api', ` "${event}" event fired`);
+ this.apiLog(` "${event}" event fired`);
this._page.mainFrame()._recalculateNetworkIdle();
}
@@ -593,7 +592,7 @@ export class Frame extends SdkObject<FrameEventMap> {
this._firedLifecycleEvents.add('networkidle');
this.emit(Frame.Events.AddLifecycle, 'networkidle');
if (this === this._page.mainFrame() && this._url !== 'about:blank')
- debugLogger.log('api', ` "networkidle" event fired`);
+ this.apiLog(` "networkidle" event fired`);
}
if (frameThatAllowsRemovingNetworkIdle !== this && this._firedLifecycleEvents.has('networkidle') && !isNetworkIdle) {
// Usually, networkidle is fired once and not removed after that.
@@ -756,7 +755,7 @@ export class Frame extends SdkObject<FrameEventMap> {
}
async querySelector(selector: string, options: types.StrictOptions): Promise<dom.ElementHandle<Element> | null> {
- debugLogger.log('api', ` finding element using the selector "${selector}"`);
+ this.apiLog(` finding element using the selector "${selector}"`);
return this.selectors.query(selector, options);
}
diff --git a/packages/playwright-core/src/server/instrumentation.ts b/packages/playwright-core/src/server/instrumentation.ts
index f468e312ed..569c1f1638 100644
--- a/packages/playwright-core/src/server/instrumentation.ts
+++ b/packages/playwright-core/src/server/instrumentation.ts
@@ -17,6 +17,7 @@
import { EventEmitter } from 'events';
import { createGuid } from './utils/crypto';
+import { debugLogger } from './utils/debugLogger';
import type { Browser } from './browser';
import type { BrowserContext } from './browserContext';
@@ -57,6 +58,11 @@ export class SdkObject<EM extends EventMap = EventMap> extends EventEmitter<EM>
this.instrumentation = parent.instrumentation;
}
+ apiLog(message: string) {
+ if (!this.attribution.playwright.options.isInternalPlaywright)
+ debugLogger.log('api', message);
+ }
+
closeReason(): string | undefined {
return this.attribution.page?._closeReason ||
this.attribution.context?._closeReason ||
diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.ts
index b94ef285fd..5b51f82abf 100644
--- a/packages/playwright-core/src/server/progress.ts
+++ b/packages/playwright-core/src/server/progress.ts
@@ -42,6 +42,9 @@ export class ProgressController {
static createForSdkObject(sdkObject: SdkObject, callMetadata: CallMetadata) {
const logName = sdkObject.logName || 'api';
return new ProgressController(callMetadata, message => {
+ // Note: "attribution.playwright" is undefined in DebugController. Unfortunate!
+ if (logName === 'api' && sdkObject.attribution.playwright?.options.isInternalPlaywright)
+ return;
debugLogger.log(logName, message);
sdkObject.instrumentation.onCallLog(sdkObject, callMetadata, logName, message);
});