Skip to content

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

feat(cli): list browsers attachable via extension in `list --all` (#40342)

Yury Semikhatskycf6894bd4f16
diff --git a/packages/playwright-core/src/tools/cli-client/channelSessions.ts b/packages/playwright-core/src/tools/cli-client/channelSessions.ts
index 1735af1342..850df85cd6 100644
--- a/packages/playwright-core/src/tools/cli-client/channelSessions.ts
+++ b/packages/playwright-core/src/tools/cli-client/channelSessions.ts
@@ -23,8 +23,15 @@ export type ChannelSession = {
channel: string;
userDataDir: string;
endpoint?: string;
+ extensionInstalled: boolean;
};
+// Keep in sync with the id declared via "key" in packages/extension/manifest.json
+// and the hardcoded url in packages/playwright-core/src/tools/mcp/cdpRelay.ts.
+const playwrightExtensionId = 'mmlmfjhmonkocbjadbfplnigmagldckm';
+
+export const playwrightExtensionInstallUrl = `https://chromewebstore.google.com/detail/playwright-mcp-bridge/${playwrightExtensionId}`;
+
export async function listChannelSessions(): Promise<ChannelSession[]> {
if (process.env.PWTEST_CLI_CHANNEL_SCAN_DISABLED_FOR_TEST)
return [];
@@ -35,14 +42,17 @@ export async function listChannelSessions(): Promise<ChannelSession[]> {
continue;
if (!await pathExists(userDataDir))
continue;
- const endpoint = await readEndpoint(userDataDir);
- result.push({ channel, userDataDir, endpoint });
+ const [endpoint, extensionInstalled] = await Promise.all([
+ readEndpoint(userDataDir),
+ hasPlaywrightExtension(userDataDir),
+ ]);
+ result.push({ channel, userDataDir, endpoint, extensionInstalled });
}
return result;
}
-export function remoteDebuggingHint(channel: string): string {
- return `to enable, launch ${channel}, navigate to chrome://inspect/#remote-debugging and check "Allow remote debugging for this browser instance"`;
+async function hasPlaywrightExtension(userDataDir: string): Promise<boolean> {
+ return await pathExists(path.join(userDataDir, 'Default', 'Extensions', playwrightExtensionId));
}
async function pathExists(p: string): Promise<boolean> {
diff --git a/packages/playwright-core/src/tools/cli-client/output.ts b/packages/playwright-core/src/tools/cli-client/output.ts
index 82853f152e..b4d9dd8b15 100644
--- a/packages/playwright-core/src/tools/cli-client/output.ts
+++ b/packages/playwright-core/src/tools/cli-client/output.ts
@@ -19,7 +19,7 @@
import path from 'path';
-import { remoteDebuggingHint } from './channelSessions';
+import { playwrightExtensionInstallUrl } from './channelSessions';
import type { ChannelSession } from './channelSessions';
import type { BrowserStatus } from '../../serverRegistry';
@@ -364,12 +364,15 @@ function renderServer(server: BrowserStatus): string {
function renderChannelSession(session: ChannelSession): string {
const lines = [`- ${session.channel}:`];
lines.push(` - data-dir: ${session.userDataDir}`);
+ if (session.extensionInstalled)
+ lines.push(` - attach (extension): \`playwright-cli attach --extension=${session.channel}\``);
+ else
+ lines.push(` - attach (extension): install at ${playwrightExtensionInstallUrl}`);
if (session.endpoint) {
- lines.push(` - endpoint: ${session.endpoint}`);
- lines.push(` - run \`playwright-cli attach --cdp=${session.channel}\` to attach`);
+ lines.push(` - attach (remote debugging): \`playwright-cli attach --cdp=${session.channel}\``);
} else {
- lines.push(` - status: remote debugging not enabled`);
- lines.push(` - ${remoteDebuggingHint(session.channel)}`);
+ const inspectScheme = session.channel.startsWith('msedge') ? 'edge' : 'chrome';
+ lines.push(` - attach (remote debugging): enable at ${inspectScheme}://inspect/#remote-debugging`);
}
return lines.join('\n');
}