blob: 9017eace44d84112c4e21c35cb6724efa69b1366 (
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
|
<!doctype html>
<meta charset='utf-8'>
<link rel='author' href='jarrydg@chromium.org' title='Jarryd Goodman'>
<script>
'use strict';
// Writing a cookie:
// Input: { cookieToSet: { name: 'cookie-name', value: 'cookie-value' } }
// Response: "Cookie has been set"
//
// Read a cookie.
// Command: { existingCookieName: 'cookie-name' }
// Response: Result of cookieStore.get('cookie-name'):
// { frameCookie: { name: 'cookie-name', value: 'cookie-value' } }
window.addEventListener('message', async function (event) {
const { opname } = event.data;
if (opname === 'set-cookie') {
const { name, value } = event.data
await cookieStore.set({
name,
value,
domain: '{{host}}',
});
event.source.postMessage('Cookie has been set', event.origin);
} else if (opname === 'get-cookie') {
const { name } = event.data
const frameCookie = await cookieStore.get(name);
event.source.postMessage({frameCookie}, event.origin);
}
});
</script>
|