Skip to content

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

chore: skip open() under coding agents (#40438)

Simon Knott05deb5d44937
diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
index 95b0db0794..bf26e56466 100644
--- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
+++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts
@@ -21,6 +21,7 @@ import open from 'open';
import { HttpServer } from '@utils/httpServer';
import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';
import { isUnderTest } from '@utils/debug';
+import { isCodingAgent } from '@utils/env';
import { libPath } from '../../../package';
import { syncLocalStorageWithSettings } from '../../launchApp';
import { launchApp } from '../../launchApp';
@@ -238,7 +239,7 @@ export async function openTraceViewerApp(url: string, browserName: string, optio
export async function openTraceInBrowser(url: string) {
// eslint-disable-next-line no-console
console.log('\nListening on ' + url);
- if (!isUnderTest())
+ if (!isUnderTest() && !isCodingAgent())
await open(url.replace('0.0.0.0', 'localhost')).catch(() => {});
}
diff --git a/packages/playwright-core/src/tools/cli-client/DEPS.list b/packages/playwright-core/src/tools/cli-client/DEPS.list
index 403e76efa8..07864bbb60 100644
--- a/packages/playwright-core/src/tools/cli-client/DEPS.list
+++ b/packages/playwright-core/src/tools/cli-client/DEPS.list
@@ -7,7 +7,6 @@
./output.ts
./session.ts
./registry.ts
-./utils.ts
[output.ts]
"strict"
@@ -33,6 +32,3 @@
[minimist.ts]
"strict"
-
-[utils.ts]
-"strict"
diff --git a/packages/playwright-core/src/tools/cli-client/program.ts b/packages/playwright-core/src/tools/cli-client/program.ts
index 88fee00f5a..1a01ca11f8 100644
--- a/packages/playwright-core/src/tools/cli-client/program.ts
+++ b/packages/playwright-core/src/tools/cli-client/program.ts
@@ -26,7 +26,6 @@ import { isKnownChannel, listChannelSessions } from './channelSessions';
import { JsonOutput, TextOutput } from './output';
import { clientKey, createClientInfo, explicitSessionName, Registry, resolveSessionName } from './registry';
import { Session } from './session';
-import { isCodingAgent } from './utils';
import { libPath } from '../../package';
import { serverRegistry } from '../../serverRegistry';
import { minimist } from './minimist';
@@ -99,7 +98,7 @@ export async function program(options?: { embedderVersion?: string}) {
output.help(command.help);
} else {
const lines = ['playwright-cli - run playwright mcp commands from terminal'];
- if (isCodingAgent())
+ if (process.env.CLAUDECODE || process.env.COPILOT_CLI)
lines.push(`Agent skill: ${path.relative(process.cwd(), libPath('tools', 'cli-client', 'skill', 'SKILL.md'))}`);
lines.push(help.global);
output.help(lines.join('\n\n'));
diff --git a/packages/playwright-core/src/tools/cli-client/utils.ts b/packages/playwright-core/src/tools/cli-client/utils.ts
deleted file mode 100644
index fab068cada..0000000000
--- a/packages/playwright-core/src/tools/cli-client/utils.ts
+++ /dev/null
@@ -1,27 +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.
- */
-
-export function guessClientName(): string {
- if (process.env.CLAUDECODE)
- return 'Claude Code';
- if (process.env.COPILOT_CLI)
- return 'GitHub Copilot';
- return 'playwright-cli';
-}
-
-export function isCodingAgent(): boolean {
- return !!process.env.CLAUDECODE || !!process.env.COPILOT_CLI;
-}
diff --git a/packages/playwright-core/src/tools/cli-daemon/DEPS.list b/packages/playwright-core/src/tools/cli-daemon/DEPS.list
index 264a2f19da..2c911112cd 100644
--- a/packages/playwright-core/src/tools/cli-daemon/DEPS.list
+++ b/packages/playwright-core/src/tools/cli-daemon/DEPS.list
@@ -2,7 +2,6 @@
../../package.ts
../utils/socketConnection.ts
../cli-client/registry.ts
-../cli-client/utils.ts
../backend/
../mcp/
@utils/**
diff --git a/packages/playwright-core/src/tools/cli-daemon/program.ts b/packages/playwright-core/src/tools/cli-daemon/program.ts
index a1750189b2..5bb2271087 100644
--- a/packages/playwright-core/src/tools/cli-daemon/program.ts
+++ b/packages/playwright-core/src/tools/cli-daemon/program.ts
@@ -20,14 +20,13 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
-import { getAsBooleanFromENV } from '@utils/env';
+import { getAsBooleanFromENV, guessClientName } from '@utils/env';
import { libPath } from '../../package';
import { startCliDaemonServer } from './daemon';
import { setupExitWatchdog } from '../mcp/watchdog';
import { createBrowserWithInfo } from '../mcp/browserFactory';
import * as configUtils from '../mcp/config';
import { createClientInfo } from '../cli-client/registry';
-import { guessClientName } from '../cli-client/utils';
import { registry as browserRegistry } from '../../server/registry/index';
import type { Command } from 'commander';
diff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.ts
index c319c3b787..96f71f21bd 100644
--- a/packages/playwright/src/reporters/html.ts
+++ b/packages/playwright/src/reporters/html.ts
@@ -26,7 +26,7 @@ import { assert } from '@isomorphic/assert';
import { MultiMap } from '@isomorphic/multimap';
import { calculateSha1 } from '@utils/crypto';
import { copyFileAndMakeWritable, removeFolders, sanitizeForFilePath, toPosixPath } from '@utils/fileUtils';
-import { getPackageManagerExecCommand } from '@utils/env';
+import { getPackageManagerExecCommand, isCodingAgent } from '@utils/env';
import { HttpServer, serveFolder } from '@utils/httpServer';
import { gracefullyProcessExitDoNotHang } from '@utils/processLauncher';
@@ -169,8 +169,7 @@ class HtmlReporter implements ReporterV2 {
if (process.env.CI || !this._buildResult)
return;
const { ok, singleTestId } = this._buildResult;
- const isCodingAgent = !!process.env.CLAUDECODE || !!process.env.COPILOT_CLI;
- const shouldOpen = !isCodingAgent && !!process.stdin.isTTY && (this._open === 'always' || (!ok && this._open === 'on-failure'));
+ const shouldOpen = !isCodingAgent() && !!process.stdin.isTTY && (this._open === 'always' || (!ok && this._open === 'on-failure'));
if (shouldOpen) {
await showHTMLReport(this._outputFolder, this._host, this._port, singleTestId);
} else if (this._options._mode === 'test' && !!process.stdin.isTTY) {
@@ -241,7 +240,8 @@ export async function showHTMLReport(reportFolder: string | undefined, host: str
if (testId)
url += `#?testId=${testId}`;
url = url.replace('0.0.0.0', 'localhost');
- await open(url, { wait: true }).catch(() => {});
+ if (!isCodingAgent())
+ await open(url, { wait: true }).catch(() => {});
await new Promise(() => {});
}
diff --git a/packages/utils/DEPS.list b/packages/utils/DEPS.list
index 8904c06d03..0834f57c8e 100644
--- a/packages/utils/DEPS.list
+++ b/packages/utils/DEPS.list
@@ -16,3 +16,6 @@ node_modules/yazl
[comparators.ts]
./image_tools
./third_party/pixelmatch
+
+[env.ts]
+"strict"
diff --git a/packages/utils/env.ts b/packages/utils/env.ts
index 840add7d98..c762b6b99e 100644
--- a/packages/utils/env.ts
+++ b/packages/utils/env.ts
@@ -56,3 +56,15 @@ export function isLikelyNpxGlobal() {
export function setPlaywrightTestProcessEnv() {
return process.env['PLAYWRIGHT_TEST'] = '1';
}
+
+export function guessClientName(): string {
+ if (process.env.CLAUDECODE)
+ return 'Claude Code';
+ if (process.env.COPILOT_CLI)
+ return 'GitHub Copilot';
+ return 'playwright-cli';
+}
+
+export function isCodingAgent(): boolean {
+ return !!process.env.CLAUDECODE || !!process.env.COPILOT_CLI;
+}