{"record":{"id":"6901da0eb5243a81","repo":"microsoft/playwright","slug":"please-use-browser-newcontext","errorCode":null,"errorMessage":"Please use browser.newContext()","messagePattern":"Please use browser\\.newContext\\(\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/client/browserContext.ts","lineNumber":314,"sourceCode":"  setDefaultTimeout(timeout: number | undefined) {\n    this._timeoutSettings.setDefaultTimeout(timeout);\n  }\n\n  browser(): Browser | null {\n    return this._browser;\n  }\n\n  pages(): Page[] {\n    return [...this._pages];\n  }\n\n  isClosed(): boolean {\n    return this._closingStatus !== 'none';\n  }\n\n  async newPage(): Promise<Page> {\n    if (this._ownerPage)\n      throw new Error('Please use browser.newContext()');\n    return Page.from((await this._channel.newPage({}, kNoTimeout)).page);\n  }\n\n  async cookies(urls?: string | string[]): Promise<network.NetworkCookie[]> {\n    if (!urls)\n      urls = [];\n    if (urls && typeof urls === 'string')\n      urls = [urls];\n    return (await this._channel.cookies({ urls: urls as string[] }, kNoTimeout)).cookies;\n  }\n\n  async addCookies(cookies: network.SetNetworkCookieParam[]): Promise<void> {\n    await this._channel.addCookies({ cookies }, kNoTimeout);\n  }\n\n  async clearCookies(options: network.ClearNetworkCookieOptions = {}): Promise<void> {\n    await this._channel.clearCookies({\n      name: isString(options.name) ? options.name : undefined,","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/client/browserContext.ts#L296-L332","documentation":"Thrown by BrowserContext.newPage() when the context is owned by a page (this._ownerPage is set). A context created via page.context() is tied to that page and cannot spawn new pages; new pages must come from a fresh browser-level context. The guard `this._ownerPage` distinguishes page-owned contexts from browser-owned ones.","triggerScenarios":"Calling `(await page.context()).newPage()`, or any flow that takes a page's context and tries to add pages to it. The ownerPage field is set when a context was created implicitly for a single page.","commonSituations":"Helper utilities that accept a Page and reuse its context to open more tabs; refactoring that accidentally passes a page-bound context where a browser-level one was expected.","solutions":["Create a new context from the browser: `const ctx = await browser.newContext(); const p = await ctx.newPage();`.","If you only have a page, reach the browser via `page.context().browser()` then newContext().","Avoid storing/reusing a page's context for multi-page workflows."],"exampleFix":"// before\nconst ctx = page.context();\nconst page2 = await ctx.newPage();\n// after\nconst browser = page.context().browser()!;\nconst ctx = await browser.newContext();\nconst page2 = await ctx.newPage();","handlingStrategy":"type-guard","validationCode":"function canCreatePage(ctx: any): boolean {\n  return !ctx._ownerPage;\n}\nif (!canCreatePage(context))\n  throw new Error('Context is page-owned; use browser.newContext() instead.');","typeGuard":"function isBrowserOwnedContext(ctx: any): boolean {\n  return !ctx._ownerPage;\n}","tryCatchPattern":null,"preventionTips":["Always create contexts from the browser, not from a page.","Don't reuse page.context() to spawn additional pages."],"tags":["browser-context","new-page","ownership"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}