Detecting the version of an ActiveX IE Browser plugin – Part Two

January 7, 2009 No Comments by Richard

Note: if you haven’t already, please read up on FireBreath, the open source cross-platform plugin framework, and consider contributing.


Last time, in Detecting the version of an ActiveX IE Browser plugin part one, I discussed the ToString() method of an ActiveX object, and how it is called when an ActiveX object is instantiated from javascript with the syntax:

var object = new ActiveXObject("PART1.PART2");

If you read my last post, then you will remember that if you don’t implement this function, you get the following message:

Object doesn't support this property or method

During my testing before, I had incorrectly assumed that this prevented the object from being instantiated.  However, all it really does is instantiates the object and then throws an exception.  So, you actually could, if you wanted, catch that exception and then check the error message.

Writing the code

So, if we wanted to write a function that would notify us when the plugin was installed, all we need to do is try this repeatedly until it works; however, we don’t want to overload the browser, so a setInterval or setTimeout would probably be appropriate.

Here is a function that I threw together that is similar to the one that I wrote for work.  I haven’t tested it, but I have tested the one I use at work, and they are pretty similar in all functional aspects, so it’ll probably work.

if (!ColonelPanic) { ColonelPanic = { }; }
ColonelPanic.ActiveXIdentifier = "ColonelPanic.AwesomePlugin";
ColonelPanic.WaitForActiveXPlugin = function(callback) {
    var plugin;
    try {
        if (new ActiveXObject(ColonelPanic.ActiveXIdentifier))
            callback(); // You could change this to pass back a version number
    } catch (e) {
        if (e.message == "Object doesn't support this property or method")
            callback(); // it created it, but doesn't support .ToString()
    setTimeout(function() { ColonelPanic.WaitForActiveXPlugin(callback); }, 300);

Making it cross-platform

Now, if you are like me, you don’t want your plugin to work on just one browser; so, we’ll make another function that will detect what plugin type is supported and call the correct function.  We’ll save the plugin detection function for NPAPI (firefox) type plugins for another post — I have a lot to write about NPAPI plugins.

ColonelPanic.WaitForPluginInstall = function(callback) {
    if (typeof(ActiveXObject) != "undefined")
        // Internet Explorer
    {   // other (firefox, safari, opera, chrome, etc)

Now, there is still one last task — we need a way of determining the actual version in case the plugin has updated since we last restarted the browser, to facilitate background updates. That will probably be my next topic =]