apify/crawlee · error · Error
Function `stopTracing()` is not available in incognito mode
Error message
Function `stopTracing()` is not available in incognito mode
What it means
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.
Source
Thrown at packages/browser-pool/src/playwright/playwright-browser.ts:78
async newPage(...args: Parameters<BrowserContext['newPage']>): ReturnType<BrowserContext['newPage']> {
return this.#browserContext.newPage(...args);
}
async newContext(): Promise<never> {
throw new Error('Function `newContext()` is not available in incognito mode');
}
async newBrowserCDPSession(): Promise<never> {
throw new Error('Function `newBrowserCDPSession()` is not available in incognito mode');
}
async startTracing(): Promise<never> {
throw new Error('Function `startTracing()` is not available in incognito mode');
}
async stopTracing(): Promise<never> {
throw new Error('Function `stopTracing()` is not available in incognito mode');
}
}
View on GitHub (pinned to dbe57fb09c)
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.
Example fix
// before
await browserController.stopTracing({ path: 'trace.zip' });
// after
await page.context().tracing.stop({ path: 'trace.zip' }); Defensive patterns
Strategy: validation
Validate before calling
if (!launchContext.useIncognitoPages) {
await browserController.stopTracing();
} Type guard
function tracingWasStartedAtBrowserLevel(useIncognitoPages: boolean): boolean {
return !useIncognitoPages;
} Try / catch
try {
await browserController.stopTracing(opts);
} catch (err) {
if (err instanceof Error && err.message.includes('stopTracing')) {
await page.context().tracing.stop(opts);
} throw err;
} Prevention
- 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.
When it happens
Trigger: Calling browserController.stopTracing() in a useIncognitoPages: true setup (typically in a finally/cleanup block after attempting tracing).
Common situations: Cleanup code that unconditionally stops tracing; paired start/stop helpers written against a non-incognito browser handle.
Related errors
- Function `startTracing()` is not available in incognito mode
- Function `newContext()` is not available in incognito mode
- Function `newBrowserCDPSession()` is not available in incogn
- A new page can be created with provided context only when us
- A new page can be created with provided context only when us
AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30).
Data as JSON: /api/errors/f81402853bc274b8.
Report an issue: GitHub.