Skip to content

Commit f6862a3

Browse files
authored
chore: check version in page, link to instructions (#918)
1 parent e664e04 commit f6862a3

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

extension/src/background.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { RelayConnection, debugLog } from './relayConnection.js';
1919
type PageMessage = {
2020
type: 'connectToMCPRelay';
2121
mcpRelayUrl: string;
22-
pwMcpVersion: string | null;
2322
} | {
2423
type: 'getTabs';
2524
} | {
@@ -50,7 +49,7 @@ class TabShareExtension {
5049
private _onMessage(message: PageMessage, sender: chrome.runtime.MessageSender, sendResponse: (response: any) => void) {
5150
switch (message.type) {
5251
case 'connectToMCPRelay':
53-
this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl, message.pwMcpVersion).then(
52+
this._connectToRelay(sender.tab!.id!, message.mcpRelayUrl).then(
5453
() => sendResponse({ success: true }),
5554
(error: any) => sendResponse({ success: false, error: error.message }));
5655
return true;
@@ -78,11 +77,7 @@ class TabShareExtension {
7877
return false;
7978
}
8079

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-
80+
private async _connectToRelay(selectorTabId: number, mcpRelayUrl: string): Promise<void> {
8681
try {
8782
debugLog(`Connecting to relay at ${mcpRelayUrl}`);
8883
const socket = new WebSocket(mcpRelayUrl);

extension/src/ui/connect.tsx

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ import { createRoot } from 'react-dom/client';
1919
import { Button, TabItem } from './tabItem.js';
2020
import type { TabInfo } from './tabItem.js';
2121

22-
type StatusType = 'connected' | 'error' | 'connecting';
22+
type Status =
23+
| { type: 'connecting'; message: string }
24+
| { type: 'connected'; message: string }
25+
| { type: 'error'; message: string }
26+
| { type: 'error'; versionMismatch: { pwMcpVersion: string; extensionVersion: string } };
2327

2428
const ConnectApp: React.FC = () => {
2529
const [tabs, setTabs] = useState<TabInfo[]>([]);
26-
const [status, setStatus] = useState<{ type: StatusType; message: string } | null>(null);
30+
const [status, setStatus] = useState<Status | null>(null);
2731
const [showButtons, setShowButtons] = useState(true);
2832
const [showTabList, setShowTabList] = useState(true);
2933
const [clientInfo, setClientInfo] = useState('unknown');
@@ -54,7 +58,22 @@ const ConnectApp: React.FC = () => {
5458
return;
5559
}
5660

57-
void connectToMCPRelay(relayUrl, params.get('pwMcpVersion'));
61+
const pwMcpVersion = params.get('pwMcpVersion');
62+
const extensionVersion = chrome.runtime.getManifest().version;
63+
if (pwMcpVersion !== extensionVersion) {
64+
setShowButtons(false);
65+
setShowTabList(false);
66+
setStatus({
67+
type: 'error',
68+
versionMismatch: {
69+
pwMcpVersion: pwMcpVersion || 'unknown',
70+
extensionVersion
71+
}
72+
});
73+
return;
74+
}
75+
76+
void connectToMCPRelay(relayUrl);
5877
void loadTabs();
5978
}, []);
6079

@@ -64,8 +83,9 @@ const ConnectApp: React.FC = () => {
6483
setStatus({ type: 'error', message });
6584
}, []);
6685

67-
const connectToMCPRelay = useCallback(async (mcpRelayUrl: string, pwMcpVersion: string | null) => {
68-
const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl, pwMcpVersion });
86+
const connectToMCPRelay = useCallback(async (mcpRelayUrl: string) => {
87+
88+
const response = await chrome.runtime.sendMessage({ type: 'connectToMCPRelay', mcpRelayUrl });
6989
if (!response.success)
7090
handleReject(response.error);
7191
}, [handleReject]);
@@ -122,7 +142,7 @@ const ConnectApp: React.FC = () => {
122142
<div className='content-wrapper'>
123143
{status && (
124144
<div className='status-container'>
125-
<StatusBanner type={status.type} message={status.message} />
145+
<StatusBanner status={status} />
126146
{showButtons && (
127147
<Button variant='reject' onClick={() => handleReject('Connection rejected. This tab can be closed.')}>
128148
Reject
@@ -156,8 +176,27 @@ const ConnectApp: React.FC = () => {
156176
);
157177
};
158178

159-
const StatusBanner: React.FC<{ type: StatusType; message: string }> = ({ type, message }) => {
160-
return <div className={`status-banner ${type}`}>{message}</div>;
179+
const VersionMismatchError: React.FC<{ pwMcpVersion: string; extensionVersion: string }> = ({ pwMcpVersion, extensionVersion }) => {
180+
const readmeUrl = 'https://github.com/microsoft/playwright-mcp/blob/main/extension/README.md';
181+
return (
182+
<div>
183+
Incompatible Playwright MCP version: {pwMcpVersion} (extension version: {extensionVersion}).
184+
Please install the latest version of the extension.{' '}
185+
See <a href={readmeUrl} target='_blank' rel='noopener noreferrer'>installation instructions</a>.
186+
</div>
187+
);
188+
};
189+
190+
const StatusBanner: React.FC<{ status: Status }> = ({ status }) => {
191+
return (
192+
<div className={`status-banner ${status.type}`}>
193+
{'versionMismatch' in status ? (
194+
<VersionMismatchError pwMcpVersion={status.versionMismatch.pwMcpVersion} extensionVersion={status.versionMismatch.extensionVersion} />
195+
) : (
196+
status.message
197+
)}
198+
</div>
199+
);
161200
};
162201

163202
// Initialize the React app

extension/tests/extension.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ for (const [mode, startClientMethod] of [
233233
});
234234

235235
const confirmationPage = await confirmationPagePromise;
236-
await expect(confirmationPage.locator('.status-banner')).toHaveText(`Incompatible Playwright MCP version: ${packageJSON.version} (extension version: 0.0.1). Please install the latest version of the extension.`);
236+
await expect(confirmationPage.locator('.status-banner')).toHaveText(`Incompatible Playwright MCP version: ${packageJSON.version} (extension version: 0.0.1). Please install the latest version of the extension. See installation instructions.`);
237237

238238
expect(await navigateResponse).toHaveResponse({
239239
result: expect.stringContaining('Extension connection timeout.'),

0 commit comments

Comments
 (0)