fix: restore headed mode by using browser context factory

- Fix browser_configure tool to properly use browser context factory
- Remove bypass of browser context factory that was ignoring configuration changes
- Headed mode now works correctly when DISPLAY is available
- Browser windows properly appear when switching from headless to headed mode

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ryan Malloy 2025-08-11 04:36:39 -06:00
parent aa84278d36
commit 5b7a1e0452

View File

@ -243,8 +243,8 @@ export class Context {
// Create a new browser context with video recording enabled
result = await this._createVideoEnabledContext();
} else {
// Use session-aware browser context factory
result = await this._createSessionIsolatedContext();
// Use the standard browser context factory
result = await this._browserContextFactory.createContext(this.clientVersion!);
}
const { browserContext } = result;
await this._setupRequestInterception(browserContext);
@ -299,42 +299,6 @@ export class Context {
};
}
private async _createSessionIsolatedContext(): Promise<{ browserContext: playwright.BrowserContext, close: () => Promise<void> }> {
// Always create isolated browser contexts for each MCP client
// This ensures complete session isolation between different clients
const browserType = playwright[this.config.browser.browserName];
// Get environment-specific browser options
const envOptions = this._environmentIntrospector.getRecommendedBrowserOptions();
const browser = await browserType.launch({
...this.config.browser.launchOptions,
...envOptions, // Include environment-detected options
handleSIGINT: false,
handleSIGTERM: false,
});
// Create isolated context options with session-specific storage
const contextOptions = {
...this.config.browser.contextOptions,
// Each session gets its own isolated storage - no shared state
storageState: undefined,
};
const browserContext = await browser.newContext(contextOptions);
testDebug(`created isolated browser context for session: ${this.sessionId}`);
return {
browserContext,
close: async () => {
testDebug(`closing isolated browser context for session: ${this.sessionId}`);
await browserContext.close();
await browser.close();
}
};
}
setVideoRecording(config: { dir: string; size?: { width: number; height: number } }, baseFilename: string) {
this._videoRecordingConfig = config;
this._videoBaseFilename = baseFilename;