Yesterday I bumped into a strange Operation Aborted error. I really did not where to start looking for this error. I tried running the web site with first chance exceptions [1][2][3] turned on, running a script debugger and HTML validator but without any luck. Seems that the error is IE app related and you have to debug the IE process itself in order to find it. I did not want to go into that muddy waters so I run a more deeper search in google and I found the reason.

One of our third party components was generating HTML on the fly while the DOM is still being created. In short the problem is that scripts that are not direct child of BODY cannot modify the BODY element while the DOM is still being created.

You can find detailed explanation on the great Infinities Loop blog and in BUG: Error message when you visit a Web page or interact with a Web application in Internet Explorer: “Operation aborted” (KB 927917).

One possible solution is to put a setTimeout call for about 0.5s which calls your script at the time when (hopefully) DOM will be ready. I would not recommend this approach in general though.

For some reason the script which was marked with DEFER attribute, obviously was not deferred until the page is loaded. The problem was detected while running IE7.

[1] First and second chance exception handling (KB 105675)

[2] How to Stop on First Chance Exceptions – Visual Studio .NET 2003

[3] Demystifying first-chance exceptions (Part 1)