我有一个奇怪的问题,我试图让网站离线工作(用适应力制作的电子学习课程),所以我创建了电子应用程序包装:
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>当我关闭developer面板时,问题就开始了,一旦完成了这个过程就不再加载,当我取消注释mainWindow.webContents.openDevTools();时,它再次工作,此时我正在使用这个解决方案:
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Close (almost) immediately
setTimeout(function (webContents) {
webContents.closeDevTools();
}, 100, mainWindow.webContents);但这是个丑陋的补丁,有人对此有什么看法吗?
发布于 2016-01-28 13:05:44
在<script>的某个地方添加非空的head标记。
解释:
如果页面上没有脚本,Chrome认为页面上没有动态内容,没有创建脚本上下文,这禁止将electron核心脚本注入页面,以及负责webview标记处理的脚本(电子github上有关于此bug的问题报告,但电子开发人员表示,这是意图行为(在Chrome中),显然是not a bug, but a feature xD)。
下面是相关问题链接。
https://stackoverflow.com/questions/35062073
复制相似问题