mirror of
https://github.com/electron/electron.git
synced 2026-01-08 15:13:52 -05:00
fix: make sure invalid URL loads promises are fulfilled. (#41194)
* fix: make sure invalid URL loads promisses are fulfilled. * fixup! fix: make sure invalid URL loads promisses are fulfilled.
This commit is contained in:
@@ -366,11 +366,6 @@ WebContents.prototype.loadURL = function (url, options) {
|
|||||||
resolveAndCleanup();
|
resolveAndCleanup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
|
|
||||||
if (!error && isMainFrame) {
|
|
||||||
error = { errorCode, errorDescription, url: validatedURL };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let navigationStarted = false;
|
let navigationStarted = false;
|
||||||
let browserInitiatedInPageNavigation = false;
|
let browserInitiatedInPageNavigation = false;
|
||||||
@@ -392,6 +387,14 @@ WebContents.prototype.loadURL = function (url, options) {
|
|||||||
navigationStarted = true;
|
navigationStarted = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const failListener = (event: Electron.Event, errorCode: number, errorDescription: string, validatedURL: string, isMainFrame: boolean) => {
|
||||||
|
if (!error && isMainFrame) {
|
||||||
|
error = { errorCode, errorDescription, url: validatedURL };
|
||||||
|
}
|
||||||
|
if (!navigationStarted && isMainFrame) {
|
||||||
|
finishListener();
|
||||||
|
}
|
||||||
|
};
|
||||||
const stopLoadingListener = () => {
|
const stopLoadingListener = () => {
|
||||||
// By the time we get here, either 'finish' or 'fail' should have fired
|
// By the time we get here, either 'finish' or 'fail' should have fired
|
||||||
// if the navigation occurred. However, in some situations (e.g. when
|
// if the navigation occurred. However, in some situations (e.g. when
|
||||||
|
|||||||
@@ -519,6 +519,10 @@ describe('webContents module', () => {
|
|||||||
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
|
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
|
||||||
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
|
await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('invalid URL load rejects', async () => {
|
||||||
|
await expect(w.loadURL('invalidURL')).to.eventually.be.rejected();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFocusedWebContents() API', () => {
|
describe('getFocusedWebContents() API', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user