在我的電子應用程序中,我從遠程URL(「http://xxxx/index.html」)加載遠程頁面(index.html),然後我試圖發送一個ipc事件到主進程然後處理它,並失敗,但如果我把index.html放在本地fs中,這是可以的。如何從電子遠程頁面訪問節點api?
所以我的問題是如何使頁面從遠程頁面訪問節點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,也無法訪問遠程頁面中的節點。這將是非常危險的。 –