最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Electron exits without emiting render-process-gone event - Stack Overflow

programmeradmin1浏览0评论

When I press a button on a certain website loaded in a BrowserView, the electron app exits. It's obviously a crash, but it doesn't emit the render-process-gone neither on the BrowserWindow (renderer) or the BrowserView. It just quits. But window-all-closed is emited

app.on('ready', () => {
  app.on('render-process-gone', (e, webContents, details) => {
    console.log('render-process-gone', details);
  });

  const win = new BrowserWindow({
    frame: false,    
    webPreferences: {
      worldSafeExecuteJavaScript: true,
      nodeIntegration: true,
      webviewTag: false,
      enableRemoteModule: false,
    }
  });

  win.loadURL('file://' + __dirname + '/renderer.html');

  const view = new BrowserView({
    webPreferences: {
      preload: 'preload.js'
      worldSafeExecuteJavaScript: true,
      nodeIntegration: false,
      nodeIntegrationInSubFrames: true,
      enableRemoteModule: false,
    }
  });

  view.webContents.loadURL('');

  view.webContents.on('render-process-gone', (e, details) => {
    console.log('render-process-gone', details);
  });

  win.setBrowserView(view);  

});

app.on('window-all-closed', () => {
  console.log('exiting...');
  app.quit();
});

Is there a way to find out what could be causing this?


update: I added sandbox: true to the webPreferences and now it doesn't crash anymore!

When I press a button on a certain website loaded in a BrowserView, the electron app exits. It's obviously a crash, but it doesn't emit the render-process-gone neither on the BrowserWindow (renderer) or the BrowserView. It just quits. But window-all-closed is emited

app.on('ready', () => {
  app.on('render-process-gone', (e, webContents, details) => {
    console.log('render-process-gone', details);
  });

  const win = new BrowserWindow({
    frame: false,    
    webPreferences: {
      worldSafeExecuteJavaScript: true,
      nodeIntegration: true,
      webviewTag: false,
      enableRemoteModule: false,
    }
  });

  win.loadURL('file://' + __dirname + '/renderer.html');

  const view = new BrowserView({
    webPreferences: {
      preload: 'preload.js'
      worldSafeExecuteJavaScript: true,
      nodeIntegration: false,
      nodeIntegrationInSubFrames: true,
      enableRemoteModule: false,
    }
  });

  view.webContents.loadURL('http://website.');

  view.webContents.on('render-process-gone', (e, details) => {
    console.log('render-process-gone', details);
  });

  win.setBrowserView(view);  

});

app.on('window-all-closed', () => {
  console.log('exiting...');
  app.quit();
});

Is there a way to find out what could be causing this?


update: I added sandbox: true to the webPreferences and now it doesn't crash anymore!

Share Improve this question edited Sep 16, 2020 at 5:12 Alex asked Sep 15, 2020 at 5:01 AlexAlex 66.2k185 gold badges460 silver badges651 bronze badges 6
  • 1 are you on electron 10? The event was added in 10 (release notes), though the docs will show the latest version's docs and will include it, so you may have found an example in the docs and used it though your Electron version doesn't support it – pushkin Commented Sep 15, 2020 at 17:19
  • Your electron version is? – tpikachu Commented Sep 21, 2020 at 16:40
  • And which os are you using? – tpikachu Commented Sep 21, 2020 at 16:44
  • it happens on both latest macos and windows 7 – Alex Commented Sep 22, 2020 at 10:27
  • So the below answer is showing that the render-process-gone event has been added instead of render-process-crashed – tpikachu Commented Sep 22, 2020 at 10:40
 |  Show 1 more ment

2 Answers 2

Reset to default 5 +500
Emitted when the renderer process crashes or is killed.

**Deprecated:** This event is superceded by the `render-process-gone` event
which contains more information about why the render process dissapeared. It
isn't always because it crashed.  The `killed` boolean can be replaced by
checking `reason === 'killed'` when you switch to that event.

#### Event: 'render-process-gone'

Returns:

* `event` Event
* `details` Object
  * `reason` String - The reason the render process is gone.  Possible values:
    * `clean-exit` - Process exited with an exit code of zero
    * `abnormal-exit` - Process exited with a non-zero exit code
    * `killed` - Process was sent a SIGTERM or otherwise killed externally
    * `crashed` - Process crashed
    * `oom` - Process ran out of memory
    * `launch-failure` - Process never successfully launched
    * `integrity-failure` - Windows code integrity checks failed

Emitted when the renderer process unexpectedly dissapears.  This is normally
because it was crashed or killed.
  • Added new render-process-gone event on app to replace the renderer-process-crashed event. #23560
  • Added new render-process-gone event to replace the crashed event. #23096

REF: https://github./electron/electron/pull/23096

https://github./electron/electron/pull/23560

I was having the same error, even the reason for 'Renderer-Process-Gone' was ing undefined. Just did npm install electron@latest and sandbox = true.

The error was not being caught by mainWindow.webContents.on() rather by app.on()

发布评论

评论列表(0)

  1. 暂无评论