Bootstrapped清单不允许使用'component'指令

时间:2016-04-30 22:02:23

标签: javascript firefox firefox-addon firefox-addon-sdk

我试图通过this示例提供命令行选项, 我在浏览器控制台中收到此错误:

  • Bootstrapped清单不允许使用'component'指令。
  • Bootstrapped清单不允许使用'contract'指令。
  • Bootstrapped清单不允许使用'category'指令。

params:-no-remote -p Developer -jsconsole -ssprint:1137403

这是我的文件的内容:

[install.rdf的]

<?xml version="1.0" encoding="utf-8"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
    <Description about="urn:mozilla:install-manifest">
          <em:id>@spidersprint</em:id>
          <em:type>2</em:type>
          <em:bootstrap>true</em:bootstrap>
          <em:unpack>false</em:unpack>
          <em:version>1.0.0</em:version>
          <em:name>SpiderSprint</em:name>
          <em:description>SpiderSprint extension (for self-using).</em:description>
          <em:creator>Alexander Macedonian</em:creator>
          <em:iconURL>resource://spidersprint/data/icon/s32.png</em:iconURL>
          <em:icon64URL>resource://spidersprint/data/icon/s64.png</em:icon64URL>

          <em:targetApplication>
            <Description>
              <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
              <em:minVersion>38.0a1</em:minVersion>
              <em:maxVersion>*</em:maxVersion>
            </Description>
          </em:targetApplication>
    </Description>
</RDF>

[chrome.manifest用于]:

component {75ceb908-0807-4395-affb-e0792ac4c548} components/commandlinehandler.js
contract @spidersprint/commandlinehandler;1 {75ceb908-0807-4395-affb-e0792ac4c548}
category command-line-handler CommandLineHandler @spidersprint/commandlinehandler;1

[commandlinehandler.js]

let {CC,Cc,Ci,Cu,Cr,components} = require('chrome');

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
const CHROME_URI = "resource://spidersprint/data/";

function openWindow(aChromeURISpec, aArgument) {
    Services.ww.openWindow(null, aChromeURISpec, "_blank",
        "chrome,menubar,toolbar,status,resizable,dialog=no", aArgument);
}

function CommandLineHandler() {};

CommandLineHandler.prototype = {
    classDescription: "myAppHandler",
    classID: components.ID("{75ceb908-0807-4395-affb-e0792ac4c548}"),
    contractID: "@spidersprint/commandlinehandler;1",
    _xpcom_categories: [{
        category: "command-line-handler",
        entry: "s-ssprint"
    }],

    QueryInterface: XPCOMUtils.generateQI([
        Ci.nsICommandLineHandler
    ]),

    handle : function clh_handle(cmdLine)
    {
        try {
            var uristr = cmdLine.handleFlagWithParam("viewapp", false);
            if (uristr) {
                var uri = cmdLine.resolveURI(uristr);
                openWindow(CHROME_URI, uri);
                cmdLine.preventDefault = true;
            }
        }
        catch (e) {
            Cu.reportError("incorrect parameter passed to -viewapp on the command line.");
        }

        if (cmdLine.handleFlag("ssprint", false)) {
            openWindow(CHROME_URI, null);
            cmdLine.preventDefault = true;
        }
    },

    helpInfo : "  -ssprint               Open My Application\n" +
        "  -viewapp <uri>       View and edit the URI in My Application,\n" +
        "                       wrapping this description\n"
};

var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);

1 个答案:

答案 0 :(得分:0)

该示例使用的chrome清单仅对(已弃用的)xul覆盖扩展类型有效。在bootstrapped扩展中,您需要提供bootstrap.js,然后使用Cu.import加载其他模块。

有关代码迁移指南,请参阅How to convert an overlay extension to restartless

此外,您可能希望跳过另一个步骤以使用SDK extension APIs,它本质上是一种特殊形式的引导扩展,可提供更稳定的API。