Jun 6, 2009

Another day in a developer's life....

Yesterday was a frustrating day.
By the morning I started to work (pairing with a really smart friend) on an apparently simple task: to automate the process of starting an internet explorer (ie) instance, navigate to a specific page stored on the local machine, wait for some processing to finish (notified by the page) and grab the results. Having some years of experience with Microsoft technologies, mainly developing COM components, and aimed with (lack of) humbleness I started to write a jscript script to drive IE through automation, after all how hard could that that be? Indeed, the first part was really easy:
var browser = new ActiveXObject("InternetExplorer.Application");
browser.Visible = true;
I run the just finished prototype and the browser opened, navigating to the desired page. I was really happy (and thinking how I am smart). So far, so good. But things started to get weird really fast. Even having a good grasp on IE's object model (I don't know it by heart) I failed miserably to retrieve a reference to a page element:
var browser = new ActiveXObject("InternetExplorer.Application");
browser.Visible = true;
while (browser.Busy) {
var element = browser.Document.getElementById("some-id");
After some time we decided to give up on using jscript and switched to C#, so I created a Windows Form application to host WebBrower control (hum... someone said IE?) but we kept seeing strange behavior. For instance, the page we were trying to load hosts a Silverlight application but IE insisted that we should install Silverlight; WTF? I do have Silverlight installed !!!

Well, at that time I was not felling so smart anymore; and since it was almost lunch time we decided to continue latter.
When I got back to work I was determined to get it working so I did what any reasonable developer does in such situations: I decided to do something else :) and I ended up watching a screencast about how to improve the experience for users that don't have Silverlight installed; hum.. interesting. 

The presenter suggested to disable the Silverlight add-on (instead of uninstalling it).
Great! Maybe the add-on was just disabled (due to some stricter security configuration when launching IE through automation).

Why I haven't thought about this before?
I started my application (C#) as fast as I could and a new browser appeared (in the same way as before), then I went to the add-on configuration dialog and voilà! There was no Silverlight add-on listed (how could I enable/disable it?).

So the problem was that, for some reason, IE was not even considering Silverlight add-on to be installed (but that was what IE was trying to say me all the time no?).

Then I launched IE manually (clicking on its icon on desktop) and opened the same add-on configuration dialog. This time I could see that Silverlight (and a lot of other add-ons) were installed and enabled.

Well, now I was starting to fell better :). But I still had to understand why I was getting different behaviors depending on how I launched IE. After some head screeching followed by some thinking and some extra searches I do figured out the issue, but that's the subject of a future post :)

Have fun! 


No comments: