{"record":{"id":"5b7dd38c3d2dfdd7","repo":"grafana/k6","slug":"navigating-s-to-history-entry-d-w","errorCode":null,"errorMessage":"navigating %s to history entry %d: %w","messagePattern":"navigating (.+?) to history entry (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1664,"sourceCode":"\ttargetURL := entries[targetIndex].URL\n\n\ttimeoutCtx, timeoutCancelFn := context.WithTimeout(p.ctx, opts.Timeout)\n\tdefer timeoutCancelFn()\n\n\tnavAction := page.NavigateToHistoryEntry(historyEntryID)\n\tif err := navAction.Do(cdp.WithExecutor(p.ctx, p.session)); err != nil {\n\t\treturn nil, fmt.Errorf(\"navigating to history entry %d: %w\", historyEntryID, err)\n\t}\n\n\twrapTimeoutError := func(err error) error {\n\t\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t\terr = &k6ext.UserFriendlyError{\n\t\t\t\tErr:     err,\n\t\t\t\tTimeout: opts.Timeout,\n\t\t\t}\n\t\t}\n\t\tp.logger.Debugf(\"Page:GoBackForward\", \"timeoutCtx done: %v\", err)\n\t\treturn fmt.Errorf(\"navigating %s to history entry %d: %w\", direction, historyEntryID, err)\n\t}\n\n\t// Poll for URL change, don't rely on lifecycle events since bfcache\n\t// restorations don't re-fire them.\n\tticker := time.NewTicker(50 * time.Millisecond)\n\tdefer ticker.Stop()\n\n\tfor {\n\t\tselect {\n\t\tcase <-p.ctx.Done():\n\t\t\treturn nil, ContextErr(p.ctx)\n\t\tcase <-timeoutCtx.Done():\n\t\t\treturn nil, wrapTimeoutError(ContextErr(timeoutCtx))\n\t\tcase <-ticker.C:\n\t\t\tmainFrame := p.frameManager.MainFrame()\n\t\t\tif mainFrame == nil {\n\t\t\t\tcontinue\n\t\t\t}","sourceCodeStart":1646,"sourceCodeEnd":1682,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/page.go#L1646-L1682","documentation":"This error is returned by Page.GoBack/GoForward (page.go history navigation) when the CDP call Page.navigate_to_history_entry fails while moving the page to a target index in the session history. The '%s' is the target URL taken from the history entries list and '%d' the history entry ID; failure usually means the browser target was closed, the navigation was interrupted, or the underlying CDP session dropped. A separate timeout wrapper converts deadline overruns into a k6ext.UserFriendlyError, so this specific wrap is for non-timeout protocol failures.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/page.go:1659 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the browser tab/target is still open before calling goBack/goForward","Retry the navigation after waiting for the page to reach a stable lifecycle state","Increase the navigation timeout option if the failure is caused by an overruns of the per-call deadline","Check that no other code (e.g. page.close()) races with the history navigation"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}