-
Notifications
You must be signed in to change notification settings - Fork 93
feat: multi-window support - closes #37 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NachoBrito
wants to merge
3
commits into
angiejones:main
Choose a base branch
from
NachoBrito:feature/multi-tab-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Implementation Summary: Multi-Tab/Window Support | ||
|
|
||
| This document summarizes the implementation of multi-tab/window support in the MCP Selenium server. | ||
|
|
||
| ## Changes | ||
|
|
||
| 1. **Added five new tools to `src/lib/server.js` for window management:** | ||
| * `get_window_handles`: Retrieves all active window handles. | ||
| * `get_current_window_handle`: Gets the handle of the currently focused window. | ||
| * `switch_to_window`: Switches focus to a specific window by its handle. | ||
| * `switch_to_latest_window`: Switches to the most recently opened window. | ||
| * `close_current_window`: Closes the currently active window without ending the session. | ||
|
|
||
| 2. **Created `docs/MULTI_TAB_USAGE.md`:** | ||
| * Provides detailed usage examples and best practices for the new window management tools. | ||
|
|
||
| 3. **Created `docs/CHANGELOG_TAB_SUPPORT.md`:** | ||
| * Documents the new features and explains how they remain backward compatible. | ||
|
|
||
| 4. **Updated `README.md`:** | ||
| * Added a new section documenting the multi-tab/window management tools. | ||
|
|
||
| ## Testing Guidance | ||
|
|
||
| To ensure the new tools function correctly, follow these testing steps: | ||
|
|
||
| 1. **Start a browser session** using the `start_browser` tool. | ||
| 2. **Open a new tab/window** by clicking a link that opens in a new tab (e.g., `<a href="..." target="_blank">`). | ||
| 3. **Use `get_window_handles`** to verify that multiple handles are returned. | ||
| 4. **Use `switch_to_latest_window`** to switch to the new tab. | ||
| 5. **Perform an action** (e.g., `get_element_text`) to confirm the context has switched. | ||
| 6. **Use `close_current_window`** to close the new tab. | ||
| 7. **Verify that the original tab** is still active and responsive. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Changelog: Multi-Tab/Window Support | ||
|
|
||
| ## New Features | ||
|
|
||
| - **Added five new tools for multi-tab/window management:** | ||
| - `get_window_handles`: Retrieves all active window handles. | ||
| - `get_current_window_handle`: Gets the handle of the currently focused window. | ||
| - `switch_to_window`: Switches focus to a specific window by its handle. | ||
| - `switch_to_latest_window`: Switches to the most recently opened window. | ||
| - `close_current_window`: Closes the currently active window. | ||
|
|
||
| ## Backward Compatibility | ||
|
|
||
| This update is fully backward compatible. Existing tools are unaffected. | ||
|
|
||
| - The `close_session` tool still closes the entire browser session, including all tabs. | ||
| - All element interaction tools (`click_element`, `send_keys`, etc.) operate on the currently focused tab, preserving existing behavior. | ||
|
|
||
| Workflows that do not involve multiple tabs will continue to function as before without any changes. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Multi-Tab/Window Usage Guide | ||
|
|
||
| This guide provides examples and best practices for using the new multi-tab/window management tools. | ||
|
|
||
| ## Available Tools | ||
|
|
||
| - `get_window_handles`: Retrieves all active window handles. | ||
| - `get_current_window_handle`: Gets the handle of the currently focused window. | ||
| - `switch_to_window`: Switches focus to a specific window by its handle. | ||
| - `switch_to_latest_window`: Switches to the most recently opened window. | ||
| - `close_current_window`: Closes the currently active window. | ||
|
|
||
| ## Example Workflow | ||
|
|
||
| Here’s a common workflow for handling multiple tabs: | ||
|
|
||
| 1. **Start a browser and navigate to a page.** | ||
| ```json | ||
| { | ||
| "tool": "start_browser", | ||
| "browser": "chrome" | ||
| } | ||
| { | ||
| "tool": "navigate", | ||
| "url": "https://example.com" | ||
| } | ||
| ``` | ||
|
|
||
| 2. **Click a link that opens a new tab.** | ||
| ```json | ||
| { | ||
| "tool": "click_element", | ||
| "by": "css", | ||
| "value": "a[target='_blank']" | ||
| } | ||
| ``` | ||
|
|
||
| 3. **Get all window handles to see the new tab's handle.** | ||
| ```json | ||
| { | ||
| "tool": "get_window_handles" | ||
| } | ||
| ``` | ||
| *Output might look like: `Window handles: CDwindow-ABC, CDwindow-DEF`* | ||
|
|
||
| 4. **Switch to the new tab.** | ||
| You can either switch by the specific handle or use `switch_to_latest_window`. | ||
| ```json | ||
| { | ||
| "tool": "switch_to_latest_window" | ||
| } | ||
| ``` | ||
|
|
||
| 5. **Perform actions in the new tab.** | ||
| ```json | ||
| { | ||
| "tool": "get_element_text", | ||
| "by": "css", | ||
| "value": "h1" | ||
| } | ||
| ``` | ||
|
|
||
| 6. **Close the new tab and switch back to the original.** | ||
| ```json | ||
| { | ||
| "tool": "close_current_window" | ||
| } | ||
| { | ||
| "tool": "switch_to_window", | ||
| "handle": "CDwindow-ABC" | ||
| } | ||
| ``` | ||
|
|
||
| ## Best Practices | ||
|
|
||
| - **Always get handles after opening a new tab:** Don't assume the handle format. Call `get_window_handles` to get the correct identifiers. | ||
| - **Use `switch_to_latest_window` for simplicity:** It's the easiest way to switch to a newly opened tab without needing to manage handles manually. | ||
| - **Be mindful of context:** After closing a tab, the driver's focus may be lost. Always switch back to a valid window handle to continue working. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.