{"record":{"id":"ba01873cd023125e","repo":"grafana/k6","slug":"creating-a-new-blank-page-w","errorCode":null,"errorMessage":"creating a new blank page: %w","messagePattern":"creating a new blank page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser.go","lineNumber":535,"sourceCode":"\t\tbc, // browser context will emit the following event:\n\t\t[]string{EventBrowserContextPage},\n\t\tfunc(e any) bool {\n\t\t\ttid := <-targetID\n\n\t\t\tb.logger.Debugf(\"Browser:newPageInContext:createWaitForEventHandler\",\n\t\t\t\t\"tid:%v ptid:%v bctxid:%v\", tid, e.(*Page).targetID, id) //nolint:forcetypeassert\n\n\t\t\t// we are only interested in the new page.\n\t\t\treturn e.(*Page).targetID == tid //nolint:forcetypeassert\n\t\t},\n\t)\n\tdefer removeEventHandler()\n\n\t// create a new page.\n\taction := target.CreateTarget(BlankPage).WithNewWindow(true).WithBrowserContextID(id)\n\ttid, err := action.Do(cdp.WithExecutor(ctx, b.conn))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating a new blank page: %w\", err)\n\t}\n\t// let the event handler know about the new page.\n\ttargetID <- tid\n\tvar page *Page\n\tselect {\n\tcase <-waitForPage:\n\t\tb.logger.Debugf(\"Browser:newPageInContext:<-waitForPage\", \"tid:%v bctxid:%v\", tid, id)\n\t\tb.pagesMu.RLock()\n\t\tpage = b.pages[tid]\n\t\tb.pagesMu.RUnlock()\n\tcase <-ctx.Done():\n\t\tb.logger.Debugf(\"Browser:newPageInContext:<-ctx.Done\", \"tid:%v bctxid:%v err:%v\", tid, id, ContextErr(ctx))\n\t}\n\n\tif err = ContextErr(ctx); err != nil {\n\t\terr = &k6ext.UserFriendlyError{\n\t\t\tErr:     err,\n\t\t\tTimeout: b.browserOpts.Timeout,","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/browser.go#L517-L553","documentation":"newPageInContext opens a new tab by sending Target.createTarget(\"about:blank\") with the context id over CDP. This error wraps that createTarget call failing. The usual causes are target/memory exhaustion in the browser, the context already being disposed, or the browser closing/lost connection.","triggerScenarios":"Calling context.newPage() when the browser has too many targets or is out of memory; creating a page after the context or browser began closing; the WS connection dying before the command completes.","commonSituations":"Loops that open pages per iteration without closing them until Chromium hits its target/memory ceiling; memory-limited containers where tab creation fails; page creation racing test teardown.","solutions":["Call page.close() when done with each page and reuse a single context across iterations","Reduce simultaneous pages or raise the browser container's memory","Retry page creation once after a short delay for transient failures","Ensure the context and browser are still open before calling newPage()"],"exampleFix":"// before\nfor (const url of urls) {\n  const p = context.newPage();\n  p.goto(url); // pages never closed -> target exhaustion\n}\n\n// after\nconst p = context.newPage();\nfor (const url of urls) {\n  await p.goto(url);\n}\nawait p.close();","handlingStrategy":"retry","validationCode":"// Bound page creation and always release pages\nconst MAX_PAGES = 10;\nlet openPages = 0;\nfunction newPage(ctx) {\n  if (openPages >= MAX_PAGES) throw new Error(`Page budget exhausted (${MAX_PAGES}); close pages first`);\n  openPages++;\n  return ctx.newPage();\n}","typeGuard":null,"tryCatchPattern":"try {\n  page = context.newPage();\n} catch (e) {\n  if (String(e).includes('creating a new blank page')) {\n    // target/memory exhaustion or closing race: close stale pages, brief pause, retry once\n    await sleep(1000);\n    page = context.newPage();\n  } else throw e;\n}","preventionTips":["Close every page when finished; reuse one page across navigations where possible","Cap pages per context and per iteration","Size browser container memory for peak tab count"],"tags":["cdp","page-creation","memory-exhaustion","browser","resource-leak"],"backgroundTag":"page-creation-failed","analyzedSha":"3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}