From bb8ebf7282cbe0ad3028d52b5d9f2a57a2312861 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 26 Oct 2022 20:58:17 +0000 Subject: [PATCH] fix: resolve loadURL properly for in-page navigations Co-authored-by: Jeremy Rose --- lib/browser/api/web-contents.ts | 2 ++ spec-main/api-web-contents-spec.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/browser/api/web-contents.ts b/lib/browser/api/web-contents.ts index aac868f6f4126..4055b68f8738a 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -449,12 +449,14 @@ WebContents.prototype.loadURL = function (url, options) { const removeListeners = () => { this.removeListener('did-finish-load', finishListener); this.removeListener('did-fail-load', failListener); + this.removeListener('did-navigate-in-page', finishListener); this.removeListener('did-start-navigation', navigationListener); this.removeListener('did-stop-loading', stopLoadingListener); this.removeListener('destroyed', stopLoadingListener); }; this.on('did-finish-load', finishListener); this.on('did-fail-load', failListener); + this.on('did-navigate-in-page', finishListener); this.on('did-start-navigation', navigationListener); this.on('did-stop-loading', stopLoadingListener); this.on('destroyed', stopLoadingListener); diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index f19fc67d49c70..3b9abab3b7852 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -362,6 +362,12 @@ describe('webContents module', () => { await expect(w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html'))).to.eventually.be.fulfilled(); }); + it('resolves when navigating within the page', async () => { + await w.loadFile(path.join(fixturesPath, 'pages', 'base-page.html')); + await new Promise(resolve => setTimeout(resolve)); + await expect(w.loadURL(w.getURL() + '#foo')).to.eventually.be.fulfilled(); + }); + it('rejects when failing to load a file URL', async () => { await expect(w.loadURL('file:non-existent')).to.eventually.be.rejected() .and.have.property('code', 'ERR_FILE_NOT_FOUND');