Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ sequence of events is `request`, `response` and `requestfinished`.
Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
is `request`, `response` and `requestfinished`.

## event: Page.agentTurn
* since: v1.58
- argument: <[Object]>
- `role` <[string]>
- `message` <[string]>
- `usage` ?<[Object]>
- `inputTokens` <[int]>
- `outputTokens` <[int]>

Emitted when the agent makes a turn.

## event: Page.webSocket
* since: v1.9
- argument: <[WebSocket]>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Emulates consistent window screen size available inside web page via `window.scr
- `provider` <[string]> LLM provider to use.
- `model` <[string]> Model identifier within provider.
- `cacheFile` ?<[string]> Cache file to use/generate code for performed actions into. Cache is not used if not specified (default).
- `cacheMode` ?<['force'|'ignore'|'auto']> Cache control, defaults to 'auto'.
- `cacheMode` ?<[CacheMode]<"force"|"ignore"|"update"|"auto">> Cache control, defaults to 'auto'.
- `secrets` ?<[Object]<[string], [string]>> Secrets to hide from the LLM.
- `maxTurns` ?<[int]> Maximum number of agentic turns to take per call. Defaults to 10.
- `maxTokens` ?<[int]> Maximum number of tokens to consume per call. The agentic loop will stop after input + output tokens exceed this value. Defaults on unlimited.
Expand Down
3 changes: 3 additions & 0 deletions examples/todomvc/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable notice/notice */

import { defineConfig, devices } from '@playwright/test';
import dotenv from 'dotenv';

dotenv.config();

/**
* See https://playwright.dev/docs/test-configuration.
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@eslint/compat": "^1.3.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.34.0",
"@lowire/loop": "^0.0.8",
"@lowire/loop": "^0.0.11",
"@modelcontextprotocol/sdk": "^1.17.5",
"@octokit/graphql-schema": "^15.26.0",
"@stylistic/eslint-plugin": "^5.2.3",
Expand Down
127 changes: 126 additions & 1 deletion packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,21 @@ export interface Page {
* @param options
*/
extract<Schema extends ZodTypeAny>(query: string, schema: Schema): Promise<ZodInfer<Schema>>;
/**
* Emitted when the agent makes a turn.
*/
on(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Emitted when the page closes.
*/
Expand Down Expand Up @@ -1243,6 +1258,21 @@ export interface Page {
*/
on(event: 'worker', listener: (worker: Worker) => any): this;

/**
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
*/
once(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
*/
Expand Down Expand Up @@ -1338,6 +1368,21 @@ export interface Page {
*/
once(event: 'worker', listener: (worker: Worker) => any): this;

/**
* Emitted when the agent makes a turn.
*/
addListener(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Emitted when the page closes.
*/
Expand Down Expand Up @@ -1545,6 +1590,21 @@ export interface Page {
*/
addListener(event: 'worker', listener: (worker: Worker) => any): this;

/**
* Removes an event listener added by `on` or `addListener`.
*/
removeListener(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Removes an event listener added by `on` or `addListener`.
*/
Expand Down Expand Up @@ -1640,6 +1700,21 @@ export interface Page {
*/
removeListener(event: 'worker', listener: (worker: Worker) => any): this;

/**
* Removes an event listener added by `on` or `addListener`.
*/
off(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Removes an event listener added by `on` or `addListener`.
*/
Expand Down Expand Up @@ -1735,6 +1810,21 @@ export interface Page {
*/
off(event: 'worker', listener: (worker: Worker) => any): this;

/**
* Emitted when the agent makes a turn.
*/
prependListener(event: 'agentturn', listener: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => any): this;

/**
* Emitted when the page closes.
*/
Expand Down Expand Up @@ -4790,6 +4880,41 @@ export interface Page {
height: number;
};

/**
* Emitted when the agent makes a turn.
*/
waitForEvent(event: 'agentturn', optionsOrPredicate?: { predicate?: (data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => boolean | Promise<boolean>, timeout?: number } | ((data: {
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}) => boolean | Promise<boolean>)): Promise<{
role: string;

message: string;

usage?: {
inputTokens: number;

outputTokens: number;
};
}>;

/**
* Emitted when the page closes.
*/
Expand Down Expand Up @@ -22118,7 +22243,7 @@ export interface BrowserContextOptions {
/**
* Cache control, defaults to 'auto'.
*/
cacheMode?: 'force'|'ignore'|'auto';
cacheMode?: "force"|"ignore"|"update"|"auto";

/**
* Secrets to hide from the LLM.
Expand Down
6 changes: 3 additions & 3 deletions packages/playwright-core/ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/loop@0.0.8 (https://github.com/pavelfeldman/lowire)
- @lowire/loop@0.0.11 (https://github.com/pavelfeldman/lowire)
- @modelcontextprotocol/sdk@1.24.2 (https://github.com/modelcontextprotocol/typescript-sdk)
- accepts@2.0.0 (https://github.com/jshttp/accepts)
- agent-base@7.1.4 (https://github.com/TooTallNate/proxy-agents)
Expand Down Expand Up @@ -135,7 +135,7 @@ This project incorporates components from the projects listed below. The origina
- zod-to-json-schema@3.25.0 (https://github.com/StefanTerdell/zod-to-json-schema)
- zod@3.25.76 (https://github.com/colinhacks/zod)

%% @lowire/loop@0.0.8 NOTICES AND INFORMATION BEGIN HERE
%% @lowire/loop@0.0.11 NOTICES AND INFORMATION BEGIN HERE
=========================================
Apache License
Version 2.0, January 2004
Expand Down Expand Up @@ -339,7 +339,7 @@ Apache License
See the License for the specific language governing permissions and
limitations under the License.
=========================================
END OF @lowire/loop@0.0.8 AND INFORMATION
END OF @lowire/loop@0.0.11 AND INFORMATION

%% @modelcontextprotocol/sdk@1.24.2 NOTICES AND INFORMATION BEGIN HERE
=========================================
Expand Down
8 changes: 4 additions & 4 deletions packages/playwright-core/bundles/mcp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/playwright-core/bundles/mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@lowire/loop": "^0.0.11",
"@modelcontextprotocol/sdk": "^1.24.0",
"@lowire/loop": "^0.0.8",
"zod": "^3.25.76",
"zod-to-json-schema": "^3.24.6"
}
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Events = {
},

Page: {
AgentTurn: 'agentturn',
Close: 'close',
Crash: 'crash',
Console: 'console',
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
this._closed = initializer.isClosed;
this._opener = Page.fromNullable(initializer.opener);

this._channel.on('agentTurn', params => this.emit(Events.Page.AgentTurn, params));
this._channel.on('bindingCall', ({ binding }) => this._onBinding(BindingCall.from(binding)));
this._channel.on('close', () => this._onClose());
this._channel.on('crash', () => this._onCrash());
Expand Down
18 changes: 13 additions & 5 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ scheme.BrowserTypeLaunchPersistentContextParams = tObject({
provider: tString,
model: tString,
cacheFile: tOptional(tString),
cacheMode: tOptional(tEnum(['ignore', 'force', 'auto'])),
cacheMode: tOptional(tEnum(['ignore', 'force', 'update', 'auto'])),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
Expand Down Expand Up @@ -707,7 +707,7 @@ scheme.BrowserNewContextParams = tObject({
provider: tString,
model: tString,
cacheFile: tOptional(tString),
cacheMode: tOptional(tEnum(['ignore', 'force', 'auto'])),
cacheMode: tOptional(tEnum(['ignore', 'force', 'update', 'auto'])),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
Expand Down Expand Up @@ -787,7 +787,7 @@ scheme.BrowserNewContextForReuseParams = tObject({
provider: tString,
model: tString,
cacheFile: tOptional(tString),
cacheMode: tOptional(tEnum(['ignore', 'force', 'auto'])),
cacheMode: tOptional(tEnum(['ignore', 'force', 'update', 'auto'])),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
Expand Down Expand Up @@ -912,7 +912,7 @@ scheme.BrowserContextInitializer = tObject({
provider: tString,
model: tString,
cacheFile: tOptional(tString),
cacheMode: tOptional(tEnum(['ignore', 'force', 'auto'])),
cacheMode: tOptional(tEnum(['ignore', 'force', 'update', 'auto'])),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
Expand Down Expand Up @@ -1180,6 +1180,14 @@ scheme.PageInitializer = tObject({
isClosed: tBoolean,
opener: tOptional(tChannel(['Page'])),
});
scheme.PageAgentTurnEvent = tObject({
role: tString,
message: tString,
usage: tOptional(tObject({
inputTokens: tInt,
outputTokens: tInt,
})),
});
scheme.PageBindingCallEvent = tObject({
binding: tChannel(['BindingCall']),
});
Expand Down Expand Up @@ -2832,7 +2840,7 @@ scheme.AndroidDeviceLaunchBrowserParams = tObject({
provider: tString,
model: tString,
cacheFile: tOptional(tString),
cacheMode: tOptional(tEnum(['ignore', 'force', 'auto'])),
cacheMode: tOptional(tEnum(['ignore', 'force', 'update', 'auto'])),
secrets: tOptional(tArray(tType('NameValue'))),
maxTurns: tOptional(tInt),
maxTokens: tOptional(tInt),
Expand Down
Loading
Loading