Home » Posts tagged 'ChromeExtensions'

Tag Archives: ChromeExtensions

An unanticipated benefit of using the Chrome Extension Gallery

I’ve written 3 Google Chrome Extensions. The first two were for use at the Day Job, so I initially hosted them on an internal server. Eventually I moved them out to the Chrome Extension Gallery. There are a few benefits to doing this over self-hosting:

  • better publicity – as it’s the prime location for extensions, people will go here looking for them, and they may find your extension
  • Google maintains the site, so uptime’s pretty good
  • the extension gallery maintains the update manifest

The first two benefits aren’t a big deal for the Day Job extensions. We’ve a team to keep the servers up, and internal advertising channels. Mostly I enjoyed being freed of the monotony of generating new update manifests.

A bonus benefit

Last night a new benefit reached out and figuratively grabbed me by the lapels and shook me. I got mail from Google Extensions. They wanted to warn me about a problem with my extension. Sort of. Here it is:

From: Google Extensions
To: Google Extensions
Subject: Important: Your extension is broken for all Chrome users – Here’s how to fix it

Hello,

You are receiving this mail because you are the owner of an extension
on chrome.google.com/extensions that was broken by a recent update to
Chrome. This affects ALL users of Chrome, so it is something you
should fix as soon as possible.

Fortunately, the fix is very simple.

In earlier versions of Chrome, the following syntax was supported:

<script src="example.js"/>

In current versions, this is no longer legal and must be changed to:

<script src="example.js"></script>

All you have to do is replace any instances of this pattern in your
extension and re-upload, and it should work again.

We try very hard to avoid ever making breaking changes to the
extension system, but in this case we did not notice it until the
release had already been shipped. Since this is affecting users right
now, we thought you’d appreciate details on what happened, and how to
fix it yourself immediately.

Thanks,

— The Chrome extensions team

There’s a new version of Chrome. It has a flaw, or at least a regression – the old syntax for including a script isn’t supported. I’m a little disappointed that that change went in, but I’ll get over it.

The point is, once a bug was discovered, Google scanned all the extensions, identified those that were affected by the bug, and alerted the owners. I appreciate that they took this step. It’s much better than just letting us sit around, waiting for users to tell us that our extension is broken.

I wish at the Day Job we had this kind of ability. As things are, when a problem is discovered at a customer’s site, we don’t have an automated way of investigating their installation to see if their data will be problematic, or if the product wizards they’ve written are going to cause a problem. We sometimes obtain copies of sites’ databases and configuration settings to diagnose a pernicious bug or to evaluate whether a proposed upgrade will be harmful. Unfortunately these instances are infrequent and are always a manual process.

At the risk of seeming ungrateful

I appreciate the notification, and will get right on the update so my user isn’t affected. However, if I had my druthers, it would have been nice to have been told

  • which extensions are affected – Google’ve already looked at all the extension. They know which ones I need to change. Save me the trouble of grepping. Of course, this would necessitate customized e-mails, rather than an all-purpose message.
  • which versions of Chrome were affected (I mean something more specific than “current versions”)
  • whether this bug is fixed, or if it’s going to be fixed in the future. I’m left not knowing if this is a temporary aberration, or if I need to use the <script></script> syntax forever
  • Advertisements

Animating Google Chrome Extension Page Action Icons

I’m enjoying using (and working on) Library Lookup, but I’m not entirely satisfied with the Page Action icons that pop up when searching, or when a book is found, or not found. In particular, I wanted a small animation while the search was ongoing, something like this: .

Unfortunately, the animated GIF didn’t work – Google Chrome Extensions don’t support them.

Briefly deterred, I regrouped and tried a different tack – something I like to call A Bunch o’ PNGs and Some Javascript. First, I got myself three PNGs to display (okay, that’s not entirely true – they’re what I made the GIF from to begin with)

  • searching_eyes_right.png
  • searching_eyes_down.png
  • searching_eyes_left.png

Next, I needed a way to switch between the frames. I put the image names in an array, initialized an index, and wrote a small function that uses window.setTimeout to switch to a new icon every 0.3 seconds.

                var searching_images = ['searching_eyes_down.png',
                                        'searching_eyes_right.png',
                                        'searching_eyes_down.png',
                                        'searching_eyes_left.png'];

                var image_index = 0;
                
                var keep_switching_icon = true;
                function rotateIcon()
                {               
                   if ( keep_switching_icon )
                   {
                      chrome.pageAction.setIcon({tabId: sender.tab.id, path: searching_images[image_index]});
                      image_index = (image_index + 1) % searching_images.length;
                      window.setTimeout(rotateIcon, 300);
                   }
                }

Then I start the rotation just before hitting the web server to see if the book’s available and stop it when a result is found. Flipping the keep_switching_icon flag as soon as the search comletes ensures that the animating thread doesn’t overwrite a “found” or “not found” icon.

                window.setTimeout(rotateIcon, 300);
                   
                var xhr = new XMLHttpRequest();
                xhr.open("GET", searchurl, true);
                xhr.onreadystatechange = function() 
                {
                    if (xhr.readyState == 4) 
                    {
                       keep_switching_icon = false;
                       if ( xhr.status != 200 )
                       {
                            chrome.pageAction.setIcon({tabId: sender.tab.id, path: 'my_book_error_19.png'});
                            // other error handling
                       }
                      // process found and not found cases
                };
                xhr.send();