Repository navigation
Expand file tree
/
Copy pathiframecontroller.html
More file actions
53 lines (49 loc) · 2.17 KB
/
Copy pathiframecontroller.html
File metadata and controls
53 lines (49 loc) · 2.17 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
51
52
53
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Testing iframe controller</title>
<style>
html, body {
margin: 0;
height: 100%;
}
</style>
</head>
<body>
<script>
// Adding the iframe with the same params from this page
var params = window.location.search;
document.body.insertAdjacentHTML("afterbegin",`
<iframe defer src="/editor.html${params}"
id="embeddedEditor" frameborder="0"
style="height:100%;width:100%;top:0px;left:0px;right:0px;bottom:0px">
</iframe>
`);
// If the 'mobileApp' flag is used we remove the window.parent
// reference from the iframe and replace it with window.host so that
// the autodection works
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('mobileApp')) {
var parentRef = window.frames["embeddedEditor"].contentWindow.parent;
window.frames["embeddedEditor"].contentWindow.parent = undefined;
window.frames["embeddedEditor"].contentWindow.host = parentRef;
}
// Logging the messages received by the parent iframe to console and
// to a function that can be accessed by the puppeteer code
window.addEventListener('message', e => {
console.log({event: e, data: e.data});
if (typeof(logEventData) != "undefined") {
logEventData(e.data);
}
});
// Just a collection of examples we can manually try when debugging/dev
/*
window.frames["embeddedEditor"].contentWindow.postMessage({ type: 'pyeditor', action: 'mobilemode'}, '*');
window.frames["embeddedEditor"].contentWindow.postMessage({ type: 'pyeditor', action: 'loadfile', filename: 'hello.py', filestring: 'hello world'}, '*');
window.frames["embeddedEditor"].contentWindow.postMessage({ type: 'pyeditor', action: 'loadfile', filename: 'hello.py', filestring: '# microbit-module: hello@0.1.0\nhello world'}, '*');
window.parent.postMessage({ type: 'pyeditor', action: 'workspacesync'}, '*');
*/
</script>
</body>
</html>