Improve documentation and error message for unexpected JavaScript errors