Search Unity

Connecting Profiler to WebGL build over WSS on HTTPS hosted page...

Discussion in 'Web' started by bsterling250DI, Oct 20, 2015.

  1. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    Hello,

    I'm currently having a memory leak in my game that is hosted on facebook.
    Facebook requires canvas games to be accessed via SSL.
    I'm trying to connect the profiler to the build running on facebook and get this error.

    Mixed Content: The page at 'https://<url_removed_for_forum_post>' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://192.168.0.198:54998/'. This request has been blocked; this endpoint must be available over WSS.
    Is there a way to change the websocket connection for the profiler to use WSS as a protocol instead of WS? maybe using a proxy like Charles or Fiddler? or in the code of the project? or is this something that is built into Unity that we can't modify?

    System Info:
    Windows 10
    Unity 5.2.1p3
    Chrome 46.0.2490.71 m
     
    Last edited: Oct 21, 2015
  2. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    I tried modifying the .js file that is output in a development build to hard-code websockets to use wss but i get an error still
    webgl.js:5379 WebSocket connection to 'wss://192.168.0.198:54998/' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED

    Code (JavaScript):
    1. try {
    2.      var runtimeConfig = Module["websocket"] && "object" === typeof Module["websocket"];
    3.      var url = "wss:#".replace("#", "//");
    4.      if (runtimeConfig) {
    5.       if ("string" === typeof Module["websocket"]["url"]) {
    6.        url = Module["websocket"]["url"];
    7.       }
    8.      }
    9.      if (url === "wss://" || url === "wss://") {
    10.       var parts = addr.split("/");
    11.       url = url + parts[0] + ":" + port + "/" + parts.slice(1).join("/");
    12.      }
    13.      var subProtocols = "binary";
    14.      if (runtimeConfig) {
    15.       if ("string" === typeof Module["websocket"]["subprotocol"]) {
    16.        subProtocols = Module["websocket"]["subprotocol"];
    17.       }
    18.      }
    19.      subProtocols = subProtocols.replace(/^ +| +$/g, "").split(/ *, */);
    20.      var opts = ENVIRONMENT_IS_NODE ? {
    21.       "protocol": subProtocols.toString()
    22.      } : subProtocols;
    23.      var WebSocket = ENVIRONMENT_IS_NODE ? require("wss") : window["WebSocket"];
    24.      ws = new WebSocket(url, opts);
    25.      ws.binaryType = "arraybuffer";
    26.     } catch (e) {
    27.      throw new FS.ErrnoError(ERRNO_CODES.EHOSTUNREACH);
    28.     }
     
  3. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    To make the profiler connection work with WebGL, Unity will spawn a node.js process running websockify (https://github.com/kanaka/websockify), a tool which bridges WebSockets to TCP connections, to host a WebSocket server on port 54998, which forwards data to the Unity editor profiler connection on port 54999. Now, according to https://github.com/kanaka/websockify/wiki/Feature_Matrix , the node.js version of websockify does not support wss://. But the python or C versions do. I had problems getting the python version to run on windows, which is why we use the node version, but you could try to see if you can set up one of those to work on your machine, and open a wss:// server on some port, which forwards to the profiler connection on port 54999, which should then work.
     
  4. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    I was able to modify our project so that it would run without being hosted on facebook canvas and thus, on a local host not over SSL.

    So i was able to attach the profiler to the game running, and use the new memory profiler that Lucas released, but I had troubles using it.

    When our game is development built, it runs at 1 frame every 5 seconds instead of a steady 30fps, and when the profiler attaches i get about 70 frames of data, and then the unity profiler stops getting data for some reason.

    I was able to take a single snapshot of the memory with the new profiler in this build, but it took about 30 minutes for it to actually take the snapshot and refresh the window in the editor. I then tried to Save the snapshot to my hard-drive but that completely locked up the editor, i left it over night for 8+ hours, and came back and the file size on the syste was still reading 0 bytes, and the unity editor was still locked up, so i had to kill the process and couldn't take a second snapshot to compare.

    In an unrelated step, I tried to instead add some calls to GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); when I had suspicions about memory being fragmented or needing cleaning up and our QA is going to do some extensive performance testing on various devices to confirm if the issue has been resolved, our QA has been a bit backed up recently with our mobile release though so I don't have the results of that testing yet.

    Will keep you updated. But for now, here's the screenshot I took of the one single snapshot i was able to get with the memory profiler.

    Attachment(s)
    webgl-resets-0.PNG

    Here is the support ticket with unity... https://support.unity3d.com/hc/requests/28462
     
  5. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    After running the profiler in the editor and taking several memory snapshots after what seems to be the trigger for running out of memory (reloading and switching scenes). It looks like although we have 130mb of texture memory, that never grows or shrinks which makes sense for our game which is all UI and using a fairly large sprite atlas so that our UI can be responsive. ALLLLL the other categories remain about the same after playing for 30 minutes, the only category that fluctuates in memory size greatly is Meshes, from 2.5mb, to 12mb, to 35mb, to 80mb, back to 12mb and then back to 30mb again.

    Here are the snapshots I was able to take in the editor hoping that it at least might show evidence of the same issue even though profiling the editor is different than profiling a webgl build. They are in order while taking a snapshot in between each time I reload the same scene.
     

    Attached Files:

  6. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    Here's a couple more screenshots...

    As you can see the Mesh memory fluctuates greatly and the Texture2D is huge, now our game is all UI and Canvases, there are no 3d meshes and most of it is textures so this makes sense that most of the memory usage is texture memory. We are using a common ui sprite atlas for modal backgrounds, buttons, anything shared that we can reuse, so though we could probably try some other image formats and be more strict about unloading textures when they aren't used (since if they are in an atlas the whole atlas stays in memory when a single image from it is being used) but we're hoping that we can keep them in the atlas so that we can have our UI be responsive.
     

    Attached Files:

  7. heroichippo1

    heroichippo1

    Joined:
    Mar 30, 2015
    Posts:
    36
    sorry, i am the Original poster, forgot i was signed into a different unity account.
     
  8. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    perhaps you could take a Detailed snapshot from your WebGL build using the old Profiler ? That should be faster.
     
  9. krab24

    krab24

    Joined:
    Mar 2, 2015
    Posts:
    20
    Guys, what about WSS support on UNET server?
    I can't share my game in facebook.
    It is very sad :(
     
    ShantuApps likes this.
  10. ShantuApps

    ShantuApps

    Joined:
    Apr 25, 2016
    Posts:
    14
    I am also getting error to connect wss://.

    The page at 'https://webglGameURL' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://192.93.23.2:6001/'. This request has been blocked; this endpoint must be available over WSS.
     
  11. ShantuApps

    ShantuApps

    Joined:
    Apr 25, 2016
    Posts:
    14
    How can i make wss:// call from webgl ? In my case, i alwys have ws:// call from https:// page. Server side i have used Nginx wss proxy, which seems to be working. All i need now to send wss calls from webgl. For more please see link
     
  12. ShantuApps

    ShantuApps

    Joined:
    Apr 25, 2016
    Posts:
    14
    Are you able to make wss:// instead of ws:// ?
     
  13. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    Hello! Please say - is any progress exist? We need to test HTTPS game with profiler, and if httpS is not work in profiler, we should change to http, but it's not work for brotli file compression, it requires httpS.. which all lead to un-testable environment.
     
  14. tuseroni

    tuseroni

    Joined:
    Jan 17, 2020
    Posts:
    9
    chrome has made it so you CANT load ws:// over HTTP, it must be wss:// even if you tell it to allow for insecure it will still obstinately refuse. and chrome also won't let me go to an http version of my site because it knows an https version exists. i can't profile my code at all.

    --edit--

    it's worse than i thought, my domain is a .app, i CAN'T go to an http version, chrome won't let me, seems neither will firefox. please someone fix this
     
    Last edited: Aug 27, 2020
  15. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    130
    4 years later, and still same issue

    no solution offered or work around.

    Actually some mobile SDK now does not allow HTTP loading anymore and become a secuirty policy to use HTTPS even for local dev.