in reply to Further question: automating Javascript with Perl in browser?
Use your favorite HTML parser to extract the onclick attributes, and then run the code through something like JavaScript::SpiderMonkey.