Connecting Profiler to WebGL build over WSS on HTTPS hosted page

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

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

try {
     var runtimeConfig = Module["websocket"] && "object" === typeof Module["websocket"];
     var url = "wss:#".replace("#", "//");
     if (runtimeConfig) {
      if ("string" === typeof Module["websocket"]["url"]) {
       url = Module["websocket"]["url"];
      }
     }
     if (url === "wss://" || url === "wss://") {
      var parts = addr.split("/");
      url = url + parts[0] + ":" + port + "/" + parts.slice(1).join("/");
     }
     var subProtocols = "binary";
     if (runtimeConfig) {
      if ("string" === typeof Module["websocket"]["subprotocol"]) {
       subProtocols = Module["websocket"]["subprotocol"];
      }
     }
     subProtocols = subProtocols.replace(/^ +| +$/g, "").split(/ *, */);
     var opts = ENVIRONMENT_IS_NODE ? {
      "protocol": subProtocols.toString()
     } : subProtocols;
     var WebSocket = ENVIRONMENT_IS_NODE ? require("wss") : window["WebSocket"];
     ws = new WebSocket(url, opts);
     ws.binaryType = "arraybuffer";
    } catch (e) {
     throw new FS.ErrnoError(ERRNO_CODES.EHOSTUNREACH);
    }

To make the profiler connection work with WebGL, Unity will spawn a node.js process running websockify (GitHub - novnc/websockify: Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.), 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 Feature_Matrix · novnc/websockify Wiki · GitHub , 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.

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

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.





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.


sorry, i am the Original poster, forgot i was signed into a different unity account.

perhaps you could take a Detailed snapshot from your WebGL build using the old Profiler ? That should be faster.

Guys, what about WSS support on UNET server?
I can’t share my game in facebook.
It is very sad :frowning:

1 Like

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.

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

Are you able to make wss:// instead of ws:// ?

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.

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

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.


Add the domain name that allows unsafe content to the browser, and you can use ws under htts