From 3d760b657b838ba23ab76d33fa16b45a48b4b7de Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 12 Feb 2025 19:27:24 -0800 Subject: [PATCH] chore: move debug, env and user agent from utils/ (#34766) --- packages/playwright-core/src/DEPS.list | 3 + .../playwright-core/src/client/android.ts | 4 +- .../playwright-core/src/client/artifact.ts | 2 +- .../playwright-core/src/client/browser.ts | 2 +- .../src/client/browserContext.ts | 6 +- .../playwright-core/src/client/browserType.ts | 2 +- .../src/client/channelOwner.ts | 15 +++-- .../src/client/clientHelper.ts | 2 +- .../playwright-core/src/client/connection.ts | 15 +++-- .../src/client/consoleMessage.ts | 2 +- .../playwright-core/src/client/electron.ts | 2 +- .../src/client/elementHandle.ts | 6 +- .../src/client/eventEmitter.ts | 2 +- packages/playwright-core/src/client/fetch.ts | 6 +- packages/playwright-core/src/client/frame.ts | 2 +- .../playwright-core/src/client/harRouter.ts | 6 +- .../playwright-core/src/client/localUtils.ts | 6 +- .../playwright-core/src/client/network.ts | 2 +- packages/playwright-core/src/client/page.ts | 6 +- .../playwright-core/src/client/selectors.ts | 10 +++- packages/playwright-core/src/common/DEPS.list | 1 + .../src/{utils => common}/fileUtils.ts | 0 .../src/{utils => common}/harBackend.ts | 4 +- .../src/{utils => common}/localUtils.ts | 6 +- .../src/{utils => common}/platform.ts | 56 ++++++++++++------- .../playwright-core/src/inProcessFactory.ts | 10 +++- packages/playwright-core/src/inprocess.ts | 2 +- packages/playwright-core/src/outofprocess.ts | 2 +- .../src/remote/playwrightConnection.ts | 2 +- .../src/remote/playwrightServer.ts | 4 +- .../src/server/android/DEPS.list | 1 + .../src/server/android/android.ts | 8 +-- .../src/server/android/backendAdb.ts | 2 +- .../src/server/bidi/bidiConnection.ts | 4 +- .../src/server/bidi/bidiOverCdp.ts | 2 +- .../playwright-core/src/server/browser.ts | 2 +- .../src/server/browserContext.ts | 4 +- .../playwright-core/src/server/browserType.ts | 4 +- .../src/server/chromium/chromium.ts | 6 +- .../src/server/chromium/crBrowser.ts | 2 +- .../src/server/chromium/crConnection.ts | 4 +- .../src/server/chromium/crPage.ts | 2 +- .../dispatchers/localUtilsDispatcher.ts | 8 +-- .../src/server/electron/DEPS.list | 1 + .../src/server/electron/electron.ts | 4 +- packages/playwright-core/src/server/fetch.ts | 4 +- .../src/server/fileUploadUtils.ts | 4 +- .../src/server/firefox/ffConnection.ts | 4 +- .../src/server/firefox/ffPage.ts | 2 +- packages/playwright-core/src/server/frames.ts | 2 +- packages/playwright-core/src/server/helper.ts | 2 +- packages/playwright-core/src/server/page.ts | 4 +- .../src/server/pipeTransport.ts | 2 +- .../playwright-core/src/server/progress.ts | 2 +- .../src/server/recorder/recorderCollection.ts | 2 +- .../src/server/registry/browserFetcher.ts | 4 +- .../src/server/registry/dependencies.ts | 4 +- .../src/server/registry/index.ts | 8 +-- .../socksClientCertificatesInterceptor.ts | 2 +- .../src/server/trace/recorder/snapshotter.ts | 2 +- .../src/server/trace/recorder/tracing.ts | 2 +- .../src/server/utils/DEPS.list | 1 + .../src/server/utils/crypto.ts | 2 +- .../src/{ => server}/utils/debugLogger.ts | 2 +- .../src/{ => server}/utils/env.ts | 0 .../src/server/utils/happyEyeballs.ts | 2 +- .../src/{ => server}/utils/hostPlatform.ts | 0 .../src/server/utils/httpServer.ts | 2 +- .../src/{ => server}/utils/linuxUtils.ts | 20 ------- .../src/server/utils/nodePlatform.ts | 49 ++++++++++++++++ .../src/server/utils/socksProxy.ts | 4 +- .../src/{ => server}/utils/userAgent.ts | 2 +- .../src/server/utils/wsServer.ts | 2 +- .../src/server/webkit/wkConnection.ts | 4 +- .../src/server/webkit/wkPage.ts | 4 +- packages/playwright-core/src/utils.ts | 11 ++-- .../src/utils/{ => isomorphic}/debug.ts | 15 +++-- .../isomorphic}/timeoutSettings.ts | 2 +- tests/library/browsertype-connect.spec.ts | 2 +- tests/library/capabilities.spec.ts | 2 +- .../library/chromium/connect-over-cdp.spec.ts | 2 +- .../events/check-listener-leaks.spec.ts | 2 +- tests/library/global-fetch.spec.ts | 2 +- tests/library/inspector/inspectorTest.ts | 2 +- tests/library/modernizr.spec.ts | 2 +- tests/playwright-test/reporter-blob.spec.ts | 2 +- 86 files changed, 248 insertions(+), 182 deletions(-) rename packages/playwright-core/src/{utils => common}/fileUtils.ts (100%) rename packages/playwright-core/src/{utils => common}/harBackend.ts (98%) rename packages/playwright-core/src/{utils => common}/localUtils.ts (98%) rename packages/playwright-core/src/{utils => common}/platform.ts (68%) rename packages/playwright-core/src/{ => server}/utils/debugLogger.ts (98%) rename packages/playwright-core/src/{ => server}/utils/env.ts (100%) rename packages/playwright-core/src/{ => server}/utils/hostPlatform.ts (100%) rename packages/playwright-core/src/{ => server}/utils/linuxUtils.ts (73%) create mode 100644 packages/playwright-core/src/server/utils/nodePlatform.ts rename packages/playwright-core/src/{ => server}/utils/userAgent.ts (98%) rename packages/playwright-core/src/utils/{ => isomorphic}/debug.ts (83%) rename packages/playwright-core/src/{common => utils/isomorphic}/timeoutSettings.ts (98%) diff --git a/packages/playwright-core/src/DEPS.list b/packages/playwright-core/src/DEPS.list index ec14e89070..2ffa077b4e 100644 --- a/packages/playwright-core/src/DEPS.list +++ b/packages/playwright-core/src/DEPS.list @@ -8,10 +8,13 @@ ** [inprocess.ts] +common/ utils/ +server/utils [outofprocess.ts] client/ +common/ protocol/ utils/ utils/isomorphic diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.ts index f6e0419c2c..f0ca11848f 100644 --- a/packages/playwright-core/src/client/android.ts +++ b/packages/playwright-core/src/client/android.ts @@ -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'; @@ -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'; diff --git a/packages/playwright-core/src/client/artifact.ts b/packages/playwright-core/src/client/artifact.ts index fc1e9bca12..815c7a358b 100644 --- a/packages/playwright-core/src/client/artifact.ts +++ b/packages/playwright-core/src/client/artifact.ts @@ -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'; diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.ts index 9d2ca1fab0..88140621fe 100644 --- a/packages/playwright-core/src/client/browser.ts +++ b/packages/playwright-core/src/client/browser.ts @@ -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'; diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 32cac6ba7f..02aa857366 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -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'; @@ -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 implements api.BrowserContext { diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index 79d2fbd521..06bae0419f 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -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'; diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index 5c5afcdc2d..40bf226c65 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -16,8 +16,7 @@ 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'; @@ -25,7 +24,7 @@ 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; @@ -158,7 +157,7 @@ export abstract class ChannelOwner ${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, @@ -189,7 +188,7 @@ export abstract class ChannelOwner await func(apiZone)); if (!isInternal) { - logApiCall(logger, `<= ${apiZone.apiName} succeeded`); + logApiCall(this._platform, logger, `<= ${apiZone.apiName} succeeded`); this._instrumentation.onApiCallEnd(apiZone); } return result; @@ -204,7 +203,7 @@ export abstract class ChannelOwner { @@ -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 }; @@ -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', '(); private _registrations: channels.SelectorsRegisterParams[] = []; async register(name: string, script: string | (() => SelectorEngine) | { path?: string, content?: string }, options: { contentScript?: boolean } = {}): Promise { - 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); diff --git a/packages/playwright-core/src/common/DEPS.list b/packages/playwright-core/src/common/DEPS.list index 43bff9dba4..a25dd41c36 100644 --- a/packages/playwright-core/src/common/DEPS.list +++ b/packages/playwright-core/src/common/DEPS.list @@ -1,4 +1,5 @@ [*] ../utils/ +../utils/isomorphic/ ../utilsBundle.ts ../zipBundle.ts diff --git a/packages/playwright-core/src/utils/fileUtils.ts b/packages/playwright-core/src/common/fileUtils.ts similarity index 100% rename from packages/playwright-core/src/utils/fileUtils.ts rename to packages/playwright-core/src/common/fileUtils.ts diff --git a/packages/playwright-core/src/utils/harBackend.ts b/packages/playwright-core/src/common/harBackend.ts similarity index 98% rename from packages/playwright-core/src/utils/harBackend.ts rename to packages/playwright-core/src/common/harBackend.ts index 304fe4b150..f59b7de5f1 100644 --- a/packages/playwright-core/src/utils/harBackend.ts +++ b/packages/playwright-core/src/common/harBackend.ts @@ -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'; diff --git a/packages/playwright-core/src/utils/localUtils.ts b/packages/playwright-core/src/common/localUtils.ts similarity index 98% rename from packages/playwright-core/src/utils/localUtils.ts rename to packages/playwright-core/src/common/localUtils.ts index 49a3c43175..5020d82b75 100644 --- a/packages/playwright-core/src/utils/localUtils.ts +++ b/packages/playwright-core/src/common/localUtils.ts @@ -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'; diff --git a/packages/playwright-core/src/utils/platform.ts b/packages/playwright-core/src/common/platform.ts similarity index 68% rename from packages/playwright-core/src/utils/platform.ts rename to packages/playwright-core/src/common/platform.ts index 5abf38e8c0..390dbf80ff 100644 --- a/packages/playwright-core/src/utils/platform.ts +++ b/packages/playwright-core/src/common/platform.ts @@ -17,36 +17,19 @@ import * as crypto from 'crypto'; import * as fs from 'fs'; import * as path from 'path'; -import * as util from 'util'; export type Platform = { calculateSha1(text: string): Promise; createGuid: () => string; fs: () => typeof fs; inspectCustom: symbol | undefined; + isLogEnabled(name: 'api' | 'channel'): boolean; + log(name: 'api' | 'channel', message: string | Error | object): void; path: () => typeof path; pathSeparator: string; ws?: (url: string) => WebSocket; }; -export const nodePlatform: Platform = { - calculateSha1: (text: string) => { - const sha1 = crypto.createHash('sha1'); - sha1.update(text); - return Promise.resolve(sha1.digest('hex')); - }, - - createGuid: () => crypto.randomBytes(16).toString('hex'), - - fs: () => fs, - - inspectCustom: util.inspect.custom, - - path: () => path, - - pathSeparator: path.sep -}; - export const webPlatform: Platform = { calculateSha1: async (text: string) => { const bytes = new TextEncoder().encode(text); @@ -64,6 +47,13 @@ export const webPlatform: Platform = { inspectCustom: undefined, + + isLogEnabled(name: 'api' | 'channel') { + return false; + }, + + log(name: 'api' | 'channel', message: string | Error | object) {}, + path: () => { throw new Error('Path module is not available'); }, @@ -72,3 +62,31 @@ export const webPlatform: Platform = { ws: (url: string) => new WebSocket(url), }; + +export const emptyPlatform: Platform = { + calculateSha1: async () => { + throw new Error('Not implemented'); + }, + + createGuid: () => { + throw new Error('Not implemented'); + }, + + fs: () => { + throw new Error('Not implemented'); + }, + + inspectCustom: undefined, + + isLogEnabled(name: 'api' | 'channel') { + return false; + }, + + log(name: 'api' | 'channel', message: string | Error | object) { }, + + path: () => { + throw new Error('Function not implemented.'); + }, + + pathSeparator: '/' +}; diff --git a/packages/playwright-core/src/inProcessFactory.ts b/packages/playwright-core/src/inProcessFactory.ts index 784bfc4c88..81b40afe19 100644 --- a/packages/playwright-core/src/inProcessFactory.ts +++ b/packages/playwright-core/src/inProcessFactory.ts @@ -21,13 +21,21 @@ import { BrowserServerLauncherImpl } from './browserServerImpl'; import { Connection } from './client/connection'; import { DispatcherConnection, PlaywrightDispatcher, RootDispatcher, createPlaywright } from './server'; import { setLibraryStackPrefix } from './utils/isomorphic/stackTrace'; +import { setDebugMode } from './utils/isomorphic/debug'; +import { getFromENV } from './server/utils/env'; +import { nodePlatform } from './server/utils/nodePlatform'; +import { setPlatformForSelectors } from './client/selectors'; import type { Playwright as PlaywrightAPI } from './client/playwright'; import type { Language } from './utils'; -import type { Platform } from './utils/platform'; +import type { Platform } from './common/platform'; + export function createInProcessPlaywright(platform: Platform): PlaywrightAPI { const playwright = createPlaywright({ sdkLanguage: (process.env.PW_LANG_NAME as Language | undefined) || 'javascript' }); + setDebugMode(getFromENV('PWDEBUG') || ''); + setPlatformForSelectors(nodePlatform); + setLibraryStackPrefix(path.join(__dirname, '..')); const clientConnection = new Connection(undefined, platform, undefined, []); diff --git a/packages/playwright-core/src/inprocess.ts b/packages/playwright-core/src/inprocess.ts index c057f7b5c0..fc0550e924 100644 --- a/packages/playwright-core/src/inprocess.ts +++ b/packages/playwright-core/src/inprocess.ts @@ -15,6 +15,6 @@ */ import { createInProcessPlaywright } from './inProcessFactory'; -import { nodePlatform } from './utils/platform'; +import { nodePlatform } from './server/utils/nodePlatform'; module.exports = createInProcessPlaywright(nodePlatform); diff --git a/packages/playwright-core/src/outofprocess.ts b/packages/playwright-core/src/outofprocess.ts index 8dcb8fa45a..c24decb900 100644 --- a/packages/playwright-core/src/outofprocess.ts +++ b/packages/playwright-core/src/outofprocess.ts @@ -20,7 +20,7 @@ import * as path from 'path'; import { Connection } from './client/connection'; import { PipeTransport } from './utils/pipeTransport'; import { ManualPromise } from './utils/isomorphic/manualPromise'; -import { nodePlatform } from './utils/platform'; +import { nodePlatform } from './server/utils/nodePlatform'; import type { Playwright } from './client/playwright'; diff --git a/packages/playwright-core/src/remote/playwrightConnection.ts b/packages/playwright-core/src/remote/playwrightConnection.ts index e276873668..00ca33b353 100644 --- a/packages/playwright-core/src/remote/playwrightConnection.ts +++ b/packages/playwright-core/src/remote/playwrightConnection.ts @@ -23,7 +23,7 @@ import { serverSideCallMetadata } from '../server/instrumentation'; import { assert, isUnderTest } from '../utils'; import { startProfiling, stopProfiling } from '../server/utils/profiler'; import { monotonicTime } from '../utils'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from '../server/utils/debugLogger'; import type { DispatcherScope, Playwright } from '../server'; import type { LaunchOptions } from '../server/types'; diff --git a/packages/playwright-core/src/remote/playwrightServer.ts b/packages/playwright-core/src/remote/playwrightServer.ts index 911fa1b97c..7f6a58a0a5 100644 --- a/packages/playwright-core/src/remote/playwrightServer.ts +++ b/packages/playwright-core/src/remote/playwrightServer.ts @@ -16,11 +16,11 @@ import { PlaywrightConnection } from './playwrightConnection'; import { createPlaywright } from '../server/playwright'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from '../server/utils/debugLogger'; import { Semaphore } from '../utils/isomorphic/semaphore'; import { WSServer } from '../server/utils/wsServer'; import { wrapInASCIIBox } from '../server/utils/ascii'; -import { getPlaywrightVersion } from '../utils/userAgent'; +import { getPlaywrightVersion } from '../server/utils/userAgent'; import type { ClientType } from './playwrightConnection'; import type { SocksProxy } from '../server/utils/socksProxy'; diff --git a/packages/playwright-core/src/server/android/DEPS.list b/packages/playwright-core/src/server/android/DEPS.list index b45c3a16a7..b852561b95 100644 --- a/packages/playwright-core/src/server/android/DEPS.list +++ b/packages/playwright-core/src/server/android/DEPS.list @@ -3,6 +3,7 @@ ../../common/ ../../protocol/ ../../utils/ +../../utils/isomorphic/ ../../utilsBundle.ts ../chromium/ ../utils diff --git a/packages/playwright-core/src/server/android/android.ts b/packages/playwright-core/src/server/android/android.ts index 68db8ab77c..c1516dea76 100644 --- a/packages/playwright-core/src/server/android/android.ts +++ b/packages/playwright-core/src/server/android/android.ts @@ -19,13 +19,13 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { TimeoutSettings } from '../../common/timeoutSettings'; +import { TimeoutSettings } from '../../utils/isomorphic/timeoutSettings'; import { PipeTransport } from '../../utils/pipeTransport'; import { createGuid } from '../utils/crypto'; -import { isUnderTest } from '../../utils/debug'; -import { getPackageManagerExecCommand } from '../../utils/env'; +import { isUnderTest } from '../../utils/isomorphic/debug'; +import { getPackageManagerExecCommand } from '../utils/env'; import { makeWaitForNextTask } from '../../utils/task'; -import { RecentLogsCollector } from '../../utils/debugLogger'; +import { RecentLogsCollector } from '../utils/debugLogger'; import { debug } from '../../utilsBundle'; import { wsReceiver, wsSender } from '../../utilsBundle'; import { validateBrowserContextOptions } from '../browserContext'; diff --git a/packages/playwright-core/src/server/android/backendAdb.ts b/packages/playwright-core/src/server/android/backendAdb.ts index 737d415050..036c74703e 100644 --- a/packages/playwright-core/src/server/android/backendAdb.ts +++ b/packages/playwright-core/src/server/android/backendAdb.ts @@ -17,7 +17,7 @@ import { EventEmitter } from 'events'; import * as net from 'net'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { createGuid } from '../utils/crypto'; import { debug } from '../../utilsBundle'; diff --git a/packages/playwright-core/src/server/bidi/bidiConnection.ts b/packages/playwright-core/src/server/bidi/bidiConnection.ts index 87b3f59c9b..0882836c38 100644 --- a/packages/playwright-core/src/server/bidi/bidiConnection.ts +++ b/packages/playwright-core/src/server/bidi/bidiConnection.ts @@ -16,11 +16,11 @@ import { EventEmitter } from 'events'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { helper } from '../helper'; import { ProtocolError } from '../protocolError'; -import type { RecentLogsCollector } from '../../utils/debugLogger'; +import type { RecentLogsCollector } from '../utils/debugLogger'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { ProtocolLogger } from '../types'; import type * as bidiCommands from './third_party/bidiCommands'; diff --git a/packages/playwright-core/src/server/bidi/bidiOverCdp.ts b/packages/playwright-core/src/server/bidi/bidiOverCdp.ts index adf7c9afbf..8acd45563d 100644 --- a/packages/playwright-core/src/server/bidi/bidiOverCdp.ts +++ b/packages/playwright-core/src/server/bidi/bidiOverCdp.ts @@ -17,7 +17,7 @@ import * as bidiMapper from 'chromium-bidi/lib/cjs/bidiMapper/BidiMapper'; import * as bidiCdpConnection from 'chromium-bidi/lib/cjs/cdp/CdpConnection'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { ChromiumBidi } from 'chromium-bidi/lib/cjs/protocol/protocol'; diff --git a/packages/playwright-core/src/server/browser.ts b/packages/playwright-core/src/server/browser.ts index d99a3f8f8a..7cf00f73c8 100644 --- a/packages/playwright-core/src/server/browser.ts +++ b/packages/playwright-core/src/server/browser.ts @@ -24,7 +24,7 @@ import { ClientCertificatesProxy } from './socksClientCertificatesInterceptor'; import type { CallMetadata } from './instrumentation'; import type * as types from './types'; import type { ProxySettings } from './types'; -import type { RecentLogsCollector } from '../utils/debugLogger'; +import type { RecentLogsCollector } from './utils/debugLogger'; import type * as channels from '@protocol/channels'; import type { ChildProcess } from 'child_process'; diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts index 48c87f7dc4..fd50994343 100644 --- a/packages/playwright-core/src/server/browserContext.ts +++ b/packages/playwright-core/src/server/browserContext.ts @@ -18,9 +18,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import { TimeoutSettings } from '../common/timeoutSettings'; +import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings'; import { createGuid } from './utils/crypto'; -import { debugMode } from '../utils/debug'; +import { debugMode } from '../utils/isomorphic/debug'; import { Clock } from './clock'; import { Debugger } from './debugger'; import { BrowserContextAPIRequestContext } from './fetch'; diff --git a/packages/playwright-core/src/server/browserType.ts b/packages/playwright-core/src/server/browserType.ts index 9952aef2f4..7fe3844c7d 100644 --- a/packages/playwright-core/src/server/browserType.ts +++ b/packages/playwright-core/src/server/browserType.ts @@ -19,7 +19,7 @@ import * as os from 'os'; import * as path from 'path'; import { normalizeProxySettings, validateBrowserContextOptions } from './browserContext'; -import { DEFAULT_TIMEOUT, TimeoutSettings } from '../common/timeoutSettings'; +import { DEFAULT_TIMEOUT, TimeoutSettings } from '../utils/isomorphic/timeoutSettings'; import { ManualPromise, assert, debugMode } from '../utils'; import { existsAsync } from './utils/fileUtils'; import { helper } from './helper'; @@ -31,7 +31,7 @@ import { isProtocolError } from './protocolError'; import { registry } from './registry'; import { ClientCertificatesProxy } from './socksClientCertificatesInterceptor'; import { WebSocketTransport } from './transport'; -import { RecentLogsCollector } from '../utils/debugLogger'; +import { RecentLogsCollector } from './utils/debugLogger'; import type { Browser, BrowserOptions, BrowserProcess } from './browser'; import type { BrowserContext } from './browserContext'; diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts index 7c520aa213..3f06e135cd 100644 --- a/packages/playwright-core/src/server/chromium/chromium.ts +++ b/packages/playwright-core/src/server/chromium/chromium.ts @@ -22,13 +22,13 @@ import * as path from 'path'; import { chromiumSwitches } from './chromiumSwitches'; import { CRBrowser } from './crBrowser'; import { kBrowserCloseMessageId } from './crConnection'; -import { TimeoutSettings } from '../../common/timeoutSettings'; +import { TimeoutSettings } from '../../utils/isomorphic/timeoutSettings'; import { debugMode, headersArrayToObject, headersObjectToArray, } from '../../utils'; import { wrapInASCIIBox } from '../utils/ascii'; -import { RecentLogsCollector } from '../../utils/debugLogger'; +import { RecentLogsCollector } from '../utils/debugLogger'; import { ManualPromise } from '../../utils/isomorphic/manualPromise'; import { fetchData } from '../utils/network'; -import { getUserAgent } from '../../utils/userAgent'; +import { getUserAgent } from '../utils/userAgent'; import { validateBrowserContextOptions } from '../browserContext'; import { BrowserType, kNoXServerRunningError } from '../browserType'; import { BrowserReadyState } from '../browserType'; diff --git a/packages/playwright-core/src/server/chromium/crBrowser.ts b/packages/playwright-core/src/server/chromium/crBrowser.ts index abd4aee685..7cc6030486 100644 --- a/packages/playwright-core/src/server/chromium/crBrowser.ts +++ b/packages/playwright-core/src/server/chromium/crBrowser.ts @@ -17,7 +17,7 @@ import * as path from 'path'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { createGuid } from '../utils/crypto'; import { Artifact } from '../artifact'; import { Browser } from '../browser'; diff --git a/packages/playwright-core/src/server/chromium/crConnection.ts b/packages/playwright-core/src/server/chromium/crConnection.ts index 424d64a500..98c566c82a 100644 --- a/packages/playwright-core/src/server/chromium/crConnection.ts +++ b/packages/playwright-core/src/server/chromium/crConnection.ts @@ -18,14 +18,14 @@ import { EventEmitter } from 'events'; import { assert, eventsHelper } from '../../utils'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { helper } from '../helper'; import { ProtocolError } from '../protocolError'; import type { RegisteredListener } from '../../utils'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; -import type { RecentLogsCollector } from '../../utils/debugLogger'; +import type { RecentLogsCollector } from '../utils/debugLogger'; import type { ProtocolLogger } from '../types'; diff --git a/packages/playwright-core/src/server/chromium/crPage.ts b/packages/playwright-core/src/server/chromium/crPage.ts index bb218202e6..34470470dc 100644 --- a/packages/playwright-core/src/server/chromium/crPage.ts +++ b/packages/playwright-core/src/server/chromium/crPage.ts @@ -17,7 +17,7 @@ import * as path from 'path'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { createGuid } from '../utils/crypto'; import { eventsHelper } from '../utils/eventsHelper'; import { rewriteErrorMessage } from '../../utils/isomorphic/stackTrace'; diff --git a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts index 37ff8c8b81..b582aa8788 100644 --- a/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts +++ b/packages/playwright-core/src/server/dispatchers/localUtilsDispatcher.ts @@ -16,9 +16,9 @@ import { Dispatcher } from './dispatcher'; import { SdkObject } from '../../server/instrumentation'; -import * as localUtils from '../../utils/localUtils'; -import { nodePlatform } from '../../utils/platform'; -import { getUserAgent } from '../../utils/userAgent'; +import * as localUtils from '../../common/localUtils'; +import { nodePlatform } from '../utils/nodePlatform'; +import { getUserAgent } from '../utils/userAgent'; import { deviceDescriptors as descriptors } from '../deviceDescriptors'; import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher'; import { Progress, ProgressController } from '../progress'; @@ -26,7 +26,7 @@ import { SocksInterceptor } from '../socksInterceptor'; import { WebSocketTransport } from '../transport'; import { fetchData } from '../utils/network'; -import type { HarBackend } from '../../utils/harBackend'; +import type { HarBackend } from '../../common/harBackend'; import type { CallMetadata } from '../instrumentation'; import type { Playwright } from '../playwright'; import type { RootDispatcher } from './dispatcher'; diff --git a/packages/playwright-core/src/server/electron/DEPS.list b/packages/playwright-core/src/server/electron/DEPS.list index 1d51da425e..1acb5c5a0e 100644 --- a/packages/playwright-core/src/server/electron/DEPS.list +++ b/packages/playwright-core/src/server/electron/DEPS.list @@ -2,5 +2,6 @@ ../ ../../common/ ../../utils/ +../../utils/isomorphic/ ../chromium/ ../utils \ No newline at end of file diff --git a/packages/playwright-core/src/server/electron/electron.ts b/packages/playwright-core/src/server/electron/electron.ts index 1728a317a8..4713324ed1 100644 --- a/packages/playwright-core/src/server/electron/electron.ts +++ b/packages/playwright-core/src/server/electron/electron.ts @@ -19,10 +19,10 @@ import * as os from 'os'; import * as path from 'path'; import * as readline from 'readline'; -import { TimeoutSettings } from '../../common/timeoutSettings'; +import { TimeoutSettings } from '../../utils/isomorphic/timeoutSettings'; import { ManualPromise } from '../../utils'; import { wrapInASCIIBox } from '../utils/ascii'; -import { RecentLogsCollector } from '../../utils/debugLogger'; +import { RecentLogsCollector } from '../utils/debugLogger'; import { eventsHelper } from '../utils/eventsHelper'; import { validateBrowserContextOptions } from '../browserContext'; import { CRBrowser } from '../chromium/crBrowser'; diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts index 08e63bb83b..6e1d6d02f1 100644 --- a/packages/playwright-core/src/server/fetch.ts +++ b/packages/playwright-core/src/server/fetch.ts @@ -21,10 +21,10 @@ import { TLSSocket } from 'tls'; import * as url from 'url'; import * as zlib from 'zlib'; -import { TimeoutSettings } from '../common/timeoutSettings'; +import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings'; import { assert, constructURLBasedOnBaseURL, eventsHelper, monotonicTime } from '../utils'; import { createGuid } from './utils/crypto'; -import { getUserAgent } from '../utils/userAgent'; +import { getUserAgent } from './utils/userAgent'; import { HttpsProxyAgent, SocksProxyAgent } from '../utilsBundle'; import { BrowserContext, verifyClientCertificates } from './browserContext'; import { CookieStore, domainMatches, parseRawCookie } from './cookieStore'; diff --git a/packages/playwright-core/src/server/fileUploadUtils.ts b/packages/playwright-core/src/server/fileUploadUtils.ts index 1c53812a0a..908e7644ac 100644 --- a/packages/playwright-core/src/server/fileUploadUtils.ts +++ b/packages/playwright-core/src/server/fileUploadUtils.ts @@ -17,8 +17,8 @@ import * as fs from 'fs'; import * as path from 'path'; -import { assert } from '../utils/debug'; -import { fileUploadSizeLimit } from '../utils/fileUtils'; +import { assert } from '../utils/isomorphic/debug'; +import { fileUploadSizeLimit } from '../common/fileUtils'; import { mime } from '../utilsBundle'; import type { WritableStreamDispatcher } from './dispatchers/writableStreamDispatcher'; diff --git a/packages/playwright-core/src/server/firefox/ffConnection.ts b/packages/playwright-core/src/server/firefox/ffConnection.ts index 6001754219..1477ace249 100644 --- a/packages/playwright-core/src/server/firefox/ffConnection.ts +++ b/packages/playwright-core/src/server/firefox/ffConnection.ts @@ -17,13 +17,13 @@ import { EventEmitter } from 'events'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { helper } from '../helper'; import { ProtocolError } from '../protocolError'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; -import type { RecentLogsCollector } from '../../utils/debugLogger'; +import type { RecentLogsCollector } from '../utils/debugLogger'; import type { ProtocolLogger } from '../types'; diff --git a/packages/playwright-core/src/server/firefox/ffPage.ts b/packages/playwright-core/src/server/firefox/ffPage.ts index c2b59ca08b..22229dff3e 100644 --- a/packages/playwright-core/src/server/firefox/ffPage.ts +++ b/packages/playwright-core/src/server/firefox/ffPage.ts @@ -25,7 +25,7 @@ import { FFSession } from './ffConnection'; import { FFExecutionContext } from './ffExecutionContext'; import { RawKeyboardImpl, RawMouseImpl, RawTouchscreenImpl } from './ffInput'; import { FFNetworkManager } from './ffNetworkManager'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { splitErrorMessage } from '../../utils/isomorphic/stackTrace'; import { BrowserContext } from '../browserContext'; import { TargetClosedError } from '../errors'; diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.ts index 87bd4f9623..dee2ad7f08 100644 --- a/packages/playwright-core/src/server/frames.ts +++ b/packages/playwright-core/src/server/frames.ts @@ -29,7 +29,7 @@ import { ProgressController } from './progress'; import * as types from './types'; import { LongStandingScope, asLocator, assert, compressCallLog, constructURLBasedOnBaseURL, makeWaitForNextTask, monotonicTime } from '../utils'; import { isSessionClosedError } from './protocolError'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from './utils/debugLogger'; import { eventsHelper } from './utils/eventsHelper'; import { isInvalidSelectorError } from '../utils/isomorphic/selectorParser'; import { ManualPromise } from '../utils/isomorphic/manualPromise'; diff --git a/packages/playwright-core/src/server/helper.ts b/packages/playwright-core/src/server/helper.ts index da049e2be6..e9fec62419 100644 --- a/packages/playwright-core/src/server/helper.ts +++ b/packages/playwright-core/src/server/helper.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from './utils/debugLogger'; import { eventsHelper } from './utils/eventsHelper'; import type { Progress } from './progress'; diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts index 300cf05e50..d2db2e4211 100644 --- a/packages/playwright-core/src/server/page.ts +++ b/packages/playwright-core/src/server/page.ts @@ -28,12 +28,12 @@ import { parseEvaluationResultValue, source } from './isomorphic/utilityScriptSe import * as js from './javascript'; import { ProgressController } from './progress'; import { Screenshotter, validateScreenshotOptions } from './screenshotter'; -import { TimeoutSettings } from '../common/timeoutSettings'; +import { TimeoutSettings } from '../utils/isomorphic/timeoutSettings'; import { LongStandingScope, assert, compressCallLog, trimStringWithEllipsis } from '../utils'; import { createGuid } from './utils/crypto'; import { asLocator } from '../utils'; import { getComparator } from './utils/comparators'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from './utils/debugLogger'; import { isInvalidSelectorError } from '../utils/isomorphic/selectorParser'; import { ManualPromise } from '../utils/isomorphic/manualPromise'; diff --git a/packages/playwright-core/src/server/pipeTransport.ts b/packages/playwright-core/src/server/pipeTransport.ts index 67bf126324..ba811e606e 100644 --- a/packages/playwright-core/src/server/pipeTransport.ts +++ b/packages/playwright-core/src/server/pipeTransport.ts @@ -16,7 +16,7 @@ */ import { makeWaitForNextTask } from '../utils'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from './utils/debugLogger'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from './transport'; diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.ts index 9766c66ebd..30db144fbb 100644 --- a/packages/playwright-core/src/server/progress.ts +++ b/packages/playwright-core/src/server/progress.ts @@ -20,7 +20,7 @@ import { ManualPromise } from '../utils/isomorphic/manualPromise'; import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation'; import type { Progress as CommonProgress } from '../common/progress'; -import type { LogName } from '../utils/debugLogger'; +import type { LogName } from './utils/debugLogger'; export interface Progress extends CommonProgress { metadata: CallMetadata; diff --git a/packages/playwright-core/src/server/recorder/recorderCollection.ts b/packages/playwright-core/src/server/recorder/recorderCollection.ts index 454fa05b90..8c7b344b8e 100644 --- a/packages/playwright-core/src/server/recorder/recorderCollection.ts +++ b/packages/playwright-core/src/server/recorder/recorderCollection.ts @@ -18,7 +18,7 @@ import { EventEmitter } from 'events'; import { performAction } from './recorderRunner'; import { collapseActions } from './recorderUtils'; -import { isUnderTest } from '../../utils/debug'; +import { isUnderTest } from '../../utils/isomorphic/debug'; import { monotonicTime } from '../../utils/isomorphic/time'; import type { Signal } from '../../../../recorder/src/actions'; diff --git a/packages/playwright-core/src/server/registry/browserFetcher.ts b/packages/playwright-core/src/server/registry/browserFetcher.ts index 0e7809cadb..fb6afb3f10 100644 --- a/packages/playwright-core/src/server/registry/browserFetcher.ts +++ b/packages/playwright-core/src/server/registry/browserFetcher.ts @@ -20,9 +20,9 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { ManualPromise } from '../../utils/isomorphic/manualPromise'; -import { getUserAgent } from '../../utils/userAgent'; +import { getUserAgent } from '../utils/userAgent'; import { progress as ProgressBar } from '../../utilsBundle'; import { colors } from '../../utils/isomorphic/colors'; import { existsAsync } from '../utils/fileUtils'; diff --git a/packages/playwright-core/src/server/registry/dependencies.ts b/packages/playwright-core/src/server/registry/dependencies.ts index e405d75c6f..5cf4a097b1 100644 --- a/packages/playwright-core/src/server/registry/dependencies.ts +++ b/packages/playwright-core/src/server/registry/dependencies.ts @@ -21,9 +21,9 @@ import * as path from 'path'; import { deps } from './nativeDeps'; import { wrapInASCIIBox } from '../utils/ascii'; -import { hostPlatform, isOfficiallySupportedPlatform } from '../../utils/hostPlatform'; +import { hostPlatform, isOfficiallySupportedPlatform } from '../utils/hostPlatform'; import { spawnAsync } from '../utils/spawnAsync'; -import { getPlaywrightVersion } from '../../utils/userAgent'; +import { getPlaywrightVersion } from '../utils/userAgent'; import { buildPlaywrightCLICommand, registry } from '.'; diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts index 87804f06dd..e0282120fb 100644 --- a/packages/playwright-core/src/server/registry/index.ts +++ b/packages/playwright-core/src/server/registry/index.ts @@ -25,16 +25,16 @@ import { dockerVersion, readDockerVersionSync, transformCommandsForRoot } from ' import { installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies'; import { calculateSha1, getAsBooleanFromENV, getFromENV, getPackageManagerExecCommand } from '../../utils'; import { wrapInASCIIBox } from '../utils/ascii'; -import { debugLogger } from '../../utils/debugLogger'; -import { hostPlatform, isOfficiallySupportedPlatform } from '../../utils/hostPlatform'; +import { debugLogger } from '../utils/debugLogger'; +import { hostPlatform, isOfficiallySupportedPlatform } from '../utils/hostPlatform'; import { fetchData } from '../utils/network'; import { spawnAsync } from '../utils/spawnAsync'; -import { getEmbedderName } from '../../utils/userAgent'; +import { getEmbedderName } from '../utils/userAgent'; import { lockfile } from '../../utilsBundle'; import { canAccessFile, existsAsync, removeFolders } from '../utils/fileUtils'; import type { DependencyGroup } from './dependencies'; -import type { HostPlatform } from '../../utils/hostPlatform'; +import type { HostPlatform } from '../utils/hostPlatform'; export { writeDockerVersion } from './dependencies'; diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts index b1943ca123..f769f60d74 100644 --- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts +++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts @@ -24,7 +24,7 @@ import { SocksProxy } from './utils/socksProxy'; import { ManualPromise, escapeHTML, generateSelfSignedCertificate, rewriteErrorMessage } from '../utils'; import { verifyClientCertificates } from './browserContext'; import { createProxyAgent } from './fetch'; -import { debugLogger } from '../utils/debugLogger'; +import { debugLogger } from './utils/debugLogger'; import { createSocket, createTLSSocket } from './utils/happyEyeballs'; import type * as types from './types'; diff --git a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts index 9a914e1ad4..f4e288d077 100644 --- a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts +++ b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts @@ -17,7 +17,7 @@ import { frameSnapshotStreamer } from './snapshotterInjected'; import { monotonicTime } from '../../../utils/isomorphic/time'; import { calculateSha1, createGuid } from '../../utils/crypto'; -import { debugLogger } from '../../../utils/debugLogger'; +import { debugLogger } from '../../utils/debugLogger'; import { eventsHelper } from '../../utils/eventsHelper'; import { mime } from '../../../utilsBundle'; import { BrowserContext } from '../../browserContext'; diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts index 26e3075a29..309867f3b0 100644 --- a/packages/playwright-core/src/server/trace/recorder/tracing.ts +++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts @@ -20,7 +20,7 @@ import * as path from 'path'; import { Snapshotter } from './snapshotter'; import { commandsWithTracingSnapshots } from '../../../protocol/debug'; -import { assert } from '../../../utils/debug'; +import { assert } from '../../../utils/isomorphic/debug'; import { monotonicTime } from '../../../utils/isomorphic/time'; import { eventsHelper } from '../../utils/eventsHelper'; import { createGuid } from '../../utils/crypto'; diff --git a/packages/playwright-core/src/server/utils/DEPS.list b/packages/playwright-core/src/server/utils/DEPS.list index 8d1b7a30f2..685e00df46 100644 --- a/packages/playwright-core/src/server/utils/DEPS.list +++ b/packages/playwright-core/src/server/utils/DEPS.list @@ -1,4 +1,5 @@ [*] +../../common ../../utils ../../utils/isomorphic ../../utilsBundle.ts diff --git a/packages/playwright-core/src/server/utils/crypto.ts b/packages/playwright-core/src/server/utils/crypto.ts index 0a35c3c8c9..7189f38b00 100644 --- a/packages/playwright-core/src/server/utils/crypto.ts +++ b/packages/playwright-core/src/server/utils/crypto.ts @@ -16,7 +16,7 @@ import * as crypto from 'crypto'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; export function createGuid(): string { return crypto.randomBytes(16).toString('hex'); diff --git a/packages/playwright-core/src/utils/debugLogger.ts b/packages/playwright-core/src/server/utils/debugLogger.ts similarity index 98% rename from packages/playwright-core/src/utils/debugLogger.ts rename to packages/playwright-core/src/server/utils/debugLogger.ts index 24b0a1dbf8..8713b3cf7e 100644 --- a/packages/playwright-core/src/utils/debugLogger.ts +++ b/packages/playwright-core/src/server/utils/debugLogger.ts @@ -16,7 +16,7 @@ import * as fs from 'fs'; -import { debug } from '../utilsBundle'; +import { debug } from '../../utilsBundle'; const debugLoggerColorMap = { 'api': 45, // cyan diff --git a/packages/playwright-core/src/utils/env.ts b/packages/playwright-core/src/server/utils/env.ts similarity index 100% rename from packages/playwright-core/src/utils/env.ts rename to packages/playwright-core/src/server/utils/env.ts diff --git a/packages/playwright-core/src/server/utils/happyEyeballs.ts b/packages/playwright-core/src/server/utils/happyEyeballs.ts index a5c6087513..da3481f4c1 100644 --- a/packages/playwright-core/src/server/utils/happyEyeballs.ts +++ b/packages/playwright-core/src/server/utils/happyEyeballs.ts @@ -20,7 +20,7 @@ import * as https from 'https'; import * as net from 'net'; import * as tls from 'tls'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { ManualPromise } from '../../utils/isomorphic/manualPromise'; import { monotonicTime } from '../../utils/isomorphic/time'; diff --git a/packages/playwright-core/src/utils/hostPlatform.ts b/packages/playwright-core/src/server/utils/hostPlatform.ts similarity index 100% rename from packages/playwright-core/src/utils/hostPlatform.ts rename to packages/playwright-core/src/server/utils/hostPlatform.ts diff --git a/packages/playwright-core/src/server/utils/httpServer.ts b/packages/playwright-core/src/server/utils/httpServer.ts index 21992195c0..0c9f0fe25a 100644 --- a/packages/playwright-core/src/server/utils/httpServer.ts +++ b/packages/playwright-core/src/server/utils/httpServer.ts @@ -19,7 +19,7 @@ import * as path from 'path'; import { mime, wsServer } from '../../utilsBundle'; import { createGuid } from './crypto'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { ManualPromise } from '../../utils/isomorphic/manualPromise'; import { createHttpServer } from './network'; diff --git a/packages/playwright-core/src/utils/linuxUtils.ts b/packages/playwright-core/src/server/utils/linuxUtils.ts similarity index 73% rename from packages/playwright-core/src/utils/linuxUtils.ts rename to packages/playwright-core/src/server/utils/linuxUtils.ts index c51d32f9d5..3c85ebe091 100644 --- a/packages/playwright-core/src/utils/linuxUtils.ts +++ b/packages/playwright-core/src/server/utils/linuxUtils.ts @@ -23,26 +23,6 @@ let osRelease: { version: string, } | undefined; -export async function getLinuxDistributionInfo(): Promise<{ id: string, version: string } | undefined> { - if (process.platform !== 'linux') - return undefined; - if (!osRelease && !didFailToReadOSRelease) { - try { - // List of /etc/os-release values for different distributions could be - // found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75 - const osReleaseText = await fs.promises.readFile('/etc/os-release', 'utf8'); - const fields = parseOSReleaseText(osReleaseText); - osRelease = { - id: fields.get('id') ?? '', - version: fields.get('version_id') ?? '', - }; - } catch (e) { - didFailToReadOSRelease = true; - } - } - return osRelease; -} - export function getLinuxDistributionInfoSync(): { id: string, version: string } | undefined { if (process.platform !== 'linux') return undefined; diff --git a/packages/playwright-core/src/server/utils/nodePlatform.ts b/packages/playwright-core/src/server/utils/nodePlatform.ts new file mode 100644 index 0000000000..1a6f2ddc25 --- /dev/null +++ b/packages/playwright-core/src/server/utils/nodePlatform.ts @@ -0,0 +1,49 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as crypto from 'crypto'; +import * as fs from 'fs'; +import * as path from 'path'; +import * as util from 'util'; + +import { Platform } from '../../common/platform'; +import { debugLogger } from './debugLogger'; + +export const nodePlatform: Platform = { + calculateSha1: (text: string) => { + const sha1 = crypto.createHash('sha1'); + sha1.update(text); + return Promise.resolve(sha1.digest('hex')); + }, + + createGuid: () => crypto.randomBytes(16).toString('hex'), + + fs: () => fs, + + inspectCustom: util.inspect.custom, + + isLogEnabled(name: 'api' | 'channel') { + return debugLogger.isEnabled(name); + }, + + log(name: 'api' | 'channel', message: string | Error | object) { + debugLogger.log(name, message); + }, + + path: () => path, + + pathSeparator: path.sep +}; diff --git a/packages/playwright-core/src/server/utils/socksProxy.ts b/packages/playwright-core/src/server/utils/socksProxy.ts index 49dab675f6..c0fe0f126a 100644 --- a/packages/playwright-core/src/server/utils/socksProxy.ts +++ b/packages/playwright-core/src/server/utils/socksProxy.ts @@ -17,9 +17,9 @@ import EventEmitter from 'events'; import * as net from 'net'; -import { assert } from '../../utils/debug'; +import { assert } from '../../utils/isomorphic/debug'; import { createGuid } from './crypto'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from './debugLogger'; import { createSocket } from './happyEyeballs'; import type { AddressInfo } from 'net'; diff --git a/packages/playwright-core/src/utils/userAgent.ts b/packages/playwright-core/src/server/utils/userAgent.ts similarity index 98% rename from packages/playwright-core/src/utils/userAgent.ts rename to packages/playwright-core/src/server/utils/userAgent.ts index 7f3e3d2275..9676a5bae5 100644 --- a/packages/playwright-core/src/utils/userAgent.ts +++ b/packages/playwright-core/src/server/utils/userAgent.ts @@ -77,6 +77,6 @@ export function getEmbedderName(): { embedderName: string, embedderVersion: stri } export function getPlaywrightVersion(majorMinorOnly = false): string { - const version = process.env.PW_VERSION_OVERRIDE || require('./../../package.json').version; + const version = process.env.PW_VERSION_OVERRIDE || require('./../../../package.json').version; return majorMinorOnly ? version.split('.').slice(0, 2).join('.') : version; } diff --git a/packages/playwright-core/src/server/utils/wsServer.ts b/packages/playwright-core/src/server/utils/wsServer.ts index b223802a1b..68362f14de 100644 --- a/packages/playwright-core/src/server/utils/wsServer.ts +++ b/packages/playwright-core/src/server/utils/wsServer.ts @@ -16,7 +16,7 @@ import { createHttpServer } from './network'; import { wsServer } from '../../utilsBundle'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from './debugLogger'; import type { WebSocket, WebSocketServer } from '../../utilsBundle'; import type http from 'http'; diff --git a/packages/playwright-core/src/server/webkit/wkConnection.ts b/packages/playwright-core/src/server/webkit/wkConnection.ts index 0012d8702f..ada50a413b 100644 --- a/packages/playwright-core/src/server/webkit/wkConnection.ts +++ b/packages/playwright-core/src/server/webkit/wkConnection.ts @@ -18,13 +18,13 @@ import { EventEmitter } from 'events'; import { assert } from '../../utils'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import { helper } from '../helper'; import { ProtocolError } from '../protocolError'; import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport'; import type { Protocol } from './protocol'; -import type { RecentLogsCollector } from '../../utils/debugLogger'; +import type { RecentLogsCollector } from '../utils/debugLogger'; import type { ProtocolLogger } from '../types'; diff --git a/packages/playwright-core/src/server/webkit/wkPage.ts b/packages/playwright-core/src/server/webkit/wkPage.ts index 91a5054123..f9e9517fb2 100644 --- a/packages/playwright-core/src/server/webkit/wkPage.ts +++ b/packages/playwright-core/src/server/webkit/wkPage.ts @@ -21,7 +21,7 @@ import { assert, debugAssert } from '../../utils'; import { headersArrayToObject } from '../../utils/isomorphic/headers'; import { createGuid } from '../utils/crypto'; import { eventsHelper } from '../utils/eventsHelper'; -import { hostPlatform } from '../../utils/hostPlatform'; +import { hostPlatform } from '../utils/hostPlatform'; import { splitErrorMessage } from '../../utils/isomorphic/stackTrace'; import { PNG, jpegjs } from '../../utilsBundle'; import { BrowserContext } from '../browserContext'; @@ -39,7 +39,7 @@ import { RawKeyboardImpl, RawMouseImpl, RawTouchscreenImpl } from './wkInput'; import { WKInterceptableRequest, WKRouteImpl } from './wkInterceptableRequest'; import { WKProvisionalPage } from './wkProvisionalPage'; import { WKWorkers } from './wkWorkers'; -import { debugLogger } from '../../utils/debugLogger'; +import { debugLogger } from '../utils/debugLogger'; import type { Protocol } from './protocol'; import type { WKBrowserContext } from './wkBrowser'; diff --git a/packages/playwright-core/src/utils.ts b/packages/playwright-core/src/utils.ts index 62058f3451..b4829cb78c 100644 --- a/packages/playwright-core/src/utils.ts +++ b/packages/playwright-core/src/utils.ts @@ -15,6 +15,7 @@ */ export * from './utils/isomorphic/colors'; +export * from './utils/isomorphic/debug'; export * from './utils/isomorphic/locatorGenerators'; export * from './utils/isomorphic/manualPromise'; export * from './utils/isomorphic/mimeType'; @@ -25,29 +26,27 @@ export * from './utils/isomorphic/time'; export * from './utils/isomorphic/timeoutRunner'; export * from './utils/isomorphic/urlMatch'; -export * from './utils/debug'; -export * from './utils/debugLogger'; -export * from './utils/env'; -export * from './utils/hostPlatform'; export * from './utils/isomorphic/headers'; export * from './utils/isomorphic/semaphore'; -export * from './utils/platform'; export * from './utils/isomorphic/stackTrace'; export * from './utils/task'; -export * from './utils/userAgent'; export * from './utils/zipFile'; export * from './utils/zones'; export * from './server/utils/ascii'; export * from './server/utils/comparators'; export * from './server/utils/crypto'; +export * from './server/utils/debugLogger'; +export * from './server/utils/env'; export * from './server/utils/eventsHelper'; export * from './server/utils/expectUtils'; export * from './server/utils/fileUtils'; +export * from './server/utils/hostPlatform'; export * from './server/utils/httpServer'; export * from './server/utils/network'; export * from './server/utils/processLauncher'; export * from './server/utils/profiler'; export * from './server/utils/socksProxy'; export * from './server/utils/spawnAsync'; +export * from './server/utils/userAgent'; export * from './server/utils/wsServer'; diff --git a/packages/playwright-core/src/utils/debug.ts b/packages/playwright-core/src/utils/isomorphic/debug.ts similarity index 83% rename from packages/playwright-core/src/utils/debug.ts rename to packages/playwright-core/src/utils/isomorphic/debug.ts index 2e199b3a31..1eec988aa9 100644 --- a/packages/playwright-core/src/utils/debug.ts +++ b/packages/playwright-core/src/utils/isomorphic/debug.ts @@ -14,8 +14,6 @@ * limitations under the License. */ -import { getFromENV } from './env'; - export function assert(value: any, message?: string): asserts value { if (!value) throw new Error(message || 'Assertion error'); @@ -26,13 +24,18 @@ export function debugAssert(value: any, message?: string): asserts value { throw new Error(message); } -const debugEnv = getFromENV('PWDEBUG') || ''; +let _debugMode: string | undefined; + +export function setDebugMode(mode: string) { + _debugMode = mode; +} + export function debugMode() { - if (debugEnv === 'console') + if (_debugMode === 'console') return 'console'; - if (debugEnv === '0' || debugEnv === 'false') + if (_debugMode === '0' || _debugMode === 'false') return ''; - return debugEnv ? 'inspector' : ''; + return _debugMode ? 'inspector' : ''; } let _isUnderTest = !!process.env.PWTEST_UNDER_TEST; diff --git a/packages/playwright-core/src/common/timeoutSettings.ts b/packages/playwright-core/src/utils/isomorphic/timeoutSettings.ts similarity index 98% rename from packages/playwright-core/src/common/timeoutSettings.ts rename to packages/playwright-core/src/utils/isomorphic/timeoutSettings.ts index 65c8be1ecf..02c02a33b5 100644 --- a/packages/playwright-core/src/common/timeoutSettings.ts +++ b/packages/playwright-core/src/utils/isomorphic/timeoutSettings.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { debugMode } from '../utils'; +import { debugMode } from './debug'; export const DEFAULT_TIMEOUT = 30000; export const DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.ts index c0475ab57e..1298e38b5e 100644 --- a/tests/library/browsertype-connect.spec.ts +++ b/tests/library/browsertype-connect.spec.ts @@ -19,7 +19,7 @@ import fs from 'fs'; import type http from 'http'; import type net from 'net'; import * as path from 'path'; -import { getUserAgent, getPlaywrightVersion } from '../../packages/playwright-core/lib/utils/userAgent'; +import { getUserAgent, getPlaywrightVersion } from '../../packages/playwright-core/lib/server/utils/userAgent'; import WebSocket from 'ws'; import { expect, playwrightTest } from '../config/browserTest'; import { parseTrace, suppressCertificateWarning } from '../config/utils'; diff --git a/tests/library/capabilities.spec.ts b/tests/library/capabilities.spec.ts index 29328f3f80..8b065834ab 100644 --- a/tests/library/capabilities.spec.ts +++ b/tests/library/capabilities.spec.ts @@ -17,7 +17,7 @@ import os from 'os'; import url from 'url'; import { contextTest as it, expect } from '../config/browserTest'; -import { hostPlatform } from '../../packages/playwright-core/src/utils/hostPlatform'; +import { hostPlatform } from '../../packages/playwright-core/src/server/utils/hostPlatform'; it('SharedArrayBuffer should work @smoke', async function({ contextFactory, httpsServer }) { const context = await contextFactory({ ignoreHTTPSErrors: true }); diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.ts index f31f60baf0..3191403be8 100644 --- a/tests/library/chromium/connect-over-cdp.spec.ts +++ b/tests/library/chromium/connect-over-cdp.spec.ts @@ -18,7 +18,7 @@ import { playwrightTest as test, expect } from '../../config/browserTest'; import http from 'http'; import fs from 'fs'; -import { getUserAgent } from '../../../packages/playwright-core/lib/utils/userAgent'; +import { getUserAgent } from '../../../packages/playwright-core/lib/server/utils/userAgent'; import { suppressCertificateWarning } from '../../config/utils'; test.skip(({ mode }) => mode === 'service2'); diff --git a/tests/library/events/check-listener-leaks.spec.ts b/tests/library/events/check-listener-leaks.spec.ts index d9b51f27ef..5a328d720f 100644 --- a/tests/library/events/check-listener-leaks.spec.ts +++ b/tests/library/events/check-listener-leaks.spec.ts @@ -22,7 +22,7 @@ import events from 'events'; import { EventEmitter } from '../../../packages/playwright-core/lib/client/eventEmitter'; -import { setUnderTest } from '../../../packages/playwright-core/lib/utils/debug'; +import { setUnderTest } from '../../../packages/playwright-core/lib/utils/isomorphic/debug'; import { test, expect } from '@playwright/test'; import * as common from './utils'; diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts index 0ad73bb9b6..9a402ed152 100644 --- a/tests/library/global-fetch.spec.ts +++ b/tests/library/global-fetch.spec.ts @@ -16,7 +16,7 @@ import os from 'os'; import * as util from 'util'; -import { getPlaywrightVersion } from '../../packages/playwright-core/lib/utils/userAgent'; +import { getPlaywrightVersion } from '../../packages/playwright-core/lib/server/utils/userAgent'; import { expect, playwrightTest as base } from '../config/browserTest'; import { kTargetClosedErrorMessage } from 'tests/config/errors'; diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.ts index fa13420fc3..c2ed97d50e 100644 --- a/tests/library/inspector/inspectorTest.ts +++ b/tests/library/inspector/inspectorTest.ts @@ -22,7 +22,7 @@ import type { Source } from '../../../packages/recorder/src/recorderTypes'; import type { CommonFixtures, TestChildProcess } from '../../config/commonFixtures'; import { stripAnsi } from '../../config/utils'; import { expect } from '@playwright/test'; -import { nodePlatform } from '../../../packages/playwright-core/lib/utils/platform'; +import { nodePlatform } from '../../../packages/playwright-core/lib/server/utils/nodePlatform'; export { expect } from '@playwright/test'; type CLITestArgs = { diff --git a/tests/library/modernizr.spec.ts b/tests/library/modernizr.spec.ts index c0a06f3714..0a1b124301 100644 --- a/tests/library/modernizr.spec.ts +++ b/tests/library/modernizr.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { hostPlatform } from '../../packages/playwright-core/src/utils/hostPlatform'; +import { hostPlatform } from '../../packages/playwright-core/src/server/utils/hostPlatform'; import { browserTest as it, expect } from '../config/browserTest'; import fs from 'fs'; import os from 'os'; diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts index bf78efc7c8..a8846e69ae 100644 --- a/tests/playwright-test/reporter-blob.spec.ts +++ b/tests/playwright-test/reporter-blob.spec.ts @@ -23,7 +23,7 @@ import { startHtmlReportServer } from '../../packages/playwright/lib/reporters/h import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures'; import extractZip from '../../packages/playwright-core/bundles/zip/node_modules/extract-zip'; import * as yazl from '../../packages/playwright-core/bundles/zip/node_modules/yazl'; -import { getUserAgent } from '../../packages/playwright-core/lib/utils/userAgent'; +import { getUserAgent } from '../../packages/playwright-core/lib/server/utils/userAgent'; import { Readable } from 'stream'; const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;