serenity/Base/res/html/misc/worker_parent.html
Andrew Kaster 1602663b9e LibWeb+WebWorker: Implement a first cut of post_message for Workers
This implementation completely ignores MessagePorts, and manually plumbs
data through LocalSockets.
2023-11-24 08:41:38 +01:00

34 lines
1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Worker</title>
</head>
<body>
<h2>Worker Test</h2>
<div id="output"></div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
console.log("Page Loaded. Sending message");
console.log("Parent Keys: ", JSON.stringify(Object.keys(this)));
var work = new Worker("worker.js");
work.onmessage = (evt) => {
console.log("Got message from worker:", evt.data);
};
document
.getElementById("btn_hello")
.addEventListener("click", function() {
console.log("Sending Message");
work.postMessage({ "msg": "Hey buddy!" });
});
});
</script>
<button id="btn_hello">
Say Hello!
</button>
</body>
</html>