背景故事:
我正在尝试根据用户输入的值为 Firefox 动态生成OpenSearch搜索插件,作为更大附加组件的一部分。我不包括围绕它的表单和杂乱无章的内容,因为我已将其范围缩小为尝试导入任何 XML 的简单失败测试用例。
代码:
简体 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>
(来自Mycroft 项目)
从我所看到的错误应该表明一个无效的 XML 文件,但对于我的生活,我找不到任何问题。我已经在 Firefox 中加载了它,修复了我发现的所有拼写错误和语法错误(以前有&
代替&
,并且浏览器可以很好地显示和解析它,但它不会作为开放式搜索引擎加载。
FF 不支持本地主机吗?我在这里画一个空白。
提前感谢您的任何见解!