{"record":{"id":"eaebc8cce8ec9f08","repo":"openclaw/openclaw","slug":"playwright-connection-attempt-was-superseded","errorCode":null,"errorMessage":"Playwright connection attempt was superseded.","messagePattern":"Playwright connection attempt was superseded\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"extensions/browser/src/browser/pw-session-connection.ts","lineNumber":443,"sourceCode":"          return await withManagedProxyForCdpUrl(connectionUrl, () =>\n            withNoProxyForCdpUrl(connectionUrl, () =>\n              chromium.connectOverCDP(connectionUrl, { timeout, headers }),\n            ),\n          );\n        };\n        let browser: Browser;\n        try {\n          browser = await connectEndpoint(endpoint);\n        } catch (err) {\n          if (!isWebSocketUrl(normalized) || endpoint === normalized) {\n            throw err;\n          }\n          browser = await connectEndpoint(normalized);\n        }\n        if (connectionAttempt.cancelled) {\n          connectionAttempt.retired = { browser, cdpUrl: normalized };\n          void closeTrackedPlaywrightConnection(connectionAttempt.retired).catch(() => {});\n          throw new Error(\"Playwright connection attempt was superseded.\");\n        }\n        const onDisconnected = () => {\n          const current = cachedByCdpUrl.get(normalized);\n          if (current?.browser === browser) {\n            cachedByCdpUrl.delete(normalized);\n          }\n        };\n        const connected: ConnectedBrowser = { browser, cdpUrl: normalized, onDisconnected };\n        cachedByCdpUrl.set(normalized, connected);\n        browser.on(\"disconnected\", onDisconnected);\n        observeBrowser(browser);\n        return connected;\n      } catch (err) {\n        lastErr = err;\n        if (connectionAttempt.cancelled) {\n          break;\n        }\n        // Don't retry rate-limit errors; retrying worsens the 429.","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/openclaw/openclaw/blob/01804a75319da4b69c9ab98ceaa30477e22b8c0b/extensions/browser/src/browser/pw-session-connection.ts#L425-L461","documentation":"A plain Error thrown when connectEndpoint succeeds but connectionAttempt.cancelled was set to true during the await. The just-opened Browser is retired (tracked for async close) and the connection attempt reports superseded rather than returning a connection the caller no longer wants. This is a cooperative-cancellation mechanism: another caller (closePlaywrightBrowserConnection, a cdpUrl change, or lifecycle teardown) cancelled the in-flight attempt.","triggerScenarios":"Two callers racing on the same cdpUrl: one connects, the other cancels (e.g. profile reconfiguration, gateway shutdown, explicit connection close). The first to land its connectEndpoint wins; the loser sees cancelled and throws. Also fires when the gateway is shutting down mid-connect.","commonSituations":"Rapid profile/endpoint switching that tears down a previous connection before its connect completes; concurrent open+close on the same cdpUrl; gateway restart during a slow remote connect; test teardown cancelled an in-flight connect.","solutions":["Retry the connect on a superseded error — by the time it propagates, the cancelling caller has usually finished and a fresh attempt will succeed.","Avoid issuing connect and close concurrently on the same cdpUrl; serialize through a single owner.","If this fires during shutdown, treat it as expected and swallow it in the teardown path.","Check for a long-running stale connection holder that keeps cancelling new attempts."],"exampleFix":"// before\nawait connectBrowser(cdpUrl); // may throw 'superseded' under concurrent close\n// after\ntry { return await connectBrowser(cdpUrl); }\ncatch (e) { if (isSupersededError(e)) return await connectBrowser(cdpUrl); throw e; }","handlingStrategy":"retry","validationCode":null,"typeGuard":"function isSupersededError(e: unknown): boolean {\n  return e instanceof Error && /superseded/.test(e.message);\n}","tryCatchPattern":"try { return await connectBrowser(cdpUrl); }\ncatch (e) {\n  if (isSupersededError(e)) return await connectBrowser(cdpUrl);\n  throw e;\n}","preventionTips":["Serialize connect and close on a single cdpUrl owner; do not race them.","Swallow 'superseded' in teardown/shutdown paths where it is expected.","Investigate a stale connection holder if superseded errors recur."],"tags":["browser","cdp","playwright","race","cancellation","connection"],"backgroundTag":null,"analyzedSha":"01804a75319da4b69c9ab98ceaa30477e22b8c0b","analyzedAt":"2026-08-12T04:37:58.197Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}