-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
76 lines (70 loc) · 2.24 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const electron = require("electron");
const webContents=require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const BrowserView=electron.BrowserView;
const {session} = require('electron');
const path = require('path')
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.allowRendererProcessReuse = true;
// create the browser window.
function createWindow() {
browserWindow = new BrowserWindow({
width:1300,
height:800,
//fullscreen:true,
center:true,
backgroundColor: "#fff",
});
//browserWindow.loadURL("https://google.com");
let browserView1 = new BrowserView({webPreferences: {
nodeIntegration:true,
webviewTag:true,
}});
let browserView2 = new BrowserView({webPreferences: {
nodeIntegration:true,
webviewTag:true,
}});
browserWindow.addBrowserView(browserView1);
browserWindow.addBrowserView(browserView2);
browserView1.setBounds({ x: 0, y: 30, width: 650, height: 600 });
browserView2.setBounds({ x: 650, y: 30, width: 650, height: 600});
browserView1.webContents.loadFile('index.html');
browserView2.webContents.loadFile('index.html');
}
app.on('ready', createWindow);
//security measures applied.
//1.Handling session permission request from Remote Content.
app.on('ready',()=>{
session
.fromPartition('some-partition')
.setPermissionRequestHandler((webContents, permission, callback) => {
const url = webContents.getURL()
if (permission === 'notifications') {
// Approves the permissions request
callback(true)
}
// Verify URL
if (!url.startsWith('https://google.com/')) {
// Denies the permissions request
return callback(false)
}
})
})
//2.limit the navigation
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
const parsedUrl = new URL(navigationUrl)
if (parsedUrl.origin !== 'https://google.com') {
event.preventDefault()
}
})
})
// Quit when all windows are closed.
app.on("window-all-closed", () => {
data = {
bounds: browserWindow.getBounds()
};
app.quit();
});