内容脚本加载但css文件被某些匹配模式忽略

时间:2013-11-10 04:34:34

标签: css google-chrome-extension

在我的Google Chrome扩展程序中,我使用 manifest.json 加载内容脚本,如下所示:

  "content_scripts": [
    {
      "matches": ["https://stackoverflow.com/questions/tagged/*sort=newest*"],
      "css":     ["content.css"],
      "js":      ["content.js"]
    }
  ]

当我现在浏览到https://stackoverflow.com/questions/tagged/sql?sort=newest&pageSize=15时,content.js已成功注入,但content.css被忽略。

但是,当我将匹配模式更改为https://stackoverflow.com/questions/tagged/*时,两者都会被加载并正确应用。

这是Chrome中的错误还是在网址中使用了多个星号?但是为什么它适用于JS呢? matches pattern documentation明确允许“< any chars>”在URL的路径部分。除了手动injecting CSS styles into the page之外,还知道如何做到这一点吗?

我也尝试过没有成功:

  • "permissions":["tab", "https://stackoverflow.com/"]添加到清单
  • "web_accessible_resources": ["content.css"]添加到清单
  • 将内容脚本声明分成两个JS和CSS对象

修改

情况正在恶化。我刚刚找到了include_globs并尝试了这个:

  "content_scripts": [
    {
      "matches":       ["https://stackoverflow.com/*"],
      "include_globs": ["*/questions/tagged/*sort=newest*"]
      "css":           ["content.css"],
      "js":            ["content.js"]
    }
  ]

JS只会注入最新的问题页面,但CSS现在应用于整个stackoverflow站点。 CSS模式匹配刚刚破解了吗?

0 个答案:

没有答案
相关问题