我开发了一个与 Firefox 24 冲突的 Firefox 插件。
我的插件根据一些用户设置将搜索引擎添加到搜索栏。为了添加搜索引擎,我使用addEngine() from nsIBrowserSearchService。
直到 Firefox 23,这个功能也选择了添加的引擎,所以用户可以立即使用它。从 Firefox 24 开始,此行为停止:正在添加引擎,但不再选择。
但是,文档仍然说:
... 新引擎将立即自动使用。
我能做些什么来强制在 Firefox 24 中也立即使用新引擎?
我开发了一个与 Firefox 24 冲突的 Firefox 插件。
我的插件根据一些用户设置将搜索引擎添加到搜索栏。为了添加搜索引擎,我使用addEngine() from nsIBrowserSearchService。
直到 Firefox 23,这个功能也选择了添加的引擎,所以用户可以立即使用它。从 Firefox 24 开始,此行为停止:正在添加引擎,但不再选择。
但是,文档仍然说:
... 新引擎将立即自动使用。
我能做些什么来强制在 Firefox 24 中也立即使用新引擎?
一个小解决方法是在添加新搜索引擎后直接更改默认搜索引擎的首选项:
browser.search.defaultenginename
此首选项采用搜索引擎的确切名称。
此外,在这个 MDN 教程中有更多关于添加搜索引擎的信息:
function startup(data, reason) {
firstRun = reason == ADDON_INSTALL;
// Re-select the search engine if this is the first run
// or we're being re-enabled.
selectSearch = firstRun || reason == ADDON_ENABLE;
// Only add the engine if it doesn't already exist.
if (!Services.search.getEngineByName(ENGINE_DETAILS.name)) {
Services.search.addEngineWithDetails.apply(Services.search,
["name", "iconURL", "alias", "description", "method", "url"].map(
function (k) ENGINE_DETAILS[k]))
}
let engine = Services.search.getEngineByName(ENGINE_DETAILS.name);
// If the engine is not hidden and this is the first run, move
// it to the first position in the engine list and select it
if (selectSearch && !engine.hidden) {
Services.search.moveEngine(engine, 0);
Services.search.currentEngine = engine;
}
}