Search code examples
browserpathfilepathrelative-pathopensearch

Is it possible to have a relative path in a Search Plugin XML? (OpenSearch)


I have an Open Search XML for a web app that looks something like this:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>AppName</ShortName>
    <Description>Search App</Description>
    <InputEncoding>UTF-8</InputEncoding>
    <Image width="32" height="32" type="image/png">https://not.my.app.url/public/favicon.png</Image>
    <Url type="text/html" method="get" template="https://not.my.app.url/$/search?q={searchTerms}"/>
</OpenSearchDescription>

A problem with this is that if I want to host the app on a different URL than https://not.my.app.url I would have to either manually edit the manifest to match the new hostname or use some sort of preprocessor that puts the right hostname there. Is there any way I can have a relative path instead? I tried simply omitting the hostname and protocol specifier, but then Firefox refused to install it as a search provider (I did not test any other browsers).


Solution

  • The OpenSearch specification defines the URL template grammar as:

    ttemplate      = tscheme ":" thier-part [ "?" tquery ] [ "#" fragment ]
    tscheme        = *( scheme / tparameter )
    thier-part     = "//" tauthority ( tpath-abempty / tpath-absolute / tpath-rootless / path-empty )
    tauthority     = [ tuserinfo "@" ] thost [ ":" tport ]
    tuserinfo      = *( userinfo / tparameter )
    thost          = *( host / tparameter )
    tport          = *( port / tparameter )
    tpath-abempty  = *( "/" tsegment )
    tsegment       = *( segment / tparameter )
    tpath-absolute = "/" [ tsegment-nz *( "/" tsegment ) ]
    tsegment-nz    = *( segment-nz / tparameter )
    tpath-rootless = tsegment-nz *( "/" tsegment )
    tparameter     = "{" tqname [ tmodifier ] "}"
    tqname         = [ tprefix ":" ] tlname
    tprefix        = *pchar
    tlname         = *pchar
    tmodifier      = "?"
    tquery         = *( query / tparameter )
    tfragement     = *( fragement / tparameter )
    

    As you can see the scheme and the hosts are required.

    In other words, relative URLs are not allowed.
    You must use an absolute URL, like http://example.com/search?q={searchTerms}.