Thursday, 28 September 2023

Is there any way to autofill text fields for a web-embedded internet speed test?

Such a simple thing, yet I'm beginning to think it's not possible. OpenSpeedTest provides HTML5 code to embed a speed test widget in your webpage. I have implemented this for my website, however there is no API to fetch the results and autofill my text fields. Obviously I also cannot access a cross-origin frame using Javascript, so I don't know what to do. Speedtest Ookla no longer has an accessible API to do this, so I'm not sure what other options I have here.

<script>
    function getSpeedTestResults() {
        // Attempt to access the iframe content
        let iframe = document.getElementById('speedtest');
        let iframeContent = iframe.contentDocument || iframe.contentWindow.document;

        // Attempt to access the results inside the iframe (this will likely be blocked)
                let downloadSpeed = iframeContent.getElementById('downResult').textContent;
        let uploadSpeed = iframeContent.getElementById('upRestxt').textContent;
        let ping = iframeContent.getElementById('pingResult').textContent;

        // Set the values in your fields
        document.getElementById('download').value = downloadSpeed;
        document.getElementById('upload').value = uploadSpeed;
        document.getElementById('ping').value = ping;
    }
</script>


from Is there any way to autofill text fields for a web-embedded internet speed test?

No comments:

Post a Comment