chore: use utils via index export (4) (#13404)

This commit is contained in:
Pavel Feldman 2022-04-07 13:36:13 -08:00 committed by GitHub
parent 40d5e3a3c9
commit a3c02222bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
82 changed files with 244 additions and 219 deletions

View file

@ -14,5 +14,20 @@
* limitations under the License.
*/
require('./lib/utils/verifyNodeJsVersion');
const currentNodeVersion = process.versions.node;
const semver = currentNodeVersion.split('.');
const [major] = [+semver[0]];
if (major < 12) {
// eslint-disable-next-line no-console
console.error(
'You are running Node.js ' +
currentNodeVersion +
'.\n' +
'Playwright requires Node.js 12 or higher. \n' +
'Please update your version of Node.js.'
);
process.exit(1);
}
module.exports = require('./lib/inprocess');

View file

@ -1,6 +1,7 @@
[*]
../../
../client
../common
../debug/injected
../generated/
../grid

View file

@ -32,7 +32,8 @@ import type { Page } from '../client/page';
import type { BrowserType } from '../client/browserType';
import type { BrowserContextOptions, LaunchOptions } from '../client/types';
import { spawn } from 'child_process';
import { spawnAsync, getPlaywrightVersion, wrapInASCIIBox } from '../utils';
import { getPlaywrightVersion } from '../common/userAgent';
import { spawnAsync, wrapInASCIIBox } from '../utils';
import { launchGridAgent } from '../grid/gridAgent';
import type { GridFactory } from '../grid/gridServer';
import { GridServer } from '../grid/gridServer';

View file

@ -1,3 +1,4 @@
[*]
../common/
../protocol/
../utils/

View file

@ -23,7 +23,7 @@ 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 '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import { Waiter } from './waiter';
import { EventEmitter } from 'events';

View file

@ -29,7 +29,7 @@ export { Locator, FrameLocator } from './locator';
export { ElementHandle } from './elementHandle';
export { FileChooser } from './fileChooser';
export type { Logger } from './types';
export { TimeoutError } from '../utils/errors';
export { TimeoutError } from '../common/errors';
export { Frame } from './frame';
export { Keyboard, Mouse, Touchscreen } from './input';
export { JSHandle } from './jsHandle';

View file

@ -20,7 +20,7 @@ import type { Page } from './page';
import { ChannelOwner } from './channelOwner';
import { Events } from './events';
import type { BrowserContextOptions } from './types';
import { isSafeCloseError, kBrowserClosedError } from '../utils/errors';
import { isSafeCloseError, kBrowserClosedError } from '../common/errors';
import type * as api from '../../types/types';
import { CDPSession } from './cdpSession';
import type { BrowserType } from './browserType';

View file

@ -25,11 +25,11 @@ import { evaluationScript } from './clientHelper';
import { Browser } from './browser';
import { Worker } from './worker';
import { Events } from './events';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import { Waiter } from './waiter';
import type { URLMatch, Headers, WaitForEventOptions, BrowserContextOptions, StorageState, LaunchOptions } from './types';
import { headersObjectToArray, mkdirIfNeeded } from '../utils';
import { isSafeCloseError } from '../utils/errors';
import { isSafeCloseError } from '../common/errors';
import type * as api from '../../types/types';
import type * as structs from '../../types/structs';
import { CDPSession } from './cdpSession';

View file

@ -25,7 +25,7 @@ import type { ChildProcess } from 'child_process';
import { envObjectToArray } from './clientHelper';
import { assert, headersObjectToArray, monotonicTime } from '../utils';
import type * as api from '../../types/types';
import { kBrowserClosedError } from '../utils/errors';
import { kBrowserClosedError } from '../common/errors';
import { raceAgainstTimeout } from '../utils';
import type { Playwright } from './playwright';

View file

@ -18,11 +18,10 @@ import { EventEmitter } from 'events';
import type * as channels from '../protocol/channels';
import type { Validator } from '../protocol/validator';
import { createScheme, ValidationError } from '../protocol/validator';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
import type { ParsedStackTrace } from '../utils/stackTrace';
import { captureRawStack, captureStackTrace } from '../utils/stackTrace';
import { isUnderTest } from '../utils';
import { zones } from '../utils/zones';
import { isUnderTest, zones } from '../utils';
import type { ClientInstrumentation } from './clientInstrumentation';
import type { Connection } from './connection';
import type { Logger } from './types';

View file

@ -33,7 +33,7 @@ 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';
import { debugLogger } from '../common/debugLogger';
import { SelectorsOwner } from './selectors';
import { Android, AndroidSocket, AndroidDevice } from './android';
import type { ParsedStackTrace } from '../utils/stackTrace';

View file

@ -19,7 +19,7 @@ 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 '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import { headersObjectToArray } from '../utils';
import { BrowserContext } from './browserContext';
import { ChannelOwner } from './channelOwner';

View file

@ -30,7 +30,7 @@ import type { BrowserContext } from './browserContext';
import { WritableStream } from './writableStream';
import { pipeline } from 'stream';
import { promisify } from 'util';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
const pipelineAsync = promisify(pipeline);

View file

@ -21,7 +21,7 @@ import type { Serializable } from '../../types/structs';
import type * as api from '../../types/types';
import type { HeadersArray } from '../common/types';
import type * as channels from '../protocol/channels';
import { kBrowserOrContextClosedError } from '../utils/errors';
import { kBrowserOrContextClosedError } from '../common/errors';
import { assert, headersObjectToArray, isFilePayload, isString, mkdirIfNeeded, objectToArray } from '../utils';
import { ChannelOwner } from './channelOwner';
import * as network from './network';

View file

@ -32,7 +32,7 @@ import { kLifecycleEvents } from './types';
import { urlMatches } from './clientHelper';
import type * as api from '../../types/types';
import type * as structs from '../../types/structs';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
export type WaitForNavigationOptions = {
timeout?: number,

View file

@ -17,7 +17,7 @@
import { Events } from './events';
import { assert } from '../utils';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import type { ParsedStackTrace } from '../utils/stackTrace';
import type * as channels from '../protocol/channels';
import { parseError, serializeError } from '../protocol/serializers';
@ -47,7 +47,7 @@ import path from 'path';
import type { Size, URLMatch, Headers, LifecycleEvent, WaitForEventOptions, SelectOption, SelectOptionOptions, FilePayload, WaitForFunctionOptions } from './types';
import { evaluationScript, urlMatches } from './clientHelper';
import { isString, isRegExp, isObject, mkdirIfNeeded, headersObjectToArray } from '../utils';
import { isSafeCloseError } from '../utils/errors';
import { isSafeCloseError } from '../common/errors';
import { Video } from './video';
import { Artifact } from './artifact';
import type { APIRequestContext } from './fetch';

View file

@ -15,8 +15,8 @@
*/
import type * as channels from '../protocol/channels';
import { TimeoutError } from '../utils/errors';
import * as socks from '../utils/socksProxy';
import { TimeoutError } from '../common/errors';
import * as socks from '../common/socksProxy';
import { Android } from './android';
import { BrowserType } from './browserType';
import { ChannelOwner } from './channelOwner';

View file

@ -16,7 +16,7 @@
import type { EventEmitter } from 'events';
import { rewriteErrorMessage } from '../utils/stackTrace';
import { TimeoutError } from '../utils/errors';
import { TimeoutError } from '../common/errors';
import { createGuid } from '../utils';
import type * as channels from '../protocol/channels';
import type { ChannelOwner } from './channelOwner';

View file

@ -0,0 +1,2 @@
[*]
../utils/

View file

@ -21,7 +21,7 @@ import net from 'net';
import util from 'util';
import { debugLogger } from './debugLogger';
import { createSocket } from './netUtils';
import { assert, createGuid } from './';
import { assert, createGuid } from '../utils';
const dnsLookupAsync = util.promisify(dns.lookup);

View file

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { debugMode } from './';
import { debugMode } from '../utils';
export const DEFAULT_TIMEOUT = 30000;

View file

@ -0,0 +1,81 @@
/**
* 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 { execSync } from 'child_process';
import fs from 'fs';
import os from 'os';
import { parseOSReleaseText } from '../utils/ubuntuVersion';
let cachedUserAgent: string | undefined;
export function getUserAgent(): string {
if (cachedUserAgent)
return cachedUserAgent;
try {
cachedUserAgent = determineUserAgent();
} catch (e) {
cachedUserAgent = 'Playwright/unknown';
}
return cachedUserAgent;
}
function determineUserAgent(): string {
let osIdentifier = 'unknown';
let osVersion = 'unknown';
if (process.platform === 'win32') {
const version = os.release().split('.');
osIdentifier = 'windows';
osVersion = `${version[0]}.${version[1]}`;
} else if (process.platform === 'darwin') {
const version = execSync('sw_vers -productVersion', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim().split('.');
osIdentifier = 'macOS';
osVersion = `${version[0]}.${version[1]}`;
} else if (process.platform === 'linux') {
try {
// List of /etc/os-release values for different distributions could be
// found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75
const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8');
const fields = parseOSReleaseText(osReleaseText);
osIdentifier = fields.get('id') || 'unknown';
osVersion = fields.get('version_id') || 'unknown';
} catch (e) {
// Linux distribution without /etc/os-release.
// Default to linux/unknown.
osIdentifier = 'linux';
}
}
const { langName, langVersion } = getClientLanguage();
return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}`;
}
export function getClientLanguage(): { langName: string, langVersion: string } {
let langName = 'unknown';
let langVersion = 'unknown';
if (!process.env.PW_LANG_NAME) {
langName = 'node';
langVersion = process.version.substring(1).split('.').slice(0, 2).join('.');
} else if (['node', 'python', 'java', 'csharp'].includes(process.env.PW_LANG_NAME)) {
langName = process.env.PW_LANG_NAME;
langVersion = process.env.PW_LANG_NAME_VERSION ?? 'unknown';
}
return { langName, langVersion };
}
export function getPlaywrightVersion(majorMinorOnly = false) {
const packageJson = require('./../../package.json');
return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version;
}

View file

@ -1,5 +1,6 @@
[*]
../client/
../common/
../dispatchers/
../remote/
../server/

View file

@ -17,7 +17,7 @@
import debug from 'debug';
import WebSocket from 'ws';
import { fork } from 'child_process';
import { getPlaywrightVersion } from '../utils';
import { getPlaywrightVersion } from '../common/userAgent';
export function launchGridAgent(agentId: string, gridURL: string) {
const log = debug(`pw:grid:agent:${agentId}`);

View file

@ -17,7 +17,7 @@
import WebSocket from 'ws';
import { Connection } from '../client/connection';
import type { Playwright } from '../client/playwright';
import { getPlaywrightVersion } from '../utils';
import { getPlaywrightVersion } from '../common/userAgent';
export class GridClient {
private _ws: WebSocket;

View file

@ -20,7 +20,8 @@ import { URL } from 'url';
import type { Server as WebSocketServer } from 'ws';
import type WebSocket from 'ws';
import { HttpServer } from '../utils/httpServer';
import { assert, createGuid, getPlaywrightVersion } from '../utils';
import { assert, createGuid } from '../utils';
import { getPlaywrightVersion } from '../common/userAgent';
export type GridAgentLaunchOptions = {
agentId: string,

View file

@ -18,7 +18,7 @@ import WebSocket from 'ws';
import debug from 'debug';
import { createPlaywright, PlaywrightDispatcher, DispatcherConnection, Root } from '../server';
import { gracefullyCloseAll } from '../utils/processLauncher';
import { SocksProxy } from '../utils/socksProxy';
import { SocksProxy } from '../common/socksProxy';
function launchGridWorker(gridURL: string, agentId: string, workerId: string) {
const log = debug(`pw:grid:worker:${workerId}`);

View file

@ -1,3 +1,4 @@
[*]
../common/
../utils/

View file

@ -14,7 +14,7 @@
* limitations under the License.
*/
import { TimeoutError } from '../utils/errors';
import { TimeoutError } from '../common/errors';
import type { SerializedError, SerializedValue } from './channels';
export function serializeError(e: any): SerializedError {

View file

@ -1,5 +1,6 @@
[*]
../client/
../common/
../dispatchers/
../server/
../utils/

View file

@ -21,7 +21,7 @@ import { Browser } from '../server/browser';
import { serverSideCallMetadata } from '../server/instrumentation';
import { gracefullyCloseAll } from '../utils/processLauncher';
import { registry } from '../server';
import { SocksProxy } from '../utils/socksProxy';
import { SocksProxy } from '../common/socksProxy';
export class PlaywrightConnection {
private _ws: WebSocket;

View file

@ -1,19 +1,20 @@
[*]
../common/
../generated/
../protocol/
../utils/
./
common/
injected/
supplements/
trace/recorder/tracing.ts
./common/
./injected/
./supplements/
./trace/recorder/tracing.ts
[browserContext.ts]
supplements/har/
./supplements/har/
[playwright.ts]
android/
chromium/
electron/
firefox/
webkit/
./android/
./chromium/
./electron/
./firefox/
./webkit/

View file

@ -1,5 +1,6 @@
[*]
../
../../common/
../../protocol/
../../utils/
../chromium/

View file

@ -30,9 +30,9 @@ import { ProgressController } from '../progress';
import { CRBrowser } from '../chromium/crBrowser';
import { helper } from '../helper';
import { PipeTransport } from '../../protocol/transport';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { RecentLogsCollector } from '../../common/debugLogger';
import { gracefullyCloseSet } from '../../utils/processLauncher';
import { TimeoutSettings } from '../../utils/timeoutSettings';
import { TimeoutSettings } from '../../common/timeoutSettings';
import type { AndroidWebView } from '../../protocol/channels';
import { SdkObject, serverSideCallMetadata } from '../instrumentation';

View file

@ -20,7 +20,7 @@ import { Page } from './page';
import { Download } from './download';
import type { ProxySettings } from './types';
import type { ChildProcess } from 'child_process';
import type { RecentLogsCollector } from '../utils/debugLogger';
import type { RecentLogsCollector } from '../common/debugLogger';
import type { CallMetadata } from './instrumentation';
import { SdkObject } from './instrumentation';
import { Artifact } from './artifact';

View file

@ -16,7 +16,7 @@
*/
import * as os from 'os';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import { debugMode, mkdirIfNeeded, createGuid } from '../utils';
import type { Browser, BrowserOptions } from './browser';
import type { Download } from './download';

View file

@ -30,10 +30,10 @@ import { PipeTransport } from './pipeTransport';
import type { Progress } from './progress';
import { ProgressController } from './progress';
import type * as types from './types';
import { DEFAULT_TIMEOUT, TimeoutSettings } from '../utils/timeoutSettings';
import { DEFAULT_TIMEOUT, TimeoutSettings } from '../common/timeoutSettings';
import { debugMode, existsAsync } from '../utils';
import { helper } from './helper';
import { RecentLogsCollector } from '../utils/debugLogger';
import { RecentLogsCollector } from '../common/debugLogger';
import type { CallMetadata } from './instrumentation';
import { SdkObject } from './instrumentation';

View file

@ -30,13 +30,14 @@ import { CRDevTools } from './crDevTools';
import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
import { Browser } from '../browser';
import type * as types from '../types';
import type { HTTPRequestParams } from '../../utils';
import { fetchData } from '../../utils';
import { debugMode, getUserAgent, headersArrayToObject, removeFolders, streamToString, wrapInASCIIBox } from '../../utils';
import { RecentLogsCollector } from '../../utils/debugLogger';
import type { HTTPRequestParams } from '../../common/netUtils';
import { fetchData } from '../../common/netUtils';
import { getUserAgent } from '../../common/userAgent';
import { debugMode, headersArrayToObject, removeFolders, streamToString, wrapInASCIIBox } from '../../utils';
import { RecentLogsCollector } from '../../common/debugLogger';
import type { Progress } from '../progress';
import { ProgressController } from '../progress';
import { TimeoutSettings } from '../../utils/timeoutSettings';
import { TimeoutSettings } from '../../common/timeoutSettings';
import { helper } from '../helper';
import type { CallMetadata } from '../instrumentation';
import http from 'http';

View file

@ -20,8 +20,8 @@ import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../
import type { Protocol } from './protocol';
import { EventEmitter } from 'events';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import type { RecentLogsCollector } from '../../utils/debugLogger';
import { debugLogger } from '../../utils/debugLogger';
import type { RecentLogsCollector } from '../../common/debugLogger';
import { debugLogger } from '../../common/debugLogger';
import type { ProtocolLogger } from '../types';
import { helper } from '../helper';
import { ProtocolError } from '../protocolError';

View file

@ -16,8 +16,8 @@
*/
import type { CRSession } from './crConnection';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import type { Protocol } from './protocol';
import type * as types from '../types';
import { assert } from '../../utils';

View file

@ -18,8 +18,8 @@
import type { CRSession } from './crConnection';
import type { Page } from '../page';
import { helper } from '../helper';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import type { Protocol } from './protocol';
import * as network from '../network';
import type * as frames from '../frames';

View file

@ -16,8 +16,8 @@
*/
import path from 'path';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import { registry } from '../registry';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import { assert, createGuid, headersArrayToObject } from '../../utils';

View file

@ -1,4 +1,5 @@
[*]
../../common/
../../protocol/
../../utils/
../**

View file

@ -22,8 +22,8 @@ import { Dispatcher } from './dispatcher';
import { BrowserContextDispatcher } from './browserContextDispatcher';
import type { CallMetadata } from '../instrumentation';
import { JsonPipeDispatcher } from '../dispatchers/jsonPipeDispatcher';
import { getUserAgent } from '../../utils';
import * as socks from '../../utils/socksProxy';
import { getUserAgent } from '../../common/userAgent';
import * as socks from '../../common/socksProxy';
import EventEmitter from 'events';
import { ProgressController } from '../progress';
import { WebSocketTransport } from '../transport';

View file

@ -21,7 +21,7 @@ import type { Validator } from '../../protocol/validator';
import { createScheme, ValidationError } from '../../protocol/validator';
import { assert, debugAssert, isUnderTest, monotonicTime } from '../../utils';
import { tOptional } from '../../protocol/validatorPrimitives';
import { kBrowserOrContextClosedError } from '../../utils/errors';
import { kBrowserOrContextClosedError } from '../../common/errors';
import type { CallMetadata } from '../instrumentation';
import { SdkObject } from '../instrumentation';
import { rewriteErrorMessage } from '../../utils/stackTrace';

View file

@ -18,8 +18,8 @@ import type * as channels from '../../protocol/channels';
import type { Browser } from '../browser';
import { GlobalAPIRequestContext } from '../fetch';
import type { Playwright } from '../playwright';
import type { SocksSocketClosedPayload, SocksSocketDataPayload, SocksSocketRequestedPayload } from '../../utils/socksProxy';
import { SocksProxy } from '../../utils/socksProxy';
import type { SocksSocketClosedPayload, SocksSocketDataPayload, SocksSocketRequestedPayload } from '../../common/socksProxy';
import { SocksProxy } from '../../common/socksProxy';
import type * as types from '../types';
import { AndroidDispatcher } from './androidDispatcher';
import { BrowserTypeDispatcher } from './browserTypeDispatcher';

View file

@ -1,4 +1,5 @@
[*]
../
../../common/
../../utils/
../chromium/

View file

@ -25,7 +25,7 @@ import type { CRPage } from '../chromium/crPage';
import { CRExecutionContext } from '../chromium/crExecutionContext';
import * as js from '../javascript';
import type { Page } from '../page';
import { TimeoutSettings } from '../../utils/timeoutSettings';
import { TimeoutSettings } from '../../common/timeoutSettings';
import { wrapInASCIIBox } from '../../utils';
import { WebSocketTransport } from '../transport';
import { launchProcess, envArrayToObject } from '../../utils/processLauncher';
@ -34,11 +34,11 @@ import type { BrowserWindow } from 'electron';
import type { Progress } from '../progress';
import { ProgressController } from '../progress';
import { helper } from '../helper';
import { eventsHelper } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils';
import type { BrowserOptions, BrowserProcess, PlaywrightOptions } from '../browser';
import type * as childProcess from 'child_process';
import * as readline from 'readline';
import { RecentLogsCollector } from '../../utils/debugLogger';
import { RecentLogsCollector } from '../../common/debugLogger';
import { serverSideCallMetadata, SdkObject } from '../instrumentation';
import type * as channels from '../../protocol/channels';
import type { BrowserContextOptions } from '../types';

View file

@ -24,8 +24,9 @@ import url from 'url';
import zlib from 'zlib';
import type { HTTPCredentials } from '../../types/types';
import type * as channels from '../protocol/channels';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { assert, createGuid, getUserAgent, monotonicTime } from '../utils';
import { TimeoutSettings } from '../common/timeoutSettings';
import { getUserAgent } from '../common/userAgent';
import { assert, createGuid, monotonicTime } from '../utils';
import { BrowserContext } from './browserContext';
import { CookieStore, domainMatches } from './cookieStore';
import { MultipartFormData } from './formData';

View file

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { kBrowserClosedError } from '../../utils/errors';
import { kBrowserClosedError } from '../../common/errors';
import { assert } from '../../utils';
import type { BrowserOptions } from '../browser';
import { Browser } from '../browser';

View file

@ -20,8 +20,8 @@ import { assert } from '../../utils';
import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport';
import type { Protocol } from './protocol';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import type { RecentLogsCollector } from '../../utils/debugLogger';
import { debugLogger } from '../../utils/debugLogger';
import type { RecentLogsCollector } from '../../common/debugLogger';
import { debugLogger } from '../../common/debugLogger';
import type { ProtocolLogger } from '../types';
import { helper } from '../helper';
import { ProtocolError } from '../protocolError';

View file

@ -15,8 +15,8 @@
* limitations under the License.
*/
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import type { FFSession } from './ffConnection';
import type { Page } from '../page';
import * as network from '../network';

View file

@ -18,8 +18,8 @@
import * as dialog from '../dialog';
import * as dom from '../dom';
import type * as frames from '../frames';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import { assert } from '../../utils';
import type { PageBinding, PageDelegate } from '../page';
import { Page, Worker } from '../page';
@ -33,7 +33,7 @@ import { FFNetworkManager } from './ffNetworkManager';
import type { Protocol } from './protocol';
import type { Progress } from '../progress';
import { splitErrorMessage } from '../../utils/stackTrace';
import { debugLogger } from '../../utils/debugLogger';
import { debugLogger } from '../../common/debugLogger';
import { ManualPromise } from '../../utils';
export const UTILITY_WORLD_NAME = '__playwright_utility_world__';

View file

@ -19,8 +19,8 @@ import type * as channels from '../protocol/channels';
import type { ConsoleMessage } from './console';
import * as dom from './dom';
import { helper } from './helper';
import type { RegisteredListener } from '../utils/eventsHelper';
import { eventsHelper } from '../utils/eventsHelper';
import type { RegisteredListener } from '../utils';
import { eventsHelper } from '../utils';
import * as js from './javascript';
import * as network from './network';
import type { Dialog } from './dialog';
@ -31,7 +31,7 @@ import type { Progress } from './progress';
import { ProgressController } from './progress';
import { assert, constructURLBasedOnBaseURL, makeWaitForNextTask } from '../utils';
import { ManualPromise } from '../utils';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
import type { CallMetadata } from './instrumentation';
import { serverSideCallMetadata, SdkObject } from './instrumentation';
import { type InjectedScript } from './injected/injectedScript';

View file

@ -18,9 +18,9 @@
import type { EventEmitter } from 'events';
import type * as types from './types';
import type { Progress } from './progress';
import { debugLogger } from '../utils/debugLogger';
import type { RegisteredListener } from '../utils/eventsHelper';
import { eventsHelper } from '../utils/eventsHelper';
import { debugLogger } from '../common/debugLogger';
import type { RegisteredListener } from '../utils';
import { eventsHelper } from '../utils';
class Helper {
static completeUserURL(urlString: string): string {

View file

@ -22,7 +22,7 @@ import * as js from './javascript';
import * as network from './network';
import type { ScreenshotOptions } from './screenshotter';
import { Screenshotter } from './screenshotter';
import { TimeoutSettings } from '../utils/timeoutSettings';
import { TimeoutSettings } from '../common/timeoutSettings';
import type * as types from './types';
import { BrowserContext } from './browserContext';
import { ConsoleMessage } from './console';
@ -32,7 +32,7 @@ import type { Progress } from './progress';
import { ProgressController } from './progress';
import { assert, isError } from '../utils';
import { ManualPromise } from '../utils';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
import type { ImageComparatorOptions } from '../utils/comparators';
import { getComparator } from '../utils/comparators';
import type { SelectorInfo, Selectors } from './selectors';

View file

@ -17,7 +17,7 @@
import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from './transport';
import { makeWaitForNextTask } from '../utils';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
export class PipeTransport implements ConnectionTransport {
private _pipeWrite: NodeJS.WritableStream;

View file

@ -24,7 +24,7 @@ import { Selectors } from './selectors';
import { WebKit } from './webkit/webkit';
import type { CallMetadata } from './instrumentation';
import { createInstrumentation, SdkObject } from './instrumentation';
import { debugLogger } from '../utils/debugLogger';
import { debugLogger } from '../common/debugLogger';
import type { Page } from './page';
export class Playwright extends SdkObject {

View file

@ -14,9 +14,9 @@
* limitations under the License.
*/
import { TimeoutError } from '../utils/errors';
import { TimeoutError } from '../common/errors';
import { assert, monotonicTime } from '../utils';
import type { LogName } from '../utils/debugLogger';
import type { LogName } from '../common/debugLogger';
import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation';
import type { ElementHandle } from './dom';
import { ManualPromise } from '../utils';

View file

@ -19,8 +19,9 @@ import extract from 'extract-zip';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { existsAsync, getUserAgent } from '../../utils';
import { debugLogger } from '../../utils/debugLogger';
import { getUserAgent } from '../../common/userAgent';
import { existsAsync } from '../../utils';
import { debugLogger } from '../../common/debugLogger';
import { download } from './download';
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string, downloadURL: string, downloadFileName: string): Promise<boolean> {

View file

@ -22,6 +22,7 @@ import * as utils from '../../utils';
import { buildPlaywrightCLICommand } from '.';
import { deps } from './nativeDeps';
import { getUbuntuVersion } from '../../utils/ubuntuVersion';
import { getPlaywrightVersion } from '../../common/userAgent';
const BIN_DIRECTORY = path.join(__dirname, '..', '..', '..', 'bin');
const packageJSON = require('../../../package.json');
@ -207,10 +208,10 @@ export async function validateDependenciesLinux(sdkLanguage: string, linuxLddDir
];
// Ignore patch versions when comparing docker container version and Playwright version:
// we **NEVER** roll browsers in patch releases, so native dependencies do not change.
if (dockerInfo && !dockerInfo.driverVersion.startsWith(utils.getPlaywrightVersion(true /* majorMinorOnly */) + '.')) {
if (dockerInfo && !dockerInfo.driverVersion.startsWith(getPlaywrightVersion(true /* majorMinorOnly */) + '.')) {
// We are running in a docker container with unmatching version.
// In this case, we know how to install dependencies in it.
const pwVersion = utils.getPlaywrightVersion();
const pwVersion = getPlaywrightVersion();
const requiredDockerImage = dockerInfo.dockerImageName.replace(dockerInfo.driverVersion, pwVersion);
errorLines.push(...[
`This is most likely due to docker image version not matching Playwright version:`,

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import ProgressBar from 'progress';
import { httpRequest } from '../../utils';
import { httpRequest } from '../../common/netUtils';
type OnProgressCallback = (downloadedBytes: number, totalBytes: number) => void;
type DownloadFileLogger = (message: string) => void;

View file

@ -21,8 +21,9 @@ import * as util from 'util';
import * as fs from 'fs';
import lockfile from 'proper-lockfile';
import { getUbuntuVersion } from '../../utils/ubuntuVersion';
import { fetchData } from '../../utils';
import { getFromENV, getAsBooleanFromENV, getClientLanguage, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, wrapInASCIIBox, transformCommandsForRoot } from '../../utils';
import { fetchData } from '../../common/netUtils';
import { getClientLanguage } from '../../common/userAgent';
import { getFromENV, getAsBooleanFromENV, calculateSha1, removeFolders, existsAsync, hostPlatform, canAccessFile, spawnAsync, wrapInASCIIBox, transformCommandsForRoot } from '../../utils';
import type { DependencyGroup } from './dependencies';
import { installDependenciesLinux, installDependenciesWindows, validateDependenciesLinux, validateDependenciesWindows } from './dependencies';
import { downloadBrowserWithProgressBar, logPolitely } from './browserFetcher';

View file

@ -22,8 +22,8 @@ import * as network from '../../network';
import { Page } from '../../page';
import type * as har from './har';
import { calculateSha1, monotonicTime } from '../../../utils';
import type { RegisteredListener } from '../../../utils/eventsHelper';
import { eventsHelper } from '../../../utils/eventsHelper';
import type { RegisteredListener } from '../../../utils';
import { eventsHelper } from '../../../utils';
import * as mime from 'mime';
import { ManualPromise } from '../../../utils';

View file

@ -1,5 +1,6 @@
[*]
../../
../../../common/
../../../protocol/
../../../utils/
../../supplements/har/

View file

@ -16,9 +16,9 @@
import { BrowserContext } from '../../browserContext';
import { Page } from '../../page';
import type { RegisteredListener } from '../../../utils/eventsHelper';
import { eventsHelper } from '../../../utils/eventsHelper';
import { debugLogger } from '../../../utils/debugLogger';
import type { RegisteredListener } from '../../../utils';
import { eventsHelper } from '../../../utils';
import { debugLogger } from '../../../common/debugLogger';
import type { Frame } from '../../frames';
import type { SnapshotData } from './snapshotterInjected';
import { frameSnapshotStreamer } from './snapshotterInjected';

View file

@ -23,8 +23,8 @@ import type { NameValue } from '../../../common/types';
import type { TracingTracingStopChunkParams } from '../../../protocol/channels';
import { commandsWithTracingSnapshots } from '../../../protocol/channels';
import { ManualPromise } from '../../../utils';
import type { RegisteredListener } from '../../../utils/eventsHelper';
import { eventsHelper } from '../../../utils/eventsHelper';
import type { RegisteredListener } from '../../../utils';
import { eventsHelper } from '../../../utils';
import { assert, calculateSha1, createGuid, mkdirIfNeeded, monotonicTime, removeFolders } from '../../../utils';
import { Artifact } from '../../artifact';
import { BrowserContext } from '../../browserContext';

View file

@ -18,9 +18,8 @@
import type { BrowserOptions } from '../browser';
import { Browser } from '../browser';
import { assertBrowserContextIsNotOwned, BrowserContext, verifyGeolocation } from '../browserContext';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import { assert } from '../../utils';
import type { RegisteredListener } from '../../utils';
import { assert, eventsHelper } from '../../utils';
import * as network from '../network';
import type { Page, PageBinding, PageDelegate } from '../page';
import type { ConnectionTransport } from '../transport';
@ -29,7 +28,7 @@ import type { Protocol } from './protocol';
import type { PageProxyMessageReceivedPayload } from './wkConnection';
import { kPageProxyMessageReceived, WKConnection, WKSession } from './wkConnection';
import { WKPage } from './wkPage';
import { kBrowserClosedError } from '../../utils/errors';
import { kBrowserClosedError } from '../../common/errors';
const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15';
const BROWSER_VERSION = '15.4';

View file

@ -20,11 +20,11 @@ import { assert } from '../../utils';
import type { ConnectionTransport, ProtocolRequest, ProtocolResponse } from '../transport';
import type { Protocol } from './protocol';
import { rewriteErrorMessage } from '../../utils/stackTrace';
import type { RecentLogsCollector } from '../../utils/debugLogger';
import { debugLogger } from '../../utils/debugLogger';
import type { RecentLogsCollector } from '../../common/debugLogger';
import { debugLogger } from '../../common/debugLogger';
import type { ProtocolLogger } from '../types';
import { helper } from '../helper';
import { kBrowserClosedError } from '../../utils/errors';
import { kBrowserClosedError } from '../../common/errors';
import { ProtocolError } from '../protocolError';
// WKPlaywright uses this special id to issue Browser.close command which we

View file

@ -24,8 +24,8 @@ import type * as accessibility from '../accessibility';
import * as dialog from '../dialog';
import * as dom from '../dom';
import type * as frames from '../frames';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import { helper } from '../helper';
import type { JSHandle } from '../javascript';
import * as network from '../network';
@ -42,7 +42,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 '../../common/debugLogger';
import { ManualPromise } from '../../utils';
const UTILITY_WORLD_NAME = '__playwright_utility_world__';

View file

@ -16,8 +16,8 @@
import type { WKSession } from './wkConnection';
import type { WKPage } from './wkPage';
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import type { Protocol } from './protocol';
import { assert } from '../../utils';

View file

@ -14,8 +14,8 @@
* limitations under the License.
*/
import type { RegisteredListener } from '../../utils/eventsHelper';
import { eventsHelper } from '../../utils/eventsHelper';
import type { RegisteredListener } from '../../utils';
import { eventsHelper } from '../../utils';
import type { Page } from '../page';
import { Worker } from '../page';
import type { Protocol } from './protocol';

View file

@ -15,7 +15,7 @@
*/
import type { SpawnOptions } from 'child_process';
import { execSync, spawn } from 'child_process';
import { spawn } from 'child_process';
import * as crypto from 'crypto';
import fs from 'fs';
import os from 'os';
@ -24,13 +24,14 @@ import removeFolder from 'rimraf';
import type stream from 'stream';
import * as URL from 'url';
import type { NameValue } from '../protocol/channels';
import { getUbuntuVersionSync, parseOSReleaseText } from './ubuntuVersion';
import { getUbuntuVersionSync } from './ubuntuVersion';
export { eventsHelper } from './eventsHelper';
export type { RegisteredListener } from './eventsHelper';
export { ManualPromise } from './manualPromise';
export { MultiMap } from './multimap';
export { raceAgainstTimeout, TimeoutRunner, TimeoutRunnerError } from './timeoutRunner';
export type { HTTPRequestParams } from './netUtils';
export { httpRequest, fetchData } from './netUtils';
export { zones } from './zones';
export const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
@ -235,66 +236,6 @@ export function canAccessFile(file: string) {
}
}
let cachedUserAgent: string | undefined;
export function getUserAgent(): string {
if (cachedUserAgent)
return cachedUserAgent;
try {
cachedUserAgent = determineUserAgent();
} catch (e) {
cachedUserAgent = 'Playwright/unknown';
}
return cachedUserAgent;
}
function determineUserAgent(): string {
let osIdentifier = 'unknown';
let osVersion = 'unknown';
if (process.platform === 'win32') {
const version = os.release().split('.');
osIdentifier = 'windows';
osVersion = `${version[0]}.${version[1]}`;
} else if (process.platform === 'darwin') {
const version = execSync('sw_vers -productVersion', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim().split('.');
osIdentifier = 'macOS';
osVersion = `${version[0]}.${version[1]}`;
} else if (process.platform === 'linux') {
try {
// List of /etc/os-release values for different distributions could be
// found here: https://gist.github.com/aslushnikov/8ceddb8288e4cf9db3039c02e0f4fb75
const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8');
const fields = parseOSReleaseText(osReleaseText);
osIdentifier = fields.get('id') || 'unknown';
osVersion = fields.get('version_id') || 'unknown';
} catch (e) {
// Linux distribution without /etc/os-release.
// Default to linux/unknown.
osIdentifier = 'linux';
}
}
const { langName, langVersion } = getClientLanguage();
return `Playwright/${getPlaywrightVersion()} (${os.arch()}; ${osIdentifier} ${osVersion}) ${langName}/${langVersion}`;
}
export function getClientLanguage(): { langName: string, langVersion: string } {
let langName = 'unknown';
let langVersion = 'unknown';
if (!process.env.PW_LANG_NAME) {
langName = 'node';
langVersion = process.version.substring(1).split('.').slice(0, 2).join('.');
} else if (['node', 'python', 'java', 'csharp'].includes(process.env.PW_LANG_NAME)) {
langName = process.env.PW_LANG_NAME;
langVersion = process.env.PW_LANG_NAME_VERSION ?? 'unknown';
}
return { langName, langVersion };
}
export function getPlaywrightVersion(majorMinorOnly = false) {
const packageJson = require('./../../package.json');
return majorMinorOnly ? packageJson.version.split('.').slice(0, 2).join('.') : packageJson.version;
}
export function constructURLBasedOnBaseURL(baseURL: string | undefined, givenURL: string): string {
try {
return (new URL.URL(givenURL, baseURL)).toString();

View file

@ -15,7 +15,6 @@
*/
import path from 'path';
import type { StackFrame } from '../protocol/channels';
import StackUtils from 'stack-utils';
import { isUnderTest } from './';
@ -38,6 +37,13 @@ const TEST_DIR_LIB = path.resolve(CORE_DIR, '..', '@playwright', 'test');
const COVERAGE_PATH = path.join(CORE_DIR, '..', '..', 'tests', 'config', 'coverage.js');
const WS_LIB = path.relative(process.cwd(), path.dirname(require.resolve('ws')));
export type StackFrame = {
file: string,
line?: number,
column?: number,
function?: string,
};
export type ParsedStackTrace = {
allFrames: StackFrame[];
frames: StackFrame[];

View file

@ -1,33 +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.
*/
const currentNodeVersion = process.versions.node;
const semver = currentNodeVersion.split('.');
const [major] = [+semver[0]];
if (major < 12) {
// eslint-disable-next-line no-console
console.error(
'You are running Node.js ' +
currentNodeVersion +
'.\n' +
'Playwright requires Node.js 12 or higher. \n' +
'Please update your version of Node.js.'
);
process.exit(1);
}
export {};

View file

@ -18,7 +18,7 @@
import fs from 'fs';
import os from 'os';
import * as path from 'path';
import { getUserAgent } from '../../packages/playwright-core/lib/utils';
import { getUserAgent } from '../../packages/playwright-core/lib/common/userAgent';
import WebSocket from 'ws';
import { expect, playwrightTest as test } from '../config/browserTest';
import { parseTrace, suppressCertificateWarning } from '../config/utils';

View file

@ -19,7 +19,7 @@ import { contextTest as test, expect } from '../../config/browserTest';
import { playwrightTest } from '../../config/browserTest';
import http from 'http';
import fs from 'fs';
import { getUserAgent } from '../../../packages/playwright-core/lib/utils';
import { getUserAgent } from '../../../packages/playwright-core/lib/common/userAgent';
import { suppressCertificateWarning } from '../../config/utils';
test('should create a worker from a service worker', async ({ page, server }) => {

View file

@ -17,7 +17,7 @@
import http from 'http';
import os from 'os';
import * as util from 'util';
import { getPlaywrightVersion } from '../../packages/playwright-core/lib/utils';
import { getPlaywrightVersion } from '../../packages/playwright-core/lib/common/userAgent';
import { expect, playwrightTest as it } from '../config/browserTest';
it.skip(({ mode }) => mode !== 'default');