Google Live Search 29

This is a script for Greasemonkey
that modifies the Google search page to make
the results show up as you type.

Steps to install:

  1. Install Greasemonkey
  2. Once that is done you can right click the following link and select
    Install User Script…: googlelivesearch.user.js

The Details

When the user types in the search field the browser fires the
input event. This event is dispatched any time the content changes
(for example when doing drag and drop or copy paste). When this happens a timer
is started and a few milliseconds later a HTTP GET request is sent
to http://www.google.com/search?q=. The
reason to use a timer here is to prevent a request to be sent after every change
and only send the request when the value of the input stabilizes. This request
is sent in the background using a XMLHttpRequest
object.

Once we get the result we remove the old results from the page using DOM
level 1 methods. Then we analyze the returned string and use
innerHTML to input the result into the current page. You have to
use innerHTML because Mozilla cannot parse text/html without
creating a view (frame/window) for it.

Udpated:

I added a hash to document.location so that when one goes back the search page the result is remembered.

29 thoughts on “Google Live Search

  1. Emil Jun 10,2005 22:48

    Nice one, seems like a silly thing but it’s actually quite helpful to see the results for the given criteria as you type, and the speed is impressive.

    Too bad I can’t get greasemonkey to run under dpa1.

  2. Erik Arvidsson Jun 10,2005 23:28

    I’m getting really tired of the internal Firefox exception that always happen when working with text inputs:

    Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]” nsresult: “0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)” location: “JS frame :: http://www.google.com/#gls=google%20live%20search :: anonymous :: line 135″ data: no]
    Source File: http://www.google.com/#gls=google%20live%20search
    Line: 135

  3. Emil Jun 11,2005 00:46

    I hear you, those kind of errors are frustrating and really should never happen. Seems to occur in a quasi-random fashion too (during similar circumstances but only occasionally)… which doesn’t make things easier to track down.

  4. Erik Arvidsson Jun 11,2005 01:04

    I believe they happen any time focus() is being called from script.

    https://bugzilla.mozilla.org/show_bug.cgi?id=236791

  5. Emil Jun 11,2005 01:25

    Hmm, figured it had something to do with focusing but I do seem to recall it happening when focus is gained in other ways too…

  6. foO Jun 11,2005 07:11

    damn, i cant even tell you how many times i’ve seen that damn error in the JS Concole in firefox of late… been driving me absolutely crazy, man.

    hell, i removed my little Comment Notifier (temporarily?) because i was getting random XML “Unknown.” errors, which i was never really able to track down properly, which sucks.

    this is really kewl, btw… it’s like that “Live Search”, but for Google :)

    luv’n it… heh.

  7. Matt McCarthy Jun 22,2005 07:36

    Neat!

    Works flawlessly on the home page. I get a few errors on the search result page when I modify my search:
    – elmAdvanced has no properties / 174 several times
    – this.footerElement.parentNode has no properties / 125
    – A Greasemonkey message saying “Exception when injecting : {}”

    Doesn’t work in Turnabout for IE yet, though. Doesn’t look like it would be hard to port, though. Do you have any plans to port it? This (and equivalents for Yahoo and MSN) might be a good candidate for including with future releases.

  8. Jesper Rønn-Jensen Jun 22,2005 09:31

    Nice. This really motivates me to dive into these greasemonkey scripts.
    Adrian Holovaty created a similar script which is more-or-less directly the functionality of Google Suggest.

  9. Erik Arvidsson Jun 23,2005 00:40

    Matt: I was actually planning to spend some work on this today but I had some high priority things holding me up the entire evening/night. I’ll look at it tomorrow.

  10. Erik Arvidsson Jun 23,2005 22:50

    Matt: elmAdvanced is not from my script

    I saw the Greasemonkey exception a few times when developing this but reinstalling the script solved that for me.

    I’m still investigating the this.footerElement.parentNode error. I don’t see this but I guess some other script tampering with innerHTML might be the cause for this (innerHTML is evil)

  11. Pingback: azadworks.com - Blog Archive - Google Live Search

  12. Edible Energy Aug 23,2005 00:20

    I put a link up to this script on Metafilter today, and someone noticed that going to google autosuggest causes an infinite loop.

  13. Rafi B. Sep 12,2005 22:09

    A solution for this error:
    Error: [Exception… “‘Permission denied to get property XULElement.selectedIndex’ when calling method: [nsIAutoCompletePopup::selectedIndex]”

    Just put autocomplete=”off” on an input you’re getting this error on,
    or use this script to go through all your necessary elements and “fix” them:

    if (document.getElementsByTagName)
    {
    var inputElements = document.getElementsByTagName(“input”);
    for (i=0; inputElements[i]; i++)
    inputElements[i].setAttribute(“autocomplete”,”off”);
    }

    Still no word from Mozilla about this awful bug.
    (https://bugzilla.mozilla.org/show_bug.cgi?id=236791)

  14. Erik Arvidsson Sep 13,2005 10:27

    Rafi: This bug has been fixed in 1.5 b1

  15. ezuk Dec 5,2005 01:07

    It just doesn’t work for me… I have Greasemonkey and FF1.5 and the script is enable for http://www.google.com/* under “Manage User Scripts”. And yet, no go…

  16. ezuk Dec 5,2005 01:13

    What it basically says in the Javascript console whenever I type a char and wait is:
    “Error: XMLHttpRequest is not a constructor
    Source File:
    Line: 165″

    And right when I load google it says:
    “Error: Selector expected. Ruleset ignored due to bad selector.
    Source File: http://www.google.com/
    Line: 5
    Error: Unexpected end of file while searching for closing } of invalid rule set.
    Source File: http://www.google.com/
    Line: 6″

  17. Anil Sharma Jan 30,2006 23:55

    The following error seems to always occur when calling focus/ blur from a onkeydown event handler.

    Error: [Exception... "'Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]” nsresult: “0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)” location: “JS frame ::

  18. Erik Arvidsson Jan 31,2006 01:04

    Anil: That is a known Firefox bug which has been fixed in 1.5 I believe.

  19. Juan F. Moncada Feb 17,2006 02:39

    Hi all: I had the same problem (“Permission denied to set property…”) and I’ve been able to solve it with Rafi’s suggestion on September 12th (thanks for your help). I’m using Firefox 1.5.0.1, so this issue hasn’t been solved in 1.5.

  20. Erik Arvidsson Feb 19,2006 13:56

    The bug is still in Firefox 1.5… I’m not sure about Firefox 2.0 alphas.

  21. Dylan Doxey Mar 18,2006 11:48

    Hi, in my DOM code I have generally used the convention of setting attributes like this:
    var inp = document.createElement(‘input’);
    inp.autocomplete = ‘off’;

    However this does not do the trick for the autocomplete attribute, because it is probably not added by the createElement() method.

    This does work:
    var inp = document.createElement(‘input’);
    inp.setAttribute(‘autocomplete’,’off’);

    Thanks for the tip!

    Dylan

  22. Erik Arvidsson Mar 20,2006 10:03

    The auto complete feature is a pretty strange beast. Setting this does not really do anything to the element. The auto complete system checks for an expando property called autocomplete instead.

    In Firefox there is a difference (rightly so) between JS/DOM properties and attributes and there isn’t any DOM property called autocomplete.

  23. derak Oct 25,2006 11:05

    You helped me fix a bug. Thank you.

  24. EER Oct 31,2006 07:23

    You helped me fix an annoying message, thanks a lot :)

  25. dirar Feb 7,2007 13:34

    Not fixed in 1.8, don’t know about 2… but autocomplete = “OFF” solved the problem

  26. Steve Bearman Feb 27,2007 06:02

    A simpler solution than setting ‘autocomplete’ = ‘off’ for each element is to set the property for the form itself. The property is then inherited by all the form elements.

  27. Spam Banjo @ The Hell Hole Jun 5,2007 07:36

    This worked for me.

    1 prev_field = document.forms['meterform'].elements[last_one] ;
    2 prev_field.setAttribute(“autocomplete”,”off”);
    3 prev_field.focus();

    If I remove line 2 I get the error. Otherwise it’s fine. I now employ this method as standard practice when manipulating field focus and it seems to work fine for me.

  28. Pingback: tkdmatze » Blog Archiv » Einstiegsdroge Userscripts

  29. Pingback: free website audit report, seo audit document, google seo audit, free seo audit tool, seo technical audit, seo audit service, search engine optimzation audit, free seo site audit

Comments are closed.