如何在 Firefox 插件中使用来自外部 URI 的 contentScriptFile

How to use a contentScriptFile from an external URI in a Firefox addon

我对 Firefox 插件的最新更新已被拒绝,因为我使用了自定义的 jquery-ui(由他们的网站生成,只有我想要的小部件)并且它没有通过他们的校验和检查。

Your add-on includes a JavaScript library file that doesn't match our checksums for known release versions. We require all add-ons to use unmodified release versions, obtained directly from the developer's website. We accept JQuery/JQuery-UI libraries downloaded from 'ajax.googleapis.com', 'jquery.com' or 'jqueryui.com'; and used without any modification. (file-name change does not matter) I'm sorry, but we cannot accept modified, re-configured or customized libraries.

很公平,我可以下载完整的并重新提交,但我想知道是否可以 link 改为一个?

如果我试试这个:

contentScriptFile: [self.data.url("https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"), self.data.url("https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"), self.data.url("api.js")],

我在运行时收到一条错误消息,告诉我内容脚本大部分是本地的。 google 和 the API 似乎对我来说都是虚幻的答案。

有谁知道这是否可行以及如何实现?

干杯

富有

self.data.url("https://...")

您似乎还没有在 data.url()

上阅读 the documentation

明确指出

The data.url() method returns a resource:// url that points at an embedded data file.

这意味着您不能 link 外部资源。


Does anyone know if this is possible and how?

不,contentScriptFile 与常规 Web 内容相比以(略微)提升的权限运行,这就是为什么您不能从可能发生变化并理论上可能在未来注入恶意代码的来源加载脚本。

如果您想依赖外部库并使它们保持最新,您可以简单地编写一个小的构建脚本,在构建新的 XPI 时始终下载最新版本。

原则上,您可以通过特权 XHR 加载脚本,然后将其作为字符串传递,但这可能无法通过 AMO 审核。


个人意见:由于您的目标是特定浏览器,因此您并不真正需要 jquery 用于其跨浏览器逻辑,现代 Web API 提供了许多方便的方法,您可以获得漂亮的仅使用香草 ES6-javascript 和最先进的 DOM API。迭代器和箭头函数也使批量操作相当简洁。