Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WebGL error handler in loader page

Discussion in 'WebGL' started by markachten88, Feb 26, 2018.

  1. markachten88

    markachten88

    Joined:
    Apr 24, 2015
    Posts:
    31
    He guys.

    Can anyone point me to a code example how I can add an errorhandler in the new webgl loader page structure? I managed the old way easily but got stuck the new way (https://docs.unity3d.com/Manual/webgl-templates.html)
    Reason for asking is cause I can't find code that actually calls the handler in case something bad happens.
    Thanks!
     
  2. markachten88

    markachten88

    Joined:
    Apr 24, 2015
    Posts:
    31
  3. samuel-levine

    samuel-levine

    Joined:
    Sep 1, 2012
    Posts:
    8
    Hello! Replying to this 4.5 year old thread just in case anyone else has this same need.

    But first... shame on Unity for not making this more explicit. Even in 2022, it doesn't seem to be in any documentation whatsoever. The "new" errorhandler also doesn't seemingly catch all errors, making it of limited usefulness, though it does seem to catch Out of Memory errors, which are a pretty serious concern.

    Anyway, the secret is to use a .jspre file in a Plugins folder under Assets. Here's an example of working contents, at least for Unity 2020.3.4f1:

    Code (JavaScript):
    1.  
    2. Module.errorHandler = function(message, filename, lineno) {
    3.  
    4.     // <your own error handling here>
    5.     // console.log(filename + ":" + lineno);
    6.  
    7.     // Return "true" to stop the default error handling
    8.     return true;
    9. };
    10.  
     
    ppirner likes this.