{"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":540,"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":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser.go#L522-L558","documentation":"Wraps the failure of the CDP Target.createTarget call that browserContext.newPage() (and browser.newPage()) issues to open a blank page inside the given browser context (browser.go:540). The %w chain carries the underlying CDP/transport error, so the real cause — lost connection, invalid browser context ID, target limit, crashed browser — is in the wrapped text.","triggerScenarios":"The chromium process or its CDP websocket is already dead (crash, OOM-kill, browser.close() already called); creating a page in a context that was just disposed; hitting chromium's target/tab limit under high parallelism; container running out of /dev/shm or file descriptors.","commonSituations":"Containers without --shm-size or memory limits where chromium dies mid-test; calling newPage() after closing the context or browser; many VUs each opening pages; a stale K6_BROWSER_EXECUTABLE_PATH pointing at an incompatible chromium build.","solutions":["Read the wrapped error: 'connection closed'/'context canceled' means chromium died — find out why (dmesg/OOM, K6_BROWSER_LOG=debug)","Raise container resources (--shm-size=1g, more memory) or reduce VUs/pages if chromium is being killed","Verify newPage() is not called on a closed context or after browser.close()","Align K6_BROWSER_EXECUTABLE_PATH with a chromium version supported by your k6 release and keep k6 updated"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// create pages while the browser/context is definitely open, early in the iteration\n// const page = ctx.newPage() — do this before heavy load, not after possible crashes","typeGuard":null,"tryCatchPattern":"try {\n  page = await ctx.newPage()\n} catch (e) {\n  if (/creating a new blank page/.test(String(e)) && /connection|target closed/i.test(String(e))) {\n    // chromium died — abort this iteration; a retry needs a new browser\n    throw e\n  }\n  throw e\n}","preventionTips":["Watch container memory and shm; chromium death is the dominant cause","Never call newPage() on a closed context or after browser.close()","Cap pages per VU to avoid target limits"],"tags":["cdp","new-page","browser-crash","resources","container"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}