I'm going through the Google Chrome Extensions "Getting Started" tutorial, and I came across this code:
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'developer.chrome.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
I also made sure to add the permissions:
{
"name": "Getting Started Example",
...
"permissions": ["declarativeContent", "storage"],
...
}
The expected behaviour is this
The browser will now show a full-color page action icon in the browser toolbar when users navigate to a URL that contains "developer.chrome.com". When the icon is full-color, users can click it to view popup.html.
(source: chrome.com)
But I am not sure why it doesn't work for me.
I've checked these posts, but nome of them seems to help me.
- Declarative content "remove rules" interpretation in chrome extensions
- Chrome extension with declarativeContent.RequestContentScript
Attempts
- I am using the permissions bellow. But it still doesn't work.
"permissions": ["declarativeContent", "activeTab", "storage"],
- I also tried to use
pageUrl: {hostContains: 'developer.chrome.com'}})
instead of
pageUrl: {hostEquals: 'developer.chrome.com'}})
- Tried
"browser_action": {...},
instead of"page_action": {...},
. I am keeping"browser_action": {...},
.