{"record":{"id":"9abea635f6540d94","repo":"microsoft/playwright","slug":"server-is-already-started","errorCode":null,"errorMessage":"Server is already started.","messagePattern":"Server is already started\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/browser.ts","lineNumber":220,"sourceCode":"    if (this.isConnected())\n      await progress.race(new Promise(x => this.once(Browser.Events.Disconnected, x)));\n  }\n}\n\nexport class BrowserServer {\n  private _browser: Browser;\n  private _pipeServer?: PlaywrightPipeServer;\n  private _wsServer?: PlaywrightWebSocketServer;\n  private _pipeSocketPath?: string;\n  private _isStarted = false;\n\n  constructor(browser: Browser) {\n    this._browser = browser;\n  }\n\n  async start(title: string, options: channels.BrowserStartServerOptions): Promise<{ endpoint: string }> {\n    if (this._isStarted)\n      throw new Error(`Server is already started.`);\n    this._isStarted = true;\n\n    let endpoint: string;\n    if (options.host !== undefined || options.port !== undefined) {\n      this._wsServer = new PlaywrightWebSocketServer(this._browser, '/' + createGuid());\n      endpoint = await this._wsServer.listen(options.port ?? 0, options.host);\n    } else {\n      this._pipeServer = new PlaywrightPipeServer(this._browser);\n      this._pipeSocketPath = await this._socketPath();\n      await this._pipeServer.listen(this._pipeSocketPath);\n      endpoint = this._pipeSocketPath;\n    }\n\n    const browserInfo: BrowserInfo = {\n      guid: this._browser.guid,\n      browserName: this._browser.options.browserType,\n      launchOptions: asClientLaunchOptions(this._browser.options.originalLaunchOptions),\n      userDataDir: this._browser.options.userDataDir,","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/browser.ts#L202-L238","documentation":"`BrowserServer.start` sets `_isStarted=true` and refuses a second invocation. BrowserServer backs `browserType.launchServer` / connect endpoints and is meant to be started exactly once per instance.","triggerScenarios":"Calling `browserServer.start(...)` twice on the same BrowserServer instance.","commonSituations":"Reuse logic that inadvertently starts a server twice; warm-start optimization that re-runs startup; buggy lifecycle management that re-invokes start on reconnect.","solutions":["Track started state yourself and only call start() once","Call `stop()` then create a new BrowserServer rather than re-starting","If you need a fresh endpoint, create a new instance instead of reusing"],"exampleFix":"// before\nawait server.start('t', {});\nawait server.start('t', {}); // throws\n\n// after\nawait server.start('t', {});\n// ... later\nawait server.stop();\nserver = browserType.launchServer();\nawait server.start('t', {});","handlingStrategy":"validation","validationCode":"if (serverStarted) {\n  throw new Error('BrowserServer already started; stop() and create a new one to restart.');\n}\nawait server.start(title, opts);\nserverStarted = true;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track started state in your own variable rather than relying on the throw","Create a new BrowserServer after stop() instead of reusing the instance","Guard startup in lifecycle hooks against double-invocation"],"tags":["browser-server","lifecycle","launch"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}