Skip to content

Commit 6b0984a

Browse files
fix(wait_for): respect the provided timeout (#630)
The issue is that locator don't modify themselves but create a new locator. Closes #624
1 parent 7fd8d1a commit 6b0984a

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
@@ -617,25 +617,19 @@ export class McpContext implements Context {
617617
return this.#networkCollector.getIdForResource(request);
618618
}
619619

620-
waitForTextOnPage({
621-
text,
622-
timeout,
623-
}: {
624-
text: string;
625-
timeout?: number | undefined;
626-
}): Promise<Element> {
620+
waitForTextOnPage(text: string, timeout?: number): Promise<Element> {
627621
const page = this.getSelectedPage();
628622
const frames = page.frames();
629623

630-
const locator = this.#locatorClass.race(
624+
let locator = this.#locatorClass.race(
631625
frames.flatMap(frame => [
632626
frame.locator(`aria/${text}`),
633627
frame.locator(`text/${text}`),
634628
]),
635629
);
636630

637631
if (timeout) {
638-
locator.setTimeout(timeout);
632+
locator = locator.setTimeout(timeout);
639633
}
640634

641635
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)