Skip to content

Commit 219ecba

Browse files
fix(wait_for): respect the provided timeout
1 parent fcaf553 commit 219ecba

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/McpContext.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,25 +625,19 @@ export class McpContext implements Context {
625625
return this.#networkCollector.getIdForResource(request);
626626
}
627627

628-
waitForTextOnPage({
629-
text,
630-
timeout,
631-
}: {
632-
text: string;
633-
timeout?: number | undefined;
634-
}): Promise<Element> {
628+
waitForTextOnPage(text: string, timeout?: number): Promise<Element> {
635629
const page = this.getSelectedPage();
636630
const frames = page.frames();
637631

638-
const locator = this.#locatorClass.race(
632+
let locator = this.#locatorClass.race(
639633
frames.flatMap(frame => [
640634
frame.locator(`aria/${text}`),
641635
frame.locator(`text/${text}`),
642636
]),
643637
);
644638

645639
if (timeout) {
646-
locator.setTimeout(timeout);
640+
locator = locator.setTimeout(timeout);
647641
}
648642

649643
return locator.wait();

src/tools/ToolDefinition.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ export type Context = Readonly<{
107107
filename: string,
108108
): Promise<{filename: string}>;
109109
waitForEventsAfterAction(action: () => Promise<unknown>): Promise<void>;
110-
waitForTextOnPage(params: {
111-
text: string;
112-
timeout?: number | undefined;
113-
}): Promise<Element>;
110+
waitForTextOnPage(text: string, timeout?: number): Promise<Element>;
114111
getDevToolsData(): Promise<DevToolsData>;
115112
/**
116113
* Returns a reqid for a cdpRequestId.

src/tools/snapshot.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export const waitFor = defineTool({
5353
...timeoutSchema,
5454
},
5555
handler: async (request, response, context) => {
56-
await context.waitForTextOnPage(request.params);
56+
await context.waitForTextOnPage(
57+
request.params.text,
58+
request.params.timeout,
59+
);
5760

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

0 commit comments

Comments
 (0)