Skip to content

Commit 22ff57a

Browse files
committed
error page
1 parent 03b4afe commit 22ff57a

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

extension/src/background.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { RelayConnection, debugLog } from './relayConnection.js';
1919
type PageMessage = {
2020
type: 'connectToMCPRelay';
2121
mcpRelayUrl: string;
22+
pwMcpVersion: string | null;
2223
} | {
2324
type: 'getTabs';
2425
} | {
@@ -49,7 +50,7 @@ class TabShareExtension {
4950
private _onMessage(message: PageMessage, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) {
5051
switch (message.type) {
5152
case 'connectToMCPRelay':
52-
this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl!).then(
53+
this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl, message.pwMcpVersion).then(
5354
() => sendResponse({ success: true }),
5455
(error: any) => sendResponse({ success: false, error: error.message }));
5556
return true;
@@ -77,7 +78,11 @@ class TabShareExtension {
7778
return false;
7879
}
7980

80-
private async _connectToRelay(selectorTabId: number, mcpRelayUrl: string): Promise<void> {
81+
private async _connectToRelay(selectorTabId: number, mcpRelayUrl: string, pwMcpVersion: string | null): Promise<void> {
82+
const version = chrome.runtime.getManifest().version;
83+
if (pwMcpVersion !== version)
84+
throw new Error(`Incompatible Playwright MCP version: ${pwMcpVersion} (extension version: ${version}). Please install the latest version of the extension.`);
85+
8186
try {
8287
debugLog(`Connecting to relay at ${mcpRelayUrl}`);
8388
const socket = new WebSocket(mcpRelayUrl);
@@ -96,8 +101,9 @@ class TabShareExtension {
96101
this._pendingTabSelection.set(selectorTabId, { connection });
97102
debugLog(`Connected to MCP relay`);
98103
} catch (error: any) {
99-
debugLog(`Failed to connect to MCP relay:`, error.message);
100-
throw error;
104+
const message = `Failed to connect to MCP relay: ${error.message}`;
105+
debugLog(message);
106+
throw new Error(message);
101107
}
102108
}
103109

extension/src/ui/connect.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,22 @@ const ConnectApp: React.FC = () => {
5454
return;
5555
}
5656

57-
void connectToMCPRelay(relayUrl);
57+
void connectToMCPRelay(relayUrl, params.get('pwMcpVersion'));
5858
void loadTabs();
5959
}, []);
6060

61-
const connectToMCPRelay = useCallback(async (mcpRelayUrl: string) => {
62-
const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl });
63-
if (!response.success)
64-
setStatus({ type: 'error', message: 'Failed to connect to MCP relay: ' + response.error });
61+
const handleReject = useCallback((message: string) => {
62+
setShowButtons(false);
63+
setShowTabList(false);
64+
setStatus({ type: 'error', message });
6565
}, []);
6666

67+
const connectToMCPRelay = useCallback(async (mcpRelayUrl: string, pwMcpVersion: string | null) => {
68+
const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl, pwMcpVersion });
69+
if (!response.success)
70+
handleReject(response.error);
71+
}, [handleReject]);
72+
6773
const loadTabs = useCallback(async () => {
6874
const response = await chrome.runtime.sendMessage({ type: 'getTabs' });
6975
if (response.success)
@@ -100,22 +106,16 @@ const ConnectApp: React.FC = () => {
100106
}
101107
}, [clientInfo, mcpRelayUrl]);
102108

103-
const handleReject = useCallback(() => {
104-
setShowButtons(false);
105-
setShowTabList(false);
106-
setStatus({ type: 'error', message: 'Connection rejected. This tab can be closed.' });
107-
}, []);
108-
109109
useEffect(() => {
110110
const listener = (message: any) => {
111111
if (message.type === 'connectionTimeout')
112-
handleReject();
112+
handleReject('Connection timed out.');
113113
};
114114
chrome.runtime.onMessage.addListener(listener);
115115
return () => {
116116
chrome.runtime.onMessage.removeListener(listener);
117117
};
118-
}, []);
118+
}, [handleReject]);
119119

120120
return (
121121
<div className='app-container'>
@@ -124,7 +124,7 @@ const ConnectApp: React.FC = () => {
124124
<div className='status-container'>
125125
<StatusBanner type={status.type} message={status.message} />
126126
{showButtons && (
127-
<Button variant='reject' onClick={handleReject}>
127+
<Button variant='reject' onClick={() => handleReject('Connection rejected. This tab can be closed.')}>
128128
Reject
129129
</Button>
130130
)}

src/extension/cdpRelay.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ export class CDPRelayServer {
122122
// Need to specify "key" in the manifest.json to make the id stable when loading from file.
123123
const url = new URL('chrome-extension://jakfalbnbhgkpmoaakfflhflbfpkailf/connect.html');
124124
url.searchParams.set('mcpRelayUrl', mcpRelayEndpoint);
125-
url.searchParams.set('client', JSON.stringify(clientInfo));
125+
const client = {
126+
name: clientInfo.name,
127+
version: clientInfo.version,
128+
};
129+
url.searchParams.set('client', JSON.stringify(client));
130+
url.searchParams.set('pwMcpVersion', packageJSON.version);
126131
const href = url.toString();
127132
const executableInfo = registry.findExecutable(this._browserChannel);
128133
if (!executableInfo)

0 commit comments

Comments
 (0)