网址包含参数时弹出带有Chrome扩展功能的警报

时间:2018-10-06 11:21:42

标签: javascript google-chrome google-chrome-extension

当URL包含一些参数时,我正在尝试使用扩展名为Chrome的操作。 我尝试为action属性添加一个警报动作,但是每次打开选项卡时都会发出警报。

function getArrayOfForbiddenParams() {
  return [
    'phishing1',
    'phishing2'
  ];
}
chrome.runtime.onInstalled.addListener(function() {
  chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
    chrome.declarativeContent.onPageChanged.addRules([
      {
        conditions: getArrayOfForbiddenParams().map(param => new chrome.declarativeContent.PageStateMatcher({
          pageUrl: { urlContains: param },
        })),
        actions: [ new chrome.declarativeContent.ShowPageAction(), alert('phishing detected') ]
      }
    ]);
  });
});

唯一发生的是常规图标的颜色更改。.

我在做什么错了?

0 个答案:

没有答案