Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(bidi): fix error messages from the utility world (#40275)
Holger Benl7b5450997df9
diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.tsindex 5d8290e5bc..3d15105369 100644--- a/packages/injected/src/injectedScript.ts+++ b/packages/injected/src/injectedScript.ts@@ -75,6 +75,7 @@ export type InjectedScriptOptions = {testIdAttributeName: string;stableRafCount: number;browserName: string;+ shouldPrependErrorPrefix?: boolean;isUtilityWorld?: boolean;customEngines: { name: string, source: string }[];};@@ -84,6 +85,7 @@ export class InjectedScript {readonly _evaluator: SelectorEvaluatorImpl;private _stableRafCount: number;private _browserName: string;+ private _shouldPrependErrorPrefix: boolean;private _isUtilityWorld: boolean;readonly onGlobalListenersRemoved: Set<() => void>;private _hitTargetInterceptor: undefined | ((event: MouseEvent | PointerEvent | TouchEvent) => void);@@ -238,6 +240,7 @@ export class InjectedScript {this._stableRafCount = options.stableRafCount;this._browserName = options.browserName;+ this._shouldPrependErrorPrefix = !!options.shouldPrependErrorPrefix;this._isUtilityWorld = !!options.isUtilityWorld;setGlobalOptions({ browserNameForWorkarounds: options.browserName });@@ -1276,13 +1279,12 @@ export class InjectedScript {}createStacklessError(message: string): Error {+ const error = this._shouldPrependErrorPrefix ? new Error('Error: ' + message) : new Error(message);if (this._browserName === 'firefox') {- const error = new Error('Error: ' + message);// Firefox cannot delete the stack, so assign to an empty string.error.stack = '';return error;}- const error = new Error(message);// Chromium/WebKit should delete the stack instead.delete error.stack;return error;diff --git a/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts b/packages/playwright-core/src/server/bidi/bidiExecutionContext.tsindex a08461ad30..4206d4ecd2 100644--- a/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts+++ b/packages/playwright-core/src/server/bidi/bidiExecutionContext.ts@@ -133,6 +133,10 @@ export class BidiExecutionContext implements js.ExecutionContextDelegate {});}+ shouldPrependErrorPrefix(): boolean {+ return false;+ }+async nodeIdForElementHandle(handle: dom.ElementHandle): Promise<bidi.Script.SharedReference> {const shared = await this._remoteValueForReference({ handle: handle._objectId });diff --git a/packages/playwright-core/src/server/chromium/crExecutionContext.ts b/packages/playwright-core/src/server/chromium/crExecutionContext.tsindex 5692d7513a..11e99ce044 100644--- a/packages/playwright-core/src/server/chromium/crExecutionContext.ts+++ b/packages/playwright-core/src/server/chromium/crExecutionContext.ts@@ -93,6 +93,10 @@ export class CRExecutionContext implements js.ExecutionContextDelegate {return;await releaseObject(this._client, handle._objectId);}++ shouldPrependErrorPrefix(): boolean {+ return false;+ }}function rewriteError(error: Error): Protocol.Runtime.evaluateReturnValue {diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.tsindex fadc55f509..13b34fb336 100644--- a/packages/playwright-core/src/server/dom.ts+++ b/packages/playwright-core/src/server/dom.ts@@ -94,6 +94,7 @@ export class FrameExecutionContext extends js.ExecutionContext {testIdAttributeName: selectorsRegistry.testIdAttributeName(),stableRafCount: this.frame._page.delegate.rafCountForStablePosition(),browserName: this.frame._page.browserContext._browser.options.name,+ shouldPrependErrorPrefix: this.delegate.shouldPrependErrorPrefix(),isUtilityWorld: this.world === 'utility',customEngines,};diff --git a/packages/playwright-core/src/server/firefox/ffExecutionContext.ts b/packages/playwright-core/src/server/firefox/ffExecutionContext.tsindex 398889146d..8d690116cc 100644--- a/packages/playwright-core/src/server/firefox/ffExecutionContext.ts+++ b/packages/playwright-core/src/server/firefox/ffExecutionContext.ts@@ -90,6 +90,10 @@ export class FFExecutionContext implements js.ExecutionContextDelegate {objectId: handle._objectId,});}++ shouldPrependErrorPrefix(): boolean {+ return true;+ }}function checkException(exceptionDetails?: Protocol.Runtime.ExceptionDetails) {diff --git a/packages/playwright-core/src/server/javascript.ts b/packages/playwright-core/src/server/javascript.tsindex 85008919d7..878964f9be 100644--- a/packages/playwright-core/src/server/javascript.ts+++ b/packages/playwright-core/src/server/javascript.ts@@ -52,6 +52,7 @@ export interface ExecutionContextDelegate {evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: JSHandle, values: any[], handles: JSHandle[]): Promise<any>;getProperties(object: JSHandle): Promise<Map<string, JSHandle>>;releaseHandle(handle: JSHandle): Promise<void>;+ shouldPrependErrorPrefix(): boolean;}export class ExecutionContext extends SdkObject {diff --git a/packages/playwright-core/src/server/webkit/wkExecutionContext.ts b/packages/playwright-core/src/server/webkit/wkExecutionContext.tsindex 17d1941059..e06f4e838f 100644--- a/packages/playwright-core/src/server/webkit/wkExecutionContext.ts+++ b/packages/playwright-core/src/server/webkit/wkExecutionContext.ts@@ -106,6 +106,10 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {return;await this._session.send('Runtime.releaseObject', { objectId: handle._objectId });}++ shouldPrependErrorPrefix(): boolean {+ return false;+ }}function potentiallyUnserializableValue(remoteObject: Protocol.Runtime.RemoteObject): any {diff --git a/tests/bidi/expectations/moz-firefox-nightly-page.txt b/tests/bidi/expectations/moz-firefox-nightly-page.txtindex e3968ba552..b9839a0f8f 100644--- a/tests/bidi/expectations/moz-firefox-nightly-page.txt+++ b/tests/bidi/expectations/moz-firefox-nightly-page.txt@@ -10,7 +10,6 @@ page/elementhandle-scroll-into-view.spec.ts › should timeout waiting for visibpage/elementhandle-scroll-into-view.spec.ts › should wait for display:none to become visible [fail]page/elementhandle-scroll-into-view.spec.ts › should wait for nested display:none to become visible [fail]page/elementhandle-scroll-into-view.spec.ts › should work @smoke [fail]-page/expect-misc.spec.ts › strict mode violation error format [fail]page/frame-evaluate.spec.ts › should allow cross-frame element handles [fail]page/frame-evaluate.spec.ts › should not allow cross-frame element handles when frames do not script each other [fail]page/frame-evaluate.spec.ts › should dispose context on cross-origin navigation [fail]@@ -98,7 +97,6 @@ page/page-expose-function.spec.ts › should work with setContent [timeout]page/page-filechooser.spec.ts › should be able to reset selected files with empty file list [timeout]page/page-filechooser.spec.ts › should emit event for iframe [timeout]page/page-filechooser.spec.ts › should respect timeout [flaky]-page/page-fill.spec.ts › should throw nice error without injected script stack when element is not an <input> [fail]page/page-goto.spec.ts › should override referrer-policy [fail]page/page-goto.spec.ts › should send referer [fail]page/page-goto.spec.ts › should send referer of cross-origin URL [fail]