【问题标题】:Binding extension content scripts to Chrome's start page?将扩展内容脚本绑定到 Chrome 的起始页?
【发布时间】:2015-03-24 23:44:13
【问题描述】:

有没有办法将内容脚本绑定到 Chrome 的起始页?

我尝试将matches 设置为"*",但它甚至没有运行。 "*://*/*" 不绑定。

【问题讨论】:

    标签: google-chrome google-chrome-extension content-script


    【解决方案1】:

    不,你不能*。从技术上讲,起始页是chrome://newtab/,出于安全原因,Chrome 扩展程序无法访问chrome:// 页面,即使拥有最广泛的"<all_urls>" 权限也是如此。

    您唯一的希望是make your own New Tab page,尽管很难复制所有默认功能(例如顶级网站的缩略图)。


    * 可以使用 Chrome 标志启用此功能:chrome://flags/#extensions-on-chrome-urls 但这仅适用于扩展程序供个人使用并且存在潜在安全风险的情况。

    【讨论】:

      【解决方案2】:

      是的! Chrome 的起始页(¿now?)具有以下表单的隐藏 URL:

      https://www.google.com/_/chrome/newtab?espv=2&ie=UTF-8
      

      以及带有manifest.jsons 的扩展,例如:

      {
          "manifest_version": 2,
          "content_scripts": [ {
              "js":               [ "HelloWorld.js" ],
              "matches":          [ "*://*/_/chrome/newtab*" ]
          } ],
          "name":         "Chrome start test",
          "description":  "Runs on the Chrome Start page",
          "version":      "1"
      }
      

      ...在“开始”页面上运行良好。

      【讨论】:

        猜你喜欢
        • 2016-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        • 1970-01-01
        • 2021-06-15
        • 2013-06-11
        相关资源
        最近更新 更多