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: 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>
<meta charset="UTF-8" />
    <title>LibreSpeed Example</title>
    <link rel="shortcut icon" href="favicon.ico">
<script type="text/javascript" src="speedtest.js"></script>
    <h1>LibreSpeed Example</h1>

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

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

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

    <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

	<a href="">Source code</a>


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