{"record":{"id":"d8feaa121e8bfa92","repo":"microsoft/playwright","slug":"the-browser-context-is-shared-between-clients-and","errorCode":null,"errorMessage":"The browser context is shared between clients and cannot be closed.","messagePattern":"The browser context is shared between clients and cannot be closed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/backend/common.ts","lineNumber":34,"sourceCode":"\nimport * as z from 'zod';\nimport { defineTabTool, defineTool } from './tool';\nimport { renderTabsMarkdown } from './response';\n\nconst close = defineTool({\n  capability: 'core',\n\n  schema: {\n    name: 'browser_close',\n    title: 'Close browser',\n    description: 'Close the page',\n    inputSchema: z.object({}),\n    type: 'action',\n  },\n\n  handle: async (context, params, response) => {\n    if (context.config.sharedBrowserContext)\n      throw new Error('The browser context is shared between clients and cannot be closed.');\n    const result = renderTabsMarkdown([]);\n    response.addTextResult(result.join('\\n'));\n    response.addCode(`await page.close()`);\n    response.setClose();\n  },\n});\n\nconst resize = defineTabTool({\n  capability: 'core',\n  schema: {\n    name: 'browser_resize',\n    title: 'Resize browser window',\n    description: 'Resize the browser window',\n    inputSchema: z.object({\n      width: z.number().describe('Width of the browser window'),\n      height: z.number().describe('Height of the browser window'),\n    }),\n    type: 'action',","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/microsoft/playwright/blob/312030cdcee20c006343e5f8420fe451b9aa6390/packages/playwright-core/src/tools/backend/common.ts#L16-L52","documentation":"The MCP `close` tab/tool refuses to close the page when the server runs with `sharedBrowserContext` enabled. In shared-context mode the browser context belongs to all connected MCP clients, so one client closing it would break the others. The tool deliberately rejects the operation instead.","triggerScenarios":"An MCP client calls the close tab tool (`handle` of the close action) while the Playwright MCP server was started with `--shared-browser-context` (config `sharedBrowserContext: true`).","commonSituations":"Teams running one MCP server shared across multiple agents/clients (e.g. Claude + Cursor) who still issue a close-tab tool call; configs migrated from single-client setups where `sharedBrowserContext` was turned on to save resources.","solutions":["Do not call the close tool in shared-context mode; leave tab lifecycle to the server or other clients.","Restart/start the MCP server without `sharedBrowserContext` (drop `--shared-browser-context`) if exclusive control is required.","Use tab navigation/selection tools instead of closing when working in a shared context."],"exampleFix":"// before (config)\n{ \"sharedBrowserContext\": true }\n// after (if exclusive close is needed)\n{ \"sharedBrowserContext\": false }","handlingStrategy":"validation","validationCode":"// client side: only call close when the server is not in shared mode\nif (serverConfig.sharedBrowserContext) {\n  throw new Error('close tool is unavailable with sharedBrowserContext');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.callTool({ name: 'browser_tab_close', arguments: {} });\n} catch (e) {\n  if (String(e.message).includes('shared between clients')) {\n    // expected in shared mode: skip close, navigate elsewhere instead\n  } else throw e;\n}","preventionTips":["Document tab-close as unsupported when sharedBrowserContext is enabled.","Gate tool availability on server config before exposing close to clients.","Prefer navigation or tab selection over closing in shared setups."],"tags":["mcp","shared-context","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"312030cdcee20c006343e5f8420fe451b9aa6390","analyzedAt":"2026-09-07T14:42:43.271Z","contentChangedAt":"2026-09-07T14:42:43.271Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}