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. Dismiss Notice

Firefox: Script error.

Discussion in 'WebGL' started by jinxed_byte, Feb 4, 2016.

  1. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    Hi everyone,

    our WebGL Build on Kongregate (http://www.kongregate.com/games/till42/volley-brawl) throws an error message popup on startup. I have the feeling that this is only since a few days. Chrome does pop up everything.

    This is the complete popup message:
    "An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was: Script error."

    In the web console, I could not find anything more than "Invoking error handler due to Script error." So nothing useful.

    It works fine, when I load the index.html directly from my local disk.

    Can anyone tell me, if I can do anything to change this? Or is it a Firefox bug? I am on V 45.0b2.

    Thanks a lot in advance for looking into this.
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Maybe something wrong in the Kongregate iframe..

    I get this log in Firefox 44:
    An unbalanced tree was written using document.write() causing data from the network to be reparsed. For more information https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing container.html:17:0
    An unbalanced tree was written using document.write() causing data from the network to be reparsed. For more information https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing container.html:17:0
    An unbalanced tree was written using document.write() causing data from the network to be reparsed. For more information https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing container.html:17:0
    SyntaxError: illegal character adServer.bs:1:6
    no element found comments.js:1:1
    Invoking error handler due to
    Script error. UnityLoader.js:1:29721
    Error: Permission denied to access property "toString"
    UnityLoader.js:1:30974
    Decompressed Release/VolleyBrawl.memgz in 83ms. You can remove this delay if you configure your web server to host files using gzip compression. UnityLoader.js:1:775
    Decompressed Release/VolleyBrawl.jsgz in 303ms. You can remove this delay if you configure your web server to host files using gzip compression. UnityLoader.js:1:775
    Decompressed Release/VolleyBrawl.datagz in 118ms. You can remove this delay if you configure your web server to host files using gzip compression. UnityLoader.js:1:775
    Error: Permission denied to access property "toString"
     
  3. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    Hi Marco,

    thank you very much for looking into my issue.

    I'll see if I can get something out of your log and keep the forum up to date.

    Does anyone else have the same issue?
     
  4. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello jinxed_byte.

    Let's make a small experiment. Open your index.html and remove the following 2 lines:
    Code (html):
    1.     <script type="text/javascript" src="http://www.kongregate.com/javascripts/kongregate_api.js"></script>
    Code (html):
    1.    kongregateAPI.loadAPI(onLoadCompleted);
    If the error message does not popup after that, this would mean that the problem is related to the kongregate api, while your Unity application works absolutely fine.
     
  5. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    Hi alexsuvorov,

    I just did like you proposed, removed the lines (as well as my Application.ExternalEval/Application.ExternalCall) calls from Unity to the Kongregate API). You are right. The error must be in the Kongregate API. Strange, that it happens only in Firefox, not in Chrome.

    Thank you a lot. I think I shall then turn to Kongregate Support (and hope they are as responsive as Unity is). Or maybe there is an update to their script...

    Let me tell by the way you how awesome the WebGL functionality has become! Great job!
     
  6. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    I think I have made it! My preview at least does not throw the error and still posts stats.

    The solution was to use the Kongregate Shell http://developers.kongregate.com/docs/api-overview/client-api
    Then I used my own .jslib script as described in the Unity Manual to access the JavaScript API.

    I will still check how to get also the user name etc. from the API.
     
  7. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    225
    I've seen the tostring issue in firefox before.
    Is your game running in an iframe? You might have a cross domain issue. I recently ran into the same/similar issue when deploying a game at a client server.
     
  8. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    Yes, my game is in the Kongregate iFrame. Since today even in two iFrames :)

    So what is your proposal to get rid of the toString Warning?
     
  9. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    225
    If your game runs fine after the error/warning I would suggest supressing the error altogether by adding this to your html (as early as possible. e.g. just after /head>)

    <script type="text/javascript">
    // Supresses error(dialogs) but logs them instead. Workaround for some Unity WebGL related issues.
    window.onerror = function(message, url, lineNumber) {
    console.log("Message: " + message + ". URL: " + url + ". LineNumber: " + lineNumber);
    return true;
    };
    </script>
     
  10. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    As the error message is caused by the Kongregate API, it probably informs you about some important Kongregate API malfunction, which may affect user authorization etc. Hiding the error message in such case might be equivalent to removing the Kongregate API related code from your page all together.
    As long as the error exist it is probably supposed to be fixed. Although this is responsibility of Kongregate, I believe they also provide a general purpose JavaScript API. If such Kongregate API works well in a simple cross-domain iframe, then it should also work well in any other page that can run in iframe (including Unity WebGL). You can communicate with such API through a jslib plugin.
     
  11. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    225
    afaik the error is not directly related to the API. It is a security issue (in FF) when you run webgl content in an iframe and then communicate with a third party api. I've seen this tostring error at other clients as well. Alwyas when run in an iframe and when communicating with another JS api.

    You can also set document.domain = String(document.domain); // workaround crossdoamin security
    but you need to set this in the iframe AND the parent page. Since you probably don't have access to that on Kongregate and the current setup fails another possible solution would then be supressing the error.

    I haven't experienced any issues with supressing it since I recall the tostring error is not critical.
     
  12. jinxed_byte

    jinxed_byte

    Joined:
    Mar 29, 2014
    Posts:
    17
    Thank you PieterAlbers!

    I will try to put this into my code for future errors.

    @alexsuvorov: You are totally right, I use the general JavaScript API now and do this via my jslib in the plugin folder.