开发者

firefox code modules components.utils.import

开发者 https://www.devze.com 2023-02-03 19:28 出处:网络
Does anyone know of an example/sample .xpi file that uses Components.utils.import开发者_如何学JAVA to load a custom code module? I cannot get it to work. Basically I cannot get it to work when I packa

Does anyone know of an example/sample .xpi file that uses Components.utils.import开发者_如何学JAVA to load a custom code module? I cannot get it to work. Basically I cannot get it to work when I package to a .jar file. Is this a limitation to use code modules?

A sample would be really helpful, probably with the code below.

var EXPORTED_SYMBOLS = ["foo", "bar"];

function foo() {
  return "foo";
}

var bar = {
  name : "bar",
  size : 3
};


Has passed some time, but here you have:

// modules/module.jsm file
var EXPORTED_SYMBOLS = ["myUniqueCode"];

// wrap your code
var myUniqueCode = {
    foo : function() {
        return "foo";
    },
    bar : {
        name : "bar",
        size : 3
    }
}

// load module where you need it
Components.utils.import("resource://your_addon_name/module.jsm"); 

// use myUniqueCode.foo()

As @felix-kling recommends:

// add to your chrome.manifest file
resource    your_addon_name     modules/
0

精彩评论

暂无评论...
验证码 换一张
取 消