Victor Quinn

Programmer, Legal Scholar, Problem Solver.

DuckDuckGo Safari Extension

DuckDuckGo.com is a great search engine alternative to Google. I first read about it on HackerNews, and was intrigued. In a nutshell, I love DuckDuckGo’s approach to privacy, offering searches over a secure channel and the way they do not cache any search history. I also like their interface and the zero-click info is fantastic, often saving me a trip to Wikipedia to parse through an entire article. Never having to page through search results was at first just neat, now when I occasionally use Google, I am annoyed because clicking the “Next” button seems antiquated. And my favorite feature, as a developer, is the bang syntax. Adding something like !php at the beginning of my search query automatically does the search on php’s website. Likewise for many other things I use on a regular basis like !drupalapi. Overall, I have grown to love it and use it as my primary search.

But this post is not meant to be solely about evangelizing DuckDuckGo (though I’m quite happy to do so!). At first, I tried using it as my primary search, but always went back to Google because there wasn’t really a good way to set it as the search default in Safari, my browser of choice. There is a Safari plugin called Glims which allows for adding DuckDuckGo as a search engine but in my experience I found it to be a bit buggy. As a web developer, I simply cannot get my work done with a buggy browser. So, this prevented me from using DuckDuckGo on an everyday basis. Until Safari Extensions came along.

Safari recently added extensions to the latest version of their web browser. And they are based entirely on web standards. And I am a web developer. And I’ve been wanting a way to add DuckDuckGo to Safari…

Taking the obvious path, I decided to write such an extension. I first tried to add DuckDuckGo to the existing Safari search widget. Turns out this is one of the things to which Safari Extension Developers do not have access. So, I went with the next best thing, creating a simple bar which had a DuckDuckGo search in it. This way, it will always be there ready for searching and I will actually use it.

I decided right off the bat to add a couple of features that make it (in my opinion) more useful than the default search. First, is the option to open a new search: in the current tab, in a background tab, in a new tab, or in a new window. This is configurable so the user can do whatever they want to suit their preferences. This is not possible in Safari’s default search. I also added a context menu search with the same options (but is separately configurable, so if you like searches in the bar to open in the same tab, but searches via the right-click menu to open in a new tab, that is possible). So, with the context menu search, in Safari, you can highlight any text, right click, and see a menu item to perform that search. I also added the option to perform the search via SSL. As mentioned above with the privacy issues, one feature that is nice with DuckDuckGo is the ability to search with SSL Encryption. So it is on by default, but there is an option in the extension so users can turn it off if they want to do plain, not secure searches.

I have had a few requests from users, the first was to add a shortcut to the extension to jump to the search field. Now, press Ctrl-d to jump to the search bar. I chose Ctrl-d because I couldn’t think of anything else it was used for and it seemed to make sense. D for Duck!

I also had a request to remove focus when performing a search. When I tested and use the extension, I prefer to have my searches open in a new tab. So I did not catch a small bug which occurred when opening a search in the current tab. The issue is that the search bar continues to have focus, so keyboard shortcuts do not work. So I added a small change to remove focus from the search bar once the search has been performed.

Another request was to reduce the size of the bar. Extension bars in Safari take up a static amount of space, so I sought to maximize the amount of space used by the bar. I also like to have a nice big font so it’s easier on the eyes. So I made the search box as large as possible while still staying in the bar. It looked pixel perfect on both of my Macs and my fiance’s laptop, so I thought everything was good to go. 

Well, apparently it is not perfect on everyone’s machine and there were a couple of requests to reduce it’s size. So, I did just that in the latest version which I put live a few minutes ago. I also updated the DuckDuckGo favicon to the newest version. It now looks like this:

While this is more explanation than anyone probably needs about an extremely rudimentary Safari Extension, I thought it worthwhile to document my progress, and who knows, someone may find something I’ve said interesting or useful.

Oh, and one other thing, this project is currently open-source and hosted on github, so if anyone wants to tweak/modify it or make other improvements, go for it!