Javascript chrome扩展-特定页面的页面操作

Javascript chrome扩展-特定页面的页面操作,javascript,google-chrome-extension,Javascript,Google Chrome Extension,我想使用pageAction api向omni box添加一个自定义图标 如何仅针对特定URL/匹配模式执行自定义页面操作?是否可以针对特定URL注册事件 例如,如果用户访问foobar.com,则执行自定义页面操作。对于其他页面,我不想做任何事情 我认为PageStateMatcher就是你想要的。在这里 比如 new chrome.declarativeContent.PageStateMatcher({ pageUrl: { hostEquals: 'www.google.c

我想使用pageAction api向omni box添加一个自定义图标

如何仅针对特定URL/匹配模式执行自定义页面操作?是否可以针对特定URL注册事件


例如,如果用户访问foobar.com,则执行自定义页面操作。对于其他页面,我不想做任何事情

我认为
PageStateMatcher
就是你想要的。在这里

比如

  new chrome.declarativeContent.PageStateMatcher({
    pageUrl: { hostEquals: 'www.google.com', schemes: ['https'] },
    css: ["input[type='password']"]
  })
这是chrome的URL页面操作示例。检查
PageStateMatcher
部分

// When the extension is installed or upgraded ...
chrome.runtime.onInstalled.addListener(function() {
  // Replace all rules ...
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    // With a new rule ...
    chrome.declarativeContent.onPageChanged.addRules([
      {
        // That fires when a page's URL contains a 'g' ...
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { urlContains: 'g' },
          })
        ],
        // And shows the extension's page action.
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    ]);
  });
});