Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Extension Content Settings: Per-Site Rules, Privacy APIs, and Browser Setting Control

How Chrome extension APIs control per-site content settings, global privacy preferences, and ChromeSetting get, set, and levelOfControl.

This page summarises Chrome Extensions documentation for two related ways to change browser behaviour from an extension: the contentSettings API for per-site rules (cookies, JavaScript, camera, and similar), and the privacy API for global privacy-related Chrome preferences. Both build on the shared ChromeSetting pattern from types. Related settings such as proxy and accessibilityFeatures use the same ChromeSetting interface.

contentSettings API: what per-site rules control

Section titled “contentSettings API: what per-site rules control”

The contentSettings API changes settings that decide whether websites can use features such as cookies, JavaScript, and plugins. In plain terms, it lets an extension customise Chrome on a per-site basis instead of only globally.

Use the chrome.contentSettings API to change settings that control whether websites can use features such as cookies, JavaScript, and plugins. More generally speaking, content settings allow you to customize Chrome’s behavior on a per-site basis instead of globally.

— Chrome, contentSettings

Each content type is exposed as its own object (for example contentSettings.cookies, contentSettings.javascript). Every object supports get(), set(), and clear() at the API level, plus getResourceIdentifiers() where applicable. Declaring the contentSettings permission triggers a user warning (MV2 reference).

Primary and secondary URL patterns: which URL wins

Section titled “Primary and secondary URL patterns: which URL wins”

The URL used when choosing a content setting depends on the content type. For notifications, the primary URL is the URL shown in the omnibox. For cookies, Chrome uses the cookie origin as the primary URL and the top-level frame URL as the secondary URL.

If multiple rules have primary and secondary patterns, the rule with the more specific primary pattern takes precedence. If there multiple rules have the same primary pattern, the rule with the more specific secondary pattern takes precedence.

— Chrome, contentSettings

Precedence Primary pattern Secondary pattern
1 (highest) https://www.moose.com/* https://www.wombat.com/*
2 https://www.moose.com/* <all_urls>
3 <all_urls> https://www.wombat.com/*
4 (lowest) <all_urls> <all_urls>

Secondary patterns are not supported for the images content setting. When calling get(), pass primaryUrl and optionally secondaryUrl; meanings differ per content type (get parameters).

contentSettings get, set, and clear: rule lifecycle

Section titled “contentSettings get, set, and clear: rule lifecycle”
  • set(details) — applies a rule with primaryPattern, optional secondaryPattern, setting, optional scope, and optional resourceIdentifier.
  • get(details) — returns the effective setting for a URL pair; optional incognito checks Incognito session rules.
  • clear(details) — removes all content setting rules set by this extension; optional scope limits where clearing applies.

Pattern syntax is defined under Content Setting Patterns in the contentSettings reference. From Chrome 96+, these methods return promises when using the browser.* namespace (browser.contentSettings).

Content types: values, defaults, and deprecated settings

Section titled “Content types: values, defaults, and deprecated settings”

The first sentence under each type in the reference defines which URLs count as primary/secondary and which values (allow, block, ask, session_only, etc.) are valid.

Object Typical question Default Primary / secondary URL role
cookies Block or limit cookies for a site? allow Primary: cookie origin; secondary: top-level frame
javascript Disable JS on a site? allow Primary: top-level frame; no secondary
images Hide images? allow Primary: top-level frame; secondary: image URL
popups Allow pop-ups? block Primary: top-level frame; no secondary

cookies also supports session_only (accept cookies only for the current session).

Permissions-style settings (camera, microphone, location, notifications)

Section titled “Permissions-style settings (camera, microphone, location, notifications)”

These usually default to ask. Primary URL is typically the document that requested access; for location, the secondary URL is the top-level frame (which may differ from the requesting document).

clipboard, automaticDownloads, and autoVerify

Section titled “clipboard, automaticDownloads, and autoVerify”
  • clipboard (Chrome 121+): controls advanced Async Clipboard capabilities (read, custom formats, write without user gesture). Default ask.
  • automaticDownloads: allow, block, or ask for multiple automatic downloads; default ask; primary is top-level frame.
  • autoVerify (Chrome 113+): Private State Tokens API; when calling set(), the primary pattern must be <all_urls>.

Do not build new features on these; calls may be ignored or values are fixed:

Setting Status
fullscreen, mouselock Deprecated; always allow
plugins, unsandboxedPlugins Deprecated since Flash removal (Chrome 88); always block; set() / clear() ignored for plugins

Resource identifiers target subtypes of a content type. Only contentSettings.plugins used them (for example adobe-flash-player). A rule with a resource identifier can outrank a more specific URL pattern without an identifier. List identifiers via getResourceIdentifiers() — the list can change with installed plugins (Resource identifiers).

privacy API: global Chrome privacy and service settings

Section titled “privacy API: global Chrome privacy and service settings”

The privacy API controls Chrome features that affect privacy. It relies on the ChromeSetting prototype from types.

Use the chrome.privacy API to control usage of the features in Chrome that can affect a user’s privacy. This API relies on the ChromeSetting prototype of the type API for getting and setting Chrome’s configuration.

— Chrome, privacy

Settings are grouped into network, services, and websites on browser.privacy (and chrome.privacy in MV2).

  • networkPredictionEnabled — when enabled, Chrome pre-resolves DNS, opens TCP/SSL early, and preloads pages. Disabling overrides site speculative loading via Speculation Rules; it does not affect page-initiated preconnects or DNS prefetch. Default true.
  • webRTCIPHandlingPolicy — trade-off between WebRTC performance and exposure of local addresses (IPHandlingPolicy, default default).

privacy.services: Google and search-provider features

Section titled “privacy.services: Google and search-provider features”

Boolean toggles include safeBrowsingEnabled, passwordSavingEnabled, searchSuggestEnabled (Omnibox text sent to default search engine), translationServiceEnabled, autofillAddressEnabled, autofillCreditCardEnabled, and others. autofillEnabled is deprecated since Chrome 70 in favour of the split autofill settings.

safeBrowsingExtendedReportingEnabled defaults to false; when enabled, Chrome may send extra information to Google when Safe Browsing blocks a page.

privacy.websites: what sites can use or send

Section titled “privacy.websites: what sites can use or send”
Setting What it does Notable constraint
thirdPartyCookiesAllowed Global third-party cookie allowance Default true; cannot set true in Incognito (throws); sites may still get cookies via exemptions or Storage Access API
referrersEnabled Send Referer headers Default true
doNotTrackEnabled Send DNT: 1 Default false
topicsEnabled, fledgeEnabled, adMeasurementEnabled Privacy Sandbox–related APIs Extensions may only disable (false); setting true throws
hyperlinkAuditingEnabled <a ping> auditing pings Default true
protectedContentEnabled Protected content IDs for plugins Windows and ChromeOS only

ChromeSetting: get, set, levelOfControl, and onChange

Section titled “ChromeSetting: get, set, levelOfControl, and onChange”

Global settings (privacy.*, proxy.settings, accessibility feature toggles) expose get(), set(), clear(), and onChange. The ChromeSetting type documents this contract.

The ChromeSetting type provides a common set of functions (get(), set(), and clear()) as well as an event publisher (onChange) for settings of the Chrome browser. The proxy settings examples demonstrate how these functions are intended to be used.

— Chrome, types

get() returns value, levelOfControl, and optionally incognitoSpecific. Before set(), verify control; otherwise the call may succeed but the user sees no lasting change.

The user won’t see any change to their settings if your extension toggles a setting that is either locked to a specific value by enterprise policies (levelOfControl will be set to “not_controllable”), or if another extension is controlling the value (levelOfControl will be set to “controlled_by_other_extensions”). The set() call will succeed, but the setting will be immediately overridden.

— Chrome, privacy

Recommended flow: call get() → only set() when levelOfControl === 'controllable_by_this_extension' → subscribe to onChange to detect enterprise policy or another extension taking control. Full control levels are documented under browser.types.ChromeSetting (MV2).

proxy exposes types.ChromeSetting<ProxyConfig>. accessibilityFeatures uses ChromeSetting with boolean or enum values such as "allowed" | "once" | "none".

contentSettings vs privacy: when to use which API

Section titled “contentSettings vs privacy: when to use which API”

Use contentSettings when the goal is a site- or pattern-specific rule: block JavaScript on one origin, allow notifications for another, or set cookie behaviour for a frame context. Use privacy when the goal is a browser-wide preference: Safe Browsing, third-party cookies globally, Topics API off, or WebRTC IP policy.

They solve different layers: contentSettings mirrors what users see in per-site permissions; privacy mirrors settings pages and policies that apply unless overridden elsewhere. Only privacy.websites settings overlap conceptually with cookies and tracking, but third-party cookie blocking via thirdPartyCookiesAllowed is global, while contentSettings.cookies is rule-based per patterns.

Common mistakes when using contentSettings and privacy

Section titled “Common mistakes when using contentSettings and privacy”
  1. Calling set() without reading levelOfControl — UI shows a toggle that does nothing under enterprise or competing extensions.
  2. Wrong primary vs secondary URL in get() — effective value differs by content type; re-read the type’s paragraph in contentSettings.
  3. Assuming allow for camera/microphone with <all_urls> / <all_urls> — invalid combination.
  4. Trying to re-enable Privacy Sandbox APIs — topicsEnabled, fledgeEnabled, and adMeasurementEnabled only accept disabling.
  5. Enabling third-party cookies in Incognito via extension — thirdPartyCookiesAllowed.set({ value: true }) throws in Incognito.
  6. Relying on plugins, fullscreen, or mouselock — deprecated; no practical effect.
  7. Forgetting contentSettings permission warning — users see an install-time warning (MV2 permissions).
  1. Add the contentSettings and/or privacy permissions your feature needs, load the unpacked extension, and confirm install warnings match expectations (contentSettings, Develop / Modify website settings).
  2. For a per-site rule, call get() with the same primaryUrl / secondaryUrl you use in production and compare the returned setting to what you set with set() (contentSettings get).
  3. For a global privacy toggle, call get() on the target privacy.* property and confirm levelOfControl is controllable_by_this_extension before expecting set() to stick (privacy).
  4. Change the setting in Chrome settings or install a second test extension, then verify your onChange listener fires with updated levelOfControl (ChromeSetting onChange).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.