event_rules
Warning
The Chrome Web Store no longer accepts Manifest V2 extensions. Please use Manifest V3 when building new extensions. You will find a section on upgrading in the navigation tree at the left, including the Manifest V2 support timeline.
The event_rules
manifest property provides a mechanism to add rules that intercept, block, or modify web requests in-flight using declarativeWebRequest or take actions depending on the content of a page, without requiring permission to read the page's content using declarativeContent.
Translating rules from javascript to manifest
The following defines a rule to display a page action if the current page has a video css tag in javascript:
chrome.declarativeContent.onPageChanged.addRules([{
actions: [
new chrome.declarativeContent.ShowPageAction()
],
conditions: [
new chrome.declarativeContent.PageStateMatcher(
{css: ["video"]}
)
]
}]);
This is the same definition in the manifest:
{
"name": "Sample extension",
"event_rules": [{
"event": "declarativeContent.onPageChanged",
"actions": [{
"type": "declarativeContent.ShowPageAction"
}],
"conditions": [{
"type": "declarativeContent.PageStateMatcher",
"css": ["video"]
}]
}],
...
}