JavaScript library not working anymore since yesterday (in Workflow Editor)

Hey,

Since today, my custom JavaScript library, which I import on app load, has stopped working in the “Workflow Editor”. When I try to test the workflow, I receive a “ReferenceError: doSomethingFunction is not defined.” Interestingly, the workflow functions correctly when I’m using the Real UI interaction in the Editor and in production. This issue did not exist before today.

Do you have any ideas on how I can resolve this?

Here is how I import the script (which worked previously):

let libScript = document.createElement(“script”);
libScript.src = “https://myhomepage.de/cdn/lib.js”;
document.head.appendChild(libScript);

Thanks

instead of document use wwLib.getFrontDocument().
for example wwLib.getFrontDocument().createElement('script')

1 Like

Actually, that’s a good idea, but unfortunately, it didn’t resolve the issue.

that is only for loading the script correctly in the editor, then it depends on what your script is doing. if you are declaring a global function you also want to be sure to check if the script is fully loaded before trying to access it.

My script only declares some global functions. I can see that the script is loaded because I log it to the console when it’s there. And i’m using wwLib.getFrontDocument() now.

I also dobule checked if the script element is part of the editor page, and yes, i found it.

how do you access the function? if it is declared globally on the window object you need to use wwLib.getFrontWindow().yourFunction.

1 Like

This is the solution! Thank you so much!

1 Like

Hello, for anyone looking, I’ve wrote an article about implementing Firebase SDK (a JavaScript embed as well) into WeWeb, the pattern of implementation is very similar to what @dorilama suggested, but it’s described a little more in depth in the article.

I actually didn’t suggest any loading pattern here. I just noticed that usually if some code works in preview but not on workflow testing it’s because you need to use the right window and document objects.

When I need to load a library I usually don’t append script tags in the page :upside_down_face:

For things like libraries that aren’t available via the NPM plugin, there currently is no other way. Unless WeWeb starts supporting plugin development :slight_smile:

one nice thing of js is that you can do the same thing in multiple ways, even more if you consider the tools of the ecosystem :wink:

1 Like