chore(extension): bind relay lifetime to browser context (#804)
This commit is contained in:
@@ -14,26 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { startCDPRelayServer } from './cdpRelay.js';
|
||||
import { ExtensionContextFactory } from './extensionContextFactory.js';
|
||||
import { BrowserServerBackend } from '../browserServerBackend.js';
|
||||
import * as mcpTransport from '../mcp/transport.js';
|
||||
|
||||
import type { FullConfig } from '../config.js';
|
||||
|
||||
export async function runWithExtension(config: FullConfig, abortController: AbortController) {
|
||||
const contextFactory = await startCDPRelayServer(config.browser.launchOptions.channel || 'chrome', abortController);
|
||||
|
||||
let backend: BrowserServerBackend | undefined;
|
||||
const serverBackendFactory = () => {
|
||||
if (backend)
|
||||
throw new Error('Another MCP client is still connected. Only one connection at a time is allowed.');
|
||||
backend = new BrowserServerBackend(config, contextFactory);
|
||||
backend.onclose = () => {
|
||||
contextFactory.clientDisconnected();
|
||||
backend = undefined;
|
||||
};
|
||||
return backend;
|
||||
};
|
||||
|
||||
export async function runWithExtension(config: FullConfig) {
|
||||
const contextFactory = new ExtensionContextFactory(config.browser.launchOptions.channel || 'chrome');
|
||||
const serverBackendFactory = () => new BrowserServerBackend(config, contextFactory);
|
||||
await mcpTransport.start(serverBackendFactory, config.server);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user