diff --git a/packages/playwright-core/src/client/android.ts b/packages/playwright-core/src/client/android.ts index 07912bfbdd..917b468ea5 100644 --- a/packages/playwright-core/src/client/android.ts +++ b/packages/playwright-core/src/client/android.ts @@ -15,20 +15,23 @@ */ import fs from 'fs'; -import { isString, isRegExp, monotonicTime } from '../utils'; -import type * as channels from '@protocol/channels'; + +import { isString, isRegExp } from '../utils/isomorphic/rtti'; +import { monotonicTime } from '../utils/isomorphic/time'; import { Events } from './events'; import { BrowserContext, prepareBrowserContextParams } from './browserContext'; import { ChannelOwner } from './channelOwner'; -import type * as api from '../../types/types'; -import type * as types from './types'; -import type { Page } from './page'; import { TimeoutSettings } from '../common/timeoutSettings'; import { Waiter } from './waiter'; import { EventEmitter } from 'events'; import { Connection } from './connection'; import { isTargetClosedError, TargetClosedError } from './errors'; import { raceAgainstDeadline } from '../utils/timeoutRunner'; + +import type * as channels from '@protocol/channels'; +import type * as api from '../../types/types'; +import type * as types from './types'; +import type { Page } from './page'; import type { AndroidServerLauncherImpl } from '../androidServerImpl'; 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 c3a53c0294..d2f5b20c3d 100644 --- a/packages/playwright-core/src/client/artifact.ts +++ b/packages/playwright-core/src/client/artifact.ts @@ -14,11 +14,13 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; -import * as fs from 'fs'; +import fs from 'fs'; + import { Stream } from './stream'; import { mkdirIfNeeded } from '../utils/fileUtils'; import { ChannelOwner } from './channelOwner'; + +import type * as channels from '@protocol/channels'; import type { Readable } from 'stream'; export class Artifact extends ChannelOwner { diff --git a/packages/playwright-core/src/client/browser.ts b/packages/playwright-core/src/client/browser.ts index be47ddeb51..94e3979d9b 100644 --- a/packages/playwright-core/src/client/browser.ts +++ b/packages/playwright-core/src/client/browser.ts @@ -15,18 +15,20 @@ */ import fs from 'fs'; -import type * as channels from '@protocol/channels'; + import { BrowserContext, prepareBrowserContextParams } from './browserContext'; -import type { Page } from './page'; import { ChannelOwner } from './channelOwner'; import { Events } from './events'; -import type { LaunchOptions, BrowserContextOptions, HeadersArray } from './types'; import { isTargetClosedError } from './errors'; -import type * as api from '../../types/types'; import { CDPSession } from './cdpSession'; -import type { BrowserType } from './browserType'; import { Artifact } from './artifact'; -import { mkdirIfNeeded } from '../utils'; +import { mkdirIfNeeded } from '../utils/fileUtils'; + +import type * as channels from '@protocol/channels'; +import type { Page } from './page'; +import type { LaunchOptions, BrowserContextOptions, HeadersArray } from './types'; +import type * as api from '../../types/types'; +import type { BrowserType } from './browserType'; export class Browser extends ChannelOwner implements api.Browser { readonly _contexts = new Set(); diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index c87fc5bc7d..2be0ea8855 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -15,12 +15,12 @@ * limitations under the License. */ +import fs from 'fs'; +import path from 'path'; + import { Page, BindingCall } from './page'; import { Frame } from './frame'; import * as network from './network'; -import type * as channels from '@protocol/channels'; -import fs from 'fs'; -import path from 'path'; import { ChannelOwner } from './channelOwner'; import { evaluationScript } from './clientHelper'; import { Browser } from './browser'; @@ -28,13 +28,8 @@ import { Worker } from './worker'; import { Events } from './events'; import { TimeoutSettings } from '../common/timeoutSettings'; import { Waiter } from './waiter'; -import type { Headers, WaitForEventOptions, BrowserContextOptions, LaunchOptions, StorageState } from './types'; -import { type URLMatch, headersObjectToArray, isRegExp, isString, urlMatchesEqual, mkdirIfNeeded } from '../utils'; -import type * as api from '../../types/types'; -import type * as structs from '../../types/structs'; import { CDPSession } from './cdpSession'; import { Tracing } from './tracing'; -import type { BrowserType } from './browserType'; import { Artifact } from './artifact'; import { APIRequestContext } from './fetch'; import { rewriteErrorMessage } from '../utils/stackTrace'; @@ -44,6 +39,18 @@ import { Dialog } from './dialog'; import { WebError } from './webError'; import { TargetClosedError, parseError } from './errors'; import { Clock } from './clock'; +import { isRegExp, isString } from '../utils/isomorphic/rtti'; +import { headersObjectToArray } from '../utils/isomorphic/headers'; +import { urlMatchesEqual } from '../utils/isomorphic/urlMatch'; +import { mkdirIfNeeded } from '../utils/fileUtils'; + +import type * as channels from '@protocol/channels'; +import type { Headers, WaitForEventOptions, BrowserContextOptions, LaunchOptions, StorageState } from './types'; +import type * as api from '../../types/types'; +import type * as structs from '../../types/structs'; +import type { BrowserType } from './browserType'; + +import type { URLMatch } from '../utils'; export class BrowserContext extends ChannelOwner implements api.BrowserContext { _pages = new Set(); diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index 06672cc64e..c2368f81ce 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -14,18 +14,21 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { Browser } from './browser'; import { BrowserContext, prepareBrowserContextParams } from './browserContext'; import { ChannelOwner } from './channelOwner'; -import type { LaunchOptions, LaunchServerOptions, ConnectOptions, LaunchPersistentContextOptions, BrowserContextOptions, Logger } from './types'; import { Connection } from './connection'; import { Events } from './events'; -import type { ChildProcess } from 'child_process'; import { envObjectToArray } from './clientHelper'; -import { assert, headersObjectToArray, monotonicTime } from '../utils'; -import type * as api from '../../types/types'; +import { assert } from '../utils/debug'; +import { headersObjectToArray } from '../utils/isomorphic/headers'; +import { monotonicTime } from '../utils/isomorphic/time'; import { raceAgainstDeadline } from '../utils/timeoutRunner'; + +import type * as channels from '@protocol/channels'; +import type { LaunchOptions, LaunchServerOptions, ConnectOptions, LaunchPersistentContextOptions, BrowserContextOptions, Logger } from './types'; +import type { ChildProcess } from 'child_process'; +import type * as api from '../../types/types'; import type { Playwright } from './playwright'; export interface BrowserServerLauncher { diff --git a/packages/playwright-core/src/client/cdpSession.ts b/packages/playwright-core/src/client/cdpSession.ts index 68d1cb57f8..6a218b7e7e 100644 --- a/packages/playwright-core/src/client/cdpSession.ts +++ b/packages/playwright-core/src/client/cdpSession.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; + +import type * as channels from '@protocol/channels'; import type { Protocol } from '../server/chromium/protocol'; import type * as api from '../../types/types'; diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts index d48ba439f0..025de64501 100644 --- a/packages/playwright-core/src/client/channelOwner.ts +++ b/packages/playwright-core/src/client/channelOwner.ts @@ -15,12 +15,13 @@ */ import { EventEmitter } from './eventEmitter'; -import type * as channels from '@protocol/channels'; import { maybeFindValidator, ValidationError, type ValidatorContext } from '../protocol/validator'; import { debugLogger } from '../utils/debugLogger'; import { captureLibraryStackTrace, stringifyStackFrames } from '../utils/stackTrace'; -import { isUnderTest } from '../utils'; +import { isUnderTest } from '../utils/debug'; import { zones } from '../utils/zones'; + +import type * as channels from '@protocol/channels'; import type { ClientInstrumentation } from './clientInstrumentation'; import type { Connection } from './connection'; import type { Logger } from './types'; diff --git a/packages/playwright-core/src/client/clientHelper.ts b/packages/playwright-core/src/client/clientHelper.ts index 540230a4fc..d84f571611 100644 --- a/packages/playwright-core/src/client/clientHelper.ts +++ b/packages/playwright-core/src/client/clientHelper.ts @@ -15,9 +15,11 @@ * limitations under the License. */ -import type * as types from './types'; import fs from 'fs'; -import { isString } from '../utils'; + +import { isString } from '../utils/isomorphic/stringUtils'; + +import type * as types from './types'; export function envObjectToArray(env: types.Env): { name: string, value: string }[] { const result: { name: string, value: string }[] = []; diff --git a/packages/playwright-core/src/client/connection.ts b/packages/playwright-core/src/client/connection.ts index 375a84265f..39f7842f03 100644 --- a/packages/playwright-core/src/client/connection.ts +++ b/packages/playwright-core/src/client/connection.ts @@ -29,7 +29,6 @@ import { parseError, TargetClosedError } from './errors'; import { CDPSession } from './cdpSession'; import { Playwright } from './playwright'; import { Electron, ElectronApplication } from './electron'; -import type * as channels from '@protocol/channels'; import { Stream } from './stream'; import { WritableStream } from './writableStream'; import { debugLogger } from '../utils/debugLogger'; @@ -43,8 +42,11 @@ import { LocalUtils } from './localUtils'; import { Tracing } from './tracing'; import { findValidator, ValidationError, type ValidatorContext } from '../protocol/validator'; import { createInstrumentation } from './clientInstrumentation'; +import { formatCallLog, rewriteErrorMessage } from '../utils/stackTrace'; +import { zones } from '../utils/zones'; + +import type * as channels from '@protocol/channels'; import type { ClientInstrumentation } from './clientInstrumentation'; -import { formatCallLog, rewriteErrorMessage, zones } from '../utils'; class Root extends ChannelOwner { constructor(connection: Connection) { diff --git a/packages/playwright-core/src/client/consoleMessage.ts b/packages/playwright-core/src/client/consoleMessage.ts index fcdc3fd149..2ca5c8003a 100644 --- a/packages/playwright-core/src/client/consoleMessage.ts +++ b/packages/playwright-core/src/client/consoleMessage.ts @@ -14,11 +14,13 @@ * limitations under the License. */ -import * as util from 'util'; +import util from 'util'; + import { JSHandle } from './jsHandle'; +import { Page } from './page'; + import type * as channels from '@protocol/channels'; import type * as api from '../../types/types'; -import { Page } from './page'; type ConsoleMessageLocation = channels.BrowserContextConsoleEvent['location']; diff --git a/packages/playwright-core/src/client/dialog.ts b/packages/playwright-core/src/client/dialog.ts index c012838b7c..3cc66c49c5 100644 --- a/packages/playwright-core/src/client/dialog.ts +++ b/packages/playwright-core/src/client/dialog.ts @@ -14,11 +14,12 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; -import type * as api from '../../types/types'; import { Page } from './page'; +import type * as channels from '@protocol/channels'; +import type * as api from '../../types/types'; + export class Dialog extends ChannelOwner implements api.Dialog { static from(dialog: channels.DialogChannel): Dialog { return (dialog as any)._object; diff --git a/packages/playwright-core/src/client/electron.ts b/packages/playwright-core/src/client/electron.ts index fe5b6e189e..072e4d7a54 100644 --- a/packages/playwright-core/src/client/electron.ts +++ b/packages/playwright-core/src/client/electron.ts @@ -14,23 +14,24 @@ * limitations under the License. */ -import type { BrowserWindow } from 'electron'; -import type * as childProcess from 'child_process'; -import type * as structs from '../../types/structs'; -import type * as api from '../../types/types'; -import type * as channels from '@protocol/channels'; import { TimeoutSettings } from '../common/timeoutSettings'; import { BrowserContext, prepareBrowserContextParams } from './browserContext'; import { ChannelOwner } from './channelOwner'; import { envObjectToArray } from './clientHelper'; import { Events } from './events'; import { JSHandle, parseResult, serializeArgument } from './jsHandle'; -import type { Page } from './page'; import { ConsoleMessage } from './consoleMessage'; -import type { Env, WaitForEventOptions, Headers, BrowserContextOptions } from './types'; import { Waiter } from './waiter'; import { TargetClosedError, isTargetClosedError } from './errors'; +import type { BrowserWindow } from 'electron'; +import type * as childProcess from 'child_process'; +import type * as structs from '../../types/structs'; +import type * as api from '../../types/types'; +import type * as channels from '@protocol/channels'; +import type { Page } from './page'; +import type { Env, WaitForEventOptions, Headers, BrowserContextOptions } from './types'; + type ElectronOptions = Omit & { env?: Env, extraHTTPHeaders?: Headers, diff --git a/packages/playwright-core/src/client/elementHandle.ts b/packages/playwright-core/src/client/elementHandle.ts index c6249e8078..f2a8ba74ec 100644 --- a/packages/playwright-core/src/client/elementHandle.ts +++ b/packages/playwright-core/src/client/elementHandle.ts @@ -13,25 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import type * as channels from '@protocol/channels'; -import { Frame } from './frame'; -import type { Locator } from './locator'; -import { JSHandle, serializeArgument, parseResult } from './jsHandle'; -import type { ChannelOwner } from './channelOwner'; -import type { SelectOption, FilePayload, Rect, SelectOptionOptions } from './types'; import fs from 'fs'; -import { mime } from '../utilsBundle'; import path from 'path'; -import { assert, isString } from '../utils'; + +import { Frame } from './frame'; +import { JSHandle, serializeArgument, parseResult } from './jsHandle'; +import { mime } from '../utilsBundle'; +import { assert } from '../utils/debug'; +import { isString } from '../utils/isomorphic/rtti'; import { fileUploadSizeLimit, mkdirIfNeeded } from '../utils/fileUtils'; -import type * as api from '../../types/types'; -import type * as structs from '../../types/structs'; -import type { BrowserContext } from './browserContext'; import { WritableStream } from './writableStream'; import { pipeline } from 'stream'; import { promisify } from 'util'; +import type * as channels from '@protocol/channels'; +import type { Locator } from './locator'; +import type { ChannelOwner } from './channelOwner'; +import type { SelectOption, FilePayload, Rect, SelectOptionOptions } from './types'; +import type * as api from '../../types/types'; +import type * as structs from '../../types/structs'; +import type { BrowserContext } from './browserContext'; + const pipelineAsync = promisify(pipeline); export class ElementHandle extends JSHandle implements api.ElementHandle { diff --git a/packages/playwright-core/src/client/errors.ts b/packages/playwright-core/src/client/errors.ts index 51555202e5..0867c95241 100644 --- a/packages/playwright-core/src/client/errors.ts +++ b/packages/playwright-core/src/client/errors.ts @@ -14,10 +14,11 @@ * limitations under the License. */ -import type { SerializedError } from '@protocol/channels'; -import { isError } from '../utils'; +import { isError } from '../utils/isomorphic/rtti'; import { parseSerializedValue, serializeValue } from '../protocol/serializers'; +import type { SerializedError } from '@protocol/channels'; + export class TimeoutError extends Error { constructor(message: string) { super(message); diff --git a/packages/playwright-core/src/client/eventEmitter.ts b/packages/playwright-core/src/client/eventEmitter.ts index 89d723eb8d..ecdfe084f2 100644 --- a/packages/playwright-core/src/client/eventEmitter.ts +++ b/packages/playwright-core/src/client/eventEmitter.ts @@ -22,12 +22,14 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import { EventEmitter as OriginalEventEmitter } from 'events'; +import { isUnderTest } from '../utils/debug'; + +import type { EventEmitter as EventEmitterType } from 'events'; + type EventType = string | symbol; type Listener = (...args: any[]) => any; type EventMap = Record; -import { EventEmitter as OriginalEventEmitter } from 'events'; -import type { EventEmitter as EventEmitterType } from 'events'; -import { isUnderTest } from '../utils'; export class EventEmitter implements EventEmitterType { diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.ts index 58928532ac..3a3ce710b7 100644 --- a/packages/playwright-core/src/client/fetch.ts +++ b/packages/playwright-core/src/client/fetch.ts @@ -16,20 +16,24 @@ import fs from 'fs'; import path from 'path'; -import * as util from 'util'; +import util from 'util'; + +import { assert } from '../utils/debug'; +import { headersObjectToArray } from '../utils/isomorphic/headers'; +import { isString } from '../utils/isomorphic/rtti'; +import { mkdirIfNeeded } from '../utils/fileUtils'; +import { ChannelOwner } from './channelOwner'; +import { RawHeaders } from './network'; +import { Tracing } from './tracing'; +import { TargetClosedError, isTargetClosedError } from './errors'; +import { toClientCertificatesProtocol } from './browserContext'; + import type { Serializable } from '../../types/structs'; import type * as api from '../../types/types'; import type { HeadersArray, NameValue } from '../common/types'; import type * as channels from '@protocol/channels'; -import { assert, headersObjectToArray, isString } from '../utils'; -import { mkdirIfNeeded } from '../utils/fileUtils'; -import { ChannelOwner } from './channelOwner'; -import { RawHeaders } from './network'; import type { ClientCertificate, FilePayload, Headers, StorageState } from './types'; import type { Playwright } from './playwright'; -import { Tracing } from './tracing'; -import { TargetClosedError, isTargetClosedError } from './errors'; -import { toClientCertificatesProtocol } from './browserContext'; export type FetchOptions = { params?: { [key: string]: string | number | boolean; } | URLSearchParams | string, diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts index c337077630..a0f4604762 100644 --- a/packages/playwright-core/src/client/frame.ts +++ b/packages/playwright-core/src/client/frame.ts @@ -15,27 +15,30 @@ * limitations under the License. */ -import { assert } from '../utils'; -import type * as channels from '@protocol/channels'; +import fs from 'fs'; + +import { assert } from '../utils/debug'; import { ChannelOwner } from './channelOwner'; import { FrameLocator, Locator, testIdAttributeName } from './locator'; -import type { LocatorOptions } from './locator'; import { getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector } from '../utils/isomorphic/locatorUtils'; -import type { ByRoleOptions } from '../utils/isomorphic/locatorUtils'; import { ElementHandle, convertSelectOptionValues, convertInputFiles } from './elementHandle'; import { assertMaxArguments, JSHandle, serializeArgument, parseResult } from './jsHandle'; -import fs from 'fs'; import * as network from './network'; -import type { Page } from './page'; import { EventEmitter } from 'events'; import { Waiter } from './waiter'; import { Events } from './events'; -import type { LifecycleEvent, SelectOption, SelectOptionOptions, FilePayload, WaitForFunctionOptions, StrictOptions } from './types'; import { kLifecycleEvents } from './types'; -import { type URLMatch, urlMatches } from '../utils'; +import { urlMatches } from '../utils/isomorphic/urlMatch'; +import { addSourceUrlToScript } from './clientHelper'; + +import type * as channels from '@protocol/channels'; +import type { LocatorOptions } from './locator'; +import type { ByRoleOptions } from '../utils/isomorphic/locatorUtils'; +import type { Page } from './page'; +import type { LifecycleEvent, SelectOption, SelectOptionOptions, FilePayload, WaitForFunctionOptions, StrictOptions } from './types'; import type * as api from '../../types/types'; import type * as structs from '../../types/structs'; -import { addSourceUrlToScript } from './clientHelper'; +import type { URLMatch } from '../utils'; export type WaitForNavigationOptions = { timeout?: number, diff --git a/packages/playwright-core/src/client/harRouter.ts b/packages/playwright-core/src/client/harRouter.ts index 5e617d7ce9..3fb2ce0e7b 100644 --- a/packages/playwright-core/src/client/harRouter.ts +++ b/packages/playwright-core/src/client/harRouter.ts @@ -15,6 +15,7 @@ */ import { debugLogger } from '../utils/debugLogger'; + import type { BrowserContext } from './browserContext'; import type { LocalUtils } from './localUtils'; import type { Route } from './network'; diff --git a/packages/playwright-core/src/client/jsHandle.ts b/packages/playwright-core/src/client/jsHandle.ts index 8577400f3d..a3abdb34ae 100644 --- a/packages/playwright-core/src/client/jsHandle.ts +++ b/packages/playwright-core/src/client/jsHandle.ts @@ -14,12 +14,13 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; import { parseSerializedValue, serializeValue } from '../protocol/serializers'; +import { isTargetClosedError } from './errors'; + +import type * as channels from '@protocol/channels'; import type * as api from '../../types/types'; import type * as structs from '../../types/structs'; -import { isTargetClosedError } from './errors'; export class JSHandle extends ChannelOwner implements api.JSHandle { private _preview: string; diff --git a/packages/playwright-core/src/client/jsonPipe.ts b/packages/playwright-core/src/client/jsonPipe.ts index 0c6b53502f..9e6635638e 100644 --- a/packages/playwright-core/src/client/jsonPipe.ts +++ b/packages/playwright-core/src/client/jsonPipe.ts @@ -14,9 +14,10 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; +import type * as channels from '@protocol/channels'; + export class JsonPipe extends ChannelOwner { static from(jsonPipe: channels.JsonPipeChannel): JsonPipe { return (jsonPipe as any)._object; diff --git a/packages/playwright-core/src/client/localUtils.ts b/packages/playwright-core/src/client/localUtils.ts index 530547b227..4b9ed808f0 100644 --- a/packages/playwright-core/src/client/localUtils.ts +++ b/packages/playwright-core/src/client/localUtils.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; + +import type * as channels from '@protocol/channels'; import type { Size } from './types'; type DeviceDescriptor = { diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts index 7784e1d685..f6dd3d47d0 100644 --- a/packages/playwright-core/src/client/locator.ts +++ b/packages/playwright-core/src/client/locator.ts @@ -14,18 +14,22 @@ * limitations under the License. */ +import util from 'util'; + +import { isString } from '../utils/isomorphic/stringUtils'; +import { monotonicTime } from '../utils/isomorphic/time'; +import { asLocator } from '../utils/isomorphic/locatorGenerators'; +import { ElementHandle } from './elementHandle'; +import { parseResult, serializeArgument } from './jsHandle'; +import { escapeForTextSelector } from '../utils/isomorphic/stringUtils'; +import { getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector } from '../utils/isomorphic/locatorUtils'; + import type * as structs from '../../types/structs'; import type * as api from '../../types/types'; import type * as channels from '@protocol/channels'; -import * as util from 'util'; -import { asLocator, isString, monotonicTime } from '../utils'; -import { ElementHandle } from './elementHandle'; import type { Frame } from './frame'; import type { FilePayload, FrameExpectParams, Rect, SelectOption, SelectOptionOptions, TimeoutOptions } from './types'; -import { parseResult, serializeArgument } from './jsHandle'; -import { escapeForTextSelector } from '../utils/isomorphic/stringUtils'; import type { ByRoleOptions } from '../utils/isomorphic/locatorUtils'; -import { getByAltTextSelector, getByLabelSelector, getByPlaceholderSelector, getByRoleSelector, getByTestIdSelector, getByTextSelector, getByTitleSelector } from '../utils/isomorphic/locatorUtils'; export type LocatorOptions = { hasText?: string | RegExp; diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index a6b40307b3..d80e87e126 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -14,26 +14,33 @@ * limitations under the License. */ -import { URLSearchParams } from 'url'; -import type * as channels from '@protocol/channels'; +import fs from 'fs'; + import { ChannelOwner } from './channelOwner'; import { Frame } from './frame'; import { Worker } from './worker'; -import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from './types'; -import fs from 'fs'; import { mime } from '../utilsBundle'; -import { assert, isString, headersObjectToArray, isRegExp, rewriteErrorMessage, MultiMap, urlMatches, zones } from '../utils'; -import type { URLMatch, Zone } from '../utils'; +import { assert } from '../utils/debug'; +import { headersObjectToArray } from '../utils/isomorphic/headers'; +import { isString, isRegExp } from '../utils/isomorphic/rtti'; +import { MultiMap } from '../utils/isomorphic/multimap'; +import { urlMatches } from '../utils/isomorphic/urlMatch'; +import { rewriteErrorMessage } from '../utils/stackTrace'; +import { zones } from '../utils/zones'; import { ManualPromise, LongStandingScope } from '../utils/manualPromise'; import { Events } from './events'; -import type { Page } from './page'; import { Waiter } from './waiter'; +import { APIResponse } from './fetch'; +import { isTargetClosedError } from './errors'; + +import type * as channels from '@protocol/channels'; +import type { Headers, RemoteAddr, SecurityDetails, WaitForEventOptions } from './types'; +import type { URLMatch, Zone } from '../utils'; +import type { Page } from './page'; import type * as api from '../../types/types'; import type { HeadersArray } from '../common/types'; -import { APIResponse } from './fetch'; import type { Serializable } from '../../types/structs'; import type { BrowserContext } from './browserContext'; -import { isTargetClosedError } from './errors'; export type NetworkCookie = { name: string, diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index d0db2cbae9..f6851efe8b 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -17,36 +17,48 @@ import fs from 'fs'; import path from 'path'; -import type * as structs from '../../types/structs'; -import type * as api from '../../types/types'; + import { serializeError, isTargetClosedError, TargetClosedError } from './errors'; import { TimeoutSettings } from '../common/timeoutSettings'; -import type * as channels from '@protocol/channels'; -import { assert, headersObjectToArray, isObject, isRegExp, isString, LongStandingScope, urlMatches, urlMatchesEqual, mkdirIfNeeded, trimStringWithEllipsis, type URLMatch } from '../utils'; + +import { assert } from '../utils/debug'; +import { isObject, isRegExp, isString } from '../utils/isomorphic/rtti'; +import { headersObjectToArray } from '../utils/isomorphic/headers'; +import { urlMatches, urlMatchesEqual } from '../utils/isomorphic/urlMatch'; +import { LongStandingScope } from '../utils/manualPromise'; +import { trimStringWithEllipsis } from '../utils/isomorphic/stringUtils'; +import { mkdirIfNeeded } from '../utils/fileUtils'; + import { Accessibility } from './accessibility'; import { Artifact } from './artifact'; -import type { BrowserContext } from './browserContext'; import { ChannelOwner } from './channelOwner'; import { evaluationScript } from './clientHelper'; import { Coverage } from './coverage'; import { Download } from './download'; import { determineScreenshotType, ElementHandle } from './elementHandle'; import { Events } from './events'; -import type { APIRequestContext } from './fetch'; import { FileChooser } from './fileChooser'; -import type { WaitForNavigationOptions } from './frame'; import { Frame, verifyLoadState } from './frame'; import { Keyboard, Mouse, Touchscreen } from './input'; import { assertMaxArguments, JSHandle, parseResult, serializeArgument } from './jsHandle'; -import type { FrameLocator, Locator, LocatorOptions } from './locator'; -import type { ByRoleOptions } from '../utils/isomorphic/locatorUtils'; -import { type RouteHandlerCallback, type Request, Response, Route, RouteHandler, validateHeaders, WebSocket, type WebSocketRouteHandlerCallback, WebSocketRoute, WebSocketRouteHandler } from './network'; -import type { FilePayload, Headers, LifecycleEvent, SelectOption, SelectOptionOptions, Size, WaitForEventOptions, WaitForFunctionOptions } from './types'; import { Video } from './video'; import { Waiter } from './waiter'; import { Worker } from './worker'; import { HarRouter } from './harRouter'; +import { Response, Route, RouteHandler, validateHeaders, WebSocket, WebSocketRoute, WebSocketRouteHandler } from './network'; + +import type * as structs from '../../types/structs'; +import type * as api from '../../types/types'; +import type * as channels from '@protocol/channels'; +import type { BrowserContext } from './browserContext'; +import type { APIRequestContext } from './fetch'; +import type { WaitForNavigationOptions } from './frame'; +import type { FrameLocator, Locator, LocatorOptions } from './locator'; +import type { ByRoleOptions } from '../utils/isomorphic/locatorUtils'; +import type { RouteHandlerCallback, Request, WebSocketRouteHandlerCallback } from './network'; +import type { FilePayload, Headers, LifecycleEvent, SelectOption, SelectOptionOptions, Size, WaitForEventOptions, WaitForFunctionOptions } from './types'; import type { Clock } from './clock'; +import type { URLMatch } from '../utils'; type PDFOptions = Omit & { width?: string | number, diff --git a/packages/playwright-core/src/client/playwright.ts b/packages/playwright-core/src/client/playwright.ts index 9933ce15de..cd80345f21 100644 --- a/packages/playwright-core/src/client/playwright.ts +++ b/packages/playwright-core/src/client/playwright.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import type * as channels from '@protocol/channels'; import { TimeoutError } from './errors'; import { Android } from './android'; import { BrowserType } from './browserType'; @@ -23,6 +22,8 @@ import { Electron } from './electron'; import { APIRequest } from './fetch'; import { Selectors, SelectorsOwner } from './selectors'; +import type * as channels from '@protocol/channels'; + export class Playwright extends ChannelOwner { readonly _android: Android; readonly _electron: Electron; diff --git a/packages/playwright-core/src/client/selectors.ts b/packages/playwright-core/src/client/selectors.ts index 2739be0e8d..17ca7d8006 100644 --- a/packages/playwright-core/src/client/selectors.ts +++ b/packages/playwright-core/src/client/selectors.ts @@ -15,11 +15,12 @@ */ import { evaluationScript } from './clientHelper'; -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; +import { setTestIdAttribute, testIdAttributeName } from './locator'; + +import type * as channels from '@protocol/channels'; import type { SelectorEngine } from './types'; import type * as api from '../../types/types'; -import { setTestIdAttribute, testIdAttributeName } from './locator'; export class Selectors implements api.Selectors { private _channels = new Set(); diff --git a/packages/playwright-core/src/client/stream.ts b/packages/playwright-core/src/client/stream.ts index bb202ac4ad..412b085e48 100644 --- a/packages/playwright-core/src/client/stream.ts +++ b/packages/playwright-core/src/client/stream.ts @@ -15,9 +15,10 @@ */ import { Readable } from 'stream'; -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; +import type * as channels from '@protocol/channels'; + export class Stream extends ChannelOwner { static from(Stream: channels.StreamChannel): Stream { return (Stream as any)._object; diff --git a/packages/playwright-core/src/client/tracing.ts b/packages/playwright-core/src/client/tracing.ts index 2481741e3e..a75f026625 100644 --- a/packages/playwright-core/src/client/tracing.ts +++ b/packages/playwright-core/src/client/tracing.ts @@ -14,11 +14,12 @@ * limitations under the License. */ -import type * as api from '../../types/types'; -import type * as channels from '@protocol/channels'; import { Artifact } from './artifact'; import { ChannelOwner } from './channelOwner'; +import type * as api from '../../types/types'; +import type * as channels from '@protocol/channels'; + export class Tracing extends ChannelOwner implements api.Tracing { private _includeSources = false; _tracesDir: string | undefined; diff --git a/packages/playwright-core/src/client/video.ts b/packages/playwright-core/src/client/video.ts index 08c39d4247..4b5ea4fbe6 100644 --- a/packages/playwright-core/src/client/video.ts +++ b/packages/playwright-core/src/client/video.ts @@ -14,11 +14,12 @@ * limitations under the License. */ +import { ManualPromise } from '../utils/manualPromise'; + import type { Page } from './page'; import type * as api from '../../types/types'; import type { Artifact } from './artifact'; import type { Connection } from './connection'; -import { ManualPromise } from '../utils'; export class Video implements api.Video { private _artifact: Promise | null = null; diff --git a/packages/playwright-core/src/client/waiter.ts b/packages/playwright-core/src/client/waiter.ts index 408a01f3d0..135de7f938 100644 --- a/packages/playwright-core/src/client/waiter.ts +++ b/packages/playwright-core/src/client/waiter.ts @@ -14,10 +14,12 @@ * limitations under the License. */ -import type { EventEmitter } from 'events'; import { rewriteErrorMessage } from '../utils/stackTrace'; import { TimeoutError } from './errors'; -import { createGuid, zones } from '../utils'; +import { createGuid } from '../utils/crypto'; +import { zones } from '../utils/zones'; + +import type { EventEmitter } from 'events'; import type { Zone } from '../utils'; import type * as channels from '@protocol/channels'; import type { ChannelOwner } from './channelOwner'; diff --git a/packages/playwright-core/src/client/worker.ts b/packages/playwright-core/src/client/worker.ts index 31d5d3057f..7dec32e79e 100644 --- a/packages/playwright-core/src/client/worker.ts +++ b/packages/playwright-core/src/client/worker.ts @@ -15,15 +15,16 @@ */ import { Events } from './events'; -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; import { assertMaxArguments, JSHandle, parseResult, serializeArgument } from './jsHandle'; +import { LongStandingScope } from '../utils/manualPromise'; +import { TargetClosedError } from './errors'; + +import type * as channels from '@protocol/channels'; import type { Page } from './page'; import type { BrowserContext } from './browserContext'; import type * as api from '../../types/types'; import type * as structs from '../../types/structs'; -import { LongStandingScope } from '../utils'; -import { TargetClosedError } from './errors'; export class Worker extends ChannelOwner implements api.Worker { _page: Page | undefined; // Set for web workers. diff --git a/packages/playwright-core/src/client/writableStream.ts b/packages/playwright-core/src/client/writableStream.ts index 8ed799292c..87168c6707 100644 --- a/packages/playwright-core/src/client/writableStream.ts +++ b/packages/playwright-core/src/client/writableStream.ts @@ -15,9 +15,10 @@ */ import { Writable } from 'stream'; -import type * as channels from '@protocol/channels'; import { ChannelOwner } from './channelOwner'; +import type * as channels from '@protocol/channels'; + export class WritableStream extends ChannelOwner { static from(Stream: channels.WritableStreamChannel): WritableStream { return (Stream as any)._object; diff --git a/packages/playwright-core/src/common/socksProxy.ts b/packages/playwright-core/src/common/socksProxy.ts index 6566262d64..db2e6b6f3b 100644 --- a/packages/playwright-core/src/common/socksProxy.ts +++ b/packages/playwright-core/src/common/socksProxy.ts @@ -15,11 +15,14 @@ */ import EventEmitter from 'events'; -import type { AddressInfo } from 'net'; import net from 'net'; + import { debugLogger } from '../utils/debugLogger'; import { createSocket } from '../utils/happy-eyeballs'; -import { assert, createGuid, } from '../utils'; +import { createGuid } from '../utils/crypto'; +import { assert } from '../utils/debug'; + +import type { AddressInfo } from 'net'; // https://tools.ietf.org/html/rfc1928 diff --git a/packages/playwright-core/src/common/timeoutSettings.ts b/packages/playwright-core/src/common/timeoutSettings.ts index 65c8be1ecf..db430a1f2c 100644 --- a/packages/playwright-core/src/common/timeoutSettings.ts +++ b/packages/playwright-core/src/common/timeoutSettings.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { debugMode } from '../utils'; +import { debugMode } from '../utils/debug'; export const DEFAULT_TIMEOUT = 30000; export const DEFAULT_LAUNCH_TIMEOUT = 3 * 60 * 1000; // 3 minutes diff --git a/packages/playwright-core/src/server/recorder/recorderCollection.ts b/packages/playwright-core/src/server/recorder/recorderCollection.ts index 9f28efd930..ff4ea0a845 100644 --- a/packages/playwright-core/src/server/recorder/recorderCollection.ts +++ b/packages/playwright-core/src/server/recorder/recorderCollection.ts @@ -19,7 +19,7 @@ import type { Frame } from '../frames'; import type { Page } from '../page'; import type { Signal } from '../../../../recorder/src/actions'; import type * as actions from '@recorder/actions'; -import { monotonicTime } from '../../utils/time'; +import { monotonicTime } from '../../utils/isomorphic/time'; import { collapseActions } from './recorderUtils'; import { performAction } from './recorderRunner'; import { isUnderTest } from '../../utils/debug'; diff --git a/packages/playwright-core/src/server/screenshotter.ts b/packages/playwright-core/src/server/screenshotter.ts index 485560b539..7406c7365b 100644 --- a/packages/playwright-core/src/server/screenshotter.ts +++ b/packages/playwright-core/src/server/screenshotter.ts @@ -24,7 +24,7 @@ import type { ParsedSelector } from '../utils/isomorphic/selectorParser'; import type * as types from './types'; import type { Progress } from './progress'; import { assert } from '../utils'; -import { MultiMap } from '../utils/multimap'; +import { MultiMap } from '../utils/isomorphic/multimap'; declare global { interface Window { diff --git a/packages/playwright-core/src/utils/DEPS.list b/packages/playwright-core/src/utils/DEPS.list index 7cfdafe4a1..10f69457f9 100644 --- a/packages/playwright-core/src/utils/DEPS.list +++ b/packages/playwright-core/src/utils/DEPS.list @@ -3,4 +3,5 @@ ../third_party/pixelmatch ../image_tools/compare.ts ../utilsBundle.ts +./isomorphic ../zipBundle.ts diff --git a/packages/playwright-core/src/utils/expectUtils.ts b/packages/playwright-core/src/utils/expectUtils.ts index 0ae21e8602..d316224a1b 100644 --- a/packages/playwright-core/src/utils/expectUtils.ts +++ b/packages/playwright-core/src/utils/expectUtils.ts @@ -15,7 +15,7 @@ */ import type { ExpectedTextValue } from '@protocol/channels'; -import { isRegExp, isString } from './rtti'; +import { isRegExp, isString } from './isomorphic/rtti'; export function serializeExpectedTextValues(items: (string | RegExp)[], options: { matchSubstring?: boolean, normalizeWhiteSpace?: boolean, ignoreCase?: boolean } = {}): ExpectedTextValue[] { return items.map(i => ({ diff --git a/packages/playwright-core/src/utils/happy-eyeballs.ts b/packages/playwright-core/src/utils/happy-eyeballs.ts index 02b78de4f0..20fd63d3e0 100644 --- a/packages/playwright-core/src/utils/happy-eyeballs.ts +++ b/packages/playwright-core/src/utils/happy-eyeballs.ts @@ -21,7 +21,7 @@ import * as net from 'net'; import * as tls from 'tls'; import { ManualPromise } from './manualPromise'; import { assert } from './debug'; -import { monotonicTime } from './time'; +import { monotonicTime } from './isomorphic/time'; // Implementation(partial) of Happy Eyeballs 2 algorithm described in // https://www.rfc-editor.org/rfc/rfc8305 diff --git a/packages/playwright-core/src/utils/index.ts b/packages/playwright-core/src/utils/index.ts index 0bc7a75b08..a0fdacff42 100644 --- a/packages/playwright-core/src/utils/index.ts +++ b/packages/playwright-core/src/utils/index.ts @@ -23,7 +23,7 @@ export * from './env'; export * from './eventsHelper'; export * from './expectUtils'; export * from './fileUtils'; -export * from './headers'; +export * from './isomorphic/headers'; export * from './hostPlatform'; export * from './httpServer'; export * from './manualPromise'; @@ -31,16 +31,16 @@ export * from './isomorphic/locatorGenerators'; export * from './isomorphic/mimeType'; export * from './isomorphic/stringUtils'; export * from './isomorphic/urlMatch'; -export * from './multimap'; +export * from './isomorphic/multimap'; export * from './network'; export * from './processLauncher'; export * from './profiler'; -export * from './rtti'; +export * from './isomorphic/rtti'; export * from './semaphore'; export * from './spawnAsync'; export * from './stackTrace'; export * from './task'; -export * from './time'; +export * from './isomorphic/time'; export * from './timeoutRunner'; export * from './traceUtils'; export * from './userAgent'; diff --git a/packages/playwright-core/src/utils/headers.ts b/packages/playwright-core/src/utils/isomorphic/headers.ts similarity index 100% rename from packages/playwright-core/src/utils/headers.ts rename to packages/playwright-core/src/utils/isomorphic/headers.ts diff --git a/packages/playwright-core/src/utils/multimap.ts b/packages/playwright-core/src/utils/isomorphic/multimap.ts similarity index 100% rename from packages/playwright-core/src/utils/multimap.ts rename to packages/playwright-core/src/utils/isomorphic/multimap.ts diff --git a/packages/playwright-core/src/utils/rtti.ts b/packages/playwright-core/src/utils/isomorphic/rtti.ts similarity index 95% rename from packages/playwright-core/src/utils/rtti.ts rename to packages/playwright-core/src/utils/isomorphic/rtti.ts index a18d3a450a..0bcaef0748 100644 --- a/packages/playwright-core/src/utils/rtti.ts +++ b/packages/playwright-core/src/utils/isomorphic/rtti.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -export { isString } from './isomorphic/stringUtils'; +export { isString } from './stringUtils'; export function isRegExp(obj: any): obj is RegExp { return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]'; diff --git a/packages/playwright-core/src/utils/isomorphic/time.ts b/packages/playwright-core/src/utils/isomorphic/time.ts new file mode 100644 index 0000000000..625fd18805 --- /dev/null +++ b/packages/playwright-core/src/utils/isomorphic/time.ts @@ -0,0 +1,19 @@ +/** + * 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. + */ + +export function monotonicTime(): number { + return (performance.now() * 1000 | 0) / 1000; +} diff --git a/packages/playwright-core/src/utils/time.ts b/packages/playwright-core/src/utils/time.ts deleted file mode 100644 index d00ee62e82..0000000000 --- a/packages/playwright-core/src/utils/time.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * 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. - */ - -// The `process.hrtime()` returns a time from some arbitrary -// date in the past; on certain systems, this is the time from the system boot. -// The `monotonicTime()` converts this to milliseconds. -// -// For a Linux server with uptime of 36 days, the `monotonicTime()` value -// will be 36 * 86400 * 1000 = 3_110_400_000, which is larger than -// the maximum value that `setTimeout` accepts as an argument: 2_147_483_647. -// -// To make the `monotonicTime()` a reasonable value, we anchor -// it to the time of the first import of this utility. -const initialTime = process.hrtime(); - -export function monotonicTime(): number { - const [seconds, nanoseconds] = process.hrtime(initialTime); - return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000; -} diff --git a/packages/trace-viewer/src/sw/snapshotServer.ts b/packages/trace-viewer/src/sw/snapshotServer.ts index e1978c79b6..75cf1168f8 100644 --- a/packages/trace-viewer/src/sw/snapshotServer.ts +++ b/packages/trace-viewer/src/sw/snapshotServer.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import type { URLSearchParams } from 'url'; import type { SnapshotRenderer } from './snapshotRenderer'; import type { SnapshotStorage } from './snapshotStorage'; import type { ResourceSnapshot } from '@trace/snapshot'; diff --git a/tests/page/page-leaks.spec.ts b/tests/page/page-leaks.spec.ts index abd33e651e..90f78d83a9 100644 --- a/tests/page/page-leaks.spec.ts +++ b/tests/page/page-leaks.spec.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { MultiMap } from '../../packages/playwright-core/lib/utils/multimap'; +import { MultiMap } from '../../packages/playwright-core/lib/utils/isomorphic/multimap'; import { test, expect } from './pageTest'; function leakedJSHandles(): string {