form.submit() causes uncaught exception in greasemonkey

1

I'm using a greasemonkey script to load a page with ajax and automatically fill in the form fields inside the page and submit the form. The problem is that when the form.submit() statement is executed I get an uncaught exception error:

"uncaught exception: [Exception... "Component is not available"
nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"
         //location: "JS frame ::
file:///home/user/.mozilla/firefox/kwrkmbls.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/components/greasemonkey.js
:: anonymous :: line 375"  data: no]" 

Strangely, if I don't use ajax to load the page, but load it manually instead, the same code works; All fields are filled in and the form is submitted.

Any idea what's at fault;

forms
events
greasemonkey
submit
asked on Stack Overflow Nov 22, 2009 by flyon • edited Nov 22, 2009 by Moayad Mardini

1 Answer

0

you can't just to request the content and try to execute it. you need to append it to the current page. something like:

document.body.appendChild(iframe);
iframe.addEventListener("load", function(e)
{
    e.target.contentDocument.forms.namedItem("namedForm").submit();
}, false);

havent tested it but you got the idea

answered on Stack Overflow Aug 8, 2010 by w35l3y

User contributions licensed under CC BY-SA 3.0