Skip to content

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

chore: throw pretty error if launchApp is launched using channel (#36881)

Max Schmitt432f03dc70b6
diff --git a/packages/playwright-core/src/server/launchApp.ts b/packages/playwright-core/src/server/launchApp.ts
index 8eee438d84..1dc29e983f 100644
--- a/packages/playwright-core/src/server/launchApp.ts
+++ b/packages/playwright-core/src/server/launchApp.ts
@@ -17,9 +17,9 @@
import fs from 'fs';
import path from 'path';
-import { isUnderTest } from '../utils';
+import { isUnderTest, rewriteErrorMessage, wrapInASCIIBox } from '../utils';
import { serverSideCallMetadata } from './instrumentation';
-import { findChromiumChannel } from './registry';
+import { buildPlaywrightCLICommand, findChromiumChannelBestEffort } from './registry';
import { registryDirectory } from './registry';
import { ProgressController } from './progress';
@@ -46,19 +46,32 @@ export async function launchApp(browserType: BrowserType, options: {
'--test-type=',
);
if (!channel && !options.persistentContextOptions?.executablePath)
- channel = findChromiumChannel(options.sdkLanguage);
+ channel = findChromiumChannelBestEffort(options.sdkLanguage);
}
const controller = new ProgressController(serverSideCallMetadata(), browserType);
- const context = await controller.run(progress => browserType.launchPersistentContext(progress, '', {
- ignoreDefaultArgs: ['--enable-automation'],
- ...options?.persistentContextOptions,
- channel,
- noDefaultViewport: options.persistentContextOptions?.noDefaultViewport ?? true,
- acceptDownloads: options?.persistentContextOptions?.acceptDownloads ?? (isUnderTest() ? 'accept' : 'internal-browser-default'),
- colorScheme: options?.persistentContextOptions?.colorScheme ?? 'no-override',
- args,
- }), 0); // Deliberately no timeout for our apps.
+ let context;
+ try {
+ context = await controller.run(progress => browserType.launchPersistentContext(progress, '', {
+ ignoreDefaultArgs: ['--enable-automation'],
+ ...options?.persistentContextOptions,
+ channel,
+ noDefaultViewport: options.persistentContextOptions?.noDefaultViewport ?? true,
+ acceptDownloads: options?.persistentContextOptions?.acceptDownloads ?? (isUnderTest() ? 'accept' : 'internal-browser-default'),
+ colorScheme: options?.persistentContextOptions?.colorScheme ?? 'no-override',
+ args,
+ }), 0); // Deliberately no timeout for our apps.
+ } catch (error) {
+ if (channel) {
+ error = rewriteErrorMessage(error, [
+ `Failed to launch "${channel}" channel.`,
+ 'Using custom channels could lead to unexpected behavior due to Enterprise policies (chrome://policy).',
+ 'Install the default browser instead:',
+ wrapInASCIIBox(`${buildPlaywrightCLICommand(options.sdkLanguage, 'install')}`, 2),
+ ].join('\n'));
+ }
+ throw error;
+ }
const [page] = context.pages();
// Chromium on macOS opens a new tab when clicking on the dock icon.
// See https://github.com/microsoft/playwright/issues/9434
diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.ts
index fde6b2f101..36ee1d92d5 100644
--- a/packages/playwright-core/src/server/registry/index.ts
+++ b/packages/playwright-core/src/server/registry/index.ts
@@ -1363,7 +1363,8 @@ export async function installBrowsersForNpmInstall(browsers: string[]) {
await registry.install(executables, false /* forceReinstall */);
}
-export function findChromiumChannel(sdkLanguage: string): string | undefined {
+// for launchApp -> UI Mode / Trace Viewer
+export function findChromiumChannelBestEffort(sdkLanguage: string): string | undefined {
// Fall back to the stable channels of popular vendors to work out of the box.
// Null means no installation and no channels found.
let channel = null;