Search The Current Site - A Firefox Extension
There are lots of search engine plugins for Firefox, and it’s easy to make a simple search plugin for your own site. That’s why it came as a bit of a surprise that I couldn’t find any search engine plugins for searching the currently open site. So I made one.
Let me clarify - I don’t mean searching my site. I’m talking about searching whatever website is displayed in the currently active Firefox tab. For example, let’s say you browse to example.com and discover their on-site search features suck/are nonexistent. With this extension you can just select “Current site” from the search bar, type in your query and hit Enter to search the entire site for the keywords you entered.
The Firefox extension that I have created will add a new search engine to the Search Bar. This search engine is called “Current site” and it will search the entire website that you’re on for whatever you enter in the search box. It uses Google to perform the actual search.
The exact behaviour of this extension depends on what you’ve got open in the current tab :
- A normal webpage - search the current site via Google.
- Google - search the last site that you searched with this extension.
- Blank tab - do a normal Google search (not constrained to a site).
This extension is experimental, so use at your own risk!
Technical Notes
This extension doesn’t use the site: command. Instead it appends the sitesearch argument to the Google search URL. The effect is the same, but sitesearch doesn’t show up in the input box on Google’s page, and any further queries you make from that page are still constrained to the website’s domain.
Creating the extension was pretty hard. For one, it really had to be an extension, not a standard search plugin, because the search engine plugin format doesn’t have a way to get information about the currently open site. I needed to write some JavaScript to get the current URL, extract the domain name and append it to the query string. That was easy enough. The real trouble began when I started trying to figure out how to attach that code to a search engine object.
Turns out there is a nsIBrowserSearchService service that manages these things. You can programmatically add a new search engine and then retrieve it as a nsISearchEngine. This interface has a method - getSubmission() - that Firefox calls when it needs to determine the URL to open when something is searched. The method returns a nsISearchSubmission object. I had to override the aforementioned method to insert an additional argument in the URL.
Oh, did I mention that none of this is really documented anywhere? Sure, there are some terse interface docs on a third party site (see below), that can be useful if you know what to look for. I didn’t, so I had to analyze the source code. Arrgh.
Some links that should get you started (or confuse you completely
)
October 7th, 2008 at 3:01 pm
@nettrotter - That looks good, I’m sure some users will find it useful.
October 7th, 2008 at 2:56 pm
Maybe you guy would like to try a bookmarklet. It doenst use any third-party plugin. Just put this bookmarklet in you bookmark toolbar. When you click it, it will pop up window for keyword input to search. the other way is that after you highlight some keyword in the page, click the bookmarklet and it will do search the current site from that keyword via google.
javascript:q%20=%20%22%22%20+%20(window.getSelection%20?%20window.getSelection()%20:%20document.getSelection%20?%20document.getSelection()%20:%20document.selection.createRange().text);%20if%20(!q)%20q%20=%20prompt(%22%E8%AF%B7%E8%BE%93%E5%85%A5%E5%85%B3%E9%94%AE%E8%AF%8D:%22,%20%22%22);%20if%20(q!=null)%20{var%20qlocation=%22%20%22;qlocation=(%22http://www.google.com/search?num=100&hl=zh-CN&newwindow=1&q=site:%22%20+%20escape(location.hostname)+%22+%22+q+%22%22);window.open(qlocation);}%20void%200
October 7th, 2008 at 2:49 pm
such a good extension. I like it very much.
October 1st, 2008 at 10:02 pm
I did some quick research and it appears that it isn’t possible to create a custom button for FF without packaging it as an extension, or using a third-party button manager addon (like Custom Buttons 2).
October 1st, 2008 at 9:22 pm
Hallelujah. At last I’ve found you.
Why this obviously desirable adaptation of a publicly accessible Google feature has been so elusive for Firefox 2, then 3, users is beyond me. Many thanks to White Shadow.
P.S. Would love to see a Firefox 3 toolbar button for it - that opens a pop-up site search input field for this search alone. The button offered above by ithinc isn’t for Firefox 3 as far as I can tell. Could we have one that does not require additional software (the way ithinc’s requires Custom Buttons 2)?
May 31st, 2008 at 4:51 pm
Hi,
Thanks a lot.
Super DragAndGo is almost what I needed, although instead of drag, “Ctrl-Click” might have more universal appeal (MS Office hangover, u c).
And yes, I did mean plain text link, rather a contiguous block of text - isn’t the extra action of selecting that, a drag on our mouse entangled wrists (or the touch-pad chafed fingertips), especially when you are researching thousands of sites.
Regards,
ItsSri
May 31st, 2008 at 12:06 pm
Heh, thanks
Can you elaborate on that “anything on a browsed page” comment? A plaintext link would be one possibility; what else?
Edit : this addon might be similar to what you’re looking for.
May 31st, 2008 at 9:33 am
Hi,
I do quite a bit of web content research and I had been searching for something like this for ages; the closest I could get to was using the Yahoo toolbar, but it sucks! and many times, I installed it whenever I was desperate and uninstalled it as soon as it frustrated me. Now, you have made my day.
This is the exact phrase I used on google today - “firefox extension to search in current website” - and your site was listed second. I wonder how I missed it earlier?
Another plugin/extension that is wanting is:
“Ctrl+Click” on anything on a browsed page = parse a link from that anything and open in another tab
If you could do it, you are sure to be deluged with …
Hey! BTW, has Abhishek sent you at least a picture of his girlfriend
ItsSri
May 26th, 2008 at 12:32 pm
I never had any problems using this little marvel with Firefox, that’s all I can say, besides the smartness of these jewels, that is Firefox and this extension!
April 28th, 2008 at 9:14 pm
No idea. I’m not that familiar with FF plugin development, so I don’t even have an idea where to start looking for the bug.
April 28th, 2008 at 9:00 pm
Sometimes this extension simply wont work. Any solution????
April 20th, 2008 at 1:27 am
Interesting
We’ll see about the extension list.
April 20th, 2008 at 12:58 am
Dude I can give you away my girlfriend for this. You are a genius, and this addon can be immensely popular if given even slight exposure. This was something that I had been looking for ages. Why dont you post this on the official addons list. Trust me there are several others looking for it. Thanks man you rock. God Bless You.
April 2nd, 2008 at 1:27 pm
[...] 3.Current Site Search 1.0 [...]
March 10th, 2008 at 2:43 am
March 10th, 2008 at 2:30 am
Erratum : I didn’t mean an executable, but an install for a search engine of a special form…. gosh, I’m no geekie am I ?! Well, I don’t know how to cook but I sure do like that cookin’ !
March 10th, 2008 at 2:25 am
As White Shadow, the author, mentions, the very specificity of this extension requiring the assistance of an executable to be installed makes it impossible to have this extension appear as other traditional Firefox extensions. It wouldn’t be much of a problem if it weren’t the consequence of bringing ‘Search The Current Side’ to few, making those few, myself anyway, feel as a privileged person!
Well, we searched, and we found!
I think it’s good that we take all opportunities - chats, forums, blogs - to spread the good word… and the link!
As for me, enjoying this little gem every day of the year!
March 10th, 2008 at 1:56 am
Thanks! I’ve been looking for this ever since I’ve made the switch to firefox 3. Installing the google toolbar or the web search pro plugin just for that would have been too much.
February 27th, 2008 at 6:41 pm
Interesting. By the way, I fixed the link in your first comment.
February 27th, 2008 at 4:53 pm
The button is Search the current site with Google, located at http://custombuttons2.com/forum/viewtopic.php?f=35&t=671.
February 27th, 2008 at 4:51 pm
Inspired by your article, I have completed a CustomButtons button (link). It is a button, besides, it adds a menuitem in the contextarea context menu, and it supports drag&drop search. Overriding of getSubmission will lead to some problem when more than one window are opened.
February 23rd, 2008 at 10:41 pm
Thank you
As I’ve mentioned previously, this plugin has a different format than other search plugins, so it probably wouldn’t be accepted in that directory.
February 23rd, 2008 at 10:12 pm
MAN, you made my day!!! Yoooohoooo, cannot believe it’s true! An absolutely indispensable extension. It is one whole year that i’ve been looking for a search engine like this, and found none (so far, that is :)))
As someone suggested above you should definitely consider adding this one to http://mycroft.mozdev.org/ - that was the first place i looked and was disappointed that i found nothing, so maybe this will prevent other people from wasting their time elsewhere.
February 19th, 2008 at 11:30 am
I uninstalled and reinstalled the extension and for some reason the icon does not show anymore in the extension manager but does in the search bar. It was there the first time. any ideas?
February 19th, 2008 at 8:57 am
A bug is found. Once you open a second window, the “Search Current Site” will encounter an error.
February 16th, 2008 at 3:57 pm
@White Shadow, one might be searching a site for occurrences rather than for redundancies ; I mean, finding the text first to search where else it appears in the site is a half solution!
February 16th, 2008 at 3:12 pm
I don’t know about Firefox, but in Opera you could select some text and press Ctrl-C followed by Ctrl-D to do that…
February 16th, 2008 at 5:58 am
This is a very nice extension. I’ve been looking for this for some time now, because the only point I missed was the site search, and I didn’t want to install Google Toolbar for that sole purpose! Thanks a lot, works great!
February 15th, 2008 at 1:47 pm
I’m looking for another search plugin to open the “selected text” directly as an url. It seems a search plugin could not satisfy either.
February 15th, 2008 at 1:35 pm
Great! It would be more appreciated if it could be a GreaseMonkey script.