chore(extension): bind relay lifetime to browser context (#804)

This commit is contained in:
Yury Semikhatsky
2025-07-31 22:25:40 -07:00
committed by GitHub
parent 3787439fc1
commit 7c07cc86eb
7 changed files with 101 additions and 83 deletions

View File

@@ -42,6 +42,7 @@ export class Context {
private static _allContexts: Set<Context> = new Set();
private _closeBrowserContextPromise: Promise<void> | undefined;
private _isRunningTool: boolean = false;
private _abortController = new AbortController();
constructor(tools: Tool[], config: FullConfig, browserContextFactory: BrowserContextFactory, sessionLog: SessionLog | undefined) {
this.tools = tools;
@@ -154,6 +155,7 @@ export class Context {
}
async dispose() {
this._abortController.abort('MCP context disposed');
await this.closeBrowserContext();
Context._allContexts.delete(this);
}
@@ -186,7 +188,7 @@ export class Context {
if (this._closeBrowserContextPromise)
throw new Error('Another browser context is being closed.');
// TODO: move to the browser context factory to make it based on isolation mode.
const result = await this._browserContextFactory.createContext(this.clientVersion!);
const result = await this._browserContextFactory.createContext(this.clientVersion!, this._abortController.signal);
const { browserContext } = result;
await this._setupRequestInterception(browserContext);
if (this.sessionLog)