我想编写一个简单的 Firefox 插件来保护我的搜索引擎,因为每次重新启动 Firefox 时,搜索引擎和关键字.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 更改搜索引擎……那就太棒了!:)