Skip to content

Commit 34da3bc

Browse files
feat: add new render-process-gone event (electron#23096)
1 parent 7f9b7b2 commit 34da3bc

4 files changed

Lines changed: 66 additions & 1 deletion

File tree

docs/api/web-contents.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ win.webContents.on('will-prevent-unload', (event) => {
338338
})
339339
```
340340

341-
#### Event: 'crashed'
341+
#### Event: 'crashed' _Deprecated_
342342

343343
Returns:
344344

@@ -347,6 +347,29 @@ Returns:
347347

348348
Emitted when the renderer process crashes or is killed.
349349

350+
**Deprecated:** This event is superceded by the `render-process-gone` event
351+
which contains more information about why the render process dissapeared. It
352+
isn't always because it crashed. The `killed` boolean can be replaced by
353+
checking `reason === 'killed'` when you switch to that event.
354+
355+
#### Event: 'render-process-gone'
356+
357+
Returns:
358+
359+
* `event` Event
360+
* `details` Object
361+
* `reason` String - The reason the render process is gone. Possible values:
362+
* `clean-exit` - Process exited with an exit code of zero
363+
* `abnormal-exit` - Process exited with a non-zero exit code
364+
* `killed` - Process was sent a SIGTERM or otherwise killed externally
365+
* `crashed` - Process crashed
366+
* `oom` - Process ran out of memory
367+
* `launch-failure` - Process never successfully launched
368+
* `integrity-failure` - Windows code integrity checks failed
369+
370+
Emitted when the renderer process unexpectedly dissapears. This is normally
371+
because it was crashed or killed.
372+
350373
#### Event: 'unresponsive'
351374

352375
Emitted when the web page becomes unresponsive.

lib/browser/guest-view-manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const supportedWebViewEvents = [
3232
'focus-change',
3333
'close',
3434
'crashed',
35+
'render-process-gone',
3536
'plugin-crashed',
3637
'destroyed',
3738
'page-title-updated',

shell/browser/api/electron_api_web_contents.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,11 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
997997

998998
void WebContents::RenderProcessGone(base::TerminationStatus status) {
999999
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
1000+
v8::HandleScope handle_scope(isolate());
1001+
gin_helper::Dictionary details =
1002+
gin_helper::Dictionary::CreateEmpty(isolate());
1003+
details.Set("reason", status);
1004+
Emit("render-process-gone", details);
10001005
}
10011006

10021007
void WebContents::PluginCrashed(const base::FilePath& plugin_path,

shell/browser/api/electron_api_web_contents.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,42 @@ namespace network {
6060
class ResourceRequestBody;
6161
}
6262

63+
namespace gin {
64+
65+
template <>
66+
struct Converter<base::TerminationStatus> {
67+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
68+
const base::TerminationStatus& status) {
69+
switch (status) {
70+
case base::TERMINATION_STATUS_NORMAL_TERMINATION:
71+
return gin::ConvertToV8(isolate, "clean-exit");
72+
case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
73+
return gin::ConvertToV8(isolate, "abnormal-exit");
74+
case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
75+
return gin::ConvertToV8(isolate, "killed");
76+
case base::TERMINATION_STATUS_PROCESS_CRASHED:
77+
return gin::ConvertToV8(isolate, "crashed");
78+
case base::TERMINATION_STATUS_STILL_RUNNING:
79+
return gin::ConvertToV8(isolate, "still-running");
80+
case base::TERMINATION_STATUS_LAUNCH_FAILED:
81+
return gin::ConvertToV8(isolate, "launch-failed");
82+
case base::TERMINATION_STATUS_OOM:
83+
return gin::ConvertToV8(isolate, "oom");
84+
#if defined(OS_WIN)
85+
case base::TERMINATION_STATUS_INTEGRITY_FAILURE:
86+
return gin::ConvertToV8(isolate, "integrity-failure");
87+
#endif
88+
case base::TERMINATION_STATUS_MAX_ENUM:
89+
NOTREACHED();
90+
return gin::ConvertToV8(isolate, "");
91+
}
92+
NOTREACHED();
93+
return gin::ConvertToV8(isolate, "");
94+
}
95+
};
96+
97+
} // namespace gin
98+
6399
namespace electron {
64100

65101
class ElectronBrowserContext;

0 commit comments

Comments
 (0)