Skip to content

Commit

Permalink
fix: make sure invalid URL loads promises are fulfilled. (#41194)
Browse files Browse the repository at this point in the history
* fix: make sure invalid URL loads promisses are fulfilled.

* fixup! fix: make sure invalid URL loads promisses are fulfilled.
  • Loading branch information
marekharanczyk committed Feb 5, 2024
1 parent dac29f9 commit 398ca2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/browser/api/web-contents.ts
Expand Up @@ -366,11 +366,6 @@ WebContents.prototype.loadURL = function (url, options) {
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 browserInitiatedInPageNavigation = false;
Expand All @@ -392,6 +387,14 @@ WebContents.prototype.loadURL = function (url, options) {
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 = () => {
// By the time we get here, either 'finish' or 'fail' should have fired
// if the navigation occurred. However, in some situations (e.g. when
Expand Down
4 changes: 4 additions & 0 deletions spec/api-web-contents-spec.ts
Expand Up @@ -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();
});

it('invalid URL load rejects', async () => {
await expect(w.loadURL('invalidURL')).to.eventually.be.rejected();
});
});

describe('getFocusedWebContents() API', () => {
Expand Down

0 comments on commit 398ca2a

Please sign in to comment.