代码之家  ›  专栏  ›  技术社区  ›  Tom

如何使用声明性内容/pagestatemacher在chrome扩展中不显示黑名单主机名的页面操作?

  •  0
  • Tom  · 技术社区  · 6 年前

    我正在使用 Declarative Content API 要仅在用户使用http、http s或文件方案时显示chrome扩展的页面操作,请执行以下操作:

    /**
     * Show page action only only supported urls.
     */
    chrome.runtime.onInstalled.addListener(() => {
      const rule = {
        conditions: [
          new chrome.declarativeContent.PageStateMatcher({
            pageUrl: { schemes: ['https', 'http', 'file'] },
          })
        ],
        actions: [ new chrome.declarativeContent.ShowPageAction() ]
      }
    
      chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
        chrome.declarativeContent.onPageChanged.addRules([rule])
      })
    })
    

    如果我想把这个扩展到 不是 加载到某个主机名上,特别是 chrome.google.com网站 ?

    这个 PageStateMatcher 支持一 urlMatcher 属性,但它基于 RE2 Regex 格式 does not seem to support a negative lookbehind (例如排除某些词)。

    0 回复  |  直到 6 年前