{"record":{"id":"f26b42f0934a3f6b","repo":"grafana/k6","slug":"hostname-s-matches-a-blocked-pattern-q","errorCode":null,"errorMessage":"hostname %s matches a blocked pattern %q","messagePattern":"hostname (.+?) matches a blocked pattern %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":729,"sourceCode":"\t\treturn\n\t}\n\n\t// Do one last check of the resolved IP\n\tip, err = m.resolver.LookupIP(host)\n\tif err != nil {\n\t\tm.logger.Debugf(\"NetworkManager:onRequestPaused\",\n\t\t\t\"resolving %q: %s\", host, err)\n\t\treturn\n\t}\n\tfailErr = checkBlockedIPs(ip, state.Options.BlacklistIPs)\n}\n\nfunc checkBlockedHosts(host string, blockedHosts *k6types.HostnameTrie) error {\n\tif blockedHosts == nil {\n\t\treturn nil\n\t}\n\tif match, blocked := blockedHosts.Contains(host); blocked {\n\t\treturn fmt.Errorf(\"hostname %s matches a blocked pattern %q\", host, match)\n\t}\n\treturn nil\n}\n\nfunc checkBlockedIPs(ip net.IP, blockedIPs []*k6lib.IPNet) error {\n\tfor _, ipnet := range blockedIPs {\n\t\tif ipnet.Contains(ip) {\n\t\t\t// TODO: Return netext.BlackListedIPError here once its private\n\t\t\t// fields are exported, or there's a constructor for it.\n\t\t\treturn fmt.Errorf(\"IP %s is in a blacklisted range %q\", ip, ipnet)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (m *NetworkManager) onAuthRequired(event *fetch.EventAuthRequired) {\n\tvar (\n\t\tres = fetch.AuthChallengeResponseResponseDefault","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L711-L747","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["If the request should succeed, remove or narrow the matching pattern in options.blockedHostnames","Use precise patterns: block 'ads.example.com' rather than '*.example.com' when subdomains of the app must load","If blocking is intentional, treat the failed request as expected (assert it was blocked rather than catching it as an error)","Check both the script's export const options and externally applied options (--config, environment, cloud) for stray block lists"],"exampleFix":"// before\nexport const options = { blockedHostnames: ['*.example.com'] }; // blocks app itself\n\n// after\nexport const options = { blockedHostnames: ['ads.example.com', 'tracker.example.com'] };","handlingStrategy":"validation","validationCode":"// mirror the block list before the request and branch deliberately\nconst BLOCKED = ['ads.example.com', 'tracker.example.com'];\nfunction isBlocked(host) {\n  return BLOCKED.some(p =>\n    p.startsWith('*.') ? host.endsWith(p.slice(1)) : host === p\n  );\n}\nif (isBlocked(new URL(targetUrl).hostname)) {\n  console.warn('expected block:', targetUrl);\n}","typeGuard":"function isBlockedHost(host, patterns) {\n  return patterns.some(p =>\n    p.startsWith('*.') ? host.endsWith(p.slice(1)) : host === p\n  );\n}","tryCatchPattern":"try {\n  await page.goto(url);\n} catch (e) {\n  if (/matches a blocked pattern/i.test(e.message)) {\n    // intentional: assert the block instead of failing the test\n    console.warn('blocked as configured:', e.message);\n  } else throw e;\n}","preventionTips":["Keep block lists next to the scenarios that need them","Prefer exact hostnames over wildcards unless domain-wide blocking is intended","Assert blocked requests as pass conditions, not errors","Audit merged options (--config, env, cloud) for inherited block lists"],"tags":["browser","network","blocklist","config","hostnames"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}