{"record":{"id":"b612bb3f5b9278a9","repo":"garrytan/gstack","slug":"cannot-recreate-context-in-headed-mode-use-discon","errorCode":null,"errorMessage":"Cannot recreate context in headed mode. Use disconnect first.","messagePattern":"Cannot recreate context in headed mode\\. Use disconnect first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/browser-manager.ts","lineNumber":1398,"sourceCode":"    // If no pages were saved, create a blank one\n    if (this.pages.size === 0) {\n      await this.newTab();\n    } else {\n      this.activeTabId = activeId ?? [...this.pages.keys()][0];\n    }\n\n    // Clear refs — pages are new, locators are stale\n    this.clearRefs();\n  }\n\n  /**\n   * Recreate the browser context to apply user agent changes.\n   * Saves and restores cookies, localStorage, sessionStorage, and open pages.\n   * Falls back to a clean slate on any failure.\n   */\n  async recreateContext(): Promise<string | null> {\n    if (this.connectionMode === 'headed') {\n      throw new Error('Cannot recreate context in headed mode. Use disconnect first.');\n    }\n    if (!this.browser || !this.context) {\n      throw new Error('Browser not launched');\n    }\n\n    try {\n      // 1. Save state\n      const state = await this.saveState();\n\n      // 2. Close old pages and context\n      for (const page of this.pages.values()) {\n        await page.close().catch(() => {});\n      }\n      this.pages.clear();\n      this.tabSessions.clear();\n      await this.context.close().catch(() => {});\n\n      // 3. Create new context with updated settings","sourceCodeStart":1380,"sourceCodeEnd":1416,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/browser-manager.ts#L1380-L1416","documentation":"Error \"Cannot recreate context in headed mode. Use disconnect first.\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/browser-manager.ts:1398 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}