{"record":{"id":"7ea73479147d20e5","repo":"grafana/k6","slug":"internal-error-while-adding-binding-to-page-w","errorCode":null,"errorMessage":"internal error while adding binding to page: %w","messagePattern":"internal error while adding binding to page: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":359,"sourceCode":"\n\t\treturn nil, err\n\t}\n\tp.frameSessionsMu.Lock()\n\tp.frameSessions[cdp.FrameID(tid)] = p.mainFrameSession\n\tp.frameSessionsMu.Unlock()\n\tp.Mouse = NewMouse(ctx, s, p.frameManager.MainFrame(), bctx.timeoutSettings, p.Keyboard)\n\tp.Touchscreen = NewTouchscreen(ctx, s, p.Keyboard)\n\n\tp.initEvents()\n\n\taction := target.SetAutoAttach(true, true).WithFlatten(true)\n\tif err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"internal error while auto attaching to browser pages: %w\", err)\n\t}\n\n\tadd := runtime.AddBinding(webVitalBinding)\n\tif err := add.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"internal error while adding binding to page: %w\", err)\n\t}\n\n\tif err := bctx.applyAllInitScripts(&p); err != nil {\n\t\treturn nil, fmt.Errorf(\"internal error while applying init scripts to page: %w\", err)\n\t}\n\n\treturn &p, nil\n}\n\nfunc (p *Page) initEvents() {\n\tp.logger.Debugf(\"Page:initEvents\",\n\t\t\"sid:%v tid:%v\", p.session.ID(), p.targetID)\n\n\tevents := []string{\n\t\tcdproto.EventRuntimeConsoleAPICalled,\n\t}\n\tp.session.on(p.ctx, events, p.eventCh)\n","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/page.go#L341-L377","documentation":"During page creation the CDP command Runtime.addBinding — used to register the web-vitals binding so the page can report Web Vitals back to k6 — failed on the new page's session. It is an infrastructure failure at page-init time, immediately after SetAutoAttach in NewPage.","triggerScenarios":"Same class as 953: page creation proceeding while the target/session dies — browser crash, connection loss, or the target destroyed between creation and AddBinding. Any page creation after the browser module's connection is already broken hits this.","commonSituations":"First page creation after chromium died in a previous iteration but the module reused the connection; page churn racing close at iteration end; flaky remote browser connections.","solutions":["Treat it as a symptom: find the first CDP failure in DEBUG=k6-browser output and fix that (crash, disconnect, binary mismatch)","Ensure page creation is not racing context/browser close","If a remote browser is used, check its health and network path between k6 and the endpoint","Upgrade k6 so module and bundled chromium stay compatible"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Same pattern as page creation: bounded retry on transient session failure\ntry {\n  page = await browser.newPage();\n} catch (e) {\n  if (/adding binding to page/.test(String(e))) {\n    page = await browser.newPage(); // one retry on a fresh target\n  } else throw e;\n}","preventionTips":["Treat any page-init internal error as browser-health signal — check for prior crash/OOM","Avoid page creation bursts at iteration end","Verify remote browser endpoint stability when used"],"tags":["cdp","browser","page-creation","web-vitals","lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}