Guys i need to open some web application into my electron app, i used <webview>
tag but [official docs][1] of electron offers to use BrowserView
.
so i used BrowserView
, BUT i got DevTools was disconnected from the page error!
simply i need DevTools for my BrowserView
not my entire app. what should i do?
myCode: just main.js
JavaScript
x
20
20
1
const {app, BrowserView, BrowserWindow} = require('electron');
2
3
let win;
4
let view;
5
app.on('ready', () => {
6
win = new BrowserWindow({width: 800, height: 600});
7
win.on('closed', () => {
8
win = null
9
});
10
view = new BrowserView({
11
webPreferences: {
12
nodeIntegration: false
13
}
14
});
15
win.setBrowserView(view);
16
view.setBounds({x: 0, y: 0, width: 800, height: 600});
17
view.webContents.loadURL('https://example.com');
18
win.openDevTools();
19
});
20
Advertisement
Answer
openDevTools
is basically a function of webContents
(when used on BrowserWindow
it’s only redirected)
So you can open devtools of main window with
JavaScript
1
2
1
win.webContents.openDevTools()
2
And for the BrowserView
with
JavaScript
1
2
1
view.webContents.openDevTools()
2