Description
Use the chrome.declarativeContent API to take actions depending on the content of a page, without requiring permission to read the page's content.
Permissions
declarativeContentUsage
The Declarative Content API allows you to enable your extension's action depending on the URL of a web page, or if a CSS selector matches an element on the page, without needing to add host permissions or inject a content script.
Use the activeTab permission to interact with a page after the user clicks on the extension's action.
Rules
Rules consists of conditions and actions. If any of the conditions is fulfilled, all actions are
executed. The actions are setIcon and showAction.
The PageStateMatcher matches web pages if and only if all listed
criteria are met. It can match a page url, a css compound selector
or the bookmarked state of a page. The following rule enables
the extension's action on Google pages when a password field is present:
let rule1 = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostSuffix: '.google.com', schemes: ['https'] },
css: ["input[type='password']"]
})
],
actions: [ new chrome.declarativeContent.ShowAction() ]
};
To also enable the extension's action for Google sites with a video, you can add a second condition, as each condition is sufficient to trigger all specified actions:
let rule2 = {
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: