Skip to content

Commit 51d86cc

Browse files
authored
fix(mcp): pass action timeout to browser_wait_for waitFor calls (#41270)
1 parent ce24537 commit 51d86cc

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

packages/playwright-core/src/tools/backend/wait.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ const wait = defineTool({
4747

4848
if (goneLocator) {
4949
response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
50-
await goneLocator.waitFor({ state: 'hidden' });
50+
await goneLocator.waitFor({ state: 'hidden', ...tab.actionTimeoutOptions });
5151
}
5252

5353
if (locator) {
5454
response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
55-
await locator.waitFor({ state: 'visible' });
55+
await locator.waitFor({ state: 'visible', ...tab.actionTimeoutOptions });
5656
}
5757

5858
response.addTextResult(`Waited for ${params.text || params.textGone || params.time}`);

tests/mcp/timeouts.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,56 @@ test('action timeout (custom)', async ({ startClient, server }) => {
7676
});
7777
});
7878

79+
test('wait_for text timeout', async ({ startClient, server }) => {
80+
const { client } = await startClient({ args: [`--timeout-action=1234`] });
81+
server.setContent('/', `
82+
<!DOCTYPE html>
83+
<html>
84+
<div>Hello World</div>
85+
</html>
86+
`, 'text/html');
87+
88+
await client.callTool({
89+
name: 'browser_navigate',
90+
arguments: {
91+
url: server.PREFIX,
92+
},
93+
});
94+
95+
expect(await client.callTool({
96+
name: 'browser_wait_for',
97+
arguments: { text: 'This text will never appear' },
98+
})).toHaveResponse({
99+
error: expect.stringContaining(`Timeout 1234ms exceeded.`),
100+
isError: true,
101+
});
102+
});
103+
104+
test('wait_for textGone timeout', async ({ startClient, server }) => {
105+
const { client } = await startClient({ args: [`--timeout-action=1234`] });
106+
server.setContent('/', `
107+
<!DOCTYPE html>
108+
<html>
109+
<div>Permanent text</div>
110+
</html>
111+
`, 'text/html');
112+
113+
await client.callTool({
114+
name: 'browser_navigate',
115+
arguments: {
116+
url: server.PREFIX,
117+
},
118+
});
119+
120+
expect(await client.callTool({
121+
name: 'browser_wait_for',
122+
arguments: { textGone: 'Permanent text' },
123+
})).toHaveResponse({
124+
error: expect.stringContaining(`Timeout 1234ms exceeded.`),
125+
isError: true,
126+
});
127+
});
128+
79129
test('navigation timeout', async ({ startClient, server }) => {
80130
const { client } = await startClient({ args: [`--timeout-navigation=1234`] });
81131
server.setRoute('/slow', async () => {

0 commit comments

Comments
 (0)