blob: 8a17b13bbbc3d182cbdee9e6af2e2c68ae243f3d (
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
|
importScripts("/speculation-rules/prerender/resources/utils.js");
const params = new URLSearchParams(location.search);
const uid = params.get('uid');
const bc = new PrerenderChannel('navigation-channel', uid);
bc.onmessage = async e => {
const data = JSON.parse(e.data);
const navigationUrl = data.navigationUrl;
const clientUrl = data.clientUrl;
const respondTo = data.respondTo;
const clients = await self.clients.matchAll();
const client = clients.find(c => c.url == clientUrl);
if (!client) {
const bc = new PrerenderChannel(respondTo, uid);
bc.postMessage('Client was not found');
bc.close();
return;
}
let result;
try {
await client.navigate(navigationUrl);
result = 'navigate() succeeded';
} catch (e) {
if (e instanceof TypeError) {
result = 'navigate() failed with TypeError';
} else {
result = 'navigate() failed with unknown error';
}
} finally {
const bc = new PrerenderChannel(respondTo, uid);
bc.postMessage(result);
bc.close();
}
};
|