-
Notifications
You must be signed in to change notification settings - Fork 1
/
multi-webview.mjs
51 lines (38 loc) · 1.02 KB
/
multi-webview.mjs
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
import { Application, ProgressBarState } from '../index.js'
const width = 800;
const height = 600;
const app = new Application();
app.onEvent(console.log)
const window = app.createBrowserWindow({
width,
height,
title: 'Multiple Webviews',
});
const webview1 = window.createWebview({
url: 'https://nodejs.org',
child: true,
width: width / 2,
height
});
const webview2 = window.createWebview({
url: 'https://deno.land',
child: true,
width: width / 2,
x: width / 2,
height,
});
webview1.onIpcMessage((message) => {
const str = message.body.toString('utf8')
console.log('Received message from webview 1:', str)
})
webview1.evaluateScript(`setTimeout(() => {
window.ipc.postMessage('Hello from webview1')
}, 1000)`)
webview2.onIpcMessage((message) => {
const str = message.body.toString('utf8')
console.log('Received message from webview 2:', str)
})
webview2.evaluateScript(`setTimeout(() => {
window.ipc.postMessage('Hello from webview2')
}, 1000)`)
app.run()