runJS suddenly stopped working

I’ve been using runJS to trigger custom javascript functions ever since I started using Wappler a few years ago. Suddenly they stopped working so I created a simple page with a runJS pageflow to run a simple function and it errors out as well. Not sure if it’s a bug or not. I’ve tried the test page in both Wappler 6.0.0 beta-16 and Wappler 5.8.2 with same errors.

Here is the code for the test page.

<!doctype html>
<html>

<head>
    <meta name="ac:route" content="/test">
    <base href="/">
    <script src="dmxAppConnect/dmxAppConnect.js"></script>
    <meta charset="UTF-8">
    <title>Untitled Document</title>

    <link rel="stylesheet" href="fontawesome6/css/all.min.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="bootstrap/5/css/bootstrap.min.css" />
    <script src="js/jquery-3.4.1.slim.min.js"></script>
    <link rel="stylesheet" href="css/style.css" />
    <link rel="stylesheet" href="dmxAppConnect/dmxDropzone/dmxDropzone.css" />
    <script src="dmxAppConnect/dmxDropzone/dmxDropzone.js" defer></script>
    <script src="assets/js/top.js" defer></script>
</head>

<body is="dmx-app" id="test">
    <script is="dmx-flow" id="flow1" type="text/dmx-flow" autorun="true">{
  runJS: {function: "test", name: "test", outputType: "text"}
}</script>
    <script src="bootstrap/5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

Here is the simple function that is in the top.js file.

function test() {
	alert('working');
}

runJS throws the following error when run.

TypeError: window[e].apply is not a function
    at n.runJS (dmxAppConnect.js:7:97153)
    at n._execStep (dmxAppConnect.js:7:47020)
    at dmxAppConnect.js:7:46449

My other scripts that I use to render a loading overlay throw a different error (below), but I have a feeling if I figure out why the simple one isn’t working, the more complex ones may possibly work again even though it’s a different error. I’ll worry about that after I figure out the simple one.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
    at n.runJS (dmxAppConnect.js:7:97153)
    at n._execStep (dmxAppConnect.js:7:47020)
    at dmxAppConnect.js:7:46449

Hopefully it’s not something simple and stupid I’m doing haha.

Thanks in advance,
Twitch

Probably the top.js file is not loaded yet when the flow is run. Try removing the autorun and run it on button click or in a load event. The error message in both cases is that the function is not defined.

@patrick thanks for the quick reply. I added test button and put runJS on the click event and it gives the same error.

Can you check if you can run the test function from the console and check in the network tab if the top.js file is loaded.

Thanks again @patrick. Works in the console and the top.js file is loaded.


I removed the function from the top.js file and added it in a script tag just above the top.js in the head tag and it works when directly on the page. It’s as though Wappler doesn’t think the top.js file is loaded.
Screenshot 2023-11-13 at 9.52.04 AM

The flow doesn’t know anything about the script, it assumes the js function is on the window object, it calls the function as window["test"].apply().

I can’t see anything wrong with your code and can’t reproduce it, created a similar js file and it works for me. Tested with the beta and stable channel.

Ok, I appears it has to do with the Chrome browser. I just tried in Safari and runJS works fine. Even in the page flow with the function in the top.js. Works fine in Firefox as well. Chrome is definitely the difference.

@patrick so is this a Chrome bug or a Wappler—>Chrome bug?

Chrome is working again now. :man_shrugging: