blob: 15426128a6bab3d6c872a539c5fc10b01f3baeec (
plain)
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
45
46
47
48
49
50
51
52
53
54
|
async function getSwContainer() {
const clients = await self.clients.matchAll({
type: "window",
includeUncontrolled: true,
});
for (let client of clients) {
if (client.url.endsWith("test_onmessageerror.html")) {
return client;
}
}
}
self.addEventListener("message", async e => {
const config = e.data;
const swContainer = await getSwContainer();
if (config == "send-bad-message") {
const serializable = true;
const deserializable = false;
swContainer.postMessage(
new StructuredCloneTester(serializable, deserializable)
);
return;
}
if (!config.serializable) {
swContainer.postMessage({
result: "Error",
reason: "Service Worker received an unserializable object",
});
return;
}
if (!config.deserializable) {
swContainer.postMessage({
result: "Error",
reason:
"Service Worker received (and deserialized) an un-deserializable object",
});
return;
}
swContainer.postMessage({ received: "message" });
});
self.addEventListener("messageerror", async () => {
const swContainer = await getSwContainer();
swContainer.postMessage({ received: "messageerror" });
});
|