Welcome What's new in Chrome extensions API reference Samples
Welcome What's new in Chrome extensions API reference Samples

event_rules

Published on Updated on

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"]
}]
}],
...
}

Updated on Improve article

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.