Open Bug 1048127 Opened 6 years ago Updated 5 years ago

addEngine "dataType" parameter documentation is potentially confusing


(Firefox :: Search, defect, P4)

31 Branch




(Reporter: jason.nichols, Unassigned)


(Whiteboard: [fxsearch])

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

Steps to reproduce:


I'm trying to dynamically generate a search plugin for Firefox based on user entered values. 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.

Simplified JS

var browserSearchService = Components

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,
Actual XML

<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns=""
  <Description>Powered By Jason</Description>
  <Image width="16" height="16" type="image/x-icon">http://localhost/logo.png</Image>

  <URL method="get" type="text/html" template=";ind=1406730191685&amp;n=14787A74345&amp;st=bar&amp;searchfor={searchTerms}" />
  <URL method="get" type="application/x-moz-keywordsearch" 
    template=";ptb=100000487&amp;ind=1406730191685&amp;n=14787A74345&amp;st=bar&amp;searchfor={searchTerms}" />
  <Url method="get" type="application/x-suggestions+json" 


Have tried as a data URI, chrome URI, and localhost from the browser console,  tried all as part of an extension, have even tried window.external.AddSearchProvider(), and nothing.

XML was validated by the browser, and I've tried changing MIME types in the data URI.

Actual results:

Error Could Not Download plugin.

Expected results:

Literally anything else.

A useful error message, success, anything.
From the console:
Error invoking addEngine install callback: [Exception... "JavaScript component does not have a method named: "onError"'JavaScript component does not have a method named: "onError"' when calling method: [nsISearchInstallCallback::onError]"  nsresult: "0x80570030 (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)"  location: "JS frame :: resource://gre/components/nsSearchService.js :: SRCH_SVC_addEngine/engine._installCallback :: line 3907"  data: no] nsSearchService.js:3909

Changed file type to .osdx, and window.external.AddSearchProvider() is now working, but addEngine still fails.
Component: Untriaged → Search
(In reply to Jason Nichols from comment #1)
> From the console:
> Error invoking addEngine install callback: [Exception... "JavaScript
> component does not have a method named: "onError"

This error occurs because your addEngine callback is not a valid nsISearchInstallCallback - you cannot pass just a JS function, you must pass an object with "onError" and "onSuccess" functions as properties, e.g.:

  onSuccess: function (engine) { console.log("Successfully installed engine: " +;  },
  onError: function (error) { console.log("Failed to add engine: " + error); }

Fixing that and then reporting the error code here might be useful (though I suspect it will return the not-so-useful error code 1, "ERROR_UNKNOWN_FAILURE").
changed the callback object.

It responded with an error and the number 1.

literally, function(err){console.log(err)} logged 1
Of note, running a Node server, I can get http://localhost/ or a dummied url ( from my host file to serve either a .osdx file and have it work via window.external.AddSearchProvider(), or an xml file with the mime type forced to 'application/opensearchdescription+xml' and have it work same.

The same URLs fail with .addEngine(). 

Further, neither 'data:application/opensearchdescription+xml,' nor 'chrome://path/to/file.osdx' nor 'chrome://path/to/file.xml' work with either method. Our operating supposition here at work is that addEngine is completely non-functional, and that window.external.AddSearchProvider is limited to http (and possibly though unconfirmed) https protocols.

Confirmed [protocol's are blocked for window.external](

not sure what else I can do to test .addEngine()

Also, .addEngineWithDetails() needs to be updated to support search suggest, but I'm sure that's already an open ticket.
(In reply to Jason Nichols from comment #3)
> literally, function(err){console.log(err)} logged 1


The list of allowed schemes for addEngine is defined at:

Can you set to true using about:config, restart Firefox, and then try again, and report back on any interesting console messages?
Should we add setting to MDN:

What would be like a good single line description for this pref is it only for opensearch plugin debugging?
Work around:
As indicated by Noitidart on the SO page, dataType should be 1 even though it's opensearch.

Second, Could not 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. (Gavin, figured that once I turned on, thanks!)

Changed filetype to .osdx, not .xml

Lastly, Setting confirm to true results in:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  
location: "JS frame :: resource://gre/components/nsSearchService.js :: 
SRCH_SVC_confirmAddEngine :: line 1370"  
data: no]

when you use a data uri because it tries to parse Using a dummied URL through my hosts file worked, as did localhost.
(In reply to Jason Nichols from comment #7)
> Work around:
> As indicated by Noitidart on the SO page, dataType should be 1 even though
> it's opensearch.

OK, sounds like this was the original issue. This is documented in the IDL:

"Must be one of the supported search engine data types defined above."

which refers to the section above labeled "Supported search engine data types.":

The "search engine types" at are an entirely different set of constants not meant to be used for addEngine() (add engine just needs to know XML vs. Sherlock, it determines whether it's OPENSEARCH or MOZSEARCH on its own).

We can try to clarify that documentation, I see how it is confusing.

> Changed filetype to .osdx, not .xml

This shouldn't matter.
Summary: addEngine isn't working → addEngine "dataType" parameter documentation is potentially confusing
Ever confirmed: true
OS: Windows 7 → All
Hardware: x86_64 → All
Priority: -- → P4
Whiteboard: [fxsearch]
Rank: 45
You need to log in before you can comment on or make changes to this bug.