Firefox说无法下载搜索插件 [英] Firefox says could not download the search plugin from

查看:193
本文介绍了Firefox说无法下载搜索插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图动态生成 /1.1rel =nofollow> OpenSearch 搜索插件的Firefox根据用户输入的值作为一个更大的附加组件的一部分。我没有包含它的形式和方式,因为我已经把它缩小到一个简单的失败的测试用例,试图导入任何XML。
$ b 代码:

简化JS


  var browserSearchService =组件
.classes [@ mozilla.org/browser/search-service;1]
.getService(Components.interfaces.nsIBrowserSearchService);
$ b $ EngineProperties = {
xml:'http://localhost/search.xml',
dataType:3,
iconURL:'http:// localhost /logo.png',
confirm:false,
callback:function addEngineCallback(){
console.log('Jason is the most');


$ b browserSearchService.addEngine(EngineProperties.xml,
EngineProperties.dataType,
EngineProperties.iconURL,
EngineProperties.confirm,
EngineProperties.callback);

实际XML

 <?xml version =1.0encoding =UTF-8?> 
< OpenSearchDescription xmlns =http://a9.com/-/spec/opensearch/1.1/
xmlns:moz =http://www.mozilla.org/2006/browser/搜索/>
< ShortName> Jason< / ShortName>
<说明> Powered By Jason< /说明>
< InputEncoding> UTF-8< / InputEncoding>
< Image width =16height =16type =image / x-icon> http://localhost/logo.png< / Image>

< URL method =gettype =text / htmltemplate =http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?ptb=100000487&amp;ind= 1406730191685& n = 14787A74345& st = bar& amp; amp; searchfor = {searchTerms}/>
template =http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?&amp; ptb = 100000487& amp; ind = 1406730191685& n = 14787A74345& st = bar& amp; searchfor = {searchTerms}/>
template =http://ssmsp.ask.com/query?q={searchTerms}&amp ; LI = FF&放大器;放大器; sstype =前缀/>

< moz:SearchForm> http://search.mywebsearch.com/mywebsearch/GGmain.jhtml< / moz:SearchForm>
< / OpenSearchDescription>

(来自 Mycroft Project



从我看到的错误应该表明一个无效的XML文件,但对于我的生活,我无法找到任何错误的。我已经在Firefox中加载了它,修复了我发现的所有拼写错误和语法错误(用来代替& amp; ,浏览器显示并解析它,但它不会作为开放式搜索引擎加载。



FF不支持localhost,也许我在这里画了一个空白。

在此先感谢您的任何见解!

解决方案

问题:

Noitidart 所示, dataType code>应该是1,即使它是opensearch

不能传递 iconURL in addEngine 。不知道是否所有的图标都是这样,但肯定是传递一个PNG或数据URI 失败。

第三,呼叫

  callback = {
onError: function(err){/ ** /},
onSuccess:function(err){/ ** /}
}


$ b

第四个文件类型应该是 .osdx ,而不是 .xml



网址网址网址
$ b

最后,在测试时,确保你有 browser.search .log 设为 true 在 about:config



您可以在错误报告 here < a>。



希望这有助于下一个人卡在 Components.classes [@ mozilla.org/browser/search-service;1 ] .getService(Components.interfaces.nsIBrowserSearchService).addEngine() -land。



更新:设置 / code>到 true 结果lts in:
$ b $ pre $ [Exception ...]组件返回的失败代码: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:否]

所以,不要那样做。



这个API如此容易访问,真是太好了。 :|


Backstory:
I'm trying to dynamically generate an
OpenSearch search plugin for Firefox based on user entered values as part of a larger add-on. I'm not including the forms and cruft surrounding it, because I've narrowed it down to a simple failing test case trying to import any XML.

Code:
Simplified 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);

Actual 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&amp;ind=1406730191685&amp;n=14787A74345&amp;st=bar&amp;searchfor={searchTerms}" />
  <URL method="get" type="application/x-moz-keywordsearch" 
    template="http://search.mywebsearch.com/mywebsearch/GGmain.jhtml?&amp;ptb=100000487&amp;ind=1406730191685&amp;n=14787A74345&amp;st=bar&amp;searchfor={searchTerms}" />
  <Url method="get" type="application/x-suggestions+json" 
    template="http://ssmsp.ask.com/query?q={searchTerms}&amp;li=ff&amp;sstype=prefix"/>

  <moz:SearchForm>http://search.mywebsearch.com/mywebsearch/GGmain.jhtml</moz:SearchForm>
</OpenSearchDescription>

(From the Mycroft Project)

From what I've seen the error should indicate an invalid XML file, but for the life of me I can't find anything wrong with this. I've loaded it in Firefox fixed all the typos and syntactical errors I found (used to have & instead of &amp;, and the browser displays and parses it fine, but yet it won't load as an open search search engine.

Does FF not support localhost, maybe? I'm drawing a blank here.

Thanks in advance for any insight!

解决方案

Problems:
As indicated by Noitidart, dataType should be 1 even though it's opensearch.

Second, cannot pass the iconURL in addEngine. Not sure if that's true for all icons, but definitely passing it a png or a data URI both failed.

Third, callback needs to be an object of the form:

callback={
    onError   : function(err){/**/},
    onSuccess : function(err){/**/}
}

Fourth the filetype should be .osdx, not .xml

URL to url to Url does not matter, never changed and extension working.

Lastly, when testing, ensure that you have browser.search.log set to true in about:config.

You can see more info at the bug report here.

Hope this helps the next guy stuck in Components.classes["@mozilla.org/browser/search-service;1"].getService(Components.interfaces.nsIBrowserSearchService).addEngine()-land.

Update: Setting confirm to true results in:

[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]

So, don't do that.

It's nice how that API is so easily accessible. :|

这篇关于Firefox说无法下载搜索插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆