Wednesday, 22 August 2012

Chrome NCR Extension

NCR : No Country Redirect
I've finally made my first Chrome Extension. This as I saw the need of something to avoid automatic country redirections for two specific Google sites: blogspot.com and google.com. I've been annoyed for a long time that when visiting google.com I get redirected to for example google.no when in Norway, google.co.uk when in the UK and so on. Same thing goes for visiting blogger blogs (blogspot.com). When I type in .com I would like to stay on the .com pages. This extension is the solution to this problem.

I didn't bother writing a tutorial on how I did this, as there already are heaps of nice once out there. This post is just a summary on what I did, including links to a few nifty resources on the subject. However, if you want to check out the source code for the extension that can be done at code.google.comgithub.com.

13th of August
It all started with some searching on the Net. I found the following pages specially useful:

After quite a short period of time I had my first extension up and running. I used the Page action by URL sample as a starting point. The tabs documentation was also very handy for me.

Version 0.1 beta beta beta. Still using the icons from the sample code.

14th of August
Ran into problems as I failed reloading my plugin while I was developing. Despite clicking the extension's "Reload (Ctrl + R)" link the extension files didn't get reloaded when I was debugging. The console showed old debugging messages in stead of new ones. When I did a "Ctrl + R" in the debugging window as well the problem got solved though. That seemed to refresh the extension code. Note that I later realised that despite of running exact version of Chrome, with the exact same extensions, this only is the problem on one of my computers. No idea why.

16th of August
Due to wonderful summer weather in Norway the development has almost been standing still the last couple of days. The first working version of the plugin is ready now though. Did spend some time getting the regular expressions correct. Might have to do some more tweaking, as the plugin is not bulletproof yet. Will start running the plugin in my own browser now, just to see how it works.

Contacted Neli, my favourite designer and asked for her help on a logo for this plugin. Luckily she found the challenge interesting and wanted to help me out. Note that on the images directly below I'm just using a temporarily icon, from the sample code.

Ready for testing.

NCR has been added to Chrome.

Looked into memory usage for the extension as well. Seemed OK. Did some optimisation of the code to avoid a few loops.

Task Manager for Google Chrome.

17th of August
Decided to create an option page for the extension, enabling the user to turn on and off the domains to be NCR'ified. Hence I needed to learn how to do this as well, including how to store values.

I struggled a bit since the example page contained an error. The code did not close the script tag. It is of course supposed to be<script src="options.js"></script>
in stead of<script src="options.js">

I also had problems due to security changes (improvements) done to version two of the manifest. The second version is stricter, which is good though, than the first, hence executing JavaScript has to be done differently.

18th of August
Solved the problems related to executing JavaScript, however I disabled the entire options page and decided to instead implement options as a feature in a later version of the extension. The first version will be options free.

Received the great logo from Neli (as a birthday present - thank you!), and implemented that in the extension.

And after a few clicks my first extension was available to the world. It's going to be interesting to see how many user that will install it. If you're interested it can be downloaded from here. I will update the extension with new features soonish. As soon as you have installed the extension the updates will happen automatically for you as a user.

22nd of August
Found several of bugs in the first version of the extension. Hence I've been debugging for a few days. Ended up with re-writing main parts of the code. Finally it now seems to be working just as planned. The new version has been published to the Chrome Web Store and is to be rolled out to all active users (two in the number, not including myself, yay).