首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电子和Asar封装应用程序

电子和Asar封装应用程序
EN

Stack Overflow用户
提问于 2016-01-28 12:53:39
回答 1查看 1.7K关注 0票数 2

我有一个奇怪的问题,我试图让网站离线工作(用适应力制作的电子学习课程),所以我创建了电子应用程序包装:

main.js创建BrowserWindow,然后加载index.html

代码语言:javascript
复制
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标记)

代码语言:javascript
复制
<!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();时,它再次工作,此时我正在使用这个解决方案:

代码语言:javascript
复制
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Close (almost) immediately
setTimeout(function (webContents) {
    webContents.closeDevTools();
}, 100, mainWindow.webContents);

但这是个丑陋的补丁,有人对此有什么看法吗?

EN

回答 1

Stack Overflow用户

发布于 2016-01-28 13:05:44

<script>的某个地方添加非空的head标记。

解释:

如果页面上没有脚本,Chrome认为页面上没有动态内容,没有创建脚本上下文,这禁止将electron核心脚本注入页面,以及负责webview标记处理的脚本(电子github上有关于此bug的问题报告,但电子开发人员表示,这是意图行为(在Chrome中),显然是not a bug, but a feature xD)。

下面是相关问题链接

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35062073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档