TypeError: Invalid calling objectThis only happens on Internet Explorer, primarily IE 11, but I've seen it on versions as old as 9. I searched through stack overflow for the cause of this error, and while many of the cases sounded like they could be my problem, further investigation showed that my case didn't match any of them. The code in particular that threw the exception was collecting resource timing information for all resources on the page. Part of the algorithm involves drilling into
iframes on the page, and this error showed up on one particular
iframe. There are a few things to note:
("performance" in frame) === true; frame.hasOwnProperty("performance") === false;The latter is not a surprise since
hasOwnProperty("performance")is not supported for window objects on IE (I've seen this before when investigating JSLint problems.) There was no problem accessing
frame.document, but accessing
frame.performancethrew an exception.
frame.performance; // <-- throws "TypeError: Invalid calling object" with error code -2147418113 frame["performance"]; // <-- throws "TypeError: Invalid calling object" with error code -2147418113In fact,
frame.<anything except document>would throw the same exception. So I looked at the
iframe's document object some more, and found this:
frame.document.pathname === "/xxx/yyy/123/4323.pdf";The frame was pointing to a PDF document, and while IE was creating a reference to hold the
performanceobject of this document, it prevented any attempts to access this reference. I tested Chrome and Firefox, and they both create and populate a
frame.performanceobject for PDF documents.