0

There is an application I use at work that only functions in old versions of Internet Explorer. I've come to find that the reason for this is due to a script in an ASPX file which accesses the document.forms property incorrectly following logon:

document.forms('frmAutoSubmit').DocList.value = window.WebCtl1.GetDocDirectoryList('');

I created a Google Chrome Extension to address the issue, since I don't have the application's source code, nor do I have access to change the application in any way. The extension creates a script element and attaches it to the page. Here is the code that executes:

**inject.js**
(function (document) {
    var i = 0, j = document.forms.length;
    // Extend document to allow functional use
    document._forms = [];
    for (; i < j; ++i) {
        document._forms[i] = document.forms[i];
    }
    document.forms = function (form) {
        return document._forms[form];
    };
    console.debug('done');
})(document);

After loading the extension and testing the page, I still get the same error, even though my console.debug statement executes first.

done inject.js:18
Uncaught TypeError: Property 'forms' of object #<HTMLDocument> is not a function

Is document.forms a readonly and unalterable parameter? Is there another way to attack this?

Micah Henning
  • 2,125
  • 1
  • 18
  • 26
  • And yes, I know the new function will return undefined for everything--I'll write that part so it works once I know I can override the parameter. – Micah Henning Feb 10 '14 at 20:29
  • Hmm, i believe this is a scope issue, you are trying to override the `document.forms` in the scope of the webpage but what you have actually done is override the `document.forms` for your content-script. See this post http://stackoverflow.com/questions/12095924/is-it-possible-to-inject-a-javascript-code-that-overrides-the-one-existing-in-a – 1337holiday Feb 10 '14 at 21:48
  • I don't think so, since I'm actually adding a script element to the page with the src attribute set to inject.js. You can see that my console.debug statement occurred in the same context as the uncaught TypeError. Would it help if I included the complete source of the chrome extension? – Micah Henning Feb 11 '14 at 15:59
  • Yes post some code so that I can simulate it. In theory it should work since u are not using `executeScript` or running it from the content script. – 1337holiday Feb 11 '14 at 18:13

0 Answers0