Skip to content

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

chore: beautify error message (#18002)

Pavel Feldman64e80f0460d1
diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts
index 89254e55a1..7b02456c4d 100644
--- a/packages/playwright-core/src/client/browserType.ts
+++ b/packages/playwright-core/src/client/browserType.ts
@@ -81,10 +81,12 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
ignoreAllDefaultArgs: !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs),
env: options.env ? envObjectToArray(options.env) : undefined,
};
- const browser = Browser.from((await this._channel.launch(launchOptions)).browser);
- browser._logger = logger;
- browser._setBrowserType(this);
- return browser;
+ return await this._wrapApiCall(async () => {
+ const browser = Browser.from((await this._channel.launch(launchOptions)).browser);
+ browser._logger = logger;
+ browser._setBrowserType(this);
+ return browser;
+ });
}
private async _connectInsteadOfLaunching(): Promise<Browser> {
@@ -119,13 +121,15 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
channel: options.channel,
userDataDir,
};
- const result = await this._channel.launchPersistentContext(persistentParams);
- const context = BrowserContext.from(result.context);
- context._options = contextParams;
- context._logger = logger;
- context._setBrowserType(this);
- await this._onDidCreateContext?.(context);
- return context;
+ return await this._wrapApiCall(async () => {
+ const result = await this._channel.launchPersistentContext(persistentParams);
+ const context = BrowserContext.from(result.context);
+ context._options = contextParams;
+ context._logger = logger;
+ context._setBrowserType(this);
+ await this._onDidCreateContext?.(context);
+ return context;
+ });
}
connect(options: api.ConnectOptions & { wsEndpoint?: string }): Promise<api.Browser>;
diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.ts
index d679595f0d..c2ebf7ada8 100644
--- a/packages/playwright-core/src/client/channelOwner.ts
+++ b/packages/playwright-core/src/client/channelOwner.ts
@@ -132,8 +132,13 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channel
return result;
} catch (e) {
const innerError = ((process.env.PWDEBUGIMPL || isUnderTest()) && e.stack) ? '\n<inner error>\n' + e.stack : '';
- e.message = apiName + ': ' + e.message;
- e.stack = e.message + '\n' + frameTexts.join('\n') + innerError;
+ if (apiName && !apiName.includes('<anonymous>'))
+ e.message = apiName + ': ' + e.message;
+ const stackFrames = '\n' + frameTexts.join('\n') + innerError;
+ if (stackFrames.trim())
+ e.stack = e.message + stackFrames;
+ else
+ e.stack = '';
csi?.onApiCallEnd(callCookie, e);
logApiCall(logger, `<= ${apiName} failed`, isInternal);
throw e;