Firefox说无法下载搜索插件
Firefox says could not download the search plugin from
背景故事:
我正在尝试动态地为Firefox生成一个OpenSearch搜索插件,该插件基于用户输入的值,作为一个更大的插件的一部分。我没有包括围绕它的表单和繁琐的东西,因为我已经把它缩小到一个简单的失败测试用例,试图导入任何XML。
Code:
简化JS
var browserSearchService = Components
.classes["@mozilla.org/browser/search-service;1"]
.getService(Components.interfaces.nsIBrowserSearchService);
var EngineProperties = {
xml : 'http://localhost/search.xml',
dataType: 3,
iconURL : 'http://localhost/logo.png',
confirm : false,
callback : function addEngineCallback(){
console.log('Jason is the greatest');
}
}
browserSearchService.addEngine( EngineProperties.xml,
EngineProperties.dataType,
EngineProperties.iconURL,
EngineProperties.confirm,
EngineProperties.callback);
实际XML <?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Jason</ShortName>
<Description>Powered By Jason</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">http://localhost/logo.png</Image>
<URL method="get" type="text/html" template="http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?ptb=100000487&ind=1406730191685&n=14787A74345&st=bar&searchfor={searchTerms}" />
<URL method="get" type="application/x-moz-keywordsearch"
template="http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?&ptb=100000487&ind=1406730191685&n=14787A74345&st=bar&searchfor={searchTerms}" />
<Url method="get" type="application/x-suggestions+json"
template="http://ssmsp.ask.com/query?q={searchTerms}&li=ff&sstype=prefix"/>
<moz:SearchForm>http://search.mywebsearch.com/mywebsearch/GGmain.jhtml</moz:SearchForm>
</OpenSearchDescription>
(From the Mycroft Project)
从我所看到的错误应该表明一个无效的XML文件,但对于我的生命,我找不到任何错误。我已经在Firefox中加载了它,修复了我发现的所有拼写错误和语法错误(以前是&
而不是&
),浏览器显示和解析它很好,但是它不能作为一个开放的搜索引擎加载。
FF可能不支持localhost ?我想不起来了。
提前感谢任何见解!
这是安全问题。我之前被这个击中过。我所做的是从本地路径(或资源路径或我不记得的东西)加载xml文件重写和xbl,我会得到xml错误,就像它是语法错误,但没有什么。我想不明白。
最后,我创建了一个chrome.manifest
文件,并给出了chrome://myaddon/content/myxml.xml
这样的xml文件的路径,它工作了。超级令人沮丧,错误应该解释更多,它浪费了我的时间,我试图修复xml语法…
创建清单,然后在这里修改代码:
var EngineProperties = {
xml : 'chrome://myaddon/content/search.xml',
dataType: 3,
iconURL : 'chrome://myaddon/content/logo.png',
confirm : false,
callback : function addEngineCallback(){
console.log('Jason is the greatest');
}
}
注意我是如何用chrome路径删除本地路径的。
所以显然XML文件必须从chrome路径加载才能正常工作。
现在,如果你想在网络上托管这个东西并像这样安装它,那么你必须使用非特权安装方式(这意味着从html页面执行此javascript)。这是:https://developer.mozilla.org/en-US/docs/Adding_search_engines_from_web_pages
window.external.AddSearchProvider('http://localhost/search.xml');
但是如果你想安装它,就像你在你的主题帖子,也就是xpcom安装,你必须使用chrome路径
好的,我深入调查了一下,发现这是一件非常轻微的事情。
-
dataType
应该是1
,这是Ci.nsISearchEngine.DATA_XML
,您使用的是3
,这是Ci.nsISearchEngine.TYPE_OPENSEARCH
。是的,我知道你的是一个opensearch xml文件,但它是xml,所以使用use 1. - 在XML中将
<URL
更改为<Url
,注意小写的r和l。
EngineProperties
中的无论如何,你可以在这里安装这个插件,它安装你的搜索引擎:https://github.com/yajd/PortableTester/tree/a9ed2432cf4fab4362b71d2c805d97caac2cd237
使用https://addons.mozilla.org/en-US/firefox/addon/github-extension-installer/插件直接从repo安装。
最后,我不知道什么原因,但回调从来没有调用addEngine后,这是如此奇怪,我不知道如何得到它的工作:(
我也不确定如果安全错误,如果不是chrome路径是真的,不确定,但它可能是在其他情况下,但也许不是在这里。你应该可以使用localhost或者本地文件路径比如file:///C:/blah.xml
问题:
如Noitidart所示,即使是opensearch, dataType
也应该是1。
第二,不能通过addEngine
中的iconURL
。我不确定这是否适用于所有图标,但肯定传递png或data URI
都失败了。
第三,callback
需要是如下形式的对象:
callback={
onError : function(err){/**/},
onSuccess : function(err){/**/}
}
第四,文件类型应该是.osdx
,而不是.xml
URL
to url
to Url
不要紧,never change and extension working.
最后,在测试时,确保在about:config
中将browser.search.log
设置为true
。
你可以在这里的bug报告中看到更多信息。
希望这能帮助下一个被困在Components.classes["@mozilla.org/browser/search-service;1"].getService(Components.interfaces.nsIBrowserSearchService).addEngine()
-land的家伙。
更新:设置confirm
为true
导致:
[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIURI.host]" nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame :: resource://gre/components/nsSearchService.js ::
SRCH_SVC_confirmAddEngine :: line 1370"
data: no]
所以,不要那样做。
这个API是如此容易访问,真是太好了。: |
- 免费的JQuery表排序插件(带搜索)
- 正在尝试为Docpad网站设置Lunr全文搜索插件.我做错了什么
- 即时搜索jquery插件
- 使用引导表插件,如何在首次加载时设置搜索字符串
- 选择带有空格的jQuery插件搜索
- 谷歌地图 API v3 位置搜索与 jQuery 自动完成插件
- 使用Spotify API插件专辑名称和歌手名称搜索曲目
- jQuery可搜索下拉插件错误
- 带有JSON数据源的jQueryDataTables插件在全局搜索中接受多个POST请求
- 在asp.net表中使用jquery快速搜索插件进行快速搜索
- 数据表上的日期范围选择器插件.可以't排序和搜索
- 如何编写firefox插件来改变右边的搜索栏到我自己的搜索服务
- 如何在HTML表单中添加jstree搜索插件
- 搜索js图像裁剪插件,无需jquery
- Firefox说无法下载搜索插件
- jQuery可搜索下拉插件不工作
- 如何使用表排序插件- jquery搜索表中的项
- 如何在Jquery选择插件中搜索乌尔都语?有没有其他的方法来搜索乌尔都语在选择框
- 可搜索下拉菜单的Jquery插件
- jQuery -在实时搜索插件上使用提交按钮执行搜索