久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否可以在電子主進程中捕獲渲染器進程的異常

Is it possible to catch exceptions of renderer processes in electrons main process?(是否可以在電子主進程中捕獲渲染器進程的異常?)
本文介紹了是否可以在電子主進程中捕獲渲染器進程的異常?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 Electrons 快速入門項目(提交 dbef48ee7d072a38724ecfa57601e39d36e9714e)來測試異常.

I'm using Electrons Quick Start Projekt (Commit dbef48ee7d072a38724ecfa57601e39d36e9714e) to test exceptions.

index.html 中,我將所需模塊的名稱從 renderer.js 更改為 rendererXXX.js.

In index.html I changed the name of the required module from renderer.js to rendererXXX.js.

require('./renderer.js')

這會導致預期的異常(在該窗口的開發工具中可見):

which results in an expected Exeption (it is visible in the devtools for that window):

Uncaught Error: Cannot find module './rendererXXX.js'

現在,如果主進程(參見 main.js)知道一個渲染器進程失敗,那就太好了.因此,我將窗口的實例化包裝到 try-catch-block 中

Now it would be nice if the main-process (see main.js) is aware that one renderer process failed. Thus I wrapped the instatiation of the window into a try-catch-block

try {
  app.on('ready', createWindow)
} catch (e) {
  console.log("Exception caught: " + e.message);
} finally {
  // nothing yet
}

但我意識到,異常沒有轉發到主進程.那么處理渲染器進程異常的典型方法是什么 - 有沒有辦法從主進程處理它們?

But I realized, that the Exception is not forwarded to the main-process. So what are typical ways to handle exceptions of renderer processes - is there a way to handle them from the main-process?

我還將加載 index.html 的行包裹到 try-catch 中,但我仍然無法處理錯誤:

I also wrapped the line that loads the index.html into try-catch, but still I can't handle the error:

  try {
    // and load the index.html of the app.
    mainWindow.loadURL(`file://${__dirname}/index.html`)
  } catch (e) {
    console.log("Exception caught in 'createWindow': " + e.message);
  }

推薦答案

電子窗口在自己的進程中渲染.因此,主進程和渲染進程之間幾乎沒有通信.您能做的最好的事情就是在渲染過程中捕獲錯誤并使用 Electrons IPC 模塊將它們傳遞回您的主進程.

Electron windows are rendered in their own process. Because of this there is little if any communication between main process and render processes. The best you can do is catch errors in the render process and use Electrons IPC module to pass them back to your main process.

在你的渲染過程中:

var ipc = require('electron').ipcRenderer;
window.onerror = function(error, url, line) {
    ipc.send('errorInWindow', error);
};

在你的主進程中:

var ipc = require('electron').ipcMain;

ipc.on('errorInWindow', function(event, data){
    console.log(data)
});

此外,您的主進程可以直接在窗口(或窗口 webContents)上觀察一組有限的事件:

Additionally your main process can watch for a limited set of events directly on the window (or on the windows webContents):

window.on('unresponsive', function() {
    console.log('window crashed');
});

...

window.webContents.on('did-fail-load', function() {
    console.log('window failed load');
});

這篇關于是否可以在電子主進程中捕獲渲染器進程的異常?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 精品国产91亚洲一区二区三区www | 久久99精品久久久久婷婷 | 亚洲激情网站 | 欧美xxxx黑人又粗又长 | 精品九九 | 精品国产乱码久久久久久中文 | 久久精品二区亚洲w码 | 日本视频一区二区三区 | 麻豆天堂 | 欧美精品二区 | 91久久久久 | 久久com| 久久r精品 | 欧美日韩亚洲在线 | 国产精品一二区 | 色频 | 精品国产色 | 久久精品免费观看 | 91精品久久久久久久久 | 狠狠干狠狠操 | 精品中文字幕一区二区三区 | 国产一区不卡 | 成人在线视频一区二区三区 | av色站 | 天天影视网天天综合色在线播放 | 动漫www.被爆羞羞av44 | 午夜精品久久久久久久久久久久久 | 精品国产网 | 国产色婷婷精品综合在线手机播放 | 亚洲一区二区精品视频在线观看 | 精品三区 | 伦理午夜电影免费观看 | 午夜日韩 | 91爱爱·com | xxxxx黄色片| 亚洲成人高清 | 在线免费中文字幕 | 国产一区欧美一区 | 久草新在线 | 国产精品久久久久久久久久东京 | 亚洲成年人免费网站 |