search broken in WebKit-based browsers

Jakub Wilk avatarJakub Wilk created an issue

In WebKit-based browsers (tested with Epiphany and Chromium), after clicking the search button only "Preparing search..." and "Searching..." messages are shown and nothing else happens.

Curiously enough, the bug triggers only when using the file:/// protocol. If I serve the very same files over HTTP, everything works as expected.

Exact steps to reproduce:

1. Build Sphinx documentation: ./ doc/ build/html/

2. Open search.html in a browser: epiphany build/html/search.html

3. Enter something into the input box, click "Search".

Comments (20)

  1. Anonymous

    My own testing for this reveals that it more complicated:

    Browser         Chrome   Safari  Firefox   Konqueror (4.4.3)
    Build OS
    linux              *        OK      OK          NO
    mac                +        OK      OK          NO
    Windows           NO        ?       NO          ?
    +=OK for Chrome on Windows, No for Chrome on Mac
    *=Untested on Chrome for Windows, No for Chrome on Mac.

    So this seems to be a combination of builds (Windows sphinx-build always bad) and browsers since Safari is nominally a Webkit-based browser asw ell.

  2. Robert Lehmann

    I reproduced the failure in Chromium last week; the error console reports:

    XMLHttpRequest cannot load file:///…/_build/html/searchindex.js.
    Origin null is not allowed by Access-Control-Allow-Origin.

    This very much sounds like a Same Origin Policy issue. Chrome has an --allow-file-access-from-files switch but other than that it's up to the browser to allow such a request (and Sphinx already does its best by using a jQuery <script> include, see sphinx/themes/basic/static/searchtools.js_t:59/loadIndex).

    Firefox does not expose the error for me and the latest Chromium update (12.0.742) partially fixed this bug, now only failing to load the source files (_build/html/_sources/*.txt). If you want to search on a local build you can always run a web server — python -m SimpleHTTPServer comes to mind.

    I'd suggest closing as wontfix.

  3. macfreek

    Thanks for analysing this issue.

    It seem that older versions of Sphinx does not suffer from this problem. I have noticed that this problem only occurred for me for Python 2.7 and Python 3.2 documentation that I downloaded recently. However, the Python documentation for Python 2.6 and 3.1 work just fine.

    When I tried to determine what has changed, I found that the documentation for Python 2.7.2 that I downloaded on 23 February 2012 does not work, but the documentation for Python 2.7.2 that I downloaded today (20 March 2012) works just fine. For some inexplicable reason, it turns out the version I downloaded last month was generated with Sphinx 1.0.7, while the version I downloaded today was generated with Sphinx 0.6.7.

    My test system is Mac OS 10.7.3 with Chrome 17.0.963.79. Safari and Firefox work just fine.

    Perhaps it is possible to revert some of the changes done between Sphinx 0.6.7 and Sphinx 1.0.7 to allow off-line search again.

    It would perhaps be better if this is fixed in Chrome, but given the age of this problem (June 2010) and that no-one is assigned yet, I don't have high hopes for a quick fix there.

  4. macfreek
    • changed status to open

    The following workaround fixes the problem for me.

    In search.html, replace:

        <script type="text/javascript">
          jQuery(function() { Search.loadIndex("searchindex.js"); });


        <script type="text/javascript" src="searchindex.js"></script>
  5. Joon Ro

    macfreek With the change, the search does work partially in a sense that it showed me:

    Search finished, found 1 page(s) matching the search query.

    However, it did NOT show the actual pages the query was found in. I tried this with Chromium and Opera in linux.

  6. Dmitry Shachnev

    It still doesn't work here (tested with Chromium 25 and Epiphany, jQuery 1.7.2). In the JS console, $.ajax(...) returns the same error as $.get(...) ("XMLHttpRequest cannot load $filename. Origin null is not allowed by Access-Control-Allow-Origin").

    (But the searchindex now loads, and number of matched pages is now displayed).

  7. Dmitry Shachnev

    Looks like it can find methods, classes and other things that don't require reading the source file, but other matches are not displayed because data !== '' check fails, and thus listItem.append() is not called.

    Here is a screenshot of Chromium and Firefox showing search results in MathJax docs, for comparison.

  8. Georg Brandl

    You're right, I was trying with a search word that found mostly objects, not text matches. With the latest revision it looks good to me (note that you can't get the fulltext snippets other than with ajax, so there will always be a difference.)

  9. Mark Mikofski

    still not working for me using file:/// on chrome (but does work on mozilla), is there a work around I'm supposed to add?

    chrome: Version 31.0.1650.63 m
    os: windows 7
    python: 2.7.6
    sphinx: 1.1.3

    If I use http (via simpleHTTPServer) then it does work on chrome.

  10. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.