-
Notifications
You must be signed in to change notification settings - Fork 54
/
helper_iframe.sub.html
31 lines (30 loc) · 1 KB
/
helper_iframe.sub.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
<!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():
// { 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>