-
Notifications
You must be signed in to change notification settings - Fork 0
/
caches.html
43 lines (37 loc) · 1.51 KB
/
caches.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
<html>
<head>
<meta name=”viewport” content=”width=device-width,initial-scale=1″>
</head>
<body>
<h1>Permanent User Tracking with window.caches</h1>
<h1 id="output"></h1>
<script>
async function set() {
var id = Math.random().toString(32).substring(2).toUpperCase();
var cache = await caches.open('test');
document.getElementById('output').innerHTML = `Your identifier <b><u>${id}</u></b> has been recorded.`;
return cache.put(id, new Response('dummy'));
}
async function get() {
var cache = await caches.open('test');
var requests = await cache.keys();
requests.forEach(function(request) {
var id = request.url.split('/').pop();
document.getElementById('output').innerHTML = `Your tracking identifier is <b><u>${id}</u></b>.`;
});
}
function restoreCache() {
var iframe = document.getElementById('iframe');
window.CacheStorage.prototype.match = iframe.contentWindow.CacheStorage.prototype.match;
window.CacheStorage.prototype.has = iframe.contentWindow.CacheStorage.prototype.has;
window.CacheStorage.prototype.delete = iframe.contentWindow.CacheStorage.prototype.delete;
window.CacheStorage.prototype.open = iframe.contentWindow.CacheStorage.prototype.open;
window.CacheStorage.prototype.keys = iframe.contentWindow.CacheStorage.prototype.keys;
}
</script>
<iframe src="internal://local/errorpage"" id="iframe"></iframe>
<button onclick="set()">Set Tracking ID</button>
<button onclick="get()">Get Tracking ID</button>
<button onclick="restoreCache()">restoreCache</button>
</body>
</html>