diff --git a/extension/src/background.ts b/extension/src/background.ts index 67b81b8..34623fa 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -19,7 +19,6 @@ import { RelayConnection, debugLog } from './relayConnection.js'; type PageMessage = { type: 'connectToMCPRelay'; mcpRelayUrl: string; - pwMcpVersion: string | null; } | { type: 'getTabs'; } | { @@ -50,7 +49,7 @@ class TabShareExtension { private _onMessage(message: PageMessage, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) { switch (message.type) { case 'connectToMCPRelay': - this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl, message.pwMcpVersion).then( + this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl).then( () => sendResponse({ success: true }), (error: any) => sendResponse({ success: false, error: error.message })); return true; @@ -78,11 +77,7 @@ class TabShareExtension { return false; } - private async _connectToRelay(selectorTabId: number, mcpRelayUrl: string, pwMcpVersion: string | null): Promise { - const version = chrome.runtime.getManifest().version; - if (pwMcpVersion !== version) - throw new Error(`Incompatible Playwright MCP version: ${pwMcpVersion} (extension version: ${version}). Please install the latest version of the extension.`); - + private async _connectToRelay(selectorTabId: number, mcpRelayUrl: string): Promise { try { debugLog(`Connecting to relay at ${mcpRelayUrl}`); const socket = new WebSocket(mcpRelayUrl); diff --git a/extension/src/ui/connect.tsx b/extension/src/ui/connect.tsx index 956a4be..e8c7812 100644 --- a/extension/src/ui/connect.tsx +++ b/extension/src/ui/connect.tsx @@ -19,11 +19,15 @@ import { createRoot } from 'react-dom/client'; import { Button, TabItem } from './tabItem.js'; import type { TabInfo } from './tabItem.js'; -type StatusType = 'connected' | 'error' | 'connecting'; +type Status = + | { type: 'connecting'; message: string } + | { type: 'connected'; message: string } + | { type: 'error'; message: string } + | { type: 'error'; versionMismatch: { pwMcpVersion: string; extensionVersion: string } }; const ConnectApp: React.FC = () => { const [tabs, setTabs] = useState([]); - const [status, setStatus] = useState<{ type: StatusType; message: string } | null>(null); + const [status, setStatus] = useState(null); const [showButtons, setShowButtons] = useState(true); const [showTabList, setShowTabList] = useState(true); const [clientInfo, setClientInfo] = useState('unknown'); @@ -54,7 +58,22 @@ const ConnectApp: React.FC = () => { return; } - void connectToMCPRelay(relayUrl, params.get('pwMcpVersion')); + const pwMcpVersion = params.get('pwMcpVersion'); + const extensionVersion = chrome.runtime.getManifest().version; + if (pwMcpVersion !== extensionVersion) { + setShowButtons(false); + setShowTabList(false); + setStatus({ + type: 'error', + versionMismatch: { + pwMcpVersion: pwMcpVersion || 'unknown', + extensionVersion + } + }); + return; + } + + void connectToMCPRelay(relayUrl); void loadTabs(); }, []); @@ -64,8 +83,9 @@ const ConnectApp: React.FC = () => { setStatus({ type: 'error', message }); }, []); - const connectToMCPRelay = useCallback(async (mcpRelayUrl: string, pwMcpVersion: string | null) => { - const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl, pwMcpVersion }); + const connectToMCPRelay = useCallback(async (mcpRelayUrl: string) => { + + const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl }); if (!response.success) handleReject(response.error); }, [handleReject]); @@ -122,7 +142,7 @@ const ConnectApp: React.FC = () => {
{status && (
- + {showButtons && (