[英]Chrome Extension Manifest Relative File Path for Scripts
I have several utility script files that are used by multiple extensions. 我有几个实用程序脚本文件,由多个扩展使用。 Thus far, I have been copy/pasting those utility scripts to each extension's root folder whenever I make a change.
到目前为止,每当我进行更改时,我都会将这些实用程序脚本复制/粘贴到每个扩展的根文件夹中。 This is becoming less and less feasible.
这变得越来越不可行。 I would like to reference the same utility script files from both extensions' manifests.
我想从两个扩展的清单中引用相同的实用程序脚本文件。 I have tried this:
我试过这个:
{
"background":
{
"scripts":
[
"../utils.js",
"background.js"
]
}
}
But, I when I reload my extension, I get an Extension error saying: 但是,当我重新加载我的扩展时,我得到一个扩展错误说:
Could not load extension from 'C:\\...'. Could not load background script '../../utils.js'.
If I use backslashes instead (this seems like a more likely solution since I'm working with windows...), I get the same error (but with backslashes). 如果我使用反斜杠(这似乎是一个更可能的解决方案,因为我正在使用Windows ...),我得到相同的错误(但使用反斜杠)。
Is it even possible to achieve this type of relative file path? 甚至可以实现这种类型的相对文件路径?
How about creating a local server that hosts the JS files you need and then your extension can access those JS file through a localhost port and use their functionality? 如何创建一个托管所需JS文件的本地服务器,然后您的扩展可以通过localhost端口访问这些JS文件并使用它们的功能? A simple lightweight server would do the trick (maybe bottle.py in Python).
一个简单的轻量级服务器可以解决这个问题(也许是Python中的bottle.py )。
Chrome v33 tightened up extension security so i'm not sure you can access a file like you tried in your manifest.json Chrome v33加强了扩展程序安全性,因此我不确定您是否可以像在manifest.json中一样访问文件
Let me know how you get around this problem! 让我知道你如何解决这个问题!
Have you considered using Shared Modules ? 您是否考虑过使用共享模块 ? According to the documentation you can export common functionality from one extension that can thusly be imported into another extension:
根据文档,您可以从一个扩展导出常用功能,因此可以导入到另一个扩展中:
"The export field indicates an extension is a Shared Module that exports its resources: “导出字段表示扩展名是导出其资源的共享模块:
{
"version": "1.0",
"name": "My Shared Module",
"export": {
// Optional list of extension IDs explicitly allowed to
// import this Shared Module's resources. If no whitelist
// is given, all extensions are allowed to import it.
"whitelist": [
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
]
}
// Note: no permissions are allowed in Shared Modules
}
The import field is used by extensions and apps to declare that they depend on the resources from particular Shared Modules: 扩展和应用程序使用导入字段来声明它们依赖于来自特定共享模块的资源:
{
"version": "1.0",
"name": "My Importing Extension",
...
"import": [
{"id": "cccccccccccccccccccccccccccccccc"},
{"id": "dddddddddddddddddddddddddddddddd"
"minimum_version": "0.5" // optional
},
]
}
" “
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.