mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: don't re-parse URL unnecessarily when handling dialogs (#50062)
* fix: fallback to opaque URL when needed inside dialog callback * refactor: remove additional URL parsing entirely when showing dialogs * test: add crash test case for URL-less dialogs * refactor: exit on events instead of on timeout for dialog crash test Co-authored-by: Robo <hop2deep@gmail.com> * style: make linter happy * style: make linter actually happy * fix: address failing `safeDialogs` tests --------- Co-authored-by: Robo <hop2deep@gmail.com>
This commit is contained in:
@@ -782,8 +782,7 @@ WebContents.prototype._init = function () {
|
||||
const originCounts = new Map<string, number>();
|
||||
const openDialogs = new Set<AbortController>();
|
||||
this.on('-run-dialog', async (info, callback) => {
|
||||
const originUrl = new URL(info.frame.url);
|
||||
const origin = originUrl.protocol === 'file:' ? originUrl.href : originUrl.origin;
|
||||
const origin = info.frame.origin === 'file://' ? info.frame.url : info.frame.origin;
|
||||
if ((originCounts.get(origin) ?? 0) < 0) return callback(false, '');
|
||||
|
||||
const prefs = this.getLastWebPreferences();
|
||||
|
||||
7
spec/fixtures/crash-cases/dialog-on-invalid-url/index.html
vendored
Normal file
7
spec/fixtures/crash-cases/dialog-on-invalid-url/index.html
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<script>
|
||||
window.open('javascript:alert()');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
22
spec/fixtures/crash-cases/dialog-on-invalid-url/index.js
vendored
Normal file
22
spec/fixtures/crash-cases/dialog-on-invalid-url/index.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
const { app, BrowserWindow } = require('electron');
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
console.error(reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
window.webContents.once('did-frame-navigate', () => {
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const win = new BrowserWindow({ show: false });
|
||||
win.loadFile('index.html');
|
||||
});
|
||||
Reference in New Issue
Block a user