Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

How to link profiler to webgl build?

Discussion in 'Web' started by Andres-Fernandez, Apr 20, 2015.

  1. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    [Reposting this from the general support forum]
    So, yeah, I feel kind of dumb asking for help on this subject because I've been using the profiler ever since I got my hands on Unity. The thing is that after building the webgl project I cannot connect the profiler to the project running on the browser.
    Having webplayer as target was easy: you checked the autoconnect option, set the target to development on the context menu and you were good to go.
    But in webgl build there's no context menu (or I am unable to activate it) so I don't know how to make it connect to the profiler. So when I hit build and run and firefox runs the project nothing happens on my profiler.
    I've seen a couple threads of ppl having performance issues (which is what I am facing here) and all they get is the "use the profiler" response, and that's exactly what I'm trying to do but damn sure I can't make it work. Is there anything to do other than checking the autoconnect option during the build process?
    Thans for your help guys.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Andres-Fernandez likes this.
  3. bsterling250DI

    bsterling250DI

    Joined:
    Sep 25, 2014
    Posts:
    78
    i tried exactly what you said and what it tells you to do as well liortal. then what, does it only work from "Build & Run"?

    I did that and the profiler did not connect...
     
    Andres-Fernandez likes this.
  4. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    Yeah, I did exactly that... and It didn't work. But thanks anyway for taking the time to answer.
    As I said, I've used the autoconnect feature in the past with webplayer builds. The thing is that when you use autoconnect, the Active Profiler dropdown list of the profiler should show the instance of your browser that is running the project. But in this case it doesn't. I attached a picture of the Active profiler dropdown list (the 127.0.0.1 is my failed attempt to connect to the firefox instance).
    Also, with webplayer build, you needed to alt+right click to bring up the context menu and select the deployment target and set development as the target, as that would connect your browser instance to the profiler. But in this case, it doesn't happen (because I haven't been able to bring up that menu).
    And I do it always using the build and run button, since the docs say that it is not possible to connect to a running instance of the project in a browser.
    So I run out of ideas. Maybe I need to alter the web template? Anyone?
     

    Attached Files:

    Last edited: Apr 21, 2015
  5. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    I just read the release notes for the latest beta version here and it says:
    • Profiling WebGL works with Firefox, but not Chrome
    And comparing those release notes with the previous ones I believe that profiling may only be used in the latest beta release. If I'm wrong, please, correct me. I'll download the beta and try to confirm this.
     
  6. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    Confirmed.
    Profiling WebGL with Firefox works on 5.1.0b3. No need to do anything.
    I just created a blank scene, built and run, and profiler started dumping info. NOTE: The Active Profiler dropdown list doesn't show the instance browser that is actually running the project, it just shows the info, but not where it's getting it from o_O.
     
  7. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    In Unity 5.0, profiling was broken on windows. That is fixed in 5.1. I actually think it should work in Chrome as well, and that that release not is wrong, and probably stems from confusion from other issues, but I have to investigate that.
     
  8. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    Yeah, forgot to mention I'm on Windows. Thanks for the response.
     
  9. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    Andres did you find a solution in 5.1? I can understand at all, how to connect profile to WebGL build uploaded to FTP
    Working with Web Player everything is clear - I see an option in Profiler to connect to web player, but not with WebGL
     
    Last edited: Jun 27, 2015
  10. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    I did not check with any final version of 5.1 but since it worked in 5.1b I believe it works now. The way to use it is by hitting build and run (to run it locally). It doesn't work on builds uploaded to the web. Again, if they didn't change it, the info will be dumped to the profiler without any hint of where it is coming from, but it should be the local instance of your browser.
     
  11. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Build & Run should not be necessary, it should also work from an arbitrary server (all Build & Run does is start a server to make your life simpler).

    But: You have to select "Autoconnect Profiler" to make the WebGL player connect to the editor. It does not work the other way around (like in other platforms, where the editor can connect to the player instance), because WebSockets don't allow a browser page to host a server other clients can connect to.
     
  12. Andres-Fernandez

    Andres-Fernandez

    Joined:
    Feb 4, 2013
    Posts:
    57
    My bad. Since last time I tried (5.1.0b3 on Windows) It didn't work deployed on a server, I guessed it remained the same. Good to know that it's fixed.
     
  13. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    Actually I did the same:
    1) choose development build + autoconnect profile
    2) upload all content to FTP
    3) starting WebGL build in a browser (Chrome/Firefox)
    nothing happens.. Editor is running in that moment
     
  14. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Do you have the profiler window open? (It won't open automatically). Also, if you open the browser console or network tab, are there any messages about connecting to a WebSocket host?
     
  15. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I got such error in Chrome Inspector (Profiler in Editor is active)
     
  16. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Ok, this looks like the browser cannot connect to the WebSocket host in the editor. Is this 5.1? Does restarting the editor help? Or restarting windows (maybe an old instance of the websockify bridge is running and blocking the port)?
     
  17. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    520
    I have tried everything you mentioned. No result. Unity version is the last one - 5.1.1f1
    May be I need some WebSocket package imported to Unity?
     
  18. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I'm getting a similar WebSocket error with 5.3 in Chrome

     
  19. Ds777

    Ds777

    Joined:
    Apr 30, 2013
    Posts:
    15
    I have the same problem in Unity 5.4, I can't connect to profiler, I've tried everything, disable firewall, restart ect..
    "WebSocket connection to 'ws://192.168.0.13:54998/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED"
     
  20. ahmadian

    ahmadian

    Joined:
    Nov 24, 2015
    Posts:
    44
    mine says Firefox can't establish a connection to the server at ws://10.5.50.87:54998/. can anyone help?
     
  21. Ewanuk

    Ewanuk

    Joined:
    Jul 9, 2011
    Posts:
    257
    Same issue
     
    Last edited: Dec 14, 2016
  22. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Does restarting Unity and making a new build help?
     
  23. Ewanuk

    Ewanuk

    Joined:
    Jul 9, 2011
    Posts:
    257
    No, same issue
     
    ahmadian likes this.
  24. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    @jonas-echterhoff can I somehow manually initiate start of local node.js server ? I can't see any services running on port 54998. I have opened unity and profiler.

    upload_2018-3-8_14-21-55.png


    upload_2018-3-8_14-22-30.png
     
  25. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    Update:
    I made a build with WebGl (not a Facebook) locally and connected it to profiler successfully.
    I think UnityEditor starts node.js server when you build for WebGL and won't it when you build for facebook.
    upload_2018-3-8_17-48-36.png

    However, when I build for Facebook (WebGL) and uploaded it to Facebook the profiler fails to connect on Chrome and Firefox`

    upload_2018-3-8_17-53-3.png

    upload_2018-3-8_18-14-49.png
     
  26. bigbrainz

    bigbrainz

    Joined:
    Jul 21, 2015
    Posts:
    190
    I too can get it to run locally in Firefox--but I CANNOT get it to run off the web. Is that all the profiler is capable/intended to do so far? Profile a WebGL build running locally?

    (My hope was to be able to use it to test performance on chromebooks and poor systems we have in house to match systems that our clients have. Testing it on my own workstation isn't nearly as helpful because it will have totally different bottlenecks.)
     
  27. bigbrainz

    bigbrainz

    Joined:
    Jul 21, 2015
    Posts:
    190
    Fixed it. There was this little error in the corner of the browser that I needed to click, then "Load unsafe scripts"

    upload_2018-5-30_14-17-6.png
     
  28. Oana

    Oana

    Joined:
    Sep 28, 2012
    Posts:
    87
    Did anyone ever figure out how to do this on Firefox for remote builds?

    The "Load unsafe scripts" works beautifully on Chrome, but I can't seem to find a Firefox equivalent.
     
  29. Oana

    Oana

    Joined:
    Sep 28, 2012
    Posts:
    87
    Found it:

    Go to about:config

    Set network.websocket.allowInsecureFromHTTPS to true.
     
  30. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    (EDIT) when I run url like "httpS:\\.." to test my build - then it will fail to connect profiler
    when I run url "http:\\" - then ok
    I forget it every time.. NORMAL ERROR message would be great (not "cant connect socket")
     
    Last edited: Jun 3, 2019
  31. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    245
    2019.2.0f1: development build + autconnect profiler -> build & run (so running on localhost via Unity's local server implementation) -> app start in Safari, but the profiler does nothing :confused:
     
  32. spvn

    spvn

    Joined:
    Dec 10, 2013
    Posts:
    80
    Can we get a response from Unity on this? There's no documentation online on how to manually connect the profiler if I restart unity after making the build.
     
    travlake likes this.
  33. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    Still this doesn't work in 2019.4.0
     
    unnanego likes this.
  34. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    449
    Having the same issue in 2020.2.b2... cannot connect to profiler in either Edge, Firefox or Chrome.

    Just doesn't find the editor's websocket ip.

    WebGL build is running on local IIS server (localhost:2004).
     
    Last edited: Sep 21, 2020
  35. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    449
    Update:

    Disabling deep-profiling has connected the player to the profiler and is now yielding these errors in the Editor:

    Autoconnected Player Stopping profiler. Profiler is not able to flush data to a file or socket and exceeded maximum allowed memory for buffering.
    Please use Profiler.maxUsedMemory API or -profiler-maxusedmemory command line parameter to increase maximum allowed memory usage.
    Using 16793600 bytes while Profiler.maxUsedMemory is 16777216 bytes.


    Unknown profiler sampler in thread block: 578


    Yet, I have this in the application:

    class ProfilerSettingUpdater
    {
    [RuntimeInitializeOnLoadMethod]
    static void InitProfiler()
    {
    if (Debug.isDebugBuild == false) { return; }
    UnityEngine.Profiling.Profiler.maxUsedMemory = 30000000;
    }
    }


    and have added to the Unity Hub starter parameters.

    -profiler-maxusedmemory
    30000000


    Final Update:
    Started working after setting -profiler-maxusedmemory to 1280000000
     
    Last edited: Sep 21, 2020
    DMorock likes this.
  36. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    EDIT: 5-post combo! TL;DR I've logged a few bug reports on this. Most of this appears broken for years, but if no-one's logged bugs on it the Unity team probably ignored it. So I've logged them below and if/when Unity accepts them I'll add the tracker links. https://forum.unity.com/threads/how-to-link-profiler-to-webgl-build.320175/#post-6594697

    Still broken in Unity 2019 LTS. Very disappointing :(

    1. Set WebGL + Development build
    2. Build
    3. Upload to server
    4. Open in Chrome
    5. Open profile window = NO PROFILING HAPPENS

    Investigating console log ...

    WebGL is doing: "Connecting directly to Ip=192.168.107.209, port=54998 ..."
    Windows is doing: "Uh, no, Unity has failed to open that port, there is nothing listening on port 54998 on this IP address. Goodbye!"

    (unless something wrong with my use of netstat. I'm mostly checking with: netstat -anoq
    )
     
    Last edited: Dec 6, 2020
  37. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    Debugging:

    1. Disabled my firewall, system-wide. WIDE OPEN.
    2. Restarted Unity
    3. ... same error in Unity console.

    So, conclusions:
    • Unity needs to fix that error message. Whoever wrote that only did half a job. Not least: why is it not saying which port it tried to connect to? This makes debugging exceptionally difficult.
    • Unity needs to fix the WebGL build system. Why does it choose a random UNKNOWABLE port number? Every other app in the world uses visible port numbers (and 99% of apps let you change them). Otherwise ... how on earth are developers/admins/network-admins supposed to setup appropriate firewall rules? "Let's disable all firewalls on all ports for all Unity executables?"
    • There appears to be at least one bug in how Unity is opening the socket in the Editor:
      • I have nothing listening to that socket.
      • I have no firewall running.
      • ...And yet Unity crashes internally when it tries to open the socket.
     
  38. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    (I tried creating a new minimal project so I could submit some bug reports - and, surprisingly, Unity now bound to the same socket it's been refusing to bind to in my main project).

    New discovery: Unity is using a single port for ALL projects ?!?! I don't see how that could ever work, since only one process can bind a port at once.

    (if you have more than one project open in Unity - ever - then you'll get profiler failures / error messages every time you try to use the profiler. In fact you'll get an error every time you even OPEN a Unity project (as reported by many people on the forums), because every editor instance is going to conflict with all the others)
     
    Last edited: Dec 6, 2020
  39. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    And another bug: If you click the ConnectToIP dropdown in desperation, then click it a second time, Unity deletes the modal dialog, but hangs the Editor (won't allow you to interact, because the dialgo is still going, but cannot be canclled because it's been made invisible now by Unity).
     
    Last edited: Dec 6, 2020
  40. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    (Case 1297612) WebGL Profiler opens port, connects, but no profiling is possible

    (Case 1297617) In ProfilerWindow, clicking the "Playmode/Editmode/IP" button a second time hangs the UnityEditor

    (Case 1297619) Cannot see the port that profiler will autoconnect to, and cannot edit it, therefore cannot open a firewall rule for it

    (Case 1297626) Experimentally: the WebGL build system always uses the same callback port for profiler's autoconnect setting
     
    Last edited: Dec 6, 2020
    Aurigan and KamilCSPS like this.
  41. bigbrainz

    bigbrainz

    Joined:
    Jul 21, 2015
    Posts:
    190
    a436t4ataf, Hopefully you can single-handedly help them get this working! Thank you!!
     
  42. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,947
    Did you ever get it working for you?

    Right now I cannot even get a brand new project to attach the profiler (2019 LTS + latest Chrome/Firefox + Windows10). Like: not even once.
     
  43. bigbrainz

    bigbrainz

    Joined:
    Jul 21, 2015
    Posts:
    190
    Long ago, but I can't get it to connect now at all.
     
  44. Havenly

    Havenly

    Joined:
    Aug 26, 2020
    Posts:
    5
    FYI, in 2019.4 LTS, in addition to setting dev build and autoconnect profiler, a couple suggestions for anyone that's stuck:
    * First, don't run in an incognito tab
    * On Chrome, go into the Privacy and Security settings for the page and set Insecure Content to Allow (as shown)

    upload_2021-4-5_19-16-55.png
     
    codestage and Alex_Dandelion like this.
  45. PavelLangweil

    PavelLangweil

    Joined:
    Mar 4, 2014
    Posts:
    28
    Yeah just confirming @Havenly 's response works. The issue might be as others mentioned but failed to make the connection, that you're testing the Unity app over https. But the mixed content policy prevents Unity connecting to "insecure" socket over ws://, it expects wss://, so it throws this error:

    ".... was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://192.168.237.152:54998/'. This request has been blocked; this endpoint must be available over WSS."
     
  46. OmarVector

    OmarVector

    Joined:
    Apr 18, 2018
    Posts:
    144
    I had the same issue, fixed with Unity 2021.3.8f1