grafana/k6 · error
updating extra HTTP headers: %w
Error message
updating extra HTTP headers: %w
What it means
Page.updateExtraHTTPHeaders fans out Network.setExtraHTTPHeaders to every frame session attached to the page, and this error is returned when any one of those CDP calls fails. It wraps the underlying frame-session failure, so the extra-headers state may be applied inconsistently across frames.
Source
Thrown at internal/js/modules/k6/browser/common/page.go:840
Width: int64(viewportSize.Width),
Height: int64(viewportSize.Height),
}
screen := Screen{
Width: int64(viewportSize.Width),
Height: int64(viewportSize.Height),
}
return p.setEmulatedSize(NewEmulatedSize(viewport, screen))
}
func (p *Page) updateExtraHTTPHeaders() error {
p.logger.Debugf("Page:updateExtraHTTPHeaders", "sid:%v", p.sessionID())
p.frameSessionsMu.RLock()
defer p.frameSessionsMu.RUnlock()
for _, fs := range p.frameSessions {
if err := fs.updateExtraHTTPHeaders(false); err != nil {
return fmt.Errorf("updating extra HTTP headers: %w", err)
}
}
return nil
}
func (p *Page) updateGeolocation() error {
p.logger.Debugf("Page:updateGeolocation", "sid:%v", p.sessionID())
p.frameSessionsMu.RLock()
defer p.frameSessionsMu.RUnlock()
for _, fs := range p.frameSessions {
p.logger.Debugf("Page:updateGeolocation:frameSession",
"sid:%v tid:%v wid:%v",
p.sessionID(), fs.targetID, fs.windowID)
if err := fs.updateGeolocation(false); err != nil {View on GitHub (pinned to 93accf6570)
Solutions
- Call page.setExtraHTTPHeaders before navigation completes or after load state is reached, not during
- Verify the page is not closing (page.isClosed()) before the call
- Retry the call once after a brief wait if it raced with iframe attachment
- Check browser logs for target crashes if it persists
Example fix
// before
await page.goto('https://example.com/');
await page.setExtraHTTPHeaders({'X-Test': '1'}); // iframes may still be attaching
// after
await page.goto('https://example.com/', { waitUntil: 'networkidle' });
await page.setExtraHTTPHeaders({'X-Test': '1'}); Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('cannot set headers on closed page'); Try / catch
try {
await page.setExtraHTTPHeaders(headers);
} catch (e) {
if (/updating extra HTTP headers/.test(e.message)) { await page.waitForTimeout(250); await page.setExtraHTTPHeaders(headers); }
else throw e;
} Prevention
- Set extra headers before goto or after networkidle, never mid-attach of iframes
- Keep header values as strings; non-string values can push invalid CDP payloads
When it happens
Trigger: page.setExtraHTTPHeaders({...}) on a page that has iframes (multiple frame sessions), where one frame's session is detached/closed, the page is navigating during the call, or the browser target is gone.
Common situations: Setting extra headers right after page.goto while an iframe is still attaching; calling it on a page whose browser context is being torn down; browser crashed mid-test.
Related errors
- getting iframe frame: %w
- getting remote node %q: %w
- updating extra HTTP headers: %w
- getting frame owner: %w
- updating page frame sessions to offline: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/9c3708d0021fe39e.
Report an issue: GitHub.