【发布时间】:2016-05-05 20:43:00
【问题描述】:
我有一个奇怪的问题,我正在尝试使网站离线工作(使用 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);
它有效,但它是一个丑陋的补丁,有人对此有什么想法吗?
【问题讨论】:
标签: javascript webview electron asar adapt