Skip to content

Commit 4a074de

Browse files
committed
Browser: Use external API
1 parent afa2418 commit 4a074de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pkg/web/test.k6.io/browser.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@
9191
}
9292
sDisplay.textContent = opts;
9393
}
94+
95+
function fetchExternalData() {
96+
const dataDisplay = document.getElementById('external-data-display');
97+
fetch('https://jsonplaceholder.typicode.com/todos/1')
98+
.then((response) => response.json())
99+
.then((data) => {
100+
dataDisplay.textContent = 'External data: ' + data.title;
101+
})
102+
.catch((error) => {
103+
console.error('Error:', error);
104+
alert('API call failed. Check console for error.');
105+
});
106+
}
94107
</script>
95108
</head>
96109

@@ -207,6 +220,12 @@
207220
</select>
208221
</td>
209222
</tr>
223+
<tr>
224+
<td><button type="button" onclick="fetchExternalData()">Fetch external data</button></td>
225+
<td>
226+
<p id="external-data-display">External data: ?</p>
227+
</td>
228+
</tr>
210229
</table>
211230

212231
<div id="off-screen" style="position: absolute; top: 150vh; left: 100px">Off page div</div>

0 commit comments

Comments
 (0)