grafana/k6 · warning
getting frame title: expected string, got %T
Error message
getting frame title: expected string, got %T
What it means
Type-check failure in frame.Title(): document.title evaluated successfully but to a non-string value. In a normal document title is always a string, so this only happens when page scripts redefine the title property (Object.defineProperty / getter) to return a non-string, or via a protocol anomaly.
Solutions
- Check what the page actually returns: page.evaluate('() => typeof document.title')
- If page scripts redefine title, read it defensively via evaluate and String() the result
- Update k6 to rule out a serialization bug
- Report to grafana/k6 if it reproduces on a clean page
Example fix
// defensive read
const t = page.evaluate('() => String(document.title)'); Defensive patterns
Strategy: try-catch
Validate before calling
const titleType = page.evaluate('() => typeof document.title');
if (titleType !== 'string') throw new Error(`document.title is ${titleType}; page redefined it`); Type guard
const isTitle = (v) => typeof v === 'string';
Try / catch
let title = '';
try {
title = page.title();
} catch (e) {
if (String(e).includes('expected string')) {
title = String(page.evaluate('() => document.title'));
} else { throw e; }
} Prevention
- On pages that redefine document.title, read it via evaluate and stringify
When it happens
Trigger: Page JavaScript overrides document.title with a getter returning a number/object; or a Chromium/k6 serialization anomaly returns a non-string remote value.
Common situations: Anti-automation or exotic SPA code redefining document.title; otherwise practically never seen.
Related errors
- an error occurred communicating with the provisioning API
- checking is in viewport: unexpected type %T
- Error while parsing selector
- failed to authenticate with k6 Cloud
- getting attribute of element: unexpected type %T (expecting…
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/f7c9dc44e077d5e6.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:1902
// Timeout will return the default timeout or the one set by the user.
// It's an internal method not to be exposed as a JS API.
func (f *Frame) Timeout() time.Duration {
return f.defaultTimeout()
}
// Title returns the title of the frame.
func (f *Frame) Title() (string, error) {
f.log.Debugf("Frame:Title", "fid:%s furl:%q", f.ID(), f.URL())
js := `() => document.title`
v, err := f.Evaluate(js)
if err != nil {
return "", fmt.Errorf("getting frame title: %w", err)
}
s, ok := v.(string)
if !ok {
return "", fmt.Errorf("getting frame title: expected string, got %T", v)
}
return s, nil
}
// Type text on the first element found matches the selector.
func (f *Frame) Type(selector, text string, popts *FrameTypeOptions) error {
f.log.Debugf("Frame:Type", "fid:%s furl:%q sel:%q text:%q", f.ID(), f.URL(), selector, text)
if err := f.typ(selector, text, popts); err != nil {
return fmt.Errorf("typing %q in %q: %w", text, selector, err)
}
applySlowMo(f.ctx)
return nil
}
View on GitHub (pinned to 3fcf5388d7)