From 49421c2e62d20098420e4264db467a306002e650 Mon Sep 17 00:00:00 2001 From: Santhosh mani Date: Wed, 18 Dec 2024 14:24:15 +0530 Subject: [PATCH] chore: Add WebContentsView API example --- src/templates.ts | 1 + static/show-me/webcontentsview/main.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 static/show-me/webcontentsview/main.js diff --git a/src/templates.ts b/src/templates.ts index fa322c386b..1cb57f016d 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -29,6 +29,7 @@ export const SHOW_ME_TEMPLATES: Templates = { Tray: 'Tray', utilityProcess: 'utilityProcess', WebContents: 'WebContents', + WebContentsView: 'WebContentsView', WebFrame: 'WebFrame', }, }; diff --git a/static/show-me/webcontentsview/main.js b/static/show-me/webcontentsview/main.js new file mode 100644 index 0000000000..d7baaf5d25 --- /dev/null +++ b/static/show-me/webcontentsview/main.js @@ -0,0 +1,21 @@ +// A View that displays a WebContents. +// +// For more info, see: +// https://electronjs.org/docs/api/web-contents-view + +// In the main process. +const { app, BaseWindow, WebContentsView } = require('electron') + +app.whenReady().then(() => { + const win = new BaseWindow({ width: 800, height: 400 }) + + const view1 = new WebContentsView() + win.contentView.addChildView(view1) + view1.setBounds({ x: 0, y: 0, width: 400, height: 400 }) + view1.webContents.loadURL('https://www.electronjs.org') + + const view2 = new WebContentsView() + win.contentView.addChildView(view2) + view2.setBounds({ x: 400, y: 0, width: 400, height: 400 }) + view2.webContents.loadURL('https://www.electronjs.org/fiddle') +})