Skip to content

Add Browser Refresh Tool - Refresh Currently Active Browser Tab #185

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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

isaiahbjork
Copy link

Summary

This PR implements a new refreshBrowser tool that allows the MCP server to refresh the currently active browser tab that is connected to the extension.

Changes Made

MCP Server (browser-tools-mcp/mcp-server.ts)

  • Added new refreshBrowser tool that sends refresh commands to the browser connector
  • Tool targets the specific tab that has the Chrome extension/devtools open
  • Includes proper error handling and user feedback

Browser Connector (browser-tools-server/browser-connector.ts)

  • Added /refresh-browser endpoint to handle refresh requests
  • Added sendRefreshCommand() method to the BrowserConnector class
  • Sends WebSocket messages to the Chrome extension with the target tab information
  • Provides detailed logging for debugging and user feedback

Chrome Extension (chrome-extension/)

  • devtools.js: Added message handler for "refresh-browser" commands
  • background.js: Added "REFRESH_TAB" message handler that calls chrome.tabs.reload()
  • Extension already has necessary "tabs" permission in manifest.json

Documentation

  • Updated README.md to include the new mcp_refreshBrowser tool in the function list

How It Works

  1. User calls the refreshBrowser tool through the MCP interface
  2. MCP server sends request to browser connector on /refresh-browser endpoint
  3. Browser connector sends WebSocket message to Chrome extension
  4. Chrome extension calls chrome.tabs.reload() on the specific tab where devtools are open
  5. Only the active/connected browser tab is refreshed, not all tabs

Benefits

  • Targeted Refresh: Only refreshes the tab with devtools open, not all browser tabs
  • Development Workflow: Perfect for refreshing applications during development/editing
  • Proper Error Handling: Provides clear feedback if extension is not connected
  • Logging: Detailed logging shows which tab and URL is being targeted

Testing

  • ✅ Successfully builds both MCP server and browser tools server
  • ✅ Chrome extension loads with updated functionality
  • ✅ Refresh command properly targets the correct browser tab
  • ✅ Error handling works when extension is not connected

This enhancement makes the browser tools more useful for development workflows where frequent page refreshes are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant