c15t
Version:
Headless JavaScript consent management platform for cookie banners, privacy preferences, consent storage, and script gating.
73 lines (48 loc) • 2.46 kB
Markdown
---
title: Network Blocker
description: Reference page for network blocker.
group: reference
---
The network blocker intercepts outgoing `fetch` and `XMLHttpRequest` calls and blocks them based on consent state and domain rules. This catches tracking requests that happen outside of script loading - for example, beacon calls, API requests to analytics endpoints, or pixel fires from already-loaded scripts.
Rules match requests using three criteria:
The `domain` field matches the request hostname. Subdomains are automatically included - a rule for `google-analytics.com` also matches `www.google-analytics.com` and `stats.google-analytics.com`.
The optional `pathIncludes` field requires the request URL path to contain the specified substring. This lets you target specific endpoints without blocking the entire domain.
The optional `methods` array restricts the rule to specific HTTP methods. If omitted, the rule applies to all methods.
Like the script loader, `category` accepts a `HasCondition`:
```tsx
// Simple
{ category: 'measurement' }
// Must have both
{ category: { and: ['measurement', 'marketing'] } }
// Must have either
{ category: { or: ['measurement', 'marketing'] } }
```
Blocked requests are logged to the console by default. Disable with `logBlockedRequests: false`.
Use `onRequestBlocked` to handle blocked requests programmatically:
```tsx
networkBlocker: {
rules: [...],
onRequestBlocked: ({ method, url, rule }) => {
console.log(`Blocked ${method} ${url} (rule: ${rule?.id})`);
},
}
```
|Property|Value|
|:--|:--|
|Type Name|\`NetworkBlockerRule\`|
|Source Path|\`./packages/core/src/libs/network-blocker/types.ts\`|
\*ExtractedTypeTable: Could not extract "NetworkBlockerRule" from "./packages/core/src/libs/network-blocker/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|Property|Value|
|:--|:--|
|Type Name|\`NetworkBlockerConfig\`|
|Source Path|\`./packages/core/src/libs/network-blocker/types.ts\`|
\*ExtractedTypeTable: Could not extract "NetworkBlockerConfig" from "./packages/core/src/libs/network-blocker/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*