如何使 chrome 扩展对任何主机都有效

Sar*_*j K 3 google-chrome-extension

我正在使用以下代码使 chrome 扩展程序对特定主机处于活动状态。

chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules([{
  conditions: [new chrome.declarativeContent.PageStateMatcher({
    pageUrl: {hostEquals: 'www.google.com'},
  })],
  actions: [new chrome.declarativeContent.Sho``wPageAction()]
}]);
Run Code Online (Sandbox Code Playgroud)

});

我希望它对所有主机都有效。

Kau*_*l28 8

您可以使用hostContains: '.'which 为所有主机激活您的扩展。我已经测试过了,它适用于所有主机。