javascript - Firefox 插件 - 图标不显示

标签 javascript firefox firefox-addon firefox-addon-sdk jpm

我正在尝试为 Firefox 编写插件。为此,我使用 Mozilla“Addon-SDK”。

当我使用“jpm run”功能时一切正常。但是一旦我将它打包到 xpi 并安装它,该图标就不会显示在工具栏中。这似乎是 SDK 中的错误。
我尝试了其他博客文章中的各种变通解决方案。

  • 编辑 package.json
  • 重命名为“图标”
  • 转向数据
  • 将图标移动到根
  • 绝对路径
  • 在 rdf 中编辑 firefox 版本
  • 调试 Index.js...

这里最有用:

Firefox add-on : extension icon not showing
https://github.com/mozilla-jetpack/jpm/issues/197

因为 Firefox 43 插件必须经过验证。我这样做了。我还在 about:config 中禁用了该功能,因此我可以更快地尝试新版本。仍然没有运气。

这是我在 index.js 中的代码:根据答案进行了编辑,但仍然无法正常工作

    var button = buttons.ActionButton(
    {
      id: "MorastLink",
      label: "In den Morast",
      icon:
      {
        "16": "./images/icon16.png",
        "32": "./images/icon32.png",
        "64": "./images/icon64.png"
      },
    onClick: CopyToMorast
    });  

这里我也试过了,移动路径,改名,使用绝对路径...

这是我的package.json

    {
      "title": "Morast",
      "name": "morastaddon",
      "version": "0.1.4",
      "description": "An Addon to insert a \"Add to Morast\" button on distributer sites.",
      "main": "index.js",
      "author": "Lisa Austen",
      "icon": "ressource://@morastaddon/data/images/icon16.png",
      "icon64": "ressource://@morastaddon/data/images/icon64.png",
      "engines": {
      "firefox": ">=38.0a1",
      "fennec": ">=38.0a1" },
      "license": "MIT",
      "keywords": [
      "jetpack"
    ]
    }

https://github.com/LAusten/MorastAddon.git

最佳答案

根据 MDN ,图标路径必须相对于 data 文件夹:

  • as a resource:// URL pointing at an icon file in your add-on's "data" directory, typically constructed using self.data.url(iconfile)

  • as a relative path: a string in the form "./iconfile", where "iconfile" is a relative path to the icon file beginning in your add-on's "data" directory

例子:

  icon:
  {
    "16": "./images/icon16.png",
    "32": "./images/icon32.png",
    "64": "./images/icon64.png"
  }

关于javascript - Firefox 插件 - 图标不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34768273/

相关文章:

javascript - 将附加 SDK 面板链接到工具栏按钮

javascript - 更改 Firefox 扩展对话框的大小?

页面加载代码上的 Javascript 使其重新加载 chrome 扩展

javascript - 如何在所有分辨率下将巨大图像上的文本保持在适当的位置?

javascript - AJAX 调用正在处理但未在 Rails View 中呈现

php - 使用基于 php 的 css 模板时无法正确使用 $_GET 值

html - FireFox CSS 动画无法运行。

firefox - 如何在firefox中查看IndexedDB内容

java - 在 FirefoxDriver 上打开 URL 失败,并出现 WebDriverException : Could not parse ""

javascript - 获取<script>元素的内容