browser_switch_to_original_window
Switch back to the original browser window after working with multiple windows or tabs during web automation tasks.
Instructions
Switches back to the original browser window
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/browserTools.ts:260-289 (handler)Inline handler function that switches the browser context back to the original (first) window handle by retrieving all handles and selecting index 0.
server.tool('browser_switch_to_original_window', 'Switches back to the original browser window', {}, async () => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); const originalHandle = windowHandles[0]; if (!originalHandle) { return { content: [ { type: 'text', text: `No original window handle found.`, }, ], }; } await driver.switchTo().window(originalHandle); return { content: [{ type: 'text', text: `Switched to original window` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to original window: ${(e as Error).message}`, }, ], }; } }); - src/tools/browserTools.ts:260-289 (registration)Registers the 'browser_switch_to_original_window' tool using server.tool with no input parameters.
server.tool('browser_switch_to_original_window', 'Switches back to the original browser window', {}, async () => { try { const driver = stateManager.getDriver(); const windowHandles = await driver.getAllWindowHandles(); const originalHandle = windowHandles[0]; if (!originalHandle) { return { content: [ { type: 'text', text: `No original window handle found.`, }, ], }; } await driver.switchTo().window(originalHandle); return { content: [{ type: 'text', text: `Switched to original window` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error switching to original window: ${(e as Error).message}`, }, ], }; } });