grafana/k6 · error
getting frame title: %w
Error message
getting frame title: %w
What it means
Frame.Title() evaluates `() => document.title` in the frame; an evaluation failure is wrapped as 'getting frame title: <cause>'. The cause is a frame/execution-context problem — navigating, detached, closed, or the k6 context cancelled — since document.title itself cannot throw.
Source
Thrown at internal/js/modules/k6/browser/common/frame.go:1890
}
return s, true, nil
}
// 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)View on GitHub (pinned to 93accf6570)
Solutions
- Wait for load state before reading the title: await page.waitForLoadState('load').
- Skip frames that are detached or about:blank/sandboxed ad frames when iterating page.frames().
- Retry once — titles are read-many times and transient context gaps resolve quickly.
Example fix
// before
for (const f of page.frames()) console.log(await f.title()); // ad frames detach
// after
for (const f of page.frames()) {
if (f !== page.mainFrame() && f.url() === 'about:blank') continue;
console.log(await f.title().catch(() => '<no title>'));
} Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('page closed');
await page.waitForLoadState('load'); Try / catch
try { return await frame.title(); }
catch (e) { if (/getting frame title/.test(e.message)) { return ''; } throw e; } Prevention
- Wait for load state before reading titles
- Skip detached/blank iframes when iterating frames
- Default titles to empty string on failure rather than failing the iteration
When it happens
Trigger: frame.title() during navigation before the new context is ready; on a detached iframe; after page.close(); when the iteration's context is cancelled by k6 timeouts.
Common situations: Calling title() immediately after goto() while redirects settle; harvesting titles for every frame in page.frames() when some iframes are ad placeholders that detach constantly.
Related errors
- getting document element handle: %w
- getting document: %w
- setting content: %w
- missing required argument 'url'
- getting injected script: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/34354da6793a11c8.
Report an issue: GitHub.