久久久久久久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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 亚洲国产成人精品女人久久久 | 亚洲欧美综合网 | 日本高清视频在线播放 | 亚洲精品久久久久久久不卡四虎 | avmans最新导航地址 | 久久久久国产一区二区三区不卡 | 视频一区二区在线观看 | 9191av| 亚洲激情网站 | av在线一区二区三区 | 亚洲精彩视频在线观看 | 国产精品成人av | 久草视频在线播放 | 国产精品视频免费播放 | 久久久久中文字幕 | 国产日韩一区二区三区 | 午夜免费网站 | 久久精品国产免费看久久精品 | 日韩第一页 | 国产精品呻吟久久av凹凸 | 啪视频在线| 偷拍自拍第一页 | 久久精品国产99国产精品 | 男女羞羞免费网站 | 国产伦一区二区三区四区 | 国产综合精品一区二区三区 | 国产成人福利视频在线观看 | 国产精品一区二区久久久久 | 久久99这里只有精品 | 日韩在线一区二区三区 | 一区二区精品 | 欧美久久一级特黄毛片 | 天天插天天操 | 日韩一区精品 | 99精品国产一区二区三区 | 久久成人国产精品 | 日韩久久久久久 | 亚洲欧美日本在线 | 毛片一区 | 中文字幕视频在线观看 | 美女黄网|