Source code

Revision control

Copy as Markdown

Other Tools

<html><body>
Creating WebSocket
<iframe id="frame" sandbox="allow-scripts"></iframe>
<script type="application/javascript">
function cleanup() {
window.document.getElementById("frame").removeAttribute("src");
window.document.getElementById("frame").remove();
}
onmessage = function(e) {
cleanup();
window.opener.postMessage(e.data, '*');
}
// Mixed content blocker will prevent loading iframes via http, so in that case pass back the error
window.document.getElementById("frame").onerror = function() {
cleanup();
window.opener.postMessage("Error - iframe not loaded", '*');
}
// Load one of the iframe variants?
if (location.search == '?https_iframe_wss') {
window.document.getElementById("frame").src = "https://example.com/tests/dom/websocket/tests/iframe_websocket_wss.html";
} else if (location.search == '?https_iframe_ws') {
} else if (location.search == '?http_iframe_wss' || location.search == '?http_iframe_ws') {
if (location.search == '?http_iframe_ws') {
iFrameUrl += "?insecure";
}
window.document.getElementById("frame").src = iFrameUrl;
}
else {
try {
let socket;
if (location.search == '?insecure') {
}
else {
}
socket.onerror = function() {
cleanup();
window.opener.postMessage("WS onerror", "*");
};
socket.onopen = function() {
socket.close();
cleanup();
window.opener.postMessage("WS onopen", "*");
};
}
catch(e) {
if (e.name == 'SecurityError') {
cleanup();
window.opener.postMessage("SecurityError", "*");
} else {
cleanup();
window.opener.postMessage("Test Throws", "*");
}
}
}
</script>
</body></html>