How can we test webgl jslib in the editor? Did you seriously force us to waste 10 minute to build whole webgl just for testing jslib?
No, there’s no way to test your jslib files outside of doing a build. If you really feel like its wasting your time then you could make an empty WebGL project and write a test class that uses your jslib file in some simulated way. You’ll still need to do the builds but if you have no compression set in your build settings it should be a pretty quick process.
@DukeRoderick Empty project webgl still take too much time. I think most of the time it took come from unity engine itself. My project actually small with less than 10 script files. All model is asset bundle
I agree that’s far from an ideal workflow.
For the time being, you could check your jslib with node (via command-line):
/Applications/Unity/Unity.app/Contents/Tools/nodejs/bin/node
you will get errors on mergeInto/autoAddDeps which usually are at the end of the file but that’s expected in this case. You can just comment them out temporarily when doing that.
@Marco-Trivellato Sadly that seem like it not an option for me. Because what I need to test now is 3rd party system. I use firebase database javascript SDK in the jslib (It miraculously work fine). And now I could load and save data. But need to develop a real game with the datalistener system of firebase
Are there any plan to fix this workflow in the next version yet?
Hello, it’s now 6 months later, I’d like to hear if there has been any improvements with regards to testing and debugging external javascript files (“jslib”) within Unity editor?
If someone sees that is just a minor annoyance please share your opinions too, because I share @Thaina 's opinion that having to build a WebGL project for testing a simple function is going to eat up my work week only doing that.
@DukeRoderick could you share how long an empty WebGL takes to build in your setup?
And here another poor soul with the same pain… 4 years ago!
still no update on this?
Joining the club here. We need a real world case escenario for testing!
Maybe we can have an option to enable a special play using a cached deployment where the game in the editor is set to interact with that instead of just playing on isolation.
Having the play session separated from the actual context that the build will have in the real world is far too limiting!
This “workaround” of making a build each time, just to find out you need to add a small change… then re-build, and so on. Oh lordy.
The current workflow is far from perfect, but you can make sure to put code as minimum as you can in the .jslib and instead use as much as you can .js outside of unity. Then, if it’s important for you to bundle files in unity, put the JS code in .jspre file
Having the javascript as external libraries or integrated with the build makes no difference whatsoever for the case. Its not entirely clear to me why do you even suggest that, but the problem is not making sure the javascript code works, there are other methods for that.
The problem is testing the interaction of the unity project with the browser side javascript, which wont happen when you play the project within the Unity Editor, but require a build even for the slightest of tests. This makes the development iteration quite painful and time wasting.
Maybe if some Unity Editor embeded javascript engine (just for the purpose of mimic’ing the browser) could serve the jslib code to the in-editor play sessions of WebGL projects, that would be a killer.
Yeah it’s seriously stupid that as of 2019 we even have project tiny but editor just don’t integrate js emulator to be test in their environment
It is very easy to bypass. I made an interface to call jslib, than made two classes, one for build and another for editor.
Then I use Application.isEditorat at the beginning of the game to create one or another class.
All my code calling interface
Can you share that?
For example you have such .jslib
mergeInto(LibraryManager.library, {
SendToBrowser: function (json) {
window.UnityMessageHandler(Pointer_stringify(json));
},
})
Here is code
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace Demo
{
public class WebController
{
private readonly INotifier notifier;
public WebController()
{
if (Application.isEditor)
{
notifier = new EditorNotifier();
}
else
{
notifier = new BrowserNotifier();
}
}
public void SendDataToBrowser(string type, string body)
{
notifier.Notify(type, body);
}
private interface INotifier
{
void Notify(string type, string body);
}
private class EditorNotifier : INotifier
{
public void Notify(string type, string body)
{
Debug.Log($"Called js with type: {type} and message: {body}");
}
}
private class BrowserNotifier : INotifier
{
/// Same as in *.jslib file
[DllImport("__Internal")]
private static extern void SendToBrowser(string json);
public void Notify(string type, string body)
{
var message = new ReqMessage
{
type = type,
body = body
};
SendToBrowser(JsonUtility.ToJson(message));
}
}
[Serializable]
private struct ReqMessage
{
public string type;
public string body;
}
}
}
Here is example how to use.
var webController = new WebController();
webController.SendDataToBrowser(type, body);
@UDN_08a62c30-cdb1-4e59-bb48-acda29f9e582 Everyone could do that man. BUT THAT NOT WHAT WE SHOULD DO. Because we want to see the behaviour of the real js SDK we include in our library too. Please stop being naive
You can go write your firebase SDK mocking class yourself. I won’t waste time do it. It was the unity editor that should be able to call jslib directly in its editor
Sorry bro, I just answered Steamc0re question.
it’s 2020. Any updates?
It seem like unity has given up on the idea of running webgl in its editor already and I think unity encourage us to use unity tiny for web platform instead. Unity tiny drop support on running in editor and try to have us launch the debug in real platform (in other word, just build and run web game in your browser directly)
Just stumbled to this thread, and reading the posts above violate community contribution guidelines in more than one way, so I am closing this thread. Please be respectful and goal-oriented when discussing with other forum members.
Unity unfortunately currently does not have a solution in place to embed a JS engine into the editor. That is an interesting idea, although that would come with a lot of restrictions and differences in place compared to running in a real browser, so not sure if people would really be happy with such an attempted solution.
To iterate on JavaScript code without having to rebuild, there is a somewhat simple workflow that I would recommend that works for many development scenarios. If one does a Development build, all the code in the .jslib files that are called by C# code will be present in the generated build.framework.js file. What one can do is to then edit that code file directly, and use browser’s F5 refresh to live-reload the changes to the executing build. Then when one is satisfied with the changes, copy all the changed code from build.framework.js file back to the source .jslib file.
That way iteration on the JS code can be achieved without needing to rebuild the project every single time (although one will still need to rebuild when iterating on the C# ↔ JS language marshalling boundary itself)
In any case, closing this thread, the above text is not something we wish anyone to need to read. Please open new threads with proper constructive tone if you would like to follow up with a conversation.