iwmlib/lib/electron.html

48 lines
1.6 KiB
HTML
Raw Permalink Normal View History

2019-03-21 09:57:27 +01:00
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Electron Node.js Test</title>
2019-05-22 16:03:19 +02:00
<link rel="stylesheet" href="./3rdparty/highlight/styles/default.css">
2019-03-21 09:57:27 +01:00
<link rel="stylesheet" href="../css/doctest.css">
2019-05-22 16:03:19 +02:00
<script src="./3rdparty/highlight/highlight.pack.js"></script>
<script src="./3rdparty/all.js"></script>
<script src="../dist/iwmlib.js"></script>
2019-03-21 09:57:27 +01:00
</head>
<body onload="Doctest.run()">
<main>
<h1>
Electron Node.js Test
</h1>
<p>
This doctest is expected to work only within the IWMBrowser. IWMBrowser windows
are opened with a preload.js which is evaluated before the HTML is loaded.
According to
<a href="https://electron.atom.io/docs/faq/">"I can not use jQuery/RequireJS/Meteor/AngularJS in Electron"</a> we
have to rename the symbols in the page before other libraries are included.
In order to access node.js modules we can use `nodeRequire` instead.
</p>
<p>As a simple test we try to load a file from the filesystem:</p>
<script class="doctest">
if (typeof(nodeRequire) != 'undefined') {
let fs = nodeRequire('fs')
let content = fs.readFileSync('./index.html')
let lines = content.toString().split(/\n/)
console.log("First line", lines[0] )
Doctest.expect(lines[0], '<html>')
}
</script>
<p>As simple as this test is, it shows that within the IWMBrowser one import all node.js
modules. Don't forget to test for nodeRequire to avoid runtime errors in other browsers.
</p>
<h2>
References
</h2>
<ul>
<li><a href="https://electron.atom.io/docs/faq/">I can not use jQuery/RequireJS/Meteor/AngularJS in Electron</a></li>
</ul>
</main>
</body>