Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 如何在manifest.json Chrome扩展中同时使用主题脚本和内容脚本?_Google Chrome Extension_Themes_Content Script_Manifest.json - Fatal编程技术网

Google chrome extension 如何在manifest.json Chrome扩展中同时使用主题脚本和内容脚本?

Google chrome extension 如何在manifest.json Chrome扩展中同时使用主题脚本和内容脚本?,google-chrome-extension,themes,content-script,manifest.json,Google Chrome Extension,Themes,Content Script,Manifest.json,我正在尝试制作一个chrome主题,它既有风格特征(在manifest“theme”元素中),也有内容脚本(在“contentscripts”元素中)。我遇到了一个奇怪的错误,内容脚本只在没有“主题”元素的情况下运行 我的content-script.js只是- console.log("content-script.js"); 当我像这样格式化manifest.json文件时,没有“theme”元素,它就工作了- { "manifest_version&q

我正在尝试制作一个chrome主题,它既有风格特征(在manifest“theme”元素中),也有内容脚本(在“contentscripts”元素中)。我遇到了一个奇怪的错误,内容脚本只在没有“主题”元素的情况下运行

我的content-script.js只是-

console.log("content-script.js");
当我像这样格式化manifest.json文件时,没有“theme”元素,它就工作了-

{
   "manifest_version": 2,
   "name": "Test",
   "version": "1.0",
   "content_scripts": [
      {
          "matches": ["<all_urls>"],
          "js": ["content-script.js"]
      }
   ]
}
{
“清单版本”:2,
“名称”:“测试”,
“版本”:“1.0”,
“内容脚本”:[
{
“匹配项”:[“”],
“js”:[“content script.js”]
}
]
}
但是,当我添加一个空的主题元素时,我的内容脚本也不会运行-

{
   "manifest_version": 2,
   "name": "Test",
   "version": "1.0",
   "content_scripts": [
      {
          "matches": ["<all_urls>"],
          "js": ["content-script.js"]
      }
   ],
   "theme": {}
}
{
“清单版本”:2,
“名称”:“测试”,
“版本”:“1.0”,
“内容脚本”:[
{
“匹配项”:[“”],
“js”:[“content script.js”]
}
],
“主题”:{}
}

有人知道为什么会发生这种情况,以及我如何解决它吗?

你不能。在Chrome中,主题和扩展是两个不同的东西

主题是一种特殊的扩展,可以改变浏览器的外观。主题像常规的扩展一样打包,但它们不包含JavaScript或HTML代码

这就是为什么在manifest.json中包含“主题”字段时,扩展无法运行任何内容脚本

我建议您检查和查看它们之间的差异


不过,对于Firefox,有一个可用的。

在Chrome中是不可能的。Firefox有一个API。