Merge pull request #8724 from electron/defer_load_url

webContents: defer url load when there is a pending navigation entry
This commit is contained in:
Kevin Sawicki 2017-03-06 10:18:36 -08:00 committed by GitHub
commit 886b47e713
4 changed files with 129 additions and 16 deletions

View file

@ -229,6 +229,11 @@ describe('BrowserWindow module', function () {
w.loadURL(`data:image/png;base64,${data}`)
})
it('should not crash when there is a pending navigation entry', function (done) {
ipcRenderer.once('navigated-with-pending-entry', () => done())
ipcRenderer.send('navigate-with-pending-entry', w.id)
})
describe('POST navigations', function () {
afterEach(() => {
w.webContents.session.webRequest.onBeforeSendHeaders(null)

View file

@ -304,6 +304,24 @@ ipcMain.on('handle-unhandled-rejection', (event, message) => {
})
})
ipcMain.on('navigate-with-pending-entry', (event, id) => {
const w = BrowserWindow.fromId(id)
w.webContents.on('did-start-loading', () => {
w.loadURL('about:blank')
})
w.webContents.on('did-navigate', (e, url) => {
if (url === 'about:blank') {
event.sender.send('navigated-with-pending-entry')
}
})
w.webContents.session.clearHostResolverCache(() => {
w.loadURL('http://host')
})
})
// Suspend listeners until the next event and then restore them
const suspendListeners = (emitter, eventName, callback) => {
const listeners = emitter.listeners(eventName)