blob: f592629d074bc3912ce64f325a3560a9d31c7f13 (
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
|
addEventListener('fetch', evt => {
if (evt.request.url.includes('worker-echo-client-id.js')) {
evt.respondWith(new Response(
'fetch("fetch-echo-client-id").then(r => r.text()).then(t => self.postMessage(t));',
{ headers: { 'Content-Type': 'application/javascript' }}));
return;
}
if (evt.request.url.includes('fetch-echo-client-id')) {
evt.respondWith(new Response(evt.clientId));
return;
}
if (evt.request.url.includes('frame.html')) {
evt.respondWith(new Response(''));
return;
}
});
addEventListener('message', evt => {
if (evt.data === 'echo-client-id') {
evt.ports[0].postMessage(evt.source.id);
return;
}
});
|