Skip to content

Commit 13e4407

Browse files
trop[bot]nmggithub
andauthored
fix: don't re-parse URL unnecessarily when handling dialogs (#50400)
* fix: fallback to opaque URL when needed inside dialog callback Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * refactor: remove additional URL parsing entirely when showing dialogs Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * test: add crash test case for URL-less dialogs Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * refactor: exit on events instead of on timeout for dialog crash test Co-authored-by: Robo <hop2deep@gmail.com> Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * style: make linter happy Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * style: make linter actually happy Co-authored-by: Noah Gregory <noahmgregory@gmail.com> * fix: address failing `safeDialogs` tests Co-authored-by: Noah Gregory <noahmgregory@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Noah Gregory <noahmgregory@gmail.com>
1 parent 16a0385 commit 13e4407

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

lib/browser/api/web-contents.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,7 @@ WebContents.prototype._init = function () {
777777
const originCounts = new Map<string, number>();
778778
const openDialogs = new Set<AbortController>();
779779
this.on('-run-dialog', async (info, callback) => {
780-
const originUrl = new URL(info.frame.url);
781-
const origin = originUrl.protocol === 'file:' ? originUrl.href : originUrl.origin;
780+
const origin = info.frame.origin === 'file://' ? info.frame.url : info.frame.origin;
782781
if ((originCounts.get(origin) ?? 0) < 0) return callback(false, '');
783782

784783
const prefs = this.getLastWebPreferences();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<body>
3+
<script>
4+
window.open('javascript:alert()');
5+
</script>
6+
</body>
7+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { app, BrowserWindow } = require('electron');
2+
3+
process.on('uncaughtException', (err) => {
4+
console.error(err);
5+
process.exit(1);
6+
});
7+
8+
process.on('unhandledRejection', (reason) => {
9+
console.error(reason);
10+
process.exit(1);
11+
});
12+
13+
app.on('browser-window-created', (_, window) => {
14+
window.webContents.once('did-frame-navigate', () => {
15+
process.exit(0);
16+
});
17+
});
18+
19+
app.whenReady().then(() => {
20+
const win = new BrowserWindow({ show: false });
21+
win.loadFile('index.html');
22+
});

0 commit comments

Comments
 (0)