最近在调研electron,在写demo的时候,发现一使用了BrowserView就会报错:开发者工具就会报:DevTools was disconnected from the page,Once page is reloaded,DevTools will automatically reconnect.具体提示信息如图:
代码,就是案例代码,还没有添加什么逻辑:
const { app, BrowserWindow, BrowserView } = require("electron");
const path = require("path");
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600
});
const view = new BrowserView();
win.setBrowserView(view);
view.setBounds({
x:0,
y: 0,
width: 800,
height: 600
});
view.webContents.loadFile(path.join(app.getAppPath(), "./test/index.html"));
win.webContents.openDevTools({
mode: "right"
});
}
app.whenReady().then(() => {
createWindow();
})
只要使用了Browserview就会报错,直接使用BrowserWindow加载页面就没有问题。
好像还没有很好的解决方案