我正在将Chrome扩展移植到Firefox。在Chrome扩展中,我指的是"chrome-extension://" + chrome.runtime.id
、下的资源
foobar = {
config: {
fontURL: "chrome-extension://" + chrome.runtime.id + "/fonts"
}
};
如何将其翻译成Firefox?
Firefox会随机化id,因此即使您编写moz-extension://
,它也不会对您有所帮助。
按照web_accessible_resources
文档中的说明使用chrome.runtime.getURL
:
let foobar = {
config: {
fontURL: chrome.runtime.getURL("/fonts")
}
};
chrome
命名空间在Firefox和Chrome中都可以使用。
关于移植Chrome扩展和不兼容的更多信息:MDN。