fix: crash when setWindowOpenHandler callback throws (#34523)

* fix: crash when setWindowOpenHandler throws

* refactor: throw as process uncaughtException event
This commit is contained in:
Shelley Vohr 2022-06-14 18:22:23 +02:00 committed by GitHub
parent 8de5cdb426
commit bed38e0985
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 8 deletions

View file

@ -482,6 +482,7 @@ WebContents.prototype._callWindowOpenHandler = function (event: Electron.Event,
if (!this._windowOpenHandler) {
return defaultResponse;
}
const response = this._windowOpenHandler(details);
if (typeof response !== 'object') {
@ -644,7 +645,15 @@ WebContents.prototype._init = function () {
postBody,
disposition
};
const result = this._callWindowOpenHandler(event, details);
let result;
try {
result = this._callWindowOpenHandler(event, details);
} catch (err) {
event.preventDefault();
throw err;
}
const options = result.browserWindowConstructorOptions;
if (!event.defaultPrevented) {
openGuestWindow({
@ -675,7 +684,15 @@ WebContents.prototype._init = function () {
referrer,
postBody
};
const result = this._callWindowOpenHandler(event, details);
let result;
try {
result = this._callWindowOpenHandler(event, details);
} catch (err) {
event.preventDefault();
throw err;
}
windowOpenOutlivesOpenerOption = result.outlivesOpener;
windowOpenOverriddenOptions = result.browserWindowConstructorOptions;
if (!event.defaultPrevented) {