Javascript and HTML ninja challenge - speedtest

Would anyone be able to help me, i am trying to implement a speedtest into my dashboard, the code is here: https://github.com/librespeed/speedtest. This uses HTML and Javascript elements which i have tried to use with reference here: Executing javascript block then modal are opened? but i am not getting anywhere with it.

I have the .js script published and i can browse to it but i cant get the html part to reference the javascript…

I have tried with Invoke-UDJavaScript and New-UDElement -Tag script -Attributes @{type=“application/javascript”} for the javascript element, and New-UDHtml -Markup.

The basic speedtest code:

<!DOCTYPE html>
<html>
<meta charset="UTF-8" />
<head>
    <title>LibreSpeed Example</title>
    <link rel="shortcut icon" href="favicon.ico">
</head>
<script type="text/javascript" src="speedtest.js"></script>
<body>
    <h1>LibreSpeed Example</h1>

    <h4>IP Address</h4>
    <p id="ip"></p>

    <h4>Download</h4>
    <p id="download"></p>

    <h4>Upload</h4>
    <p id="upload"></p>

    <h4>Latency</h4>
    <p id="ping"></p>

    <script type="text/javascript">
        var s=new Speedtest();
        s.onupdate = function (data) { // when status is received, put the values in the appropriate fields
            document.getElementById('download').textContent = data.dlStatus + ' Mbit/s'
            document.getElementById('upload').textContent = data.ulStatus + ' Mbit/s'
            document.getElementById('ping').textContent = data.pingStatus + ' ms, ' + data.jitterStatus + ' ms jitter'
            document.getElementById('ip').textContent = data.clientIp
        }
        s.start(); // start the speedtest with default settings
    </script>

	<a href="https://github.com/librespeed/speedtest">Source code</a>

</body>
</html>

Just incase anyone is bored - i wish i knew more about js.

Hi @neo,

Any errors in the browser console?
Is the js file present at the client?

Should be a matter of just using invoke-udjavascript and pass the .js file to the client.

Can you run the snippet in the browser console?

Gave it a quick look.
Seems like you’d need to include the speedtest_worker.js in the same directory as your speedtest.js file.
The speedtest.js loads the worker on line #322


Haven’t tried actually importing to UD yet, but i can give it a go if you run into any troubles beyond this.

Have a good one!

1 Like