diff --git a/extension/src/background.ts b/extension/src/background.ts index 3fbf024..1a873cd 100644 --- a/extension/src/background.ts +++ b/extension/src/background.ts @@ -1,26 +1,10 @@ import { RelayConnection, logger } from './relayConnection' import { createStore } from 'zustand/vanilla' +import type { ExtensionState, ConnectionState, TabState, TabInfo } from './types' // Relay URL - fixed port for MCP bridge const RELAY_URL = 'ws://localhost:19988/extension' -type ConnectionState = 'disconnected' | 'reconnecting' | 'connected' | 'error' -type TabState = 'connecting' | 'connected' | 'error' - -interface TabInfo { - targetId: string - state: TabState - errorText?: string -} - -interface ExtensionState { - connection: RelayConnection | undefined - connectedTabs: Map - connectionState: ConnectionState - currentTabId: number | undefined - errorText: string | undefined -} - const useExtensionStore = createStore((set) => ({ connection: undefined, connectedTabs: new Map(), diff --git a/extension/src/types.ts b/extension/src/types.ts new file mode 100644 index 0000000..6b46740 --- /dev/null +++ b/extension/src/types.ts @@ -0,0 +1,18 @@ +import type { RelayConnection } from './relayConnection' + +export type ConnectionState = 'disconnected' | 'reconnecting' | 'connected' | 'error' +export type TabState = 'connecting' | 'connected' | 'error' + +export interface TabInfo { + targetId: string + state: TabState + errorText?: string +} + +export interface ExtensionState { + connection: RelayConnection | undefined + connectedTabs: Map + connectionState: ConnectionState + currentTabId: number | undefined + errorText: string | undefined +} diff --git a/playwriter/package.json b/playwriter/package.json index 3f8503d..e9611b2 100644 --- a/playwriter/package.json +++ b/playwriter/package.json @@ -27,6 +27,7 @@ "license": "", "devDependencies": { "@mizchi/selector-generator": "1.50.0-next", + "@types/chrome": "^0.0.315", "@types/node": "^24.10.1", "@vitest/ui": "^4.0.8", "mcp-extension": "workspace:*", diff --git a/playwriter/src/mcp.test.ts b/playwriter/src/mcp.test.ts index 5d65522..004cbed 100644 --- a/playwriter/src/mcp.test.ts +++ b/playwriter/src/mcp.test.ts @@ -55,7 +55,6 @@ declare global { var toggleExtensionForActiveTab: () => Promise<{ isConnected: boolean; state: ExtensionState }>; var getExtensionState: () => ExtensionState; var disconnectEverything: () => Promise; - var chrome: any; } describe('MCP Server Tests', () => { @@ -224,13 +223,12 @@ describe('MCP Server Tests', () => { // Get extension state to verify the page is marked as connected const extensionState = await serviceWorker.evaluate(async () => { const state = globalThis.getExtensionState() - const chrome = globalThis.chrome const tabs = await chrome.tabs.query({}) const testTab = tabs.find((t: any) => t.url?.includes('mcp-test')) return { - connected: !!testTab && state.connectedTabs.has(testTab.id), + connected: !!testTab && !!testTab.id && state.connectedTabs.has(testTab.id), tabId: testTab?.id, - tabInfo: testTab ? state.connectedTabs.get(testTab.id) : null, + tabInfo: testTab?.id ? state.connectedTabs.get(testTab.id) : null, connectionState: state.connectionState } }) @@ -583,8 +581,8 @@ describe('MCP Server Tests', () => { const tabA = tabs.find((t: any) => t.url?.includes('tab-a')) const tabB = tabs.find((t: any) => t.url?.includes('tab-b')) return { - idA: state.connectedTabs.get(tabA?.id)?.targetId, - idB: state.connectedTabs.get(tabB?.id)?.targetId + idA: state.connectedTabs.get(tabA?.id ?? -1)?.targetId, + idB: state.connectedTabs.get(tabB?.id ?? -1)?.targetId } }) @@ -669,8 +667,8 @@ describe('MCP Server Tests', () => { const tabA = tabs.find((t: any) => t.url?.includes('tab-a')) const tabB = tabs.find((t: any) => t.url?.includes('tab-b')) return { - idA: state.connectedTabs.get(tabA?.id)?.targetId, - idB: state.connectedTabs.get(tabB?.id)?.targetId + idA: state.connectedTabs.get(tabA?.id ?? -1)?.targetId, + idB: state.connectedTabs.get(tabB?.id ?? -1)?.targetId } }) diff --git a/playwriter/tsconfig.json b/playwriter/tsconfig.json index c17b043..1bb3589 100644 --- a/playwriter/tsconfig.json +++ b/playwriter/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../tsconfig.base.json", "compilerOptions": { "rootDir": "src", - "outDir": "dist" + "outDir": "dist", + "types": ["node", "chrome"] }, "include": ["src"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8f37e75..4b9421a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -94,6 +94,9 @@ importers: '@mizchi/selector-generator': specifier: 1.50.0-next version: 1.50.0-next + '@types/chrome': + specifier: ^0.0.315 + version: 0.0.315 '@types/node': specifier: ^24.10.1 version: 24.10.1