microsoft/playwright · error · Error

The browser context is shared between clients and cannot be

Error message

The browser context is shared between clients and cannot be closed.

What it means

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.

Source

Thrown at packages/playwright-core/src/tools/backend/common.ts:34

import * as z from 'zod';
import { defineTabTool, defineTool } from './tool';
import { renderTabsMarkdown } from './response';

const close = defineTool({
  capability: 'core',

  schema: {
    name: 'browser_close',
    title: 'Close browser',
    description: 'Close the page',
    inputSchema: z.object({}),
    type: 'action',
  },

  handle: async (context, params, response) => {
    if (context.config.sharedBrowserContext)
      throw new Error('The browser context is shared between clients and cannot be closed.');
    const result = renderTabsMarkdown([]);
    response.addTextResult(result.join('\n'));
    response.addCode(`await page.close()`);
    response.setClose();
  },
});

const resize = defineTabTool({
  capability: 'core',
  schema: {
    name: 'browser_resize',
    title: 'Resize browser window',
    description: 'Resize the browser window',
    inputSchema: z.object({
      width: z.number().describe('Width of the browser window'),
      height: z.number().describe('Height of the browser window'),
    }),
    type: 'action',

View on GitHub (pinned to 312030cdce)

Solutions

  1. Do not call the close tool in shared-context mode; leave tab lifecycle to the server or other clients.
  2. Restart/start the MCP server without `sharedBrowserContext` (drop `--shared-browser-context`) if exclusive control is required.
  3. Use tab navigation/selection tools instead of closing when working in a shared context.

Example fix

// before (config)
{ "sharedBrowserContext": true }
// after (if exclusive close is needed)
{ "sharedBrowserContext": false }
Defensive patterns

Strategy: validation

Validate before calling

// client side: only call close when the server is not in shared mode
if (serverConfig.sharedBrowserContext) {
  throw new Error('close tool is unavailable with sharedBrowserContext');
}

Try / catch

try {
  await client.callTool({ name: 'browser_tab_close', arguments: {} });
} catch (e) {
  if (String(e.message).includes('shared between clients')) {
    // expected in shared mode: skip close, navigate elsewhere instead
  } else throw e;
}

Prevention

When it happens

Trigger: 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`).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of microsoft/playwright@312030cdce (2026-09-07). Data as JSON: /api/errors/d8feaa121e8bfa92. Report an issue: GitHub.