Skip to content

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

chore: fix evaluate on pause (#37177)

Pavel Feldman9dd68d6a1e83
diff --git a/packages/injected/src/consoleApi.ts b/packages/injected/src/consoleApi.ts
index 2f2da420b2..2406c2e894 100644
--- a/packages/injected/src/consoleApi.ts
+++ b/packages/injected/src/consoleApi.ts
@@ -21,6 +21,7 @@ import { escapeForTextSelector } from '@isomorphic/stringUtils';
import type { InjectedScript } from './injectedScript';
import type { Language } from '@isomorphic/locatorGenerators';
import type { ByRoleOptions } from '@isomorphic/locatorUtils';
+import type { AriaTreeOptions } from './ariaSnapshot';
const selectorSymbol = Symbol('selector');
@@ -91,8 +92,8 @@ export class ConsoleAPI {
inspect: (selector: string) => this._inspect(selector),
selector: (element: Element) => this._selector(element),
generateLocator: (element: Element, language?: Language) => this._generateLocator(element, language),
- ariaSnapshot: (element?: Element) => {
- return this._injectedScript.ariaSnapshot(element || this._injectedScript.document.body, { mode: 'expect' });
+ ariaSnapshot: (element?: Element, options?: AriaTreeOptions) => {
+ return this._injectedScript.ariaSnapshot(element || this._injectedScript.document.body, options || { mode: 'expect' });
},
resume: () => this._resume(),
...new Locator(this._injectedScript, ''),
diff --git a/packages/playwright/src/mcp/browser/tools.ts b/packages/playwright/src/mcp/browser/tools.ts
index c9ddcccec9..69e20772a4 100644
--- a/packages/playwright/src/mcp/browser/tools.ts
+++ b/packages/playwright/src/mcp/browser/tools.ts
@@ -91,15 +91,12 @@ export const evaluate = defineTool({
},
handle: async (page, params) => {
- if (params.ref && params.element) {
- const locator = await refLocator(page, { ref: params.ref, element: params.element });
- const result = await locator.evaluate(params.function);
- return {
- content: [{ type: 'text', text: JSON.stringify(result, null, 2) || 'undefined' }],
- };
- }
+ let locator: playwright.Locator | undefined;
+ if (params.ref && params.element)
+ locator = await refLocator(page, { ref: params.ref, element: params.element });
- const result = await page.evaluate(params.function);
+ const receiver = locator ?? page as any;
+ const result = await receiver._evaluateFunction(params.function);
return {
content: [{ type: 'text', text: JSON.stringify(result, null, 2) || 'undefined' }],
};