Skip to content

Commit cdc7a29

Browse files
chore: Add WebContentsView API example (#1668)
1 parent dbdfa73 commit cdc7a29

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/templates.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const SHOW_ME_TEMPLATES: Templates = {
2929
Tray: 'Tray',
3030
utilityProcess: 'utilityProcess',
3131
WebContents: 'WebContents',
32+
WebContentsView: 'WebContentsView',
3233
WebFrame: 'WebFrame',
3334
},
3435
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A View that displays a WebContents.
2+
//
3+
// For more info, see:
4+
// https://electronjs.org/docs/api/web-contents-view
5+
6+
// In the main process.
7+
const { app, BaseWindow, WebContentsView } = require('electron')
8+
9+
app.whenReady().then(() => {
10+
const win = new BaseWindow({ width: 800, height: 400 })
11+
12+
const view1 = new WebContentsView()
13+
win.contentView.addChildView(view1)
14+
view1.setBounds({ x: 0, y: 0, width: 400, height: 400 })
15+
view1.webContents.loadURL('https://www.electronjs.org')
16+
17+
const view2 = new WebContentsView()
18+
win.contentView.addChildView(view2)
19+
view2.setBounds({ x: 400, y: 0, width: 400, height: 400 })
20+
view2.webContents.loadURL('https://www.electronjs.org/fiddle')
21+
})

0 commit comments

Comments
 (0)