declarativeContent

The declarativeContent API allowed an extension to show its page action icon based on the content of a page, without needing to read the page's content itself. The API is effectively obsolete: page actions were removed in Manifest V3, so the only declared action (ShowPageAction) no longer functions. New extensions should use chrome.action.setIcon / chrome.action.enable together with scripting and a host permission (or activeTab).

What it does

  • Allowed an extension to declare rules in the background.
  • These rules would be evaluated by the browser itself.
  • If a rule's conditions were met (e.g., a CSS selector matched an element on the page), the browser would perform a declared action (e.g., show the extension's action icon).
  • This was more private and efficient than injecting a content script on every page just to check for a condition.

When to use it

It was used for extensions that were only relevant on specific types of pages.

Examples:

  • A "video downloader" extension that would only enable its icon on pages containing a <video> tag.
  • An RSS feed reader extension whose icon would only appear on pages that had a <link rel="alternate" type="application/rss+xml"> tag.

Manifest Declaration

{
  "name": "My Declarative Content Extension",
  "version": "1.0",
  "manifest_version": 2,
  "permissions": [
    "declarativeContent"
  ],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "page_action": {
    "default_title": "I'm active on this page!"
  }
}

Note: In Manifest V3, this API is not available. The recommended alternative is to use scripting with activeTab or specific host_permissions to check page content when the user clicks the action icon, and then use chrome.action.setIcon() or chrome.action.enable()/disable().

Security & Privacy

Why is it not risky?

This was a privacy-focused permission available in older extensions. It allowed an extension to show its icon only on certain pages (e.g., a video downloader that only appears on YouTube) without actually reading the page's content.

Because the browser itself checked the page content instead of the extension, the extension couldn't access any of your data. This made it very safe to use. Modern extensions achieve similar results using different methods.

API Usage Example

// background.js (Manifest V2)

chrome.runtime.onInstalled.addListener(function() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    chrome.declarativeContent.onPageChanged.addRules([{
      conditions: [
        new chrome.declarativeContent.PageStateMatcher({
          // Show the page action if the page has a <video> element
          css: ["video"]
        })
      ],
      actions: [ new chrome.declarativeContent.ShowPageAction() ]
    }]);
  });
});

Extensions with the declarativeContent permission

Here are some popular browser extensions that use the "declarativeContent" permission. To explore more, try our Advanced search.

Permission Metrics

Popularity

Security Risk


Usage by Platform