Firefox插件访问配置

时间:2013-02-25 16:59:17

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

我想编写一个简单的Firefox插件来保护我的搜索引擎,导致每次重新启动firefox的searchengine以及keyword.URL设置为u-search。

我尝试了插件BrowserProtect,但它不保护keyword.URL! 所以我开始在builder.addons.mozilla.org上创建一个插件,因为它似乎很容易使用。

我的代码看起来像这样(从代码片段中添加到一起):

var Widget = require("widget").Widget;
var tabs = require('tabs');

exports.main = function() {

    new Widget({
        id: "searchengineprotect",
        label: "SearchEngineProtect",
        contentURL: "http://www.mozilla.org/favicon.ico",

        onClick: function(event) {
            var {Cc, Ci} = require("chrome");
            var prefs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsIPrefBranch);
            prefs.setCharPref("keyworld.URL", "http://google.de/search?q=");
        }
    });
};

我刚刚更改了“onClick”功能中的代码。

但是当我点击firefox中的小按钮时,控制台会报告此错误:

Fehler: searchengineprotect: An exception occurred.
NS_ERROR_XPC_GS_RETURNED_FAILURE: Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]
undefined 35
Traceback (most recent call last):
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/searchengineprotect/lib/main.js", line 35, in exports.main/<.onClick
    var prefs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsIPrefBranch);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/deprecated/events.js", line 153, in _emitOnObject
    listener.apply(targetObj, params);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/deprecated/events.js", line 123, in _emit
    return this._emitOnObject.apply(this, args);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/widget.js", line 282, in _onEvent
    this._emit(type, eventData);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/widget.js", line 431, in WidgetView__onEvent
    this._baseWidget._onEvent(type, this._public);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/widget.js", line 850, in WC_addEventHandlers/listener/<
    self._widget._onEvent(EVENTS[e.type], null, self.node);
  File "resource://jid0-zg1n2skgq7y6lrq6hbl96hno8ke-at-jetpack/addon-sdk/lib/sdk/timers.js", line 31, in notify
    callback.apply(null, args);

所以,如果你知道如何解决这个错误,甚至我怎么能阻止firefox改变搜索引擎......真棒! :)

1 个答案:

答案 0 :(得分:1)

评论之后 - 这是一个拼写错误的问题 使用keyword.URL而不是keyworld.URL(不带“L”)