How to add additional links to an extension page action

I am developing an action with a page extension that only works on a specific domain, can I add multiple links to the page action? My background.js is this.

is it possible to add additional links to background.html for action on extension page?

//background.js

chrome.runtime.onInstalled.addListener(function() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {

  chrome.declarativeContent.onPageChanged.addRules([ 
{
  conditions: [
    new chrome.declarativeContent.PageStateMatcher({
      pageUrl: { urlContains: 'www.exemple.com' },
 })
],
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);

      

+3


source to share


1 answer


Yes, you can register page action for multiple sites by adding multiple PageStateMatcher

to the list conditions

.

chrome.runtime.onInstalled.addListener(function() {
    chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
        chrome.declarativeContent.onPageChanged.addRules([{
            conditions: [
                new chrome.declarativeContent.PageStateMatcher({
                    pageUrl: { hostSuffix: 'example.com' }
                }),
                new chrome.declarativeContent.PageStateMatcher({
                    pageUrl: { hostSuffix: 'example.net' }
                }),
            ],
            actions: [ new chrome.declarativeContent.ShowPageAction() ]
       }]);
    });
});

      



Note. I replaced urlContains

with hostSuffix

because you wanted to show page action on specific domains, not all pages whose URL contains the website host (for example, you probably don't want to match http://localhost/path/containing/www.example.com

). For details on page mapping, see the UrlFilter

type
documentation .

+5


source







All Articles