{"record":{"id":"e8e017d6aa6b6c6a","repo":"microsoft/playwright","slug":"failed-to-create-tab","errorCode":null,"errorMessage":"Failed to create tab","messagePattern":"Failed to create tab","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/mcp/browserModel.ts","lineNumber":144,"sourceCode":"  onDebuggerDetach(source: Debuggee): void {\n    if (source.tabId !== undefined)\n      this._detachTab(source.tabId);\n  }\n\n  // ─── Playwright → model commands ──────────────────────────────────────\n\n  // Turn auto-attach on and attach to every tab we already know about.\n  // Called in response to Playwright's `Target.setAutoAttach` on the root session.\n  async enableAutoAttach(): Promise<void> {\n    this._autoAttach = true;\n    const tabIds = [...this._knownTabs.keys()];\n    await Promise.all(tabIds.map(tabId => this._attachTab(tabId).catch(logUnhandledError)));\n  }\n\n  async createTarget(url: string | undefined): Promise<{ targetId: string | undefined }> {\n    const tab = await this._sendToExtension('chrome.tabs.create', [{ url }]);\n    if (tab?.id === undefined)\n      throw new Error('Failed to create tab');\n    this._knownTabs.set(tab.id, tab);\n    const tabSession = await this._attachTab(tab.id);\n    return { targetId: tabSession.targetInfo?.targetId };\n  }\n\n  async closeTarget(targetId: string | undefined): Promise<{ success: boolean }> {\n    const tabSession = targetId ? this._findTabSession(s => s.targetInfo?.targetId === targetId) : undefined;\n    if (!tabSession)\n      return { success: false };\n    await this._sendToExtension('chrome.tabs.remove', [tabSession.tabId]);\n    return { success: true };\n  }\n\n  getTargetInfo(sessionId: string | undefined): any {\n    if (!sessionId)\n      return undefined;\n    return this._findTabSession(s => s.sessionId === sessionId)?.targetInfo;\n  }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/mcp/browserModel.ts#L126-L162","documentation":"Thrown by the extension-backed browser model's `createTarget` after calling `chrome.tabs.create` via the extension, when the returned tab object has no `id` (`tab?.id === undefined`). Without a tab id the new tab cannot be attached or tracked, so the operation is reported as a failure.","triggerScenarios":"The extension host rejects `chrome.tabs.create` (permissions not granted, tab blocked by policy, extension context invalidated), or returns a tab object missing the `id` field. Also possible if the extension is in a transient state (just connected, mid-handshake) when create is called.","commonSituations":"Using the browser-extension connection mode (`--extension`) without granting the `tabs` permission; the extension was reloaded/updated mid-session; an enterprise policy blocks tab creation; calling create immediately after connect before the extension is fully ready.","solutions":["Confirm the Playwright browser extension is installed, enabled, and has the required permissions (re-grant if prompted).","Retry the operation after the extension connection is fully established (await `establishExtensionConnection`).","Check for enterprise/policy restrictions on `chrome.tabs.create` in the managed browser.","If the extension was updated, reconnect (restart the relay/browser) to get a fresh extension context."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await model.createTarget(url);\n} catch (e) {\n  if (/Failed to create tab/.test((e as Error).message)) {\n    // re-check extension health, then retry once\n    await relay.establishExtensionConnection(clientName);\n    await model.createTarget(url);\n  } else throw e;\n}","preventionTips":["Ensure the extension is installed, enabled, and granted tabs/debugger permissions.","Await establishExtensionConnection before driving tabs.","Reconnect if the extension was reloaded/updated mid-session."],"tags":["extension","tabs","browser-model","cdp-relay","create-target"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}