Unable to log in to Webfig using .NET WebBrowser class

Does anyone here have experience in accessing the WebFig interface of a MikroTik (RouterOS) interface using the .NET 4.5 WebBrowser class (e.g. via Visual Basic 2012)?

After getting the login page and sending the username/password details, I get a script error that doesn’t occur when using Firefox or IE10, the “Loading” page displays indefinitely, and the login won’t complete.

This is the script error:

https://docs.google.com/file/d/0BwMiBOnKkP0kTVZmMFg5MGZqUTA/edit?usp=sharing

This is the script referred to in the error:

https://docs.google.com/file/d/0BwMiBOnKkP0kM0FJaDc4djFsNVE/edit?usp=sharing

The error seems to be in the function initWebfig, but I can’t work out what this is trying to do, and why it should work for “real” browsers, but not the WebBrowser class.

Suppressing script errors in the code avoids the error being shown, but the login still doesn’t complete.