diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index f6eb816f86e..6dfb8592736 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -3708,7 +3708,11 @@ gin::Handle WebContents::New( const gin_helper::Dictionary& options) { gin::Handle handle = gin::CreateHandle(isolate, new WebContents(isolate, options)); + v8::TryCatch try_catch(isolate); gin_helper::CallMethod(isolate, handle.get(), "_init"); + if (try_catch.HasCaught()) { + node::errors::TriggerUncaughtException(isolate, try_catch); + } return handle; } @@ -3719,7 +3723,11 @@ gin::Handle WebContents::CreateAndTake( Type type) { gin::Handle handle = gin::CreateHandle( isolate, new WebContents(isolate, std::move(web_contents), type)); + v8::TryCatch try_catch(isolate); gin_helper::CallMethod(isolate, handle.get(), "_init"); + if (try_catch.HasCaught()) { + node::errors::TriggerUncaughtException(isolate, try_catch); + } return handle; } @@ -3739,7 +3747,11 @@ gin::Handle WebContents::FromOrCreate( WebContents* api_web_contents = From(web_contents); if (!api_web_contents) { api_web_contents = new WebContents(isolate, web_contents); + v8::TryCatch try_catch(isolate); gin_helper::CallMethod(isolate, api_web_contents, "_init"); + if (try_catch.HasCaught()) { + node::errors::TriggerUncaughtException(isolate, try_catch); + } } return gin::CreateHandle(isolate, api_web_contents); } diff --git a/shell/common/node_includes.h b/shell/common/node_includes.h index a2ff95669ef..05b655f893c 100644 --- a/shell/common/node_includes.h +++ b/shell/common/node_includes.h @@ -64,6 +64,7 @@ #include "env.h" #include "node.h" #include "node_buffer.h" +#include "node_errors.h" #include "node_internals.h" #include "node_options-inl.h" #include "node_options.h" diff --git a/spec-main/fixtures/crash-cases/webview-contents-error-on-creation/index.js b/spec-main/fixtures/crash-cases/webview-contents-error-on-creation/index.js new file mode 100644 index 00000000000..cbfc7eb98b4 --- /dev/null +++ b/spec-main/fixtures/crash-cases/webview-contents-error-on-creation/index.js @@ -0,0 +1,14 @@ +const { app, BrowserWindow } = require('electron'); + +app.whenReady().then(() => { + const mainWindow = new BrowserWindow({ + show: false + }); + mainWindow.loadFile('about:blank'); + + app.on('web-contents-created', () => { + throw new Error(); + }); + + app.quit(); +});