Greasemonkey script: Google Suggest

Written by Adrian Holovaty on March 19, 2005

I can't get enough of Greasemonkey, Aaron Boodman's Firefox extension that takes my All Music Guide extension idea to the next level by making it super simple to create and distribute scripts that alter Web pages.

Here's a Greasemonkey script I just cooked up: Google Suggest for Greasemonkey. It makes the dynamic drop-down from Google Suggest a bona fide part of Google, placing it on the Google home page and on search-result pages.

Installation directions for Greasemonkey novices:

  • Run Mozilla Firefox.
  • Install the Greasemonkey browser extension.
  • Restart your browser.
  • Go to my script's page, click "Tools | Install User Script...", and say OK to the prompts.
  • Go to Google, type in search terms, and watch the suggested search terms appear.

Tech note: The cool thing about the script is that it leverages Google's well-abstracted autocompletion library by dynamically appending it to the page as a <script> element and running a single initialization function. The dynamic <script>-appending technique could be a handy way to do more powerful stuff with Greasemonkey in the future.

UPDATE, April 26: If you don't want to install Greasemonkey, just install this super-simple Firefox extension to get the same functionality:

Google Suggest extension


Posted by Aaron on March 19, 2005, at 9:13 p.m.:

Awesome, adrian.

Posted by Michael Bierman on March 20, 2005, at 6:16 a.m.:

Great idea! But it doesn't seem to work.

Posted by Jed on March 20, 2005, at 8:31 a.m.:

Yeah, it doesn't work for me either.

Posted by Jed on March 20, 2005, at 8:34 a.m.:

Actually, I think it doesn't work with Butler. When I have Butler activated I get Javascript errors, but when I deactivate it, this works fine.

Posted by Adrian on March 20, 2005, at 11:22 a.m.:

Thanks for the report, Jed! I'll look into better interoperability with Butler.

Incidentally, this brings up an interesting problem that Greasemonkey should probably address in the long term -- script dependencies/compatibilities. We've talked about it a little bit on the GM mailing list, but nothing's come of it just yet.

Posted by Scott Johnson on March 20, 2005, at 8:20 p.m.:

Weird...I have Butler running, and this script works fine for me. :)

Posted by Follower on March 22, 2005, at 7:48 a.m.:


In the code you make the comment "Use setTimeout because there's a slight delay between the point at which the <script> is created and the point at which the InstallAC() function is available." I used to do that too, but discovered you can actually add an "load" event handler instead.

Below I've copied in a comment I made here: <>


Update: Okay, here's a much nicer implementation of the injection code that doesn't require the timeout hack. It relies on using a "load" event triggered when the inserted script element has loaded--handy really: (Inject External File Bookmarklet 2)

javascript:(function(){if(typeof(extjs)=='undefined'){extjs='';};extjs=prompt('File to inject:',extjs);var script=document.createElement('script');script.src=extjs;var evl=new Object();evl.handleEvent=function (e){onInject();};script.addEventListener('load',evl,true); document.getElementsByTagName('head')[0].appendChild(script);})();

Posted by Adrian on March 22, 2005, at 3:55 p.m.:

Follower/Phil -- Thanks! I've updated the script. I'd been wondering about a better way to do that. Excellent.

Posted by Adrian on March 22, 2005, at 4 p.m.:

FYI, this script has been incorporated into (with permission).

Posted by Daniel on March 23, 2005, at 4:13 a.m.:

I've also updated the script at with the latest Google Suggest script.

Posted by Anthony on March 24, 2005, at 3:55 a.m.:

Finally, an easier way to make webpages work better!

Posted by Etienne on April 1, 2005, at 8:44 a.m.:

This is the most useful GM script I've yet seen.

Suggested improvement - change the @include line to "http://*.google.*/*" - that way, international editions of google also get google suggest (i.e. not just, but also,, etc.).

Posted by Adrian on April 1, 2005, at 2 p.m.:

Nice idea, Etienne! Thanks.

I've implemented it, with the caveat that it'll work on non-Google sites that happen to have a ".google." subdomain -- such as

Posted by Jeremy Dunck on April 8, 2005, at 12:49 a.m.:

Yeah, so this is a wart.

http://*.google.*/* will match international, but it will also match

The wildcard is nice and simple for folks that aren't up on RegEx, but it's also pretty loose. You'd basically have to write an @include for every top level domain to include only what you actually meant to.

@include http://**

@include http://**


ad nauseum.

So that sucks.

Maybe GM should be a little smarter and do its own TLD matching, so that

@include http://*.google.*/*

actually means what people want, which is:

@include http://*.google.<any valid TLD>.

(scurries off to bugzilla)

Posted by Jeremy Dunck on April 8, 2005, at 12:56 a.m.:

Logged as 9808. But it won't be fixed soon. More important issues to deal with. Thank you, please drive through. :)

Posted by Robert Andrews on April 16, 2005, at 11:49 a.m.:

So how do I get rid of the bar at the foot of the browser, which has "google_suggest" on it, on a blue background?


Posted by Adrian on April 18, 2005, at 5:04 p.m.:

Robert -- I don't see anything like that. Any idea how I could reproduce the problem?

Posted by Anton on April 21, 2005, at 2:57 p.m.:

why isn't autocomplete turned off on the input box? Looks bad when I get my earlier searches in another dropdown. Also it should be turned off on the new google history service, because it doesn't make sense to have it there (perhaps it should rather give you autocomplete on your previous search?)

Posted by anonymous on May 20, 2005, at 5:12 a.m.:

It seems as if your script doesn't work for the new Google personalized homepage at

Posted by Koushiro on May 20, 2005, at 9:12 p.m.:

It won't work on the personalized homepage because the search form there has action=, while the script searches for a form with action=/search. I'm no javascript hacker, so I'm not quite sure how to fix it elegantly: a very clumsy fix would be to just replace the line:

return document.evaluate("//form[@action='/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

with something like:

if (document.evaluate("//form[@action='/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) {

return document.evaluate("//form[@action='/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

} else if (document.evaluate("//form[@action='']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) {

return document.evaluate("//form[@action='']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;


But, as I say, that's a relatively clumsy way of doing it. Works, though.

Posted by Neil Grover on May 26, 2005, at 6 p.m.:

nice work. one fix if I may suggest one. The browsers autocomplete feature will popup overtop of the javascript one. to prevent this I added the line:


now my code looks like this:

(function() {

get_search_form = function() {

return document.evaluate("//form[@action='/search']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;


// Find the search form. If it doesn't exist on this page, don't bother.

if (!get_search_form()) return;

// "Import" Google Suggest JavaScript by dynamically appending it to the

// current page as a <script> element.

var s = document.createElement('script');

s.src = '';

var ev = new Object();

ev.handleEvent = function (e) {

var f = get_search_form();


InstallAC(f, f.q, f.btnG, 'search', 'en');


s.addEventListener('load', ev, true);



Posted by Aron Dazim on May 30, 2005, at 8:49 a.m.:

The above code is implemented in the CustomizeGoogle script (if you don't want to edit the code by yourself)

Posted by anonymous on June 3, 2005, at 4:42 a.m.:

I am using your Firefox extension for a little while and I am fascinated with it. But have one question - a problem I can not resolve: when I use "shift" and try to copy any word in a "Google search window", it is deleted immediately. Is it possible to abort such function?

Posted by Sallu on January 23, 2006, at 12:35 p.m.:

Google is offerring an 2005/2006 version NAV which is a great product by symantec.. (well almost) - I saw some news on google av on - is this free antivirus software? where can I download the latest version of google av?

Posted by Suraj jain on May 10, 2006, at 1:49 a.m.:

Here is the code to display entries from database as Google Suggest . It is an combination of ASP + JS . works with acces database . Download the full source code and see example at

Posted by Thibaud on June 28, 2006, at 8:59 a.m.:

Didn't work for me. Firefox Greasemonkey 0.6.4.

When I go to Google and type in the search field nothing like Google Suggest happens.


Comments have been turned off for this page.