Connect+Documentation
ExtensionsAPI reference

connect.net

Content blocking — adblock-tier control plus your own declarative (DNR) rules.

Content blocking, in two halves — both per-profile. Adblock-tier control is a facade over Connect+'s own adblocker; declarative rules are your own DNR-equivalent block/allow/redirect rules that run ahead of the adblocker.

  • Capabilities: net.observe (read-only status), net.block (toggle + rules)
  • Namespace: connect.net

Walkthrough

Block a tracker with a declarative rule.

  1. Declare net.block (or just net.observe if you only read status):
    { "capabilities": ["net.block"] }
  2. Add a rule — an all-or-nothing batch:
    await connect.net.updateRules({ addRules: [{
      id: 1, priority: 1, action: { type: 'block' },
      condition: { urlFilter: '||doubleclick.net^', resourceTypes: ['script', 'image'] },
    }]});
  3. Read status any time with status().
  4. Remember rules are cleared on uninstall.

Methods

net.status()

Read adblock status.

How to use it

  1. Call it to read { enabled, siteTiers } — needs only net.observe.

Signatureconnect.net.status() · Capability: net.observe

ReturnsPromise<{ enabled, siteTiers }>.

net.setEnabled(enabled)

Master adblock toggle for the profile.

How to use it

  1. Pass true / false to turn the profile's adblocker on / off.

Signatureconnect.net.setEnabled(enabled) · Capability: net.block

Parameters

ParameterTypeRequiredDescription
enabledbooleanyesTurn the profile's adblocker on/off.

ReturnsPromise<void>.

net.setSiteTier(host, tier)

Set the blocking tier for one site.

How to use it

  1. Pass a host and a tier ('full' / 'essential' / 'off').

Signatureconnect.net.setSiteTier(host, tier) · Capability: net.block

Parameters

ParameterTypeRequiredDescription
hoststringyesThe site.
tier'full' | 'essential' | 'off'yesHow aggressively to block on it.

ReturnsPromise<void>.

net.getRules()

Read your declarative rules.

How to use it

  1. Call it to see your current rule set (e.g. to compute a diff before updateRules).

Signatureconnect.net.getRules() · Capability: net.block · Returns Promise<Rule[]>.

net.updateRules(changes)

Add and/or remove declarative rules — an all-or-nothing batch.

How to use it

  1. Build removeRuleIds and/or addRules (each rule needs a unique id).
  2. await the batch — it all applies or none does.
  3. Keep under 5000 rules per extension.

Signatureconnect.net.updateRules({ removeRuleIds?, addRules? }) · Capability: net.block

Parameters

ParameterTypeRequiredDescription
removeRuleIdsnumber[]noRule ids to remove first.
addRulesRule[]noRules to add. Max 5000 per extension.

ReturnsPromise<void>. The whole batch applies or none of it does.

A rule (DNR subset)

FieldTypeDescription
idnumberUnique per extension.
prioritynumberHigher wins.
action.type'block' | 'allow' | 'redirect'What to do.
condition.urlFilterstringMatch pattern, e.g. ||doubleclick.net^.
condition.resourceTypesstring[]e.g. ['script', 'image'].
await connect.net.updateRules({
  addRules: [{
    id: 1, priority: 1,
    action: { type: 'block' },
    condition: { urlFilter: '||doubleclick.net^', resourceTypes: ['script', 'image'] },
  }],
});

Notes

  • Declarative rules run before the built-in adblocker and are cleared on uninstall (they live on the request hot path).
  • Reading status needs only net.observe; anything that changes behaviour needs net.block.

On this page