I have this weird problem, I'm trying to make the website work offline (elearning course made with Adapt), so I've created the Electron App wrapper:
main.js
creates the BrowserWindow
which then loads 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;
});
}
the launcher of the course (that hosts the webview tag)
<!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>
and the problem starts when I've turned off the developer tools panel, once done the course is no longer loaded, when I uncomment mainWindow.webContents.openDevTools();
then it works again, at the moment I'm using this workaround:
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Close (almost) immediately
setTimeout(function (webContents) {
webContents.closeDevTools();
}, 100, mainWindow.webContents);
and it works but it is an ugly patch, any thoughts on that anyone?
Add non-empty
<script>
tag somewhere inhead
.Explanation:
If there is no scripts on page,
Chrome
thinks page has no dynamic content on it and doesn't creates scripting context, which prohibits fromelectron
core scripts to be injected into page, and that scripts responsible aboutwebview
tag handling (there is issue reports about this bug on electron github repo, but developers of electron stated, that that is intended behaviour (in Chrome core), apparently,not a bug, but a feature
xD).Here's related issue link.