grafana/k6 · error
setting HTTP credentials in target ID
Error message
setting HTTP credentials in target ID %s: %w
What it means
Thrown by the deprecated SetHTTPCredentials: it stores credentials on the context and then calls updateHTTPCredentials (Network.setExtraHTTPHeaders) on every existing page; the page named by targetID failed. k6 also logs a deprecation warning because this API is scheduled for removal — the replacement is the httpCredentials option of browser.newContext().
Solutions
- Replace setHTTPCredentials with browser.newContext({ httpCredentials: { username, password } }) — this is the supported path and applies before pages exist
- If you must use the deprecated call, do it immediately after newContext() while no pages are open
- Ensure pages in the context are alive when the call runs
- Wrap in try/catch if it lives on a cleanup path
Example fix
// before
const ctx = browser.newContext();
const page = ctx.newPage();
ctx.setHTTPCredentials({ username: 'u', password: 'p' }); // deprecated, per-page update can fail
// after
const ctx = browser.newContext({ httpCredentials: { username: 'u', password: 'p' } });
const page = ctx.newPage(); Defensive patterns
Strategy: fallback
Validate before calling
// supported replacement: credentials via context options, applied before pages exist
const ctx = browser.newContext({
httpCredentials: { username: 'u', password: 'p' },
});
const page = ctx.newPage(); Prevention
- Migrate off setHTTPCredentials — it is deprecated and will be removed
- If credentials must change, create a new context with new httpCredentials instead of updating the old one
- Never call deprecated per-page updaters when pages are closing
When it happens
Trigger: browserContext.setHTTPCredentials({ username, password }) while some page in the context has a dead CDP session, or after the browser connection dropped; calling it after pages were closed.
Common situations: Legacy scripts from before the httpCredentials option existed; basic-auth setups where credentials change mid-run; cleanup ordering where the call lands after teardown of pages.
Related errors
- adding init script to browser context
- can't fetch the page for unknown reason
- cannot set cookies
- capturing screenshot
- clearing permissions
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/874763afcceddab7.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:322
return nil
}
// SetHTTPCredentials sets username/password credentials to use for HTTP authentication.
//
// Deprecated: Create a new BrowserContext with httpCredentials instead.
// See for details:
// - https://github.com/microsoft/playwright/issues/2196#issuecomment-627134837
// - https://github.com/microsoft/playwright/pull/2763
func (b *BrowserContext) SetHTTPCredentials(hc Credentials) error {
b.logger.Warnf("setHTTPCredentials", "setHTTPCredentials is deprecated."+
" Create a new BrowserContext with httpCredentials instead.")
b.logger.Debugf("BrowserContext:SetHTTPCredentials", "bctxid:%v", b.id)
b.opts.HTTPCredentials = hc
for _, p := range b.browser.getPages() {
if err := p.updateHTTPCredentials(); err != nil {
return fmt.Errorf("setting HTTP credentials in target ID %s: %w", p.targetID, err)
}
}
return nil
}
// SetOffline toggles the browser's connectivity on/off.
func (b *BrowserContext) SetOffline(offline bool) error {
b.logger.Debugf("BrowserContext:SetOffline", "bctxid:%v offline:%t", b.id, offline)
b.opts.Offline = offline
for _, p := range b.browser.getPages() {
if err := p.updateOffline(); err != nil {
return fmt.Errorf(
"setting offline status to %t for the browser context ID %s: %w",
offline, b.id, err,
)
}View on GitHub (pinned to 01ffac6f24)