grafana/k6 · warning

hostname %s matches a blocked pattern %q

Error message

hostname %s matches a blocked pattern %q

What it means

Returned by checkBlockedHosts when a request's hostname matches a pattern in the k6 options blockedHostnames trie. This is intentional enforcement, not a malfunction: the browser NetworkManager intercepts paused requests, resolves the host, and fails any request whose hostname matches a blocked pattern so the page behaves as if the network call was refused.

Source

Thrown at internal/js/modules/k6/browser/common/network_manager.go:729

		return
	}

	// Do one last check of the resolved IP
	ip, err = m.resolver.LookupIP(host)
	if err != nil {
		m.logger.Debugf("NetworkManager:onRequestPaused",
			"resolving %q: %s", host, err)
		return
	}
	failErr = checkBlockedIPs(ip, state.Options.BlacklistIPs)
}

func checkBlockedHosts(host string, blockedHosts *k6types.HostnameTrie) error {
	if blockedHosts == nil {
		return nil
	}
	if match, blocked := blockedHosts.Contains(host); blocked {
		return fmt.Errorf("hostname %s matches a blocked pattern %q", host, match)
	}
	return nil
}

func checkBlockedIPs(ip net.IP, blockedIPs []*k6lib.IPNet) error {
	for _, ipnet := range blockedIPs {
		if ipnet.Contains(ip) {
			// TODO: Return netext.BlackListedIPError here once its private
			// fields are exported, or there's a constructor for it.
			return fmt.Errorf("IP %s is in a blacklisted range %q", ip, ipnet)
		}
	}
	return nil
}

func (m *NetworkManager) onAuthRequired(event *fetch.EventAuthRequired) {
	var (
		res = fetch.AuthChallengeResponseResponseDefault

View on GitHub (pinned to 93accf6570)

Solutions

  1. If the request should succeed, remove or narrow the matching pattern in options.blockedHostnames
  2. Use precise patterns: block 'ads.example.com' rather than '*.example.com' when subdomains of the app must load
  3. If blocking is intentional, treat the failed request as expected (assert it was blocked rather than catching it as an error)
  4. Check both the script's export const options and externally applied options (--config, environment, cloud) for stray block lists

Example fix

// before
export const options = { blockedHostnames: ['*.example.com'] }; // blocks app itself

// after
export const options = { blockedHostnames: ['ads.example.com', 'tracker.example.com'] };
Defensive patterns

Strategy: validation

Validate before calling

// mirror the block list before the request and branch deliberately
const BLOCKED = ['ads.example.com', 'tracker.example.com'];
function isBlocked(host) {
  return BLOCKED.some(p =>
    p.startsWith('*.') ? host.endsWith(p.slice(1)) : host === p
  );
}
if (isBlocked(new URL(targetUrl).hostname)) {
  console.warn('expected block:', targetUrl);
}

Type guard

function isBlockedHost(host, patterns) {
  return patterns.some(p =>
    p.startsWith('*.') ? host.endsWith(p.slice(1)) : host === p
  );
}

Try / catch

try {
  await page.goto(url);
} catch (e) {
  if (/matches a blocked pattern/i.test(e.message)) {
    // intentional: assert the block instead of failing the test
    console.warn('blocked as configured:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: options.blockedHostnames contains a pattern (e.g. '*.ads.example', 'tracker.io') and the page under test requests a matching host; navigation itself to a blocked host also trips it. The hostname must fully match a trie entry, so subdomains of blocked domains match patterns with wildcards.

Common situations: Blocking ads/trackers/third-party analytics to speed up tests and isolate the target; accidentally broad patterns like '*.example.com' also blocking 'login.example.com'; copying block lists between scripts where the app itself is on a blocked domain; expecting fetch to succeed while the block list forbids it.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/f26b42f0934a3f6b. Report an issue: GitHub.