-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (39 loc) · 1.09 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<title>Text Search Worker Memory Test</title>
</head>
<body>
<script type="module">
window.__workerDidLaunch = 0 // 0: not launched, 1: launched, 2: error
const worker = new Worker('/dist/aboutWorkerMain.js', {
type: 'module',
name: 'Worker',
})
const channel = new MessageChannel()
// Send initialize message with message port
worker.postMessage(
{
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: ['message-port', channel.port2],
},
[channel.port2]
)
worker.onmessage = (event) => {
if (event.data?.jsonrpc === '2.0' && event.data?.id === 1) {
window.__workerDidLaunch = 1
}
}
worker.onerror = (error) => {
window.__workerDidLaunch = 2
console.error('Worker error:', error)
}
channel.port1.onmessage = (event) => {
// Handle responses from worker through message port
console.log('Message from worker:', event.data)
}
</script>
</body>
</html>