Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

5.1 and console.logError not found in generated .js file

Discussion in 'Web' started by bsterling250DI, Jun 9, 2015.

  1. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    I'm seeing a strange thing with my WebGL project in 5.1 that i haven't seen with any 5.0x builds.

    If i host the game on my localhost with xampp i don't seem to get the problem unless i'm loading it through https. (which had no problems yesterday on 5.1.0f2).

    Without any exceptions turned on, i just get an error "Script Error". So i turn on exceptions, and then i get a bit more detail. "console.logError is not a function".

    So i opened up the .js file for my game and looked for console.logError, and there it was, just one reference.

    i changed it to console.log instead of logError and that fixed it.

    The code that's generated looks like this... (i've formatted it to make it easier to read)


    Code (CSharp):
    1. function _JS_Cursor_SetCursorString(cursor)
    2. {
    3.     try
    4.     {
    5.         if(document.styleSheets.length==0)
    6.         {
    7.             console.log("can't set cursor because there is no style sheet.");
    8.             return
    9.         }
    10.         var styleSheet=document.styleSheets[0];
    11.         var rule="canvas.emscripten { border: 0px none; cursor: "+cursor+"; }";
    12.         for(var i=0; i<styleSheet.cssRules.length; i++)
    13.         {
    14.             if(styleSheet.cssRules[i].cssText.indexOf("canvas.emscripten")!=-1)
    15.             {
    16.                 styleSheet.deleteRule(i);
    17.                 styleSheet.insertRule(rule,0);
    18.                 return
    19.             }
    20.         }
    21.         styleSheet.insertRule(rule,0)
    22.     }catch(e)
    23.     {
    24.         console.logError("Could not set cursor due to exception "+e)
    25.     }
    26. }
    is this a problem with emscripten? or something new in 5.1?

    I'm not doing anything with the Cursor in my project anywhere.
     
  2. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    Don't know why this occurs but a quick fix without having to do string-replace for each export is to just add this line to any javascript in your page:
    console.logError = console.log;

    Then it will just work.
     
  3. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    ya, i was able to fix it even just by doing a find and replace but that's not a very good solution since our build pipeline is automated and wouldn't support that.
     
  4. aiab_animech

    aiab_animech

    Joined:
    Jul 4, 2012
    Posts:
    177
    Yeah, thats why I think my suggestion is at least slightly better. Even with an automated build pipeline you could have a WebplayerTemplate or just html-file that you don't rebuild every time, that has this little snippet:
    <script type="text/javascript">
    console.logError = console.log;
    </script>

    Then you could use your automated build pipeline without the need for find&replace.
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Thanks for reporting this, it will be fixed in 5.2. The workaround should work for now.

    Though, I don't know why this would have worked for you before. The issue is that you'd get an exception here because you have css styles from a different domain, which cannot be accessed due to CORS restrictions. When trying to set the cursor, Unity would iterate over these and throw a security exception - we did not catch that exception in 5.0.
     
  6. Picky-Salamander

    Picky-Salamander

    Joined:
    Apr 26, 2013
    Posts:
    27
    Will the cursor setting be fixed in 5.2 as well? It seems to me that developers using style sheets from a different domain will be a common occurrence.
     
  7. srmatthe

    srmatthe

    Joined:
    May 15, 2016
    Posts:
    11
    An old thread, I know but is there any update on this ?
    I'm still seeing it in 5.3.4
     
  8. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    The original bug has been fixed. If you still see an issue, could you file a new bug report with a repro project and post the case number here?