Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 46ebcab

Browse files
committed
Merge pull request #9623 from brave/issue-9620
close tab if the download is the initial navigation
1 parent f7f4df5 commit 46ebcab

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/filtering.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,19 @@ function updateDownloadState (downloadId, item, state) {
488488

489489
function registerForDownloadListener (session) {
490490
session.on('will-download', function (event, item, webContents) {
491-
const win = BrowserWindow.getFocusedWindow()
491+
if (webContents.isDestroyed()) {
492+
event.preventDefault()
493+
return
494+
}
495+
496+
const hostWebContents = webContents.hostWebContents || webContents
497+
const win = BrowserWindow.fromWebContents(hostWebContents) || BrowserWindow.getFocusedWindow()
498+
499+
// TODO(bridiver) - move this fix to muon
500+
const controller = webContents.controller()
501+
if (controller && controller.isValid() && controller.isInitialNavigation()) {
502+
webContents.forceClose()
503+
}
492504

493505
// special handling for data URLs where another 'will-download' event handler is trying to suggest a filename via item.setSavePath
494506
// see the IPC handler for RENDER_URL_TO_PDF in app/index.js for example

0 commit comments

Comments
 (0)