{"record":{"id":"fcbf47a2fe256bca","repo":"grafana/k6","slug":"bringing-page-to-front-w","errorCode":null,"errorMessage":"bringing page to front: %w","messagePattern":"bringing page to front: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":913,"sourceCode":"\t}\n\n\treturn nil\n}\n\nfunc (p *Page) viewportSize() Size {\n\treturn Size{\n\t\tWidth:  float64(p.emulatedSize.Viewport.Width),\n\t\tHeight: float64(p.emulatedSize.Viewport.Height),\n\t}\n}\n\n// BringToFront activates the browser tab for this page.\nfunc (p *Page) BringToFront() error {\n\tp.logger.Debugf(\"Page:BringToFront\", \"sid:%v\", p.sessionID())\n\n\taction := page.BringToFront()\n\tif err := action.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {\n\t\treturn fmt.Errorf(\"bringing page to front: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// SetChecked sets the checked state of the element matching the provided selector.\nfunc (p *Page) SetChecked(selector string, checked bool, popts *FrameCheckOptions) error {\n\tp.logger.Debugf(\"Page:SetChecked\", \"sid:%v selector:%s checked:%t\", p.sessionID(), selector, checked)\n\n\treturn p.MainFrame().SetChecked(selector, checked, popts)\n}\n\n// Check checks an element matching the provided selector.\nfunc (p *Page) Check(selector string, popts *FrameCheckOptions) error {\n\tp.logger.Debugf(\"Page:Check\", \"sid:%v selector:%s\", p.sessionID(), selector)\n\n\treturn p.MainFrame().Check(selector, popts)\n}","sourceCodeStart":895,"sourceCodeEnd":931,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/page.go#L895-L931","documentation":"Page.BringToFront executes the CDP Page.bringToFront command and wraps any protocol-level failure. The command activates the browser tab for this page; it fails when the target no longer accepts commands (closed/crashed tab) or the CDP session is detached.","triggerScenarios":"page.bringToFront() after the tab was closed manually or programmatically, after a browser crash, or while the page's session is being torn down at test end.","commonSituations":"Calling bringToFront() on a stale page handle reused across iterations; headless environments where the target was already destroyed; scripts that close pages early then continue interacting.","solutions":["Check page.isClosed() before calling bringToFront()","Re-acquire the page handle (newPage) instead of reusing one from a previous iteration","Confirm the browser process is still alive (check for earlier errors in the log)","Drop the call if the tab activation is not required for the test logic"],"exampleFix":"// before\nawait page.close();\nawait page.bringToFront(); // session already gone\n\n// after\nif (!page.isClosed()) {\n  await page.bringToFront();\n}","handlingStrategy":"validation","validationCode":"if (!page.isClosed()) await page.bringToFront();","typeGuard":null,"tryCatchPattern":"try { await page.bringToFront(); } catch (e) { if (!/bringing page to front/.test(e.message)) throw e; }","preventionTips":["Always gate tab commands on page.isClosed()","Never reuse page handles across k6 iterations"],"tags":["browser","cdp","tab-management","page-lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}