debugginggoogle-chromesyntax-error

Chrome: Uncaught SyntaxError: Unexpected end of input


When loading my page in Google Chrome, I get a vague error in the console:

Uncaught SyntaxError: Unexpected end of input

I have no idea what is causing it. How would I go about debugging this error?


Solution

  • The error message "Unexpected end of input" in V8 often indicates a syntax error in your JavaScript code, such as a missing } or similar.

    Example given, this will yield "Unexpected end of input" too:

    eval('[{"test": 4}') // notice the missing ]
    

    But the root cause of the problems seems to be that the requested JSON url has a Content-Type of text/html which Chrome apparently tries to parse as HTML, which then results in the unexpected end of input due to the fact that the included image tags are being parsed.

    Try setting the Content-Type to text/plain I think it should fix the issues.

    Nonetheless, V8 could do a better Job about telling one exactly where the input ended unexpectedly.