Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move debug, env and user agent from utils/ #34766

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/playwright-core/src/DEPS.list
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
**

[inprocess.ts]
common/
utils/
server/utils

[outofprocess.ts]
client/
common/
protocol/
utils/
utils/isomorphic
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ChannelOwner } from './channelOwner';
import { TargetClosedError, isTargetClosedError } from './errors';
import { Events } from './events';
import { Waiter } from './waiter';
import { TimeoutSettings } from '../common/timeoutSettings';
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';
import { isRegExp, isString } from '../utils/isomorphic/rtti';
import { monotonicTime } from '../utils/isomorphic/time';
import { raceAgainstDeadline } from '../utils/isomorphic/timeoutRunner';
Expand All @@ -30,7 +30,7 @@ import type { Page } from './page';
import type * as types from './types';
import type * as api from '../../types/types';
import type { AndroidServerLauncherImpl } from '../androidServerImpl';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

type Direction = 'down' | 'up' | 'left' | 'right';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { ChannelOwner } from './channelOwner';
import { Stream } from './stream';
import { mkdirIfNeeded } from '../utils/fileUtils';
import { mkdirIfNeeded } from '../common/fileUtils';

import type * as channels from '@protocol/channels';
import type { Readable } from 'stream';
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CDPSession } from './cdpSession';
import { ChannelOwner } from './channelOwner';
import { isTargetClosedError } from './errors';
import { Events } from './events';
import { mkdirIfNeeded } from '../utils/fileUtils';
import { mkdirIfNeeded } from '../common/fileUtils';

import type { BrowserType } from './browserType';
import type { Page } from './page';
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import { Tracing } from './tracing';
import { Waiter } from './waiter';
import { WebError } from './webError';
import { Worker } from './worker';
import { TimeoutSettings } from '../common/timeoutSettings';
import { mkdirIfNeeded } from '../utils/fileUtils';
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';
import { mkdirIfNeeded } from '../common/fileUtils';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { urlMatchesEqual } from '../utils/isomorphic/urlMatch';
import { isRegExp, isString } from '../utils/isomorphic/rtti';
Expand All @@ -46,7 +46,7 @@ import type { BrowserContextOptions, Headers, LaunchOptions, StorageState, WaitF
import type * as structs from '../../types/structs';
import type * as api from '../../types/types';
import type { URLMatch } from '../utils/isomorphic/urlMatch';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel> implements api.BrowserContext {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BrowserContext, prepareBrowserContextParams } from './browserContext';
import { ChannelOwner } from './channelOwner';
import { envObjectToArray } from './clientHelper';
import { Events } from './events';
import { assert } from '../utils/debug';
import { assert } from '../utils/isomorphic/debug';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { monotonicTime } from '../utils/isomorphic/time';
import { raceAgainstDeadline } from '../utils/isomorphic/timeoutRunner';
Expand Down
15 changes: 7 additions & 8 deletions packages/playwright-core/src/client/channelOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

import { EventEmitter } from './eventEmitter';
import { ValidationError, maybeFindValidator } from '../protocol/validator';
import { isUnderTest } from '../utils/debug';
import { debugLogger } from '../utils/debugLogger';
import { isUnderTest } from '../utils/isomorphic/debug';
import { captureLibraryStackTrace, stringifyStackFrames } from '../utils/isomorphic/stackTrace';
import { zones } from '../utils/zones';

import type { ClientInstrumentation } from './clientInstrumentation';
import type { Connection } from './connection';
import type { Logger } from './types';
import type { ValidatorContext } from '../protocol/validator';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

type Listener = (...args: any[]) => void;
Expand Down Expand Up @@ -158,7 +157,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
apiZone.params = params;
apiZone.reported = true;
this._instrumentation.onApiCallBegin(apiZone);
logApiCall(this._logger, `=> ${apiZone.apiName} started`);
logApiCall(this._platform, this._logger, `=> ${apiZone.apiName} started`);
return await this._connection.sendMessageToServer(this, prop, validatedParams, apiZone.apiName, apiZone.frames, apiZone.stepId);
}
// Since this api call is either internal, or has already been reported/traced once,
Expand Down Expand Up @@ -189,7 +188,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
try {
const result = await zones.run('apiZone', apiZone, async () => await func(apiZone));
if (!isInternal) {
logApiCall(logger, `<= ${apiZone.apiName} succeeded`);
logApiCall(this._platform, logger, `<= ${apiZone.apiName} succeeded`);
this._instrumentation.onApiCallEnd(apiZone);
}
return result;
Expand All @@ -204,7 +203,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
e.stack = '';
if (!isInternal) {
apiZone.error = e;
logApiCall(logger, `<= ${apiZone.apiName} failed`);
logApiCall(this._platform, logger, `<= ${apiZone.apiName} failed`);
this._instrumentation.onApiCallEnd(apiZone);
}
throw e;
Expand All @@ -227,10 +226,10 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
}
}

function logApiCall(logger: Logger | undefined, message: string) {
function logApiCall(platform: Platform, logger: Logger | undefined, message: string) {
if (logger && logger.isEnabled('api', 'info'))
logger.log('api', 'info', message, [], { color: 'cyan' });
debugLogger.log('api', message);
platform.log('api', message);
}

function tChannelImplToWire(names: '*' | string[], arg: any, path: string, context: ValidatorContext) {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/clientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { isString } from '../utils/isomorphic/rtti';

import type * as types from './types';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';

export function envObjectToArray(env: types.Env): { name: string, value: string }[] {
const result: { name: string, value: string }[] = [];
Expand Down
15 changes: 7 additions & 8 deletions packages/playwright-core/src/client/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ import { Tracing } from './tracing';
import { Worker } from './worker';
import { WritableStream } from './writableStream';
import { ValidationError, findValidator } from '../protocol/validator';
import { debugLogger } from '../utils/debugLogger';
import { formatCallLog, rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
import { zones } from '../utils/zones';

import type { ClientInstrumentation } from './clientInstrumentation';
import type { HeadersArray } from './types';
import type { ValidatorContext } from '../protocol/validator';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

class Root extends ChannelOwner<channels.RootChannel> {
Expand Down Expand Up @@ -139,9 +138,9 @@ export class Connection extends EventEmitter {
const type = object._type;
const id = ++this._lastId;
const message = { id, guid, method, params };
if (debugLogger.isEnabled('channel')) {
if (this.platform.isLogEnabled('channel')) {
// Do not include metadata in debug logs to avoid noise.
debugLogger.log('channel', 'SEND> ' + JSON.stringify(message));
this.platform.log('channel', 'SEND> ' + JSON.stringify(message));
}
const location = frames[0] ? { file: frames[0].file, line: frames[0].line, column: frames[0].column } : undefined;
const metadata: channels.Metadata = { apiName, location, internal: !apiName, stepId };
Expand All @@ -159,8 +158,8 @@ export class Connection extends EventEmitter {

const { id, guid, method, params, result, error, log } = message as any;
if (id) {
if (debugLogger.isEnabled('channel'))
debugLogger.log('channel', '<RECV ' + JSON.stringify(message));
if (this.platform.isLogEnabled('channel'))
this.platform.log('channel', '<RECV ' + JSON.stringify(message));
const callback = this._callbacks.get(id);
if (!callback)
throw new Error(`Cannot find command to respond: ${id}`);
Expand All @@ -176,8 +175,8 @@ export class Connection extends EventEmitter {
return;
}

if (debugLogger.isEnabled('channel'))
debugLogger.log('channel', '<EVENT ' + JSON.stringify(message));
if (this.platform.isLogEnabled('channel'))
this.platform.log('channel', '<EVENT ' + JSON.stringify(message));
if (method === '__create__') {
this._createRemoteObject(guid, params.type, params.guid, params.initializer);
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/consoleMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { JSHandle } from './jsHandle';
import { Page } from './page';

import type * as api from '../../types/types';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

type ConsoleMessageLocation = channels.BrowserContextConsoleEvent['location'];
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TargetClosedError, isTargetClosedError } from './errors';
import { Events } from './events';
import { JSHandle, parseResult, serializeArgument } from './jsHandle';
import { Waiter } from './waiter';
import { TimeoutSettings } from '../common/timeoutSettings';
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';

import type { Page } from './page';
import type { BrowserContextOptions, Env, Headers, WaitForEventOptions } from './types';
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/elementHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { promisify } from 'util';

import { Frame } from './frame';
import { JSHandle, parseResult, serializeArgument } from './jsHandle';
import { assert } from '../utils/debug';
import { fileUploadSizeLimit, mkdirIfNeeded } from '../utils/fileUtils';
import { assert } from '../utils/isomorphic/debug';
import { fileUploadSizeLimit, mkdirIfNeeded } from '../common/fileUtils';
import { isString } from '../utils/isomorphic/rtti';
import { mime } from '../utilsBundle';
import { WritableStream } from './writableStream';
Expand All @@ -31,7 +31,7 @@ import type { Locator } from './locator';
import type { FilePayload, Rect, SelectOption, SelectOptionOptions } from './types';
import type * as structs from '../../types/structs';
import type * as api from '../../types/types';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

const pipelineAsync = promisify(pipeline);
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import { EventEmitter as OriginalEventEmitter } from 'events';

import { isUnderTest } from '../utils/debug';
import { isUnderTest } from '../utils/isomorphic/debug';

import type { EventEmitter as EventEmitterType } from 'events';

Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { ChannelOwner } from './channelOwner';
import { TargetClosedError, isTargetClosedError } from './errors';
import { RawHeaders } from './network';
import { Tracing } from './tracing';
import { assert } from '../utils/debug';
import { mkdirIfNeeded } from '../utils/fileUtils';
import { assert } from '../utils/isomorphic/debug';
import { mkdirIfNeeded } from '../common/fileUtils';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { isString } from '../utils/isomorphic/rtti';

Expand All @@ -29,7 +29,7 @@ import type { ClientCertificate, FilePayload, Headers, SetStorageState, StorageS
import type { Serializable } from '../../types/structs';
import type * as api from '../../types/types';
import type { HeadersArray, NameValue } from '../common/types';
import type { Platform } from '../utils/platform';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';
import type * as fs from 'fs';

Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { FrameLocator, Locator, testIdAttributeName } from './locator';
import * as network from './network';
import { kLifecycleEvents } from './types';
import { Waiter } from './waiter';
import { assert } from '../utils/debug';
import { assert } from '../utils/isomorphic/debug';
import { getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector } from '../utils/isomorphic/locatorUtils';
import { urlMatches } from '../utils/isomorphic/urlMatch';

Expand Down
6 changes: 2 additions & 4 deletions packages/playwright-core/src/client/harRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

import { debugLogger } from '../utils/debugLogger';

import type { BrowserContext } from './browserContext';
import type { LocalUtils } from './localUtils';
import type { Route } from './network';
Expand Down Expand Up @@ -57,7 +55,7 @@ export class HarRouter {
});

if (response.action === 'redirect') {
debugLogger.log('api', `HAR: ${route.request().url()} redirected to ${response.redirectURL}`);
route._platform.log('api', `HAR: ${route.request().url()} redirected to ${response.redirectURL}`);
await route._redirectNavigationRequest(response.redirectURL!);
return;
}
Expand All @@ -79,7 +77,7 @@ export class HarRouter {
}

if (response.action === 'error')
debugLogger.log('api', 'HAR: ' + response.message!);
route._platform.log('api', 'HAR: ' + response.message!);
// Report the error, but fall through to the default handler.

if (this._notFoundAction === 'abort') {
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/localUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

import { ChannelOwner } from './channelOwner';
import { Connection } from './connection';
import * as localUtils from '../utils/localUtils';
import * as localUtils from '../common/localUtils';

import type { HeadersArray, Size } from './types';
import type { HarBackend } from '../utils/harBackend';
import type { Platform } from '../utils/platform';
import type { HarBackend } from '../common/harBackend';
import type { Platform } from '../common/platform';
import type * as channels from '@protocol/channels';

type DeviceDescriptor = {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { APIResponse } from './fetch';
import { Frame } from './frame';
import { Waiter } from './waiter';
import { Worker } from './worker';
import { assert } from '../utils/debug';
import { assert } from '../utils/isomorphic/debug';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { urlMatches } from '../utils/isomorphic/urlMatch';
import { LongStandingScope, ManualPromise } from '../utils/isomorphic/manualPromise';
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { Response, Route, RouteHandler, WebSocket, WebSocketRoute, WebSocketRou
import { Video } from './video';
import { Waiter } from './waiter';
import { Worker } from './worker';
import { TimeoutSettings } from '../common/timeoutSettings';
import { assert } from '../utils/debug';
import { mkdirIfNeeded } from '../utils/fileUtils';
import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings';
import { assert } from '../utils/isomorphic/debug';
import { mkdirIfNeeded } from '../common/fileUtils';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { trimStringWithEllipsis } from '../utils/isomorphic/stringUtils';
import { urlMatches, urlMatchesEqual } from '../utils/isomorphic/urlMatch';
Expand Down
10 changes: 8 additions & 2 deletions packages/playwright-core/src/client/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@
import { ChannelOwner } from './channelOwner';
import { evaluationScript } from './clientHelper';
import { setTestIdAttribute, testIdAttributeName } from './locator';
import { nodePlatform } from '../utils/platform';
import { emptyPlatform } from '../common/platform';

import type { SelectorEngine } from './types';
import type * as api from '../../types/types';
import type * as channels from '@protocol/channels';
import type { Platform } from '../common/platform';

let platform = emptyPlatform;

export function setPlatformForSelectors(p: Platform) {
platform = p;
}

export class Selectors implements api.Selectors {
private _channels = new Set<SelectorsOwner>();
private _registrations: channels.SelectorsRegisterParams[] = [];

async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise<void> {
const source = await evaluationScript(nodePlatform, script, undefined, false);
const source = await evaluationScript(platform, script, undefined, false);
const params = { ...options, name, source };
for (const channel of this._channels)
await channel._channel.register(params);
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/common/DEPS.list
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[*]
../utils/
../utils/isomorphic/
../utilsBundle.ts
../zipBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { ZipFile } from './zipFile';
import { ZipFile } from '../utils/zipFile';

import type { HeadersArray } from '../common/types';
import type { HeadersArray } from './types';
import type * as har from '@trace/har';
import type { Platform } from './platform';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import * as path from 'path';

import { removeFolders } from './fileUtils';
import { HarBackend } from './harBackend';
import { ManualPromise } from './isomorphic/manualPromise';
import { ZipFile } from './zipFile';
import { ManualPromise } from '../utils/isomorphic/manualPromise';
import { ZipFile } from '../utils/zipFile';
import { yauzl, yazl } from '../zipBundle';
import { serializeClientSideCallMetadata } from '../utils/isomorphic/traceUtils';
import { assert } from '../utils/debug';
import { assert } from '../utils/isomorphic/debug';

import type { Platform } from './platform';
import type * as channels from '@protocol/channels';
Expand Down
Loading
Loading