Skip to content

Commit 8b7de1a

Browse files
committed
Update formatting
1 parent 45a9c2b commit 8b7de1a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

docs/tool-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
153153
- **type** (enum: "url", "back", "forward", "reload") _(optional)_: Navigate the page by URL, back or forward in history, or reload.
154154
- **url** (string) _(optional)_: Target URL (only type=url)
155+
- **initScript** (string) _(optional)_: Script to execute whenever a page is navigated to.
155156

156157
---
157158

src/tools/pages.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ export const navigatePage = defineTool({
116116
.boolean()
117117
.optional()
118118
.describe('Whether to ignore cache on reload.'),
119-
initScript: zod.string().optional().describe(
120-
`(optional) A JavaScript function to be executed by the tool on new document for every page load before any other scripts.
121-
`),
119+
initScript: zod
120+
.string()
121+
.optional()
122+
.describe(
123+
'(optional) A JavaScript function to be executed by the tool on new document for every page load before any other scripts.',
124+
),
122125
...timeoutSchema,
123126
},
124127
handler: async (request, response, context) => {
@@ -135,8 +138,8 @@ export const navigatePage = defineTool({
135138
request.params.type = 'url';
136139
}
137140

138-
if(request.params.initScript){
139-
page.evaluateOnNewDocument(request.params.initScript);
141+
if (request.params.initScript) {
142+
await page.evaluateOnNewDocument(request.params.initScript);
140143
}
141144

142145
await context.waitForEventsAfterAction(async () => {

tests/tools/pages.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,21 @@ describe('pages', () => {
196196
it('navigates to correct page with initScript', async () => {
197197
await withBrowser(async (response, context) => {
198198
await navigatePage.handler(
199-
{params: {url: 'data:text/html,<div>Hello MCP</div>', initScript: 'window.initScript = "completed"'}},
199+
{
200+
params: {
201+
url: 'data:text/html,<div>Hello MCP</div>',
202+
initScript: 'window.initScript = "completed"',
203+
},
204+
},
200205
response,
201206
context,
202207
);
203208
const page = context.getSelectedPage();
204209

205210
// wait for up to 1s for the global variable to set by the initScript to exist
206-
await page.waitForFunction("window.initScript==='completed'", {timeout: 1000});
211+
await page.waitForFunction("window.initScript==='completed'", {
212+
timeout: 1000,
213+
});
207214

208215
assert.ok(response.includePages);
209216
});

0 commit comments

Comments
 (0)