我有这个奇怪的问题,我试图让网站离线工作(使用 Adapt 制作的电子学习课程),所以我创建了 Electron App 包装器:
main.js
创建BrowserWindow
然后加载index.html
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
"min-width": 800,
"min-height": 530,
resize: true,
"use-content-size": true
});
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Set Window Resizable
mainWindow.isResizable(true);
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
课程的启动器(承载 webview 标签)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body {
margin: 0;
padding: 0;
background-color: #6e6e6e;
width: 100vw;
height: 100vh;
}
webview {
display: block;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<webview src="build/scorm_test_harness.html" disablewebsecurity></webview>
</body>
</html>
当我关闭开发人员工具面板时,问题就开始了,一旦完成,课程将不再加载,当我取消注释时mainWindow.webContents.openDevTools();
,它会再次起作用,目前我正在使用这种解决方法:
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Close (almost) immediately
setTimeout(function (webContents) {
webContents.closeDevTools();
}, 100, mainWindow.webContents);
它有效,但它是一个丑陋的补丁,有人对此有什么想法吗?