Last active
June 15, 2016 00:52
-
-
Save rosshinkley/bfd73776fa9b3b30b7ea758780471d07 to your computer and use it in GitHub Desktop.
Electron load fail on `session.on('will-download')`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('electron').app; | |
var BrowserWindow = require('electron').BrowserWindow; | |
app.on('ready', function() { | |
console.log('ready!'); | |
win = new BrowserWindow({}); | |
win.webContents.on('did-fail-load', (event, code, detail, failedUrl, isMainFrame) => { | |
console.log(`fail: ${code} ${detail} ${failedUrl}`); | |
}); | |
win.webContents.on('did-finish-load', () => { | |
console.log('did-finish-load'); | |
}); | |
win.webContents.on('did-get-response-details', (event, status, newUrl, oldUrl, statusCode, method, referrer, headers, resourceType) => { | |
console.log(`did-get-response-details ${statusCode}`); | |
}); | |
win.webContents.on('did-get-redirect-request', (event, oldUrl, newUrl, isMainFrame, httpResponseCode, requestMethod, referrer, headers) => { | |
console.log(`did-get-redirect-request ${oldUrl} ${newUrl} ${httpResponseCode}`); | |
}); | |
win.webContents.session.on('will-download', (event, downloadItem, webContents) => { | |
downloadItem.setSavePath(require('path').join(__dirname, downloadItem.getFilename())); | |
downloadItem.on('done', (event, state) => { | |
console.log(`${downloadItem.getFilename()} done with state ${state}`); | |
app.exit(0); | |
}); | |
console.log(`will-download ${downloadItem.getFilename()}`); | |
}); | |
console.log('loading url'); | |
win.webContents.loadURL('https://codeload.github.com/electron/electron/zip/master'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment