{"record":{"id":"f81402853bc274b8","repo":"apify/crawlee","slug":"function-stoptracing-is-not-available-in-incog","errorCode":null,"errorMessage":"Function `stopTracing()` is not available in incognito mode","messagePattern":"Function `stopTracing\\(\\)` is not available in incognito mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-pool/src/playwright/playwright-browser.ts","lineNumber":78,"sourceCode":"\n    async newPage(...args: Parameters<BrowserContext['newPage']>): ReturnType<BrowserContext['newPage']> {\n        return this.#browserContext.newPage(...args);\n    }\n\n    async newContext(): Promise<never> {\n        throw new Error('Function `newContext()` is not available in incognito mode');\n    }\n\n    async newBrowserCDPSession(): Promise<never> {\n        throw new Error('Function `newBrowserCDPSession()` is not available in incognito mode');\n    }\n\n    async startTracing(): Promise<never> {\n        throw new Error('Function `startTracing()` is not available in incognito mode');\n    }\n\n    async stopTracing(): Promise<never> {\n        throw new Error('Function `stopTracing()` is not available in incognito mode');\n    }\n}\n","sourceCodeStart":60,"sourceCodeEnd":81,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/browser-pool/src/playwright/playwright-browser.ts#L60-L81","documentation":"stopTracing() pairs with startTracing(), which is disabled in incognito mode because tracing belongs to the Playwright Browser rather than the incognito BrowserContext. With no tracing ever started, stopTracing() always throws. Use the context's tracing API to stop recordings started through context.tracing.","triggerScenarios":"Calling browserController.stopTracing() in a useIncognitoPages: true setup (typically in a finally/cleanup block after attempting tracing).","commonSituations":"Cleanup code that unconditionally stops tracing; paired start/stop helpers written against a non-incognito browser handle.","solutions":["Stop via the underlying context: page.context().tracing.stop({ path: 'trace.zip' }).","Remove or conditionally skip tracing start/stop calls when running with incognito pages.","Run tracing on a dedicated non-incognito browser instance if browser-level tracing is required."],"exampleFix":"// before\nawait browserController.stopTracing({ path: 'trace.zip' });\n// after\nawait page.context().tracing.stop({ path: 'trace.zip' });","handlingStrategy":"validation","validationCode":"if (!launchContext.useIncognitoPages) {\n  await browserController.stopTracing();\n}","typeGuard":"function tracingWasStartedAtBrowserLevel(useIncognitoPages: boolean): boolean {\n  return !useIncognitoPages;\n}","tryCatchPattern":"try {\n  await browserController.stopTracing(opts);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('stopTracing')) {\n    await page.context().tracing.stop(opts);\n  } throw err;\n}","preventionTips":["Pair start/stop with the same API level (browser-level only when not incognito).","Use context.tracing for incognito setups to keep cleanup symmetric.","Guard cleanup paths so they skip browser-level tracing calls in incognito mode."],"tags":["browser-pool","playwright","incognito","tracing"],"backgroundTag":"api-not-supported-in-mode","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}