Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new render-process-gone event #24309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion docs/api/web-contents.md
Expand Up @@ -325,7 +325,7 @@ win.webContents.on('will-prevent-unload', (event) => {
})
```

#### Event: 'crashed'
#### Event: 'crashed' _Deprecated_

Returns:

Expand All @@ -334,6 +334,29 @@ Returns:

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.

#### Event: 'unresponsive'

Emitted when the web page becomes unresponsive.
Expand Down
1 change: 1 addition & 0 deletions lib/browser/guest-view-manager.js
Expand Up @@ -32,6 +32,7 @@ const supportedWebViewEvents = [
'focus-change',
'close',
'crashed',
'render-process-gone',
'plugin-crashed',
'destroyed',
'page-title-updated',
Expand Down
5 changes: 5 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -991,6 +991,11 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {

void WebContents::RenderProcessGone(base::TerminationStatus status) {
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
v8::HandleScope handle_scope(isolate());
gin_helper::Dictionary details =
gin_helper::Dictionary::CreateEmpty(isolate());
details.Set("reason", status);
Emit("render-process-gone", details);
}

void WebContents::PluginCrashed(const base::FilePath& plugin_path,
Expand Down
36 changes: 36 additions & 0 deletions shell/browser/api/electron_api_web_contents.h
Expand Up @@ -60,6 +60,42 @@ namespace network {
class ResourceRequestBody;
}

namespace gin {

template <>
struct Converter<base::TerminationStatus> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::TerminationStatus& status) {
switch (status) {
case base::TERMINATION_STATUS_NORMAL_TERMINATION:
return gin::ConvertToV8(isolate, "clean-exit");
case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
return gin::ConvertToV8(isolate, "abnormal-exit");
case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
return gin::ConvertToV8(isolate, "killed");
case base::TERMINATION_STATUS_PROCESS_CRASHED:
return gin::ConvertToV8(isolate, "crashed");
case base::TERMINATION_STATUS_STILL_RUNNING:
return gin::ConvertToV8(isolate, "still-running");
case base::TERMINATION_STATUS_LAUNCH_FAILED:
return gin::ConvertToV8(isolate, "launch-failed");
case base::TERMINATION_STATUS_OOM:
return gin::ConvertToV8(isolate, "oom");
#if defined(OS_WIN)
case base::TERMINATION_STATUS_INTEGRITY_FAILURE:
return gin::ConvertToV8(isolate, "integrity-failure");
#endif
case base::TERMINATION_STATUS_MAX_ENUM:
NOTREACHED();
return gin::ConvertToV8(isolate, "");
}
NOTREACHED();
return gin::ConvertToV8(isolate, "");
}
};

} // namespace gin

namespace electron {

class ElectronBrowserContext;
Expand Down