{"record":{"id":"96abb81f682c8777","repo":"grafana/k6","slug":"getting-page-title-expected-string-got-t","errorCode":null,"errorMessage":"getting page title: expected string, got %T","messagePattern":"getting page title: expected string, got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1803,"sourceCode":"\n// Timeout will return the default timeout or the one set by the user.\n// It's an internal method not to be exposed as a JS API.\nfunc (p *Page) Timeout() time.Duration {\n\treturn p.defaultTimeout()\n}\n\n// Title returns the page title.\nfunc (p *Page) Title() (string, error) {\n\tp.logger.Debugf(\"Page:Title\", \"sid:%v\", p.sessionID())\n\n\tjs := `() => document.title`\n\tv, err := p.Evaluate(js)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"getting page title: %w\", err)\n\t}\n\ts, ok := v.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"getting page title: expected string, got %T\", v)\n\t}\n\n\treturn s, nil\n}\n\n// ThrottleCPU will slow the CPU down from chrome's perspective to simulate\n// a test being run on a slower device.\nfunc (p *Page) ThrottleCPU(cpuProfile CPUProfile) error {\n\tp.logger.Debugf(\"Page:ThrottleCPU\", \"sid:%v\", p.sessionID())\n\n\tp.frameSessionsMu.RLock()\n\tdefer p.frameSessionsMu.RUnlock()\n\n\tfor _, fs := range p.frameSessions {\n\t\tif err := fs.throttleCPU(cpuProfile); err != nil {\n\t\t\treturn err\n\t\t}\n\t}","sourceCodeStart":1785,"sourceCodeEnd":1821,"githubUrl":"https://github.com/grafana/k6/blob/3fcf5388d78cb382f0c0d42ec556a06bfd1b8dee/internal/js/modules/k6/browser/common/page.go#L1785-L1821","documentation":"Thrown by Page.Title() when the result of evaluating `() => document.title` is not a Go string. In JavaScript document.title is always a string, so in practice this type assertion (v.(string)) fails only when the evaluation returns a non-string sobek/Go value — for example an error object or a serialized wrapper from the evaluation bridge. It is a defensive invariant check, not an expected runtime condition.","triggerScenarios":"The Evaluate call succeeds but returns a value that is not a string — e.g. undefined/null leaked through an evaluation bridge bug, or a sobek value wrapper that does not convert to string. Extremely rare; indicates a k6/browser bridge issue rather than a user-script problem.","commonSituations":"Almost never seen in normal use; if it appears, it usually coincides with a k6 browser module version regression or an exotic page whose title evaluation returns a proxy/undefined during teardown.","solutions":["Upgrade to the latest k6 release — this indicates the evaluation bridge returned an unexpected type, likely a fixed bug.","Reproduce with a minimal script (page.goto + page.title()) and report it with the k6 version to the k6 issue tracker.","As a workaround, read the title via page.evaluate(() => document.title) and coerce with String() in your script."],"exampleFix":"// before\nconst title = page.title(); // internal assertion failure\n\n// after (workaround in test script)\nconst title = String(page.evaluate(() => document.title));","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let title;\ntry {\n  title = page.title();\n} catch (e) {\n  if (/expected string/i.test(String(e))) {\n    title = String(page.evaluate(() => document.title)); // fallback read\n  } else throw e;\n}","preventionTips":["Keep k6 updated — this assertion failing indicates a module regression.","Prefer page.evaluate(() => document.title) in scripts that must never fail on the wrapper."],"tags":["k6","browser","type-assertion","page-title"],"backgroundTag":"unexpected-result-type","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"}