Customize error handling
Customize how Unity handles errors in your Web builds.
Read time 1 minuteLast updated 10 days ago
Choose how to handle errors in your Web builds.
Unity writes some JavaScript code to builds by default, which handles errors. This code displays warning messages when running on unsupported platforms and parses error and exception strings from the browser to check for known errors and display error dialogs with more comprehensive error messages. You can customize this handling, for instance, if you want to suppress the warning messages.
To customize error handling:
-
Open thefile in your Web template.
index.html -
Add or uncomment the following code as a parameter in theobject:
var config = {}errorHandler: function(err, url, line) { alert("error " + err + " occurred at line " + line); // Return 'true' if you handled this error and don't want Unity // to process it further, 'false' otherwise. return true; },
The function is called when the page invokes its event handler and uses the same parameters. Return from this function to signal that your error handler has processed the error, in order to suppress Unity's default error handler from executing. Return to pass the error to Unity’s default error handler to process.
errorhandlerwindow.onerrortruefalse