Skip to content

Commit 00d7234

Browse files
committed
docs: Add instructions for Copilot CLI (#227)
Fixes #180
1 parent efb106d commit 00d7234

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

docs/tool-reference.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138

139139
**Parameters:**
140140

141+
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
141142
- **url** (string) **(required)**: URL to navigate the page to
142143

143144
---
@@ -149,6 +150,7 @@
149150
**Parameters:**
150151

151152
- **navigate** (enum: "back", "forward") **(required)**: Whether to navigate back or navigate forward in the selected pages history
153+
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
152154

153155
---
154156

@@ -158,6 +160,7 @@
158160

159161
**Parameters:**
160162

163+
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
161164
- **url** (string) **(required)**: URL to load in a new page.
162165

163166
---
@@ -179,6 +182,7 @@
179182
**Parameters:**
180183

181184
- **text** (string) **(required)**: Text to appear on the page
185+
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
182186

183187
---
184188

src/McpResponse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class McpResponse implements Response {
154154
response.push(`## Network emulation`);
155155
response.push(`Emulating: ${networkConditions}`);
156156
response.push(
157-
`Navigation timeout set to ${context.getNavigationTimeout()} ms`,
157+
`Default navigation timeout set to ${context.getNavigationTimeout()} ms`,
158158
);
159159
}
160160

src/tools/ToolDefinition.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import type {Dialog, ElementHandle, Page} from 'puppeteer-core';
8-
import type z from 'zod';
8+
import z from 'zod';
99

1010
import type {TraceResult} from '../trace-processing/parse.js';
1111

@@ -85,3 +85,16 @@ export function defineTool<Schema extends z.ZodRawShape>(
8585

8686
export const CLOSE_PAGE_ERROR =
8787
'The last open page cannot be closed. It is fine to keep it open.';
88+
89+
export const timeoutSchema = {
90+
timeout: z
91+
.number()
92+
.int()
93+
.optional()
94+
.describe(
95+
`Maximum wait time in milliseconds. If set to 0, the default timeout will be used.`,
96+
)
97+
.transform(value => {
98+
return value && value <= 0 ? undefined : value;
99+
}),
100+
};

src/tools/pages.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import z from 'zod';
99
import {logger} from '../logger.js';
1010

1111
import {ToolCategories} from './categories.js';
12-
import {CLOSE_PAGE_ERROR, defineTool} from './ToolDefinition.js';
12+
import {CLOSE_PAGE_ERROR, defineTool, timeoutSchema} from './ToolDefinition.js';
1313

1414
export const listPages = defineTool({
1515
name: 'list_pages',
@@ -83,12 +83,15 @@ export const newPage = defineTool({
8383
},
8484
schema: {
8585
url: z.string().describe('URL to load in a new page.'),
86+
...timeoutSchema,
8687
},
8788
handler: async (request, response, context) => {
8889
const page = await context.newPage();
8990

9091
await context.waitForEventsAfterAction(async () => {
91-
await page.goto(request.params.url);
92+
await page.goto(request.params.url, {
93+
timeout: request.params.timeout,
94+
});
9295
});
9396

9497
response.setIncludePages(true);
@@ -104,12 +107,15 @@ export const navigatePage = defineTool({
104107
},
105108
schema: {
106109
url: z.string().describe('URL to navigate the page to'),
110+
...timeoutSchema,
107111
},
108112
handler: async (request, response, context) => {
109113
const page = context.getSelectedPage();
110114

111115
await context.waitForEventsAfterAction(async () => {
112-
await page.goto(request.params.url);
116+
await page.goto(request.params.url, {
117+
timeout: request.params.timeout,
118+
});
113119
});
114120

115121
response.setIncludePages(true);
@@ -129,15 +135,18 @@ export const navigatePageHistory = defineTool({
129135
.describe(
130136
'Whether to navigate back or navigate forward in the selected pages history',
131137
),
138+
...timeoutSchema,
132139
},
133140
handler: async (request, response, context) => {
134141
const page = context.getSelectedPage();
135-
142+
const options = {
143+
timeout: request.params.timeout,
144+
};
136145
try {
137146
if (request.params.navigate === 'back') {
138-
await page.goBack();
147+
await page.goBack(options);
139148
} else {
140-
await page.goForward();
149+
await page.goForward(options);
141150
}
142151
} catch {
143152
response.appendResponseLine(

src/tools/snapshot.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Locator} from 'puppeteer-core';
88
import z from 'zod';
99

1010
import {ToolCategories} from './categories.js';
11-
import {defineTool} from './ToolDefinition.js';
11+
import {defineTool, timeoutSchema} from './ToolDefinition.js';
1212

1313
export const takeSnapshot = defineTool({
1414
name: 'take_snapshot',
@@ -33,17 +33,24 @@ export const waitFor = defineTool({
3333
},
3434
schema: {
3535
text: z.string().describe('Text to appear on the page'),
36+
...timeoutSchema,
3637
},
3738
handler: async (request, response, context) => {
3839
const page = context.getSelectedPage();
3940
const frames = page.frames();
4041

41-
const locators = frames.flatMap(frame => [
42-
frame.locator(`aria/${request.params.text}`),
43-
frame.locator(`text/${request.params.text}`),
44-
]);
42+
const locator = Locator.race(
43+
frames.flatMap(frame => [
44+
frame.locator(`aria/${request.params.text}`),
45+
frame.locator(`text/${request.params.text}`),
46+
]),
47+
);
48+
49+
if (request.params.timeout) {
50+
locator.setTimeout(request.params.timeout);
51+
}
4552

46-
await Locator.race(locators).wait();
53+
await locator.wait();
4754

4855
response.appendResponseLine(
4956
`Element with text "${request.params.text}" found.`,

tests/McpResponse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ uid=1_0 RootWebArea "My test page"
105105
`# test response
106106
## Network emulation
107107
Emulating: Slow 3G
108-
Navigation timeout set to 100000 ms`,
108+
Default navigation timeout set to 100000 ms`,
109109
);
110110
});
111111
});

0 commit comments

Comments
 (0)