引导清单不允许使用 'component' 指令

Bootstrapped manifest not allowed to use 'component' directive

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

参数:-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]);

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

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

此外,您可能想向前跳过一步以使用 SDK extension APIs,它本质上是一种特殊形式的自举扩展,可提供更稳定的 API.