Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ test-results
.eslintcache
playwright.env
/firefox/
.playwright/
55 changes: 52 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ignores = [
"test-results/",
"tests/assets/",
"tests/components/",
"tests/config/ghaMarkdownReporter.ts",
"tests/installation/fixture-scripts/",
"tests/third_party/",
"utils/",
Expand Down Expand Up @@ -357,17 +358,65 @@ export default [
},
},
{
files: ["packages/playwright-core/src/tools/**/*.ts"],
files: ["packages/playwright-core/src/**/*.ts"],
ignores: [
"packages/playwright-core/src/entry/**",
],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [{
group: ["**/client", "**/client/**"],
message: "tools/ must not import from client/",
group: ["**/coreBundle"],
message: "coreBundle can only be imported from entry/ files. Use direct imports instead.",
}],
},
],
},
},
{
files: ["packages/playwright-core/src/**/*.ts"],
ignores: [
"packages/playwright-core/src/package.ts",
"packages/playwright-core/src/cli/programWithTestStub.ts",
],
rules: {
"no-restricted-properties": [
"error",
{
object: "process",
property: "exit",
message:
"Please use gracefullyProcessExitDoNotHang function to exit the process.",
},
{ object: "process", property: "stdout" },
{ object: "process", property: "stderr" },
{
object: "require",
property: "resolve",
message: "Use libPath() from package.ts instead of require.resolve.",
},
],
},
},
{
files: ["packages/playwright-core/src/tools/**/*.ts"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["**/client", "**/client/**"],
message: "tools/ must not import from client/",
},
{
group: ["**/coreBundle"],
message: "coreBundle can only be imported from entry/ files. Use direct imports instead.",
},
],
},
],
"no-restricted-syntax": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-browser-chromium/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let install;

try {
if (!require('playwright-core/lib/coreBundle').serverUtils.isLikelyNpxGlobal())
install = require('playwright-core/lib/coreBundle').sever.installBrowsersForNpmInstall;
install = require('playwright-core/lib/coreBundle').registry.installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-browser-firefox/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let install;

try {
if (!require('playwright-core/lib/coreBundle').serverUtils.isLikelyNpxGlobal())
install = require('playwright-core/lib/coreBundle').sever.installBrowsersForNpmInstall;
install = require('playwright-core/lib/coreBundle').registry.installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-browser-webkit/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let install;

try {
if (!require('playwright-core/lib/coreBundle').serverUtils.isLikelyNpxGlobal())
install = require('playwright-core/lib/coreBundle').sever.installBrowsersForNpmInstall;
install = require('playwright-core/lib/coreBundle').registry.installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-chromium/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let install;

try {
if (!require('playwright-core/lib/coreBundle').serverUtils.isLikelyNpxGlobal())
install = require('playwright-core/lib/coreBundle').sever.installBrowsersForNpmInstall;
install = require('playwright-core/lib/coreBundle').registry.installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
Expand Down
3 changes: 2 additions & 1 deletion packages/playwright-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"./lib/mcpBundle": "./lib/mcpBundle.js",
"./lib/utilsBundle": "./lib/utilsBundle.js",
"./lib/zipBundle": "./lib/zipBundle.js",
"./lib/zodBundle": "./lib/zodBundle.js"
"./lib/zodBundle": "./lib/zodBundle.js",
"./lib/tools/cli-client/program": "./lib/tools/cli-client/program.js"
},
"bin": {
"playwright-core": "cli.js"
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/DEPS.list
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ utilsBundle.ts

[outofprocess.ts]
client/
package.ts
protocol/
utils/
utils/isomorphic
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-core/src/cli/DEPS.list
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[*]
../inprocess.ts
../package.ts
../server/
../server/registry/
../server/utils/
../remote/
../utils/
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/cli/browserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import path from 'path';

import { playwright } from '../inprocess';
import { gracefullyProcessExitDoNotHang, ManualPromise } from '../utils';
import { dotenv, program } from '../utilsBundle';
import { debug, dotenv, program } from '../utilsBundle';

import type { Browser } from '../client/browser';
import type { BrowserContext } from '../client/browserContext';
Expand Down Expand Up @@ -267,7 +267,7 @@ async function maybeSetupTestHooks(browser: Browser, closeBrowser: () => Promise

// Make sure we exit abnormally when browser crashes.
const logs: string[] = [];
require('playwright-core/lib/utilsBundle').debug.log = (...args: any[]) => {
debug.log = (...args: any[]) => {
const line = require('util').format(...args) + '\n';
logs.push(line);
// eslint-disable-next-line no-restricted-properties
Expand Down
4 changes: 3 additions & 1 deletion packages/playwright-core/src/cli/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/* eslint-disable no-console */

import fs from 'fs';
import path from 'path';

import { packageRoot } from '../package';
import { playwright } from '../inprocess';
import { PipeTransport } from '../server/utils/pipeTransport';
import { PlaywrightServer } from '../remote/playwrightServer';
Expand All @@ -29,7 +31,7 @@ import type { LaunchServerOptions } from '../client/types';

export function printApiJson() {
// Note: this file is generated by build-playwright-driver.sh
console.log(JSON.stringify(require('../../api.json')));
console.log(JSON.stringify(require(path.join(packageRoot, 'api.json'))));
}

export function runDriver() {
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/cli/installActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

import path from 'path';

import { registry, writeDockerVersion } from '../server';
import { registry, writeDockerVersion } from '../server/registry';
import { isLikelyNpxGlobal } from '../utils';
import { assert } from '../utils';
import { wrapInASCIIBox } from '../server/utils/ascii';

import type { BrowserInfo } from '../server';
import type { BrowserInfo } from '../server/registry';

function printInstalledBrowsers(browsers: BrowserInfo[]) {
const browserPaths = new Set<string>();
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/cli/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* eslint-disable no-console */

import '../bootstrap';
import { packageJSON } from '../package';
import { gracefullyProcessExitDoNotHang, getPackageManagerExecCommand } from '../utils';
import { addTraceCommands } from '../tools/trace/traceCli';
import { program } from '../utilsBundle';
Expand All @@ -25,7 +26,6 @@ import type { TraceViewerServerOptions } from '../server/trace/viewer/traceViewe
import type { Command } from '../utilsBundle';

export function decorateProgram(program: Command) {
const packageJSON = require('../../package.json');

program
.version('Version ' + (process.env.PW_CLI_DISPLAY_VERSION || packageJSON.version))
Expand Down
5 changes: 3 additions & 2 deletions packages/playwright-core/src/client/clientStackTrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ export function captureLibraryStackTrace(platform: Platform): { frames: StackFra
function normalizeAPIName(name?: string): string {
if (!name)
return '';
const match = name.match(/(API|JS|CDP|[A-Z])(.*)/);
// (\d) is to tolerate bundler renames Locator2 instead of Locator.
const match = name.match(/(API|JS|CDP|[A-Z])([^\d]+)\d?\.(.*)/);
if (!match)
return name;
return match[1].toLowerCase() + match[2];
return match[1].toLowerCase() + match[2] + '.' + match[3];
}

// This is for the inspector so that it did not include the test runner stack frames.
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export class APIResponse implements api.APIResponse {
private readonly _initializer: channels.APIResponse;
private readonly _headers: RawHeaders;
readonly _request: APIRequestContext;
_apiName = 'APIResponse';

constructor(context: APIRequestContext, initializer: channels.APIResponse) {
this._request = context;
Expand Down
17 changes: 17 additions & 0 deletions packages/playwright-core/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* 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 * from './eventEmitter';
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type LocatorOptions = {
export class Locator implements api.Locator {
_frame: Frame;
_selector: string;
_apiName = 'Locator';

constructor(frame: Frame, selector: string, options?: LocatorOptions) {
this._frame = frame;
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type ExpectScreenshotOptions = Omit<channels.PageExpectScreenshotOptions,
export class Page extends ChannelOwner<channels.PageChannel> implements api.Page {
private _browserContext: BrowserContext;
_ownedContext: BrowserContext | undefined;
_apiName = 'Page';

private _mainFrame: Frame;
private _frames = new Set<Frame>();
Expand Down
5 changes: 2 additions & 3 deletions packages/playwright-core/src/coreBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

export * as client from './client';
export * as iso from './utils/isomorphic';
export * as serverUtils from './server/utils';
export * as tools from './tools';
export * as libCli from './cli/program';
export * as libCliTestStub from './cli/programWithTestStub';
export * as inprocess from './inprocess';
export * as oop from './outofprocess';
export * as remote from './remote/playwrightServer';
export * as mcp from './tools/mcp/program';
export * as cli from './tools/cli-client/program';
export * as registry from './server/registry/index';
export * as sever from './server/index';
export * as tools from './tools';
4 changes: 4 additions & 0 deletions packages/playwright-core/src/entry/DEPS.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*]
../coreBundle.ts
../package.ts
../utilsBundle.ts
21 changes: 21 additions & 0 deletions packages/playwright-core/src/entry/cliDaemon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 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 { tools } from '../coreBundle';
import { program } from '../utilsBundle';

tools.decorateCliDaemonProgram(program);
void program.parseAsync();
19 changes: 19 additions & 0 deletions packages/playwright-core/src/entry/dashboardApp.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

import { tools } from '../coreBundle';

tools.openDashboardApp();
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
* limitations under the License.
*/

import { program } from '../../utilsBundle';
import { decorateMCPCommand } from './program';
import { program } from '../utilsBundle';
import { tools, serverUtils } from '../coreBundle';
import { packageJSON } from '../package';

const packageJSON = require('../../../package.json');
const p = program.version('Version ' + packageJSON.version).name('Playwright MCP');
decorateMCPCommand(p);
void program.parseAsync(process.argv);
tools.decorateMCPCommand(p);
program.parseAsync(process.argv).catch(e => {
// eslint-disable-next-line no-console
console.error(e.message);
serverUtils.gracefullyProcessExitDoNotHang(1);
});
19 changes: 19 additions & 0 deletions packages/playwright-core/src/entry/oopBrowserDownload.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

import { registry } from '../coreBundle';

registry.runOopDownloadBrowserMain();
3 changes: 2 additions & 1 deletion packages/playwright-core/src/outofprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as childProcess from 'child_process';
import path from 'path';

import { Connection } from './client/connection';
import { packageRoot } from './package';
import { PipeTransport } from './server/utils/pipeTransport';
import { ManualPromise } from './utils/isomorphic/manualPromise';
import { nodePlatform } from './server/utils/nodePlatform';
Expand All @@ -38,7 +39,7 @@ class PlaywrightClient {
private _closePromise = new ManualPromise<void>();

constructor(env: any) {
this._driverProcess = childProcess.fork(path.join(__dirname, '..', 'cli.js'), ['run-driver'], {
this._driverProcess = childProcess.fork(path.join(packageRoot, 'cli.js'), ['run-driver'], {
stdio: 'pipe',
detached: true,
env: {
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright-core/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ import path from 'path';
export const packageJSON = require('../package.json');
export const packageRoot = path.dirname(require.resolve('../package.json'));
export const binPath = path.join(packageRoot, 'bin');

export function libPath(...parts: string[]): string {
return path.join(packageRoot, 'lib', ...parts);
}
Loading
Loading