Skip to content

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

chore: render call log in perform (#38783)

Pavel Feldman3928d3a3e8ed
diff --git a/docs/src/api/params.md b/docs/src/api/params.md
index 12a8186fe3..bd319b19ad 100644
--- a/docs/src/api/params.md
+++ b/docs/src/api/params.md
@@ -390,10 +390,17 @@ Defaults to context-wide value specified in `agent` property.
Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
+## page-agent-timeout
+* since: v1.58
+- `timeout` <[int]>
+
+Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
+
## page-agent-call-options-v1.58
- %%-page-agent-cache-key-%%
- %%-page-agent-max-tokens-%%
- %%-page-agent-max-turns-%%
+- %%-page-agent-timeout-%%
## fetch-param-url
- `url` <[string]>
diff --git a/package-lock.json b/package-lock.json
index 4ee02fc2e2..e3cd66d46e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -18,7 +18,7 @@
"@eslint/compat": "^1.3.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.34.0",
- "@lowire/loop": "^0.0.18",
+ "@lowire/loop": "^0.0.19",
"@modelcontextprotocol/sdk": "^1.17.5",
"@octokit/graphql-schema": "^15.26.0",
"@stylistic/eslint-plugin": "^5.2.3",
@@ -1065,9 +1065,9 @@
}
},
"node_modules/@lowire/loop": {
- "version": "0.0.18",
- "resolved": "https://registry.npmjs.org/@lowire/loop/-/loop-0.0.18.tgz",
- "integrity": "sha512-ZusERFapOfczMai18jPV516lLOpC2Vu0yqOHIJ4W0gewfQ9T8VRgKQeX65NPrKAhVuxPtCJ2tvnW9I1bU3aBuA==",
+ "version": "0.0.19",
+ "resolved": "https://registry.npmjs.org/@lowire/loop/-/loop-0.0.19.tgz",
+ "integrity": "sha512-uugjYtmA1mNSwHzbZEnvFedjB2EUX0s4NDbDbUcGuz6CH8fzZV2FFodY6fneik+r3GdLJtpvzpOP+cU/M0ba3w==",
"dev": true,
"license": "Apache-2.0",
"engines": {
diff --git a/package.json b/package.json
index a5fbc8cf41..8db7c35f51 100644
--- a/package.json
+++ b/package.json
@@ -55,7 +55,7 @@
"@eslint/compat": "^1.3.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.34.0",
- "@lowire/loop": "^0.0.18",
+ "@lowire/loop": "^0.0.19",
"@modelcontextprotocol/sdk": "^1.17.5",
"@octokit/graphql-schema": "^15.26.0",
"@stylistic/eslint-plugin": "^5.2.3",
diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts
index 158f8717d2..1dfa0737ad 100644
--- a/packages/playwright-client/types/types.d.ts
+++ b/packages/playwright-client/types/types.d.ts
@@ -5411,6 +5411,11 @@ export interface PageAgent {
* Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
*/
maxTurns?: number;
+
+ /**
+ * Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
+ */
+ timeout?: number;
}): Promise<void>;
/**
@@ -5442,6 +5447,11 @@ export interface PageAgent {
* Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
*/
maxTurns?: number;
+
+ /**
+ * Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
+ */
+ timeout?: number;
}): Promise<{
usage: {
turns: number;
diff --git a/packages/playwright-core/ThirdPartyNotices.txt b/packages/playwright-core/ThirdPartyNotices.txt
index 97c06433bb..71cefc3d7d 100644
--- a/packages/playwright-core/ThirdPartyNotices.txt
+++ b/packages/playwright-core/ThirdPartyNotices.txt
@@ -4,7 +4,7 @@ THIRD-PARTY SOFTWARE NOTICES AND INFORMATION
This project incorporates components from the projects listed below. The original copyright notices and the licenses under which Microsoft received such components are set forth below. Microsoft reserves all rights not expressly granted herein, whether by implication, estoppel or otherwise.
-- @lowire/[email protected] (https://github.com/pavelfeldman/lowire)
+- @lowire/[email protected] (https://github.com/pavelfeldman/lowire)
- @modelcontextprotocol/[email protected] (https://github.com/modelcontextprotocol/typescript-sdk)
- [email protected] (https://github.com/jshttp/accepts)
- [email protected] (https://github.com/TooTallNate/proxy-agents)
@@ -135,7 +135,7 @@ This project incorporates components from the projects listed below. The origina
- [email protected] (https://github.com/StefanTerdell/zod-to-json-schema)
- [email protected] (https://github.com/colinhacks/zod)
-%% @lowire/[email protected] NOTICES AND INFORMATION BEGIN HERE
+%% @lowire/[email protected] NOTICES AND INFORMATION BEGIN HERE
=========================================
Apache License
Version 2.0, January 2004
@@ -339,7 +339,7 @@ Apache License
See the License for the specific language governing permissions and
limitations under the License.
=========================================
-END OF @lowire/[email protected] AND INFORMATION
+END OF @lowire/[email protected] AND INFORMATION
%% @modelcontextprotocol/[email protected] NOTICES AND INFORMATION BEGIN HERE
=========================================
diff --git a/packages/playwright-core/bundles/mcp/package-lock.json b/packages/playwright-core/bundles/mcp/package-lock.json
index 5adb3518e1..33a47d828b 100644
--- a/packages/playwright-core/bundles/mcp/package-lock.json
+++ b/packages/playwright-core/bundles/mcp/package-lock.json
@@ -8,16 +8,16 @@
"name": "mcp-bundle",
"version": "0.0.1",
"dependencies": {
- "@lowire/loop": "^0.0.18",
+ "@lowire/loop": "^0.0.19",
"@modelcontextprotocol/sdk": "^1.24.0",
"zod": "^3.25.76",
"zod-to-json-schema": "^3.24.6"
}
},
"node_modules/@lowire/loop": {
- "version": "0.0.18",
- "resolved": "https://registry.npmjs.org/@lowire/loop/-/loop-0.0.18.tgz",
- "integrity": "sha512-ZusERFapOfczMai18jPV516lLOpC2Vu0yqOHIJ4W0gewfQ9T8VRgKQeX65NPrKAhVuxPtCJ2tvnW9I1bU3aBuA==",
+ "version": "0.0.19",
+ "resolved": "https://registry.npmjs.org/@lowire/loop/-/loop-0.0.19.tgz",
+ "integrity": "sha512-uugjYtmA1mNSwHzbZEnvFedjB2EUX0s4NDbDbUcGuz6CH8fzZV2FFodY6fneik+r3GdLJtpvzpOP+cU/M0ba3w==",
"license": "Apache-2.0",
"engines": {
"node": ">=20"
diff --git a/packages/playwright-core/bundles/mcp/package.json b/packages/playwright-core/bundles/mcp/package.json
index ab0c970c5d..f3209bf1bc 100644
--- a/packages/playwright-core/bundles/mcp/package.json
+++ b/packages/playwright-core/bundles/mcp/package.json
@@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"dependencies": {
- "@lowire/loop": "^0.0.18",
+ "@lowire/loop": "^0.0.19",
"@modelcontextprotocol/sdk": "^1.24.0",
"zod": "^3.25.76",
"zod-to-json-schema": "^3.24.6"
diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts
index 665e7a552b..5106ff9df8 100644
--- a/packages/playwright-core/src/protocol/validator.ts
+++ b/packages/playwright-core/src/protocol/validator.ts
@@ -2909,6 +2909,7 @@ scheme.PageAgentPerformParams = tObject({
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
cacheKey: tOptional(tString),
+ timeout: tOptional(tInt),
});
scheme.PageAgentPerformResult = tObject({
usage: tType('AgentUsage'),
@@ -2918,6 +2919,7 @@ scheme.PageAgentExpectParams = tObject({
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
cacheKey: tOptional(tString),
+ timeout: tOptional(tInt),
});
scheme.PageAgentExpectResult = tObject({
usage: tType('AgentUsage'),
@@ -2928,6 +2930,7 @@ scheme.PageAgentExtractParams = tObject({
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
cacheKey: tOptional(tString),
+ timeout: tOptional(tInt),
});
scheme.PageAgentExtractResult = tObject({
result: tAny,
diff --git a/packages/playwright-core/src/server/agent/actionRunner.ts b/packages/playwright-core/src/server/agent/actionRunner.ts
index fe889d9555..4a46612a11 100644
--- a/packages/playwright-core/src/server/agent/actionRunner.ts
+++ b/packages/playwright-core/src/server/agent/actionRunner.ts
@@ -18,7 +18,6 @@ import { serializeExpectedTextValues } from '../utils/expectUtils';
import { monotonicTime } from '../../utils/isomorphic/time';
import { createGuid } from '../utils/crypto';
import { parseAriaSnapshotUnsafe } from '../../utils/isomorphic/ariaSnapshot';
-import { ProgressController } from '../progress';
import { yaml } from '../../utilsBundle';
import { serializeError } from '../errors';
@@ -30,27 +29,23 @@ import type { ExpectResult, Frame } from '../frames';
import type { CallMetadata } from '../instrumentation';
import type * as channels from '@protocol/channels';
-export async function runAction(parentProgress: Progress, mode: 'generate' | 'run', page: Page, action: actions.Action, secrets: NameValue[]) {
- const timeout = mode === 'generate' ? generateActionTimeout(action) : performActionTimeout(action);
- const mt = monotonicTime();
- const deadline = mt + timeout;
- const minDeadline = parentProgress.deadline ? Math.min(parentProgress.deadline, deadline) : deadline;
- const pc = new ProgressController();
- return await pc.run(async progress => {
- const frame = page.mainFrame();
- const callMetadata = callMetadataForAction(frame, action);
- await frame.instrumentation.onBeforeCall(frame, callMetadata, parentProgress.metadata.id);
+export async function runAction(progress: Progress, mode: 'generate' | 'run', page: Page, action: actions.Action, secrets: NameValue[]) {
+ const parentMetadata = progress.metadata;
+ const frame = page.mainFrame();
+ const callMetadata = callMetadataForAction(progress, frame, action);
+ callMetadata.log = parentMetadata.log;
+ progress.metadata = callMetadata;
- let error: Error | undefined;
- const result = await innerRunAction(progress, mode, page, action, secrets).catch(e => error = e);
- callMetadata.endTime = monotonicTime();
- callMetadata.error = error ? serializeError(error) : undefined;
- callMetadata.result = error ? undefined : result;
- await frame.instrumentation.onAfterCall(frame, callMetadata);
- if (error)
- throw error;
- return result;
- }, minDeadline - mt);
+ await frame.instrumentation.onBeforeCall(frame, callMetadata, parentMetadata.id);
+ let error: Error | undefined;
+ const result = await innerRunAction(progress, mode, page, action, secrets).catch(e => error = e);
+ callMetadata.endTime = monotonicTime();
+ callMetadata.error = error ? serializeError(error) : undefined;
+ callMetadata.result = error ? undefined : result;
+ await frame.instrumentation.onAfterCall(frame, callMetadata);
+ if (error)
+ throw error;
+ return result;
}
async function innerRunAction(progress: Progress, mode: 'generate' | 'run', page: Page, action: actions.Action, secrets: NameValue[]) {
@@ -134,47 +129,8 @@ async function innerRunAction(progress: Progress, mode: 'generate' | 'run', page
}
}
-export function generateActionTimeout(action: actions.Action): number {
- switch (action.method) {
- case 'navigate':
- return 10000;
- case 'click':
- case 'drag':
- case 'hover':
- case 'selectOption':
- case 'pressKey':
- case 'pressSequentially':
- case 'fill':
- case 'setChecked':
- return 5000;
- case 'expectVisible':
- case 'expectValue':
- case 'expectAria':
- return 1; // one shot
- }
-}
-
-export function performActionTimeout(action: actions.Action): number {
- switch (action.method) {
- case 'navigate':
- case 'click':
- case 'drag':
- case 'hover':
- case 'selectOption':
- case 'pressKey':
- case 'pressSequentially':
- case 'fill':
- case 'setChecked':
- return 0; // no timeout
- case 'expectVisible':
- case 'expectValue':
- case 'expectAria':
- return 5000; // default expect timeout.
- }
-}
-
-export function traceParamsForAction(action: actions.Action): { title?: string, type: string, method: string, params: any } {
- const timeout = generateActionTimeout(action);
+export function traceParamsForAction(progress: Progress, action: actions.Action): { title?: string, type: string, method: string, params: any } {
+ const timeout = progress.timeout;
switch (action.method) {
case 'navigate': {
const params: channels.FrameGotoParams = {
@@ -306,7 +262,7 @@ export function traceParamsForAction(action: actions.Action): { title?: string,
}
}
-function callMetadataForAction(frame: Frame, action: actions.Action): CallMetadata {
+function callMetadataForAction(progress: Progress, frame: Frame, action: actions.Action): CallMetadata {
const callMetadata: CallMetadata = {
id: `call@${createGuid()}`,
objectId: frame.guid,
@@ -315,7 +271,7 @@ function callMetadataForAction(frame: Frame, action: actions.Action): CallMetada
startTime: monotonicTime(),
endTime: 0,
log: [],
- ...traceParamsForAction(action),
+ ...traceParamsForAction(progress, action),
};
return callMetadata;
}
diff --git a/packages/playwright-core/src/server/agent/pageAgent.ts b/packages/playwright-core/src/server/agent/pageAgent.ts
index be64e92b00..7de4f38fff 100644
--- a/packages/playwright-core/src/server/agent/pageAgent.ts
+++ b/packages/playwright-core/src/server/agent/pageAgent.ts
@@ -67,7 +67,6 @@ export async function pageAgentExpect(progress: Progress, context: Context, expe
${expectation}
`;
- callParams.maxTurns = callParams.maxTurns ?? 3;
await runLoop(progress, context, expectTools, task, undefined, callParams);
await updateCache(context, cacheKey);
}
@@ -130,7 +129,8 @@ async function runLoop(progress: Progress, context: Context, toolDefinitions: To
task.push('### Page snapshot');
task.push(full);
task.push('');
- await loop.run(task.join('\n'));
+
+ await loop.run(task.join('\n'), { signal: progress.signal });
return { result: resultSchema ? reportedResult() : undefined };
}
diff --git a/packages/playwright-core/src/server/dispatchers/dispatcher.ts b/packages/playwright-core/src/server/dispatchers/dispatcher.ts
index 8fda388cae..f3f50166cf 100644
--- a/packages/playwright-core/src/server/dispatchers/dispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/dispatcher.ts
@@ -18,7 +18,7 @@ import { EventEmitter } from 'events';
import { eventsHelper } from '../utils/eventsHelper';
import { ValidationError, createMetadataValidator, findValidator } from '../../protocol/validator';
-import { assert, monotonicTime, rewriteErrorMessage, debugLogger } from '../../utils';
+import { assert, monotonicTime, rewriteErrorMessage } from '../../utils';
import { isUnderTest } from '../utils/debug';
import { TargetClosedError, isTargetClosedError, serializeError } from '../errors';
import { createRootSdkObject, SdkObject } from '../instrumentation';
@@ -101,11 +101,7 @@ export class Dispatcher<Type extends SdkObject, ChannelType, ParentScopeType ext
}
async _runCommand(callMetadata: CallMetadata, method: string, validParams: any) {
- const controller = new ProgressController(callMetadata, message => {
- const logName = this._object.logName || 'api';
- debugLogger.log(logName, message);
- this._object.instrumentation.onCallLog(this._object, callMetadata, logName, message);
- });
+ const controller = ProgressController.createForSdkObject(this._object, callMetadata);
this._activeProgressControllers.add(controller);
try {
return await controller.run(progress => (this as any)[method](validParams, progress), validParams?.timeout);
diff --git a/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
index c0f3455308..d830d65daf 100644
--- a/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/pageAgentDispatcher.ts
@@ -71,7 +71,6 @@ export class PageAgentDispatcher extends Dispatcher<SdkObject, channels.PageAgen
onBeforeTurn(params: { conversation: loopTypes.Conversation }) {
const userMessage = params.conversation.messages.find(m => m.role === 'user');
self._dispatchEvent('turn', { role: 'user', message: userMessage?.content ?? '' });
- return 'continue' as const;
},
onAfterTurn(params: { assistantMessage: loopTypes.AssistantMessage, totalUsage: loopTypes.Usage }) {
@@ -81,23 +80,19 @@ export class PageAgentDispatcher extends Dispatcher<SdkObject, channels.PageAgen
if (!params.assistantMessage.content.filter(c => c.type === 'tool_call').length)
self._dispatchEvent('turn', { role: 'assistant', message: `no tool calls`, usage });
self._usage = { turns: self._usage.turns + 1, inputTokens: self._usage.inputTokens + usage.inputTokens, outputTokens: self._usage.outputTokens + usage.outputTokens };
- return 'continue' as const;
},
onBeforeToolCall(params: { toolCall: loopTypes.ToolCallContentPart }) {
self._dispatchEvent('turn', { role: 'assistant', message: `call tool "${params.toolCall.name}"` });
- return 'continue' as const;
},
onAfterToolCall(params: { toolCall: loopTypes.ToolCallContentPart, result: loopTypes.ToolResult }) {
const suffix = params.toolCall.result?.isError ? 'failed' : 'succeeded';
self._dispatchEvent('turn', { role: 'user', message: `tool "${params.toolCall.name}" ${suffix}` });
- return 'continue' as const;
},
onToolCallError(params: { toolCall: loopTypes.ToolCallContentPart, error: Error }) {
self._dispatchEvent('turn', { role: 'user', message: `tool "${params.toolCall.name}" failed: ${params.error.message}` });
- return 'continue' as const;
}
};
}
diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.ts
index 46900117d8..8274edb3f6 100644
--- a/packages/playwright-core/src/server/progress.ts
+++ b/packages/playwright-core/src/server/progress.ts
@@ -15,11 +15,11 @@
*/
import { TimeoutError } from './errors';
-import { assert, monotonicTime } from '../utils';
+import { assert, monotonicTime, debugLogger } from '../utils';
import { ManualPromise } from '../utils/isomorphic/manualPromise';
import type { Progress } from '@protocol/progress';
-import type { CallMetadata } from './instrumentation';
+import type { CallMetadata, SdkObject } from './instrumentation';
export type { Progress } from '@protocol/progress';
@@ -30,11 +30,21 @@ export class ProgressController {
private _onCallLog?: (message: string) => void;
readonly metadata: CallMetadata;
+ private _controller: AbortController;
constructor(metadata?: CallMetadata, onCallLog?: (message: string) => void) {
this.metadata = metadata || { id: '', startTime: 0, endTime: 0, type: 'Internal', method: '', params: {}, log: [], internal: true };
this._onCallLog = onCallLog;
this._forceAbortPromise.catch(e => null); // Prevent unhandled promise rejection.
+ this._controller = new AbortController();
+ }
+
+ static createForSdkObject(sdkObject: SdkObject, callMetadata: CallMetadata) {
+ const logName = sdkObject.logName || 'api';
+ return new ProgressController(callMetadata, message => {
+ debugLogger.log(logName, message);
+ sdkObject.instrumentation.onCallLog(sdkObject, callMetadata, logName, message);
+ });
}
async abort(error: Error) {
@@ -42,6 +52,7 @@ export class ProgressController {
(error as any)[kAbortErrorSymbol] = true;
this._state = { error };
this._forceAbortPromise.reject(error);
+ this._controller.abort();
}
await this._donePromise;
}
@@ -52,6 +63,7 @@ export class ProgressController {
this._state = 'running';
const progress: Progress = {
+ timeout: timeout ?? 0,
deadline,
log: message => {
if (this._state === 'running')
@@ -73,6 +85,7 @@ export class ProgressController {
const promise = new Promise<void>(f => timer = setTimeout(f, timeout));
return progress.race(promise).finally(() => clearTimeout(timer));
},
+ signal: this._controller.signal,
};
let timer: NodeJS.Timeout | undefined;
@@ -85,6 +98,7 @@ export class ProgressController {
(timeoutError as any)[kAbortErrorSymbol] = true;
this._state = { error: timeoutError };
this._forceAbortPromise.reject(timeoutError);
+ this._controller.abort(timeoutError);
}
}, deadline - monotonicTime());
}
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index 158f8717d2..1dfa0737ad 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -5411,6 +5411,11 @@ export interface PageAgent {
* Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
*/
maxTurns?: number;
+
+ /**
+ * Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
+ */
+ timeout?: number;
}): Promise<void>;
/**
@@ -5442,6 +5447,11 @@ export interface PageAgent {
* Maximum number of agentic turns during this call, defaults to context-wide value specified in `agent` property.
*/
maxTurns?: number;
+
+ /**
+ * Request timeout in milliseconds. Defaults to action timeout. Pass `0` to disable timeout.
+ */
+ timeout?: number;
}): Promise<{
usage: {
turns: number;
diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.ts
index 2f78521ef4..d967dd43cf 100644
--- a/packages/protocol/src/channels.d.ts
+++ b/packages/protocol/src/channels.d.ts
@@ -5115,11 +5115,13 @@ export type PageAgentPerformParams = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentPerformOptions = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentPerformResult = {
usage: AgentUsage,
@@ -5129,11 +5131,13 @@ export type PageAgentExpectParams = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentExpectOptions = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentExpectResult = {
usage: AgentUsage,
@@ -5144,11 +5148,13 @@ export type PageAgentExtractParams = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentExtractOptions = {
maxTurns?: number,
maxTokens?: number,
cacheKey?: string,
+ timeout?: number,
};
export type PageAgentExtractResult = {
result: any,
diff --git a/packages/protocol/src/progress.d.ts b/packages/protocol/src/progress.d.ts
index 96e0a33b97..f5748ad421 100644
--- a/packages/protocol/src/progress.d.ts
+++ b/packages/protocol/src/progress.d.ts
@@ -35,9 +35,11 @@ import type { CallMetadata } from './callMetadata';
// should be used to cleanup. Whether the cleanup is awaited or not depends on the method details.
// For the trickiest cases, look at `raceUncancellableOperationWithCleanup()` helper method.
export interface Progress {
+ timeout: number;
deadline: number;
log(message: string): void;
race<T>(promise: Promise<T> | Promise<T>[], options?: { timeout?: number }): Promise<T>;
wait(timeout: number): Promise<void>;
+ signal: AbortSignal;
metadata: CallMetadata;
}
diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.yml
index 18179b925e..80611cb16f 100644
--- a/packages/protocol/src/protocol.yml
+++ b/packages/protocol/src/protocol.yml
@@ -4370,6 +4370,7 @@ PageAgentOptions:
maxTurns: int?
maxTokens: int?
cacheKey: string?
+ timeout: int?
AgentUsage:
type: object
diff --git a/tests/library/perform-task.spec.ts b/tests/library/perform-task.spec.ts
index a85c2520f7..3ff85854d9 100644
--- a/tests/library/perform-task.spec.ts
+++ b/tests/library/perform-task.spec.ts
@@ -101,3 +101,21 @@ test('page.perform history', async ({ page, agent }) => {
await agent.perform('click the Fox button again');
expect(clicked).toBe(2);
});
+
+test('page.perform error', async ({ page, agent, agentOptions }, testInfo) => {
+ if (testInfo.config.runAgents !== 'none') {
+ await page.setContent(`
+ <button>Wolf</button>
+ <button>Fox</button>
+ `);
+ await agent.perform('click the Fox button');
+ } else {
+ await page.setContent(`
+ <button>Wolf</button>
+ <button>Rabbit</button>
+ `);
+ const error = await agent.perform('click the Fox button', { timeout: 3000 }).catch(e => e);
+ expect(error.message).toContain('Timeout 3000ms exceeded.');
+ expect(error.message).toContain(`waiting for getByRole('button', { name: 'Fox' })`);
+ }
+});