Skip to content

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

chore: move utils that are user in server to server/utils (1) (#34734)

Pavel Feldman25a168fae5da
diff --git a/eslint.config.mjs b/eslint.config.mjs
index d47653345e..6fa060cf78 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -188,11 +188,6 @@ const noRestrictedGlobalsRules = {
const importOrderRules = {
'import/order': [2, {
- 'alphabetize': {
- 'order': 'asc',
- 'caseInsensitive': false
- },
- 'named': true,
'groups': ['builtin', 'external', 'internal', ['parent', 'sibling'], 'index', 'type'],
'newlines-between': 'always',
}],
diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.json
index d99b9e2d6a..9acacd9f12 100644
--- a/packages/playwright-core/package.json
+++ b/packages/playwright-core/package.json
@@ -23,14 +23,14 @@
},
"./package.json": "./package.json",
"./lib/outofprocess": "./lib/outofprocess.js",
- "./lib/image_tools/stats": "./lib/image_tools/stats.js",
- "./lib/image_tools/compare": "./lib/image_tools/compare.js",
- "./lib/image_tools/imageChannel": "./lib/image_tools/imageChannel.js",
- "./lib/image_tools/colorUtils": "./lib/image_tools/colorUtils.js",
"./lib/cli/program": "./lib/cli/program.js",
- "./lib/server/registry/index": "./lib/server/registry/index.js",
"./lib/remote/playwrightServer": "./lib/remote/playwrightServer.js",
"./lib/server": "./lib/server/index.js",
+ "./lib/server/utils/image_tools/stats": "./lib/server/utils/image_tools/stats.js",
+ "./lib/server/utils/image_tools/compare": "./lib/server/utils/image_tools/compare.js",
+ "./lib/server/utils/image_tools/imageChannel": "./lib/server/utils/image_tools/imageChannel.js",
+ "./lib/server/utils/image_tools/colorUtils": "./lib/server/utils/image_tools/colorUtils.js",
+ "./lib/server/registry/index": "./lib/server/registry/index.js",
"./lib/utils": "./lib/utils/index.js",
"./lib/utilsBundle": "./lib/utilsBundle.js",
"./lib/zipBundle": "./lib/zipBundle.js",
diff --git a/packages/playwright-core/src/cli/DEPS.list b/packages/playwright-core/src/cli/DEPS.list
index 54eb6a5e49..6d8d6a1569 100644
--- a/packages/playwright-core/src/cli/DEPS.list
+++ b/packages/playwright-core/src/cli/DEPS.list
@@ -7,6 +7,7 @@
../server/
../server/injected/
../server/trace
+../server/utils
../utils
../utilsBundle.ts
diff --git a/packages/playwright-core/src/cli/driver.ts b/packages/playwright-core/src/cli/driver.ts
index cb7ade9d7a..2b49b65ee7 100644
--- a/packages/playwright-core/src/cli/driver.ts
+++ b/packages/playwright-core/src/cli/driver.ts
@@ -22,7 +22,7 @@ import * as playwright from '../..';
import { PipeTransport } from '../protocol/transport';
import { PlaywrightServer } from '../remote/playwrightServer';
import { DispatcherConnection, PlaywrightDispatcher, RootDispatcher, createPlaywright } from '../server';
-import { gracefullyProcessExitDoNotHang } from '../server/processLauncher';
+import { gracefullyProcessExitDoNotHang } from '../server/utils/processLauncher';
import type { BrowserType } from '../client/browserType';
import type { LaunchServerOptions } from '../client/types';
diff --git a/packages/playwright-core/src/cli/program.ts b/packages/playwright-core/src/cli/program.ts
index 38b3072f3a..b79f09eb35 100644
--- a/packages/playwright-core/src/cli/program.ts
+++ b/packages/playwright-core/src/cli/program.ts
@@ -25,7 +25,8 @@ import { launchBrowserServer, printApiJson, runDriver, runServer } from './drive
import { isTargetClosedError } from '../client/errors';
import { gracefullyProcessExitDoNotHang, registry, writeDockerVersion } from '../server';
import { runTraceInBrowser, runTraceViewerApp } from '../server/trace/viewer/traceViewer';
-import { assert, getPackageManagerExecCommand, isLikelyNpxGlobal, wrapInASCIIBox } from '../utils';
+import { assert, getPackageManagerExecCommand, isLikelyNpxGlobal } from '../utils';
+import { wrapInASCIIBox } from '../server/utils/ascii';
import { dotenv, program } from '../utilsBundle';
import type { Browser } from '../client/browser';
diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts
index b9f8e9c405..bd36e905b4 100644
--- a/packages/playwright-core/src/protocol/validator.ts
+++ b/packages/playwright-core/src/protocol/validator.ts
@@ -16,7 +16,6 @@
// This file is generated by generate_channels.js, do not edit manually.
-/* eslint-disable import/order */
import { scheme, tOptional, tObject, tBoolean, tNumber, tString, tAny, tEnum, tArray, tBinary, tChannel, tType } from './validatorPrimitives';
export type { Validator, ValidatorContext } from './validatorPrimitives';
export { ValidationError, findValidator, maybeFindValidator, createMetadataValidator } from './validatorPrimitives';
diff --git a/packages/playwright-core/src/remote/DEPS.list b/packages/playwright-core/src/remote/DEPS.list
index 69b2850494..62660da37d 100644
--- a/packages/playwright-core/src/remote/DEPS.list
+++ b/packages/playwright-core/src/remote/DEPS.list
@@ -4,5 +4,6 @@
../server/
../server/android/
../server/dispatchers/
+../server/utils/
../utils/
../utilsBundle.ts
diff --git a/packages/playwright-core/src/remote/playwrightServer.ts b/packages/playwright-core/src/remote/playwrightServer.ts
index 232ead0806..d3c8c0d745 100644
--- a/packages/playwright-core/src/remote/playwrightServer.ts
+++ b/packages/playwright-core/src/remote/playwrightServer.ts
@@ -16,10 +16,11 @@
import { PlaywrightConnection } from './playwrightConnection';
import { createPlaywright } from '../server/playwright';
-import { userAgentVersionMatchesErrorMessage } from '../utils';
import { debugLogger } from '../utils/debugLogger';
import { Semaphore } from '../utils/semaphore';
import { WSServer } from '../utils/wsServer';
+import { wrapInASCIIBox } from '../server/utils/ascii';
+import { getPlaywrightVersion } from '../utils/userAgent';
import type { ClientType } from './playwrightConnection';
import type { SocksProxy } from '../common/socksProxy';
@@ -131,3 +132,28 @@ export class PlaywrightServer {
await this._wsServer.close();
}
}
+
+function userAgentVersionMatchesErrorMessage(userAgent: string) {
+ const match = userAgent.match(/^Playwright\/(\d+\.\d+\.\d+)/);
+ if (!match) {
+ // Cannot parse user agent - be lax.
+ return;
+ }
+ const received = match[1].split('.').slice(0, 2).join('.');
+ const expected = getPlaywrightVersion(true);
+ if (received !== expected) {
+ return wrapInASCIIBox([
+ `Playwright version mismatch:`,
+ ` - server version: v${expected}`,
+ ` - client version: v${received}`,
+ ``,
+ `If you are using VSCode extension, restart VSCode.`,
+ ``,
+ `If you are connecting to a remote service,`,
+ `keep your local Playwright version in sync`,
+ `with the remote service version.`,
+ ``,
+ `<3 Playwright Team`
+ ].join('\n'), 1);
+ }
+}
diff --git a/packages/playwright-core/src/server/DEPS.list b/packages/playwright-core/src/server/DEPS.list
index 4446d36a24..6b389baead 100644
--- a/packages/playwright-core/src/server/DEPS.list
+++ b/packages/playwright-core/src/server/DEPS.list
@@ -13,6 +13,7 @@
./recorder/
./registry/
./trace/recorder/tracing.ts
+./utils/
[playwright.ts]
./android/
diff --git a/packages/playwright-core/src/server/android/DEPS.list b/packages/playwright-core/src/server/android/DEPS.list
index 10e75d06f0..b45c3a16a7 100644
--- a/packages/playwright-core/src/server/android/DEPS.list
+++ b/packages/playwright-core/src/server/android/DEPS.list
@@ -5,4 +5,5 @@
../../utils/
../../utilsBundle.ts
../chromium/
+../utils
../registry/
\ No newline at end of file
diff --git a/packages/playwright-core/src/server/android/android.ts b/packages/playwright-core/src/server/android/android.ts
index 47c46ca2cf..e47e115112 100644
--- a/packages/playwright-core/src/server/android/android.ts
+++ b/packages/playwright-core/src/server/android/android.ts
@@ -28,10 +28,10 @@ import { wsReceiver, wsSender } from '../../utilsBundle';
import { validateBrowserContextOptions } from '../browserContext';
import { chromiumSwitches } from '../chromium/chromiumSwitches';
import { CRBrowser } from '../chromium/crBrowser';
-import { removeFolders } from '../fileUtils';
+import { removeFolders } from '../utils/fileUtils';
import { helper } from '../helper';
import { SdkObject, serverSideCallMetadata } from '../instrumentation';
-import { gracefullyCloseSet } from '../processLauncher';
+import { gracefullyCloseSet } from '../utils/processLauncher';
import { ProgressController } from '../progress';
import { registry } from '../registry';
diff --git a/packages/playwright-core/src/server/bidi/DEPS.list b/packages/playwright-core/src/server/bidi/DEPS.list
index 9be31302c5..86c54ff797 100644
--- a/packages/playwright-core/src/server/bidi/DEPS.list
+++ b/packages/playwright-core/src/server/bidi/DEPS.list
@@ -2,6 +2,7 @@
../../utils/
../
../isomorphic/
+../utils
./third_party/
[bidiOverCdp.ts]
diff --git a/packages/playwright-core/src/server/bidi/bidiChromium.ts b/packages/playwright-core/src/server/bidi/bidiChromium.ts
index 8df3460b72..a258338537 100644
--- a/packages/playwright-core/src/server/bidi/bidiChromium.ts
+++ b/packages/playwright-core/src/server/bidi/bidiChromium.ts
@@ -16,7 +16,8 @@
import * as os from 'os';
-import { assert, wrapInASCIIBox } from '../../utils';
+import { assert } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { BrowserReadyState, BrowserType, kNoXServerRunningError } from '../browserType';
import { BidiBrowser } from './bidiBrowser';
import { kBrowserCloseMessageId } from './bidiConnection';
@@ -24,7 +25,7 @@ import { chromiumSwitches } from '../chromium/chromiumSwitches';
import type { BrowserOptions } from '../browser';
import type { SdkObject } from '../instrumentation';
-import type { Env } from '../processLauncher';
+import type { Env } from '../utils/processLauncher';
import type { ProtocolError } from '../protocolError';
import type { ConnectionTransport } from '../transport';
import type * as types from '../types';
diff --git a/packages/playwright-core/src/server/bidi/bidiFirefox.ts b/packages/playwright-core/src/server/bidi/bidiFirefox.ts
index 566d2aae95..5f0d7ac12e 100644
--- a/packages/playwright-core/src/server/bidi/bidiFirefox.ts
+++ b/packages/playwright-core/src/server/bidi/bidiFirefox.ts
@@ -17,7 +17,8 @@
import * as os from 'os';
import * as path from 'path';
-import { assert, wrapInASCIIBox } from '../../utils';
+import { assert } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { BrowserReadyState, BrowserType, kNoXServerRunningError } from '../browserType';
import { BidiBrowser } from './bidiBrowser';
import { kBrowserCloseMessageId } from './bidiConnection';
@@ -25,7 +26,7 @@ import { createProfile } from './third_party/firefoxPrefs';
import type { BrowserOptions } from '../browser';
import type { SdkObject } from '../instrumentation';
-import type { Env } from '../processLauncher';
+import type { Env } from '../utils/processLauncher';
import type { ProtocolError } from '../protocolError';
import type { ConnectionTransport } from '../transport';
import type * as types from '../types';
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.ts
index f6380e8d66..6241b8d855 100644
--- a/packages/playwright-core/src/server/browserContext.ts
+++ b/packages/playwright-core/src/server/browserContext.ts
@@ -23,7 +23,7 @@ import { createGuid, debugMode } from '../utils';
import { Clock } from './clock';
import { Debugger } from './debugger';
import { BrowserContextAPIRequestContext } from './fetch';
-import { mkdirIfNeeded } from './fileUtils';
+import { mkdirIfNeeded } from './utils/fileUtils';
import { HarRecorder } from './har/harRecorder';
import { helper } from './helper';
import { SdkObject, serverSideCallMetadata } from './instrumentation';
diff --git a/packages/playwright-core/src/server/browserType.ts b/packages/playwright-core/src/server/browserType.ts
index 19c40e7813..9952aef2f4 100644
--- a/packages/playwright-core/src/server/browserType.ts
+++ b/packages/playwright-core/src/server/browserType.ts
@@ -21,11 +21,11 @@ import * as path from 'path';
import { normalizeProxySettings, validateBrowserContextOptions } from './browserContext';
import { DEFAULT_TIMEOUT, TimeoutSettings } from '../common/timeoutSettings';
import { ManualPromise, assert, debugMode } from '../utils';
-import { existsAsync } from './fileUtils';
+import { existsAsync } from './utils/fileUtils';
import { helper } from './helper';
import { SdkObject } from './instrumentation';
import { PipeTransport } from './pipeTransport';
-import { envArrayToObject, launchProcess } from './processLauncher';
+import { envArrayToObject, launchProcess } from './utils/processLauncher';
import { ProgressController } from './progress';
import { isProtocolError } from './protocolError';
import { registry } from './registry';
@@ -36,7 +36,7 @@ import { RecentLogsCollector } from '../utils/debugLogger';
import type { Browser, BrowserOptions, BrowserProcess } from './browser';
import type { BrowserContext } from './browserContext';
import type { CallMetadata } from './instrumentation';
-import type { Env } from './processLauncher';
+import type { Env } from './utils/processLauncher';
import type { Progress } from './progress';
import type { ProtocolError } from './protocolError';
import type { BrowserName } from './registry';
diff --git a/packages/playwright-core/src/server/chromium/chromium.ts b/packages/playwright-core/src/server/chromium/chromium.ts
index ad28e5b6a3..9b0d81e6ab 100644
--- a/packages/playwright-core/src/server/chromium/chromium.ts
+++ b/packages/playwright-core/src/server/chromium/chromium.ts
@@ -24,7 +24,7 @@ import { CRBrowser } from './crBrowser';
import { kBrowserCloseMessageId } from './crConnection';
import { TimeoutSettings } from '../../common/timeoutSettings';
import { debugMode, headersArrayToObject, headersObjectToArray, } from '../../utils';
-import { wrapInASCIIBox } from '../../utils/ascii';
+import { wrapInASCIIBox } from '../utils/ascii';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { ManualPromise } from '../../utils/manualPromise';
import { fetchData } from '../../utils/network';
@@ -37,14 +37,14 @@ import { registry } from '../registry';
import { WebSocketTransport } from '../transport';
import { CRDevTools } from './crDevTools';
import { Browser } from '../browser';
-import { removeFolders } from '../fileUtils';
-import { gracefullyCloseSet } from '../processLauncher';
+import { removeFolders } from '../utils/fileUtils';
+import { gracefullyCloseSet } from '../utils/processLauncher';
import { ProgressController } from '../progress';
import type { HTTPRequestParams } from '../../utils/network';
import type { BrowserOptions, BrowserProcess } from '../browser';
import type { CallMetadata, SdkObject } from '../instrumentation';
-import type { Env } from '../processLauncher';
+import type { Env } from '../utils/processLauncher';
import type { Progress } from '../progress';
import type { ProtocolError } from '../protocolError';
import type { ConnectionTransport, ProtocolRequest } from '../transport';
diff --git a/packages/playwright-core/src/server/chromium/crProtocolHelper.ts b/packages/playwright-core/src/server/chromium/crProtocolHelper.ts
index 71cf3b5816..570b404d9b 100644
--- a/packages/playwright-core/src/server/chromium/crProtocolHelper.ts
+++ b/packages/playwright-core/src/server/chromium/crProtocolHelper.ts
@@ -18,7 +18,7 @@
import * as fs from 'fs';
import { splitErrorMessage } from '../../utils/stackTrace';
-import { mkdirIfNeeded } from '../fileUtils';
+import { mkdirIfNeeded } from '../utils/fileUtils';
import type { CRSession } from './crConnection';
import type { Protocol } from './protocol';
diff --git a/packages/playwright-core/src/server/chromium/videoRecorder.ts b/packages/playwright-core/src/server/chromium/videoRecorder.ts
index 5dfd32569a..160fd35481 100644
--- a/packages/playwright-core/src/server/chromium/videoRecorder.ts
+++ b/packages/playwright-core/src/server/chromium/videoRecorder.ts
@@ -17,7 +17,7 @@
import { assert, monotonicTime } from '../../utils';
import { serverSideCallMetadata } from '../instrumentation';
import { Page } from '../page';
-import { launchProcess } from '../processLauncher';
+import { launchProcess } from '../utils/processLauncher';
import { ProgressController } from '../progress';
import type { Progress } from '../progress';
diff --git a/packages/playwright-core/src/server/debugController.ts b/packages/playwright-core/src/server/debugController.ts
index c29cbb5a20..62f45ef69a 100644
--- a/packages/playwright-core/src/server/debugController.ts
+++ b/packages/playwright-core/src/server/debugController.ts
@@ -15,7 +15,7 @@
*/
import { SdkObject, createInstrumentation, serverSideCallMetadata } from './instrumentation';
-import { gracefullyProcessExitDoNotHang } from './processLauncher';
+import { gracefullyProcessExitDoNotHang } from './utils/processLauncher';
import { Recorder } from './recorder';
import { asLocator } from '../utils';
import { parseAriaSnapshotUnsafe } from '../utils/isomorphic/ariaSnapshot';
diff --git a/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts b/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts
index d0bc6967d2..db5b4496bc 100644
--- a/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/artifactDispatcher.ts
@@ -18,7 +18,7 @@ import * as fs from 'fs';
import { Dispatcher, existingDispatcher } from './dispatcher';
import { StreamDispatcher } from './streamDispatcher';
-import { mkdirIfNeeded } from '../fileUtils';
+import { mkdirIfNeeded } from '../utils/fileUtils';
import type { DispatcherScope } from './dispatcher';
import type { Artifact } from '../artifact';
diff --git a/packages/playwright-core/src/server/electron/DEPS.list b/packages/playwright-core/src/server/electron/DEPS.list
index 99583c8624..1d51da425e 100644
--- a/packages/playwright-core/src/server/electron/DEPS.list
+++ b/packages/playwright-core/src/server/electron/DEPS.list
@@ -3,3 +3,4 @@
../../common/
../../utils/
../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 f20813fc5b..ce4480b428 100644
--- a/packages/playwright-core/src/server/electron/electron.ts
+++ b/packages/playwright-core/src/server/electron/electron.ts
@@ -20,7 +20,8 @@ import * as path from 'path';
import * as readline from 'readline';
import { TimeoutSettings } from '../../common/timeoutSettings';
-import { ManualPromise, wrapInASCIIBox } from '../../utils';
+import { ManualPromise } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { eventsHelper } from '../../utils/eventsHelper';
import { validateBrowserContextOptions } from '../browserContext';
@@ -32,7 +33,7 @@ import { ConsoleMessage } from '../console';
import { helper } from '../helper';
import { SdkObject, serverSideCallMetadata } from '../instrumentation';
import * as js from '../javascript';
-import { envArrayToObject, launchProcess } from '../processLauncher';
+import { envArrayToObject, launchProcess } from '../utils/processLauncher';
import { ProgressController } from '../progress';
import { WebSocketTransport } from '../transport';
diff --git a/packages/playwright-core/src/server/firefox/firefox.ts b/packages/playwright-core/src/server/firefox/firefox.ts
index c3d21446dd..1332fbc4d0 100644
--- a/packages/playwright-core/src/server/firefox/firefox.ts
+++ b/packages/playwright-core/src/server/firefox/firefox.ts
@@ -20,13 +20,13 @@ import * as path from 'path';
import { FFBrowser } from './ffBrowser';
import { kBrowserCloseMessageId } from './ffConnection';
-import { wrapInASCIIBox } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { BrowserType, kNoXServerRunningError } from '../browserType';
import { BrowserReadyState } from '../browserType';
import type { BrowserOptions } from '../browser';
import type { SdkObject } from '../instrumentation';
-import type { Env } from '../processLauncher';
+import type { Env } from '../utils/processLauncher';
import type { ProtocolError } from '../protocolError';
import type { ConnectionTransport } from '../transport';
import type * as types from '../types';
diff --git a/packages/playwright-core/src/server/index.ts b/packages/playwright-core/src/server/index.ts
index 1627192370..c35615e40c 100644
--- a/packages/playwright-core/src/server/index.ts
+++ b/packages/playwright-core/src/server/index.ts
@@ -31,5 +31,7 @@ export type { Playwright } from './playwright';
export { installRootRedirect, openTraceInBrowser, openTraceViewerApp, runTraceViewerApp, startTraceViewerServer } from './trace/viewer/traceViewer';
export { serverSideCallMetadata } from './instrumentation';
export { SocksProxy } from '../common/socksProxy';
-export * from './fileUtils';
-export * from './processLauncher';
+export * from './utils/processLauncher';
+export * from './utils/ascii';
+export * from './utils/comparators';
+export * from './utils/fileUtils';
diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.ts
index 0f50455155..ac7f6dfd81 100644
--- a/packages/playwright-core/src/server/page.ts
+++ b/packages/playwright-core/src/server/page.ts
@@ -31,7 +31,7 @@ import { Screenshotter, validateScreenshotOptions } from './screenshotter';
import { TimeoutSettings } from '../common/timeoutSettings';
import { LongStandingScope, assert, compressCallLog, createGuid, trimStringWithEllipsis } from '../utils';
import { asLocator } from '../utils';
-import { getComparator } from '../utils/comparators';
+import { getComparator } from './utils/comparators';
import { debugLogger } from '../utils/debugLogger';
import { isInvalidSelectorError } from '../utils/isomorphic/selectorParser';
import { ManualPromise } from '../utils/manualPromise';
@@ -45,7 +45,7 @@ import type { Progress } from './progress';
import type { ScreenshotOptions } from './screenshotter';
import type * as types from './types';
import type { TimeoutOptions } from '../common/types';
-import type { ImageComparatorOptions } from '../utils/comparators';
+import type { ImageComparatorOptions } from './utils/comparators';
import type * as channels from '@protocol/channels';
export interface PageDelegate {
diff --git a/packages/playwright-core/src/server/registry/browserFetcher.ts b/packages/playwright-core/src/server/registry/browserFetcher.ts
index 91e9c21f3d..e7ffda483f 100644
--- a/packages/playwright-core/src/server/registry/browserFetcher.ts
+++ b/packages/playwright-core/src/server/registry/browserFetcher.ts
@@ -24,7 +24,7 @@ import { debugLogger } from '../../utils/debugLogger';
import { ManualPromise } from '../../utils/manualPromise';
import { getUserAgent } from '../../utils/userAgent';
import { colors, progress as ProgressBar } from '../../utilsBundle';
-import { existsAsync } from '../fileUtils';
+import { existsAsync } from '../utils/fileUtils';
import { browserDirectoryToMarkerFilePath } from '.';
diff --git a/packages/playwright-core/src/server/registry/dependencies.ts b/packages/playwright-core/src/server/registry/dependencies.ts
index 4b61f59058..8a077e5c6a 100644
--- a/packages/playwright-core/src/server/registry/dependencies.ts
+++ b/packages/playwright-core/src/server/registry/dependencies.ts
@@ -20,7 +20,7 @@ import * as os from 'os';
import * as path from 'path';
import { deps } from './nativeDeps';
-import * as utils from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { hostPlatform, isOfficiallySupportedPlatform } from '../../utils/hostPlatform';
import { spawnAsync } from '../../utils/spawnAsync';
import { getPlaywrightVersion } from '../../utils/userAgent';
@@ -271,7 +271,7 @@ export async function validateDependenciesLinux(sdkLanguage: string, linuxLddDir
]);
}
- throw new Error('\n' + utils.wrapInASCIIBox(errorLines.join('\n'), 1));
+ throw new Error('\n' + wrapInASCIIBox(errorLines.join('\n'), 1));
}
function isSharedLib(basename: string) {
diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts
index 74313fb113..3986e152b0 100644
--- a/packages/playwright-core/src/server/registry/index.ts
+++ b/packages/playwright-core/src/server/registry/index.ts
@@ -23,14 +23,15 @@ import * as util from 'util';
import { downloadBrowserWithProgressBar, logPolitely } from './browserFetcher';
import { dockerVersion, readDockerVersionSync, transformCommandsForRoot } from './dependencies';
import { installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies';
-import { calculateSha1, getAsBooleanFromENV, getFromENV, getPackageManagerExecCommand, wrapInASCIIBox } from '../../utils';
+import { calculateSha1, getAsBooleanFromENV, getFromENV, getPackageManagerExecCommand } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
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 { lockfile } from '../../utilsBundle';
-import { canAccessFile, existsAsync, removeFolders } from '../fileUtils';
+import { canAccessFile, existsAsync, removeFolders } from '../utils/fileUtils';
import type { DependencyGroup } from './dependencies';
import type { HostPlatform } from '../../utils/hostPlatform';
diff --git a/packages/playwright-core/src/server/trace/recorder/DEPS.list b/packages/playwright-core/src/server/trace/recorder/DEPS.list
index 201a4b001d..11a449d26d 100644
--- a/packages/playwright-core/src/server/trace/recorder/DEPS.list
+++ b/packages/playwright-core/src/server/trace/recorder/DEPS.list
@@ -7,4 +7,5 @@
../../../utilsBundle.ts
../../../zipBundle.ts
../../dispatchers/dispatcher.ts
-../common/
\ No newline at end of file
+../../utils
+../common/
diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.ts
index 12fd42d2bc..a3dedc8485 100644
--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts
+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts
@@ -25,7 +25,7 @@ import { Artifact } from '../../artifact';
import { BrowserContext } from '../../browserContext';
import { Dispatcher } from '../../dispatchers/dispatcher';
import { serializeError } from '../../errors';
-import { SerializedFS, removeFolders } from '../../fileUtils';
+import { SerializedFS, removeFolders } from '../../utils/fileUtils';
import { HarTracer } from '../../har/harTracer';
import { SdkObject } from '../../instrumentation';
import { Page } from '../../page';
diff --git a/packages/playwright-core/src/server/utils/DEPS.list b/packages/playwright-core/src/server/utils/DEPS.list
new file mode 100644
index 0000000000..53cad9639a
--- /dev/null
+++ b/packages/playwright-core/src/server/utils/DEPS.list
@@ -0,0 +1,9 @@
+[*]
+../../utils
+../../utilsBundle.ts
+../../zipBundle.ts
+
+[comparators.ts]
+./image_tools
+../../third_party/pixelmatch
+
diff --git a/packages/playwright-core/src/utils/ascii.ts b/packages/playwright-core/src/server/utils/ascii.ts
similarity index 100%
rename from packages/playwright-core/src/utils/ascii.ts
rename to packages/playwright-core/src/server/utils/ascii.ts
diff --git a/packages/playwright-core/src/utils/comparators.ts b/packages/playwright-core/src/server/utils/comparators.ts
similarity index 96%
rename from packages/playwright-core/src/utils/comparators.ts
rename to packages/playwright-core/src/server/utils/comparators.ts
index ac6bc24421..072133d833 100644
--- a/packages/playwright-core/src/utils/comparators.ts
+++ b/packages/playwright-core/src/server/utils/comparators.ts
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-import { compare } from '../image_tools/compare';
+import { compare } from './image_tools/compare';
// @ts-ignore
-import pixelmatch from '../third_party/pixelmatch';
-import { colors, jpegjs } from '../utilsBundle';
-import { diff } from '../utilsBundle';
-import { PNG } from '../utilsBundle';
+import pixelmatch from '../../third_party/pixelmatch';
+import { colors, jpegjs } from '../../utilsBundle';
+import { diff } from '../../utilsBundle';
+import { PNG } from '../../utilsBundle';
export type ImageComparatorOptions = { threshold?: number, maxDiffPixels?: number, maxDiffPixelRatio?: number, comparator?: string };
export type ComparatorResult = { diff?: Buffer; errorMessage: string; } | null;
diff --git a/packages/playwright-core/src/server/fileUtils.ts b/packages/playwright-core/src/server/utils/fileUtils.ts
similarity index 98%
rename from packages/playwright-core/src/server/fileUtils.ts
rename to packages/playwright-core/src/server/utils/fileUtils.ts
index b2ac823844..5f196963b7 100644
--- a/packages/playwright-core/src/server/fileUtils.ts
+++ b/packages/playwright-core/src/server/utils/fileUtils.ts
@@ -17,8 +17,8 @@
import * as fs from 'fs';
import * as path from 'path';
-import { ManualPromise } from '../utils/manualPromise';
-import { yazl } from '../zipBundle';
+import { ManualPromise } from '../../utils/manualPromise';
+import { yazl } from '../../zipBundle';
import type { EventEmitter } from 'events';
diff --git a/packages/playwright-core/src/image_tools/colorUtils.ts b/packages/playwright-core/src/server/utils/image_tools/colorUtils.ts
similarity index 100%
rename from packages/playwright-core/src/image_tools/colorUtils.ts
rename to packages/playwright-core/src/server/utils/image_tools/colorUtils.ts
diff --git a/packages/playwright-core/src/image_tools/compare.ts b/packages/playwright-core/src/server/utils/image_tools/compare.ts
similarity index 100%
rename from packages/playwright-core/src/image_tools/compare.ts
rename to packages/playwright-core/src/server/utils/image_tools/compare.ts
diff --git a/packages/playwright-core/src/image_tools/imageChannel.ts b/packages/playwright-core/src/server/utils/image_tools/imageChannel.ts
similarity index 100%
rename from packages/playwright-core/src/image_tools/imageChannel.ts
rename to packages/playwright-core/src/server/utils/image_tools/imageChannel.ts
diff --git a/packages/playwright-core/src/image_tools/stats.ts b/packages/playwright-core/src/server/utils/image_tools/stats.ts
similarity index 100%
rename from packages/playwright-core/src/image_tools/stats.ts
rename to packages/playwright-core/src/server/utils/image_tools/stats.ts
diff --git a/packages/playwright-core/src/server/processLauncher.ts b/packages/playwright-core/src/server/utils/processLauncher.ts
similarity index 99%
rename from packages/playwright-core/src/server/processLauncher.ts
rename to packages/playwright-core/src/server/utils/processLauncher.ts
index 6f67ebc699..a7bc0a3865 100644
--- a/packages/playwright-core/src/server/processLauncher.ts
+++ b/packages/playwright-core/src/server/utils/processLauncher.ts
@@ -20,7 +20,7 @@ import * as fs from 'fs';
import * as readline from 'readline';
import { removeFolders } from './fileUtils';
-import { isUnderTest } from '../utils';
+import { isUnderTest } from '../../utils';
export type Env = {[key: string]: string | number | boolean | undefined};
diff --git a/packages/playwright-core/src/server/webkit/webkit.ts b/packages/playwright-core/src/server/webkit/webkit.ts
index f92f7b58ee..a3d1647f07 100644
--- a/packages/playwright-core/src/server/webkit/webkit.ts
+++ b/packages/playwright-core/src/server/webkit/webkit.ts
@@ -18,13 +18,13 @@
import * as path from 'path';
import { kBrowserCloseMessageId } from './wkConnection';
-import { wrapInASCIIBox } from '../../utils';
+import { wrapInASCIIBox } from '../utils/ascii';
import { BrowserType, kNoXServerRunningError } from '../browserType';
import { WKBrowser } from '../webkit/wkBrowser';
import type { BrowserOptions } from '../browser';
import type { SdkObject } from '../instrumentation';
-import type { Env } from '../processLauncher';
+import type { Env } from '../utils/processLauncher';
import type { ProtocolError } from '../protocolError';
import type { ConnectionTransport } from '../transport';
import type * as types from '../types';
diff --git a/packages/playwright-core/src/utils/DEPS.list b/packages/playwright-core/src/utils/DEPS.list
index 7cfdafe4a1..0e2297dfdb 100644
--- a/packages/playwright-core/src/utils/DEPS.list
+++ b/packages/playwright-core/src/utils/DEPS.list
@@ -1,6 +1,4 @@
[*]
./
-../third_party/pixelmatch
-../image_tools/compare.ts
../utilsBundle.ts
../zipBundle.ts
diff --git a/packages/playwright-core/src/utils/index.ts b/packages/playwright-core/src/utils/index.ts
index 03fc46d237..70ec0e450b 100644
--- a/packages/playwright-core/src/utils/index.ts
+++ b/packages/playwright-core/src/utils/index.ts
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-export * from './ascii';
-export * from './comparators';
export * from './crypto';
export * from './debug';
export * from './debugLogger';
diff --git a/packages/playwright-core/src/utils/userAgent.ts b/packages/playwright-core/src/utils/userAgent.ts
index 40bb41a49f..7f3e3d2275 100644
--- a/packages/playwright-core/src/utils/userAgent.ts
+++ b/packages/playwright-core/src/utils/userAgent.ts
@@ -17,7 +17,6 @@
import { execSync } from 'child_process';
import * as os from 'os';
-import { wrapInASCIIBox } from './ascii';
import { getLinuxDistributionInfoSync } from '../utils/linuxUtils';
let cachedUserAgent: string | undefined;
@@ -81,28 +80,3 @@ export function getPlaywrightVersion(majorMinorOnly = false): string {
const version = process.env.PW_VERSION_OVERRIDE || require('./../../package.json').version;
return majorMinorOnly ? version.split('.').slice(0, 2).join('.') : version;
}
-
-export function userAgentVersionMatchesErrorMessage(userAgent: string) {
- const match = userAgent.match(/^Playwright\/(\d+\.\d+\.\d+)/);
- if (!match) {
- // Cannot parse user agent - be lax.
- return;
- }
- const received = match[1].split('.').slice(0, 2).join('.');
- const expected = getPlaywrightVersion(true);
- if (received !== expected) {
- return wrapInASCIIBox([
- `Playwright version mismatch:`,
- ` - server version: v${expected}`,
- ` - client version: v${received}`,
- ``,
- `If you are using VSCode extension, restart VSCode.`,
- ``,
- `If you are connecting to a remote service,`,
- `keep your local Playwright version in sync`,
- `with the remote service version.`,
- ``,
- `<3 Playwright Team`
- ].join('\n'), 1);
- }
-}
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index 9b0fb456ab..313c548c62 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -18,7 +18,8 @@ import * as fs from 'fs';
import * as path from 'path';
import * as playwrightLibrary from 'playwright-core';
-import { addInternalStackPrefix, asLocator, createGuid, debugMode, isString, jsonStringifyForceASCII, zones } from 'playwright-core/lib/utils';
+import { jsonStringifyForceASCII } from 'playwright-core/lib/server';
+import { addInternalStackPrefix, asLocator, createGuid, debugMode, isString, zones } from 'playwright-core/lib/utils';
import { currentTestInfo } from './common/globals';
import { rootTestType } from './common/testType';
diff --git a/packages/playwright/src/matchers/toMatchSnapshot.ts b/packages/playwright/src/matchers/toMatchSnapshot.ts
index 4fcd49a0cd..42d210b8f2 100644
--- a/packages/playwright/src/matchers/toMatchSnapshot.ts
+++ b/packages/playwright/src/matchers/toMatchSnapshot.ts
@@ -18,7 +18,8 @@ import * as fs from 'fs';
import * as path from 'path';
import { sanitizeForFilePath } from 'playwright-core/lib/server';
-import { compareBuffersOrStrings, getComparator, isString } from 'playwright-core/lib/utils';
+import { compareBuffersOrStrings, getComparator } from 'playwright-core/lib/server';
+import { isString } from 'playwright-core/lib/utils';
import { colors } from 'playwright-core/lib/utilsBundle';
import { mime } from 'playwright-core/lib/utilsBundle';
@@ -37,7 +38,7 @@ import type { FullProjectInternal } from '../common/config';
import type { TestInfoImpl, TestStepInfoImpl } from '../worker/testInfo';
import type { Locator, Page } from 'playwright-core';
import type { ExpectScreenshotOptions, Page as PageEx } from 'playwright-core/lib/client/page';
-import type { Comparator, ImageComparatorOptions } from 'playwright-core/lib/utils';
+import type { Comparator, ImageComparatorOptions } from 'playwright-core/lib/server';
type NameOrSegments = string | string[];
const snapshotNamesSymbol = Symbol('snapshotNames');
diff --git a/tests/config/browserTest.ts b/tests/config/browserTest.ts
index ac996eebcb..d2ec226534 100644
--- a/tests/config/browserTest.ts
+++ b/tests/config/browserTest.ts
@@ -19,7 +19,7 @@ import * as os from 'os';
import * as path from 'path';
import { baseTest } from './baseTest';
import { RunServer, RemoteServer } from './remoteServer';
-import { removeFolders } from '../../packages/playwright-core/lib/server/fileUtils';
+import { removeFolders } from '../../packages/playwright-core/lib/server/utils/fileUtils';
import { parseHar } from '../config/utils';
import { createSkipTestPredicate } from '../bidi/expectationUtil';
diff --git a/tests/config/comparator.ts b/tests/config/comparator.ts
index 3376da3e80..16ca27aaa9 100644
--- a/tests/config/comparator.ts
+++ b/tests/config/comparator.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { getComparator } from '../../packages/playwright-core/lib/utils/comparators';
+import { getComparator } from '../../packages/playwright-core/lib/server/utils/comparators';
const pngComparator = getComparator('image/png');
type ComparatorResult = { diff?: Buffer; errorMessage: string; } | null;
diff --git a/tests/image_tools/fixtures.spec.ts b/tests/image_tools/fixtures.spec.ts
index d67a279715..22a23a9eef 100644
--- a/tests/image_tools/fixtures.spec.ts
+++ b/tests/image_tools/fixtures.spec.ts
@@ -16,7 +16,7 @@
import { test, expect } from '../playwright-test/stable-test-runner';
import { PNG } from 'playwright-core/lib/utilsBundle';
-import { compare } from 'playwright-core/lib/image_tools/compare';
+import { compare } from 'playwright-core/lib/server/utils/image_tools/compare';
import fs from 'fs';
import path from 'path';
diff --git a/tests/image_tools/unit.spec.ts b/tests/image_tools/unit.spec.ts
index f565a5d0a0..8d68cc28c0 100644
--- a/tests/image_tools/unit.spec.ts
+++ b/tests/image_tools/unit.spec.ts
@@ -15,9 +15,9 @@
*/
import { test } from '../playwright-test/stable-test-runner';
-import { ssim, FastStats } from 'playwright-core/lib/image_tools/stats';
-import { ImageChannel } from 'playwright-core/lib/image_tools/imageChannel';
-import { srgb2xyz, xyz2lab, colorDeltaE94 } from 'playwright-core/lib/image_tools/colorUtils';
+import { ssim, FastStats } from 'playwright-core/lib/server/utils/image_tools/stats';
+import { ImageChannel } from 'playwright-core/lib/server/utils/image_tools/imageChannel';
+import { srgb2xyz, xyz2lab, colorDeltaE94 } from 'playwright-core/lib/server/utils/image_tools/colorUtils';
import referenceSSIM from 'ssim.js';
import { randomPNG, assertEqual, grayChannel } from './utils';
diff --git a/tests/image_tools/utils.ts b/tests/image_tools/utils.ts
index 2587411d61..a3d933c9d9 100644
--- a/tests/image_tools/utils.ts
+++ b/tests/image_tools/utils.ts
@@ -15,7 +15,7 @@
*/
import { PNG } from 'playwright-core/lib/utilsBundle';
-import { ImageChannel } from 'playwright-core/lib/image_tools/imageChannel';
+import { ImageChannel } from 'playwright-core/lib/server/utils/image_tools/imageChannel';
// mulberry32
export function createRandom(seed) {
diff --git a/tests/installation/globalSetup.ts b/tests/installation/globalSetup.ts
index bf2b7df3e4..214f586987 100644
--- a/tests/installation/globalSetup.ts
+++ b/tests/installation/globalSetup.ts
@@ -17,7 +17,7 @@
import path from 'path';
import fs from 'fs';
import { spawnAsync } from '../../packages/playwright-core/lib/utils/spawnAsync';
-import { removeFolders } from '../../packages/playwright-core/lib/server/fileUtils';
+import { removeFolders } from '../../packages/playwright-core/lib/server/utils/fileUtils';
import { TMP_WORKSPACES } from './npmTest';
const PACKAGE_BUILDER_SCRIPT = path.join(__dirname, '..', '..', 'utils', 'pack_package.js');
diff --git a/tests/installation/npmTest.ts b/tests/installation/npmTest.ts
index 128e7a7ab6..84dc11e99b 100644
--- a/tests/installation/npmTest.ts
+++ b/tests/installation/npmTest.ts
@@ -22,7 +22,7 @@ import debugLogger from 'debug';
import { Registry } from './registry';
import type { CommonFixtures, CommonWorkerFixtures } from '../config/commonFixtures';
import { commonFixtures } from '../config/commonFixtures';
-import { removeFolders } from '../../packages/playwright-core/lib/server/fileUtils';
+import { removeFolders } from '../../packages/playwright-core/lib/server/utils/fileUtils';
import { spawnAsync } from '../../packages/playwright-core/lib/utils/spawnAsync';
import type { SpawnOptions } from 'child_process';
diff --git a/tests/library/headful.spec.ts b/tests/library/headful.spec.ts
index 13445b9ce4..715d0bf86d 100644
--- a/tests/library/headful.spec.ts
+++ b/tests/library/headful.spec.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { compare } from 'playwright-core/lib/image_tools/compare';
+import { compare } from 'playwright-core/lib/server/utils/image_tools/compare';
import { PNG } from 'playwright-core/lib/utilsBundle';
import { expect, playwrightTest as it } from '../config/browserTest';
diff --git a/utils/generate_channels.js b/utils/generate_channels.js
index d6bfdf020f..827250ad8c 100755
--- a/utils/generate_channels.js
+++ b/utils/generate_channels.js
@@ -153,7 +153,6 @@ const validator_ts = [
// This file is generated by ${path.basename(__filename)}, do not edit manually.
-/* eslint-disable import/order */
import { scheme, tOptional, tObject, tBoolean, tNumber, tString, tAny, tEnum, tArray, tBinary, tChannel, tType } from './validatorPrimitives';
export type { Validator, ValidatorContext } from './validatorPrimitives';
export { ValidationError, findValidator, maybeFindValidator, createMetadataValidator } from './validatorPrimitives';