Google Live Search
This is a script for Greasemonkey
that modifies the Google search page to make
the results show up as you type.
Steps to install:
- Install Greasemonkey
- 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.
June 10th, 2005 at 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.
June 10th, 2005 at 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: “0×8057001e (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
June 11th, 2005 at 0: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.
June 11th, 2005 at 1:04
I believe they happen any time focus() is being called from script.
https://bugzilla.mozilla.org/show_bug.cgi?id=236791
June 11th, 2005 at 1: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…
June 11th, 2005 at 7: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.
June 22nd, 2005 at 7: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.
June 22nd, 2005 at 9: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.
June 23rd, 2005 at 0: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.
June 23rd, 2005 at 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)
August 22nd, 2005 at 23:27
[...]
« Gmail Preview Bubbles
Google Live Search
Google Live Search This is a script for Greasemonkey that modifies the Google search page to m [...]
August 23rd, 2005 at 0:20
I put a link up to this script on Metafilter today, and someone noticed that going to google autosuggest causes an infinite loop.
September 12th, 2005 at 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)
September 13th, 2005 at 10:27
Rafi: This bug has been fixed in 1.5 b1
December 5th, 2005 at 1: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…
December 5th, 2005 at 1: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″
January 30th, 2006 at 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: “0×8057001e (NS_ERROR_XPC_JS_THREW_STRING)” location: “JS frame ::
January 31st, 2006 at 1:04
Anil: That is a known Firefox bug which has been fixed in 1.5 I believe.
February 17th, 2006 at 2: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.
February 19th, 2006 at 13:56
The bug is still in Firefox 1.5… I’m not sure about Firefox 2.0 alphas.
March 18th, 2006 at 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
March 20th, 2006 at 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.
October 25th, 2006 at 11:05
You helped me fix a bug. Thank you.
October 31st, 2006 at 7:23
You helped me fix an annoying message, thanks a lot
February 7th, 2007 at 13:34
Not fixed in 1.8, don’t know about 2… but autocomplete = “OFF” solved the problem
February 27th, 2007 at 6: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.
June 5th, 2007 at 7: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.
July 10th, 2007 at 1:27
[...] eingefügt werden, bekannt unter anderem durch den Youtube Videodownloader oder Google Live Search. Userscripts sind die Möglichkeit der Seitennachbearbeitung. Man kann beliebige Inhalte [...]