From 80190fdd982c4a20df400056af62de00f8286401 Mon Sep 17 00:00:00 2001 From: dhivakaranthonydoss7-eng Date: Mon, 27 Oct 2025 12:28:55 +0900 Subject: [PATCH 1/2] Add alert handling tools to server --- src/lib/server.js | 86 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/src/lib/server.js b/src/lib/server.js index 78d7514..2705b94 100755 --- a/src/lib/server.js +++ b/src/lib/server.js @@ -444,6 +444,90 @@ server.tool( } ); +// Alert/Modal Handling Tools +server.tool( + "accept_alert", + "accepts a browser alert, confirmation, or prompt dialog", + {}, + async () => { + try { + const driver = getDriver(); + const alert = await driver.switchTo().alert(); + await alert.accept(); + return { + content: [{ type: 'text', text: 'Alert accepted' }] + }; + } catch (e) { + return { + content: [{ type: 'text', text: `Error accepting alert: ${e.message}` }] + }; + } + } +); + +server.tool( + "dismiss_alert", + "dismisses/cancels a browser alert, confirmation, or prompt dialog", + {}, + async () => { + try { + const driver = getDriver(); + const alert = await driver.switchTo().alert(); + await alert.dismiss(); + return { + content: [{ type: 'text', text: 'Alert dismissed' }] + }; + } catch (e) { + return { + content: [{ type: 'text', text: `Error dismissing alert: ${e.message}` }] + }; + } + } +); + +server.tool( + "get_alert_text", + "gets the text content from a browser alert, confirmation, or prompt dialog", + {}, + async () => { + try { + const driver = getDriver(); + const alert = await driver.switchTo().alert(); + const text = await alert.getText(); + return { + content: [{ type: 'text', text }] + }; + } catch (e) { + return { + content: [{ type: 'text', text: `Error getting alert text: ${e.message}` }] + }; + } + } +); + +server.tool( + "send_alert_text", + "sends text to a browser prompt dialog", + { + text: z.string().describe("Text to send to the prompt dialog") + }, + async ({ text }) => { + try { + const driver = getDriver(); + const alert = await driver.switchTo().alert(); + await alert.sendKeys(text); + await alert.accept(); + return { + content: [{ type: 'text', text: `Text "${text}" sent to alert and accepted` }] + }; + } catch (e) { + return { + content: [{ type: 'text', text: `Error sending text to alert: ${e.message}` }] + }; + } + } +); + // Resources server.resource( "browser-status", @@ -477,4 +561,4 @@ process.on('SIGINT', cleanup); // Start the server const transport = new StdioServerTransport(); -await server.connect(transport); \ No newline at end of file +await server.connect(transport); From 9d0ae35a9d152fa2c7c7222efd321aa3778be71c Mon Sep 17 00:00:00 2001 From: dhivakaranthonydoss7-eng Date: Mon, 27 Oct 2025 14:17:46 +0900 Subject: [PATCH 2/2] Add timeout option for alert handling tools --- src/lib/server.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/lib/server.js b/src/lib/server.js index 2705b94..05996d8 100755 --- a/src/lib/server.js +++ b/src/lib/server.js @@ -448,10 +448,13 @@ server.tool( server.tool( "accept_alert", "accepts a browser alert, confirmation, or prompt dialog", - {}, - async () => { + { + timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds") + }, + async ({ timeout = 10000 }) => { try { const driver = getDriver(); + await driver.wait(until.alertIsPresent(), timeout); const alert = await driver.switchTo().alert(); await alert.accept(); return { @@ -468,10 +471,13 @@ server.tool( server.tool( "dismiss_alert", "dismisses/cancels a browser alert, confirmation, or prompt dialog", - {}, - async () => { + { + timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds") + }, + async ({ timeout = 10000 }) => { try { const driver = getDriver(); + await driver.wait(until.alertIsPresent(), timeout); const alert = await driver.switchTo().alert(); await alert.dismiss(); return { @@ -488,10 +494,13 @@ server.tool( server.tool( "get_alert_text", "gets the text content from a browser alert, confirmation, or prompt dialog", - {}, - async () => { + { + timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds") + }, + async ({ timeout = 10000 }) => { try { const driver = getDriver(); + await driver.wait(until.alertIsPresent(), timeout); const alert = await driver.switchTo().alert(); const text = await alert.getText(); return { @@ -509,11 +518,13 @@ server.tool( "send_alert_text", "sends text to a browser prompt dialog", { - text: z.string().describe("Text to send to the prompt dialog") + text: z.string().describe("Text to send to the prompt dialog"), + timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds") }, - async ({ text }) => { + async ({ text, timeout = 10000 }) => { try { const driver = getDriver(); + await driver.wait(until.alertIsPresent(), timeout); const alert = await driver.switchTo().alert(); await alert.sendKeys(text); await alert.accept();