【发布时间】:2016-01-17 08:24:07
【问题描述】:
在我的电子应用程序中,我从远程 url 加载远程页面(index.html),例如(“http://xxxx/index.html”),然后我尝试向主进程发送一个 ipc 事件然后处理它,但失败了,但是如果我将 index.html 放在本地 fs 中,就可以了。
所以我的问题是如何使页面能够从远程页面访问节点 api(如 require、ipc 等)。
-----(主进程)
mainWindow = new BrowserWindow({width: 800, height: 600});
// and load the index.html of the app.
mainWindow.loadUrl('http://localhost:8080');
//mainWindow.loadUrl('file://' + __dirname + '/index.html');
var ipc = require('ipc');
ipc.on('spawn-ext-process', function () {
console.log("spawn-ext-process");
});
--------- http://localhost:8080/index.html(渲染进程)
<script>
var ipc = require('ipc');
ipc.send('spawn-ext-process');
</script>
【问题讨论】:
-
即使使用 Electron,您也无法访问远程页面中的节点。那将是非常危险的。