【问题标题】:Packaging app With Electron and Asar使用 Electron 和 Asar 打包应用程序
【发布时间】: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


    【解决方案1】:

    head的某处添加非空&lt;script&gt;标签。


    说明:

    如果页面上没有脚本,Chrome 认为页面上没有动态内容并且不创建脚本上下文,这将禁止将electron 核心脚本注入页面,并且该脚本负责 @ 987654326@ 标签处理(在电子 github 存储库上有关于此错误的问题报告,但电子开发人员表示,这是预期的行为(在 Chrome 核心中),显然,not a bug, but a feature xD)。


    这里是相关问题link

    【讨论】:

    • 你能详细说明一下,在哪里以及为什么?
    • 正在添加解释 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 2017-08-31
    • 2019-10-17
    • 2016-07-29
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多