Skip to content

Commit a9091bc

Browse files
committed
Added sample code for moving guestinstance not working
1 parent dc1585b commit a9091bc

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

index.html

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
<html>
33
<head>
44
<meta charset="UTF-8">
5-
<title>Hello World!</title>
5+
<title>Webview GuestInstance Undefined</title>
6+
<script>require('./renderer.js')</script>
67
</head>
8+
79
<body>
8-
<h1>Hello World!</h1>
9-
<!-- All of the Node.js APIs are available in this renderer process. -->
10-
We are using Node.js <script>document.write(process.versions.node)</script>,
11-
Chromium <script>document.write(process.versions.chrome)</script>,
12-
and Electron <script>document.write(process.versions.electron)</script>.
10+
<div>
11+
<button type="button" id="button">Move Webview</button>
12+
13+
<div id="webviews">
14+
<div class="container">
15+
<h1>Container A</h1>
16+
<webview id="webview" src="https://example.com"></webview>
17+
</div>
1318

14-
<script>
15-
// You can also require other files to run in this process
16-
require('./renderer.js')
17-
</script>
19+
<div class="container">
20+
<h1>Container B</h1>
21+
</div>
22+
</div>
23+
</div>
1824
</body>
1925
</html>

renderer.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1-
// This file is required by the index.html file and will
2-
// be executed in the renderer process for that window.
3-
// All of the Node.js APIs are available in this process.
1+
function moveWebview(existingWebview, container) {
2+
const webview = document.createElement('webview');
3+
const { attributes } = existingWebview;
4+
const originalGuestInstance = existingWebview.guestinstance;
5+
6+
console.log('original guestinstance', existingWebview.guestinstance);
7+
8+
for (let i = 0; i < attributes.length; i += 1) {
9+
webview.setAttribute(attributes[i].nodeName, attributes[i].nodeValue);
10+
}
11+
12+
console.log('copied guestinstance', webview.guestinstance);
13+
14+
container.appendChild(webview);
15+
existingWebview.parentNode.removeChild(existingWebview);
16+
17+
return webview;
18+
}
19+
20+
window.addEventListener("load", () => {
21+
const button = document.getElementById("button");
22+
const webviews = document.getElementById("webviews");
23+
24+
let index = 0;
25+
26+
button.addEventListener("click", () => {
27+
index = (index + 1) % 2;
28+
moveWebview(document.getElementById("webview"), webviews.children[index]);
29+
});
30+
});

0 commit comments

Comments
 (0)