-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
50 lines (44 loc) · 1.67 KB
/
index.html
File metadata and controls
50 lines (44 loc) · 1.67 KB
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
44
45
46
47
48
49
50
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Browser testing with puppeteer</title>
<!-- avoid 404 for favicon.ico -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
</head>
<body>
<div id="content"></div>
<p id="output"></p>
<script>
function updateParagraphTextContent(event) {
document.querySelector('#output').innerHTML = event.target.value;
}
const updateFunction = {
regular: 'updateParagraphTextContent(event)',
shadowed: 'updateParagraphTextContent(event)',
iframe: 'parent.updateParagraphTextContent(event)',
}
const content = (type) => `
<label>
${type}
<input onkeyup=${updateFunction[type]}>
</label>
`;
class ShadowedInput extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
this.shadowRoot.innerHTML = content('shadowed');
}
}
window.customElements.define("shadowed-input", ShadowedInput);
document.querySelector('#content').innerHTML = content('regular');
document.querySelector('#content').innerHTML += `<shadowed-input></shadowed-input>`;
document.querySelector('#content').innerHTML += `<iframe srcdoc="${content('iframe')}"></iframe>`;
document.querySelector('iframe').updateParagraphTextContent = updateParagraphTextContent;
</script>
</body>
</html>